package com.ruoyi.web.v2.v1.controller;


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsProduceRecall;
import com.ruoyi.web.v2.v1.service.IJsProduceRecallService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * <p>
 * v2.0产品召回 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-05-26
 */
@RestController
@RequestMapping("/js-produce-recall")
@Api("2.0产品召回")
public class JsProduceRecallController {

    @Autowired
    private IJsProduceRecallService recallService;

    @ApiOperation("产品召回添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsProduceRecall produceRecall) {
        return recallService.add(produceRecall);
    }

    @ApiOperation("产品召回修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsProduceRecall produceRecall) {
        return recallService.edit(produceRecall);
    }

    @ApiOperation("产品召回删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return recallService.delete(ids);
    }

    @ApiOperation("产品召回列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return recallService.listAll();
    }

    @ApiOperation("产品召回分页")
    @GetMapping("/page")
    public AjaxResult page(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize
            , @RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "produceName", required = false) String produceName
            , @RequestParam(value = "animalType", required = false) String animalType
    ) {
        return recallService.page(pageNum, pageSize, startTime, endTime,produceName,animalType);
    }

    @ApiOperation("产品召回详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(recallService.getById(id));
    }

}
