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


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsDistribution;
import com.ruoyi.web.v2.v1.model.JsProduceCode;
import com.ruoyi.web.v2.v1.service.IJsDistributionService;
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-distribution")
@Api("2.0分销登记")
public class JsDistributionController {

    @Autowired
    private IJsDistributionService distributionService;

    @ApiOperation("分销登记添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsDistribution distribution) {
        return distributionService.add(distribution);
    }

    @ApiOperation("分销登记修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsDistribution distribution) {
        return distributionService.edit(distribution);
    }

    @ApiOperation("分销登记删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return distributionService.delete(ids);
    }

    @ApiOperation("分销登记列表")
    @PostMapping("/list")
    public AjaxResult listAll() {
        return distributionService.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 = "supplierName", required = false) String supplierName
            , @RequestParam(value = "purchaserName", required = false) String purchaserName
            , @RequestParam(value = "animalCertNo", required = false) String animalCertNo) {

        return distributionService.page(pageNum, pageSize, startTime, endTime, supplierName, purchaserName, animalCertNo);
    }

    @ApiOperation("分销登记详情")
    @PostMapping("/listById")
    public AjaxResult listById(@RequestBody Map<String, String> paramsMap) {
        String id = paramsMap.get("id");
        return success(distributionService.getById(id));
    }

    @ApiOperation("屠宰生产清单")
    @Anonymous
    @GetMapping("/productionPage")
    public AjaxResult productionPage(@RequestParam("pageNum") Integer pageNum,
                                     @RequestParam("pageSize") Integer pageSize
            ,@RequestParam(value = "startTime", required = false) String startTime
            , @RequestParam(value = "endTime", required = false) String endTime
            , @RequestParam(value = "animalCertNo", required = false) String animalCertNo) {
        return success(distributionService.productionPage(pageNum, pageSize, startTime, endTime, animalCertNo));
    }

    @ApiOperation("合格证修改")
    @PostMapping("/editProduce")
    public AjaxResult editProduce(@RequestBody JsProduceCode jsProduceCode) {
        return distributionService.editProduce(jsProduceCode);
    }


}
