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


import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.web.v2.v1.model.JsProducePlan;
import com.ruoyi.web.v2.v1.service.IJsProducePlanService;
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>
 * 生产计划登记 前端控制器
 * </p>
 *
 * @author coede
 * @since 2025-10-16
 */
@RestController
@RequestMapping("/js-producePlan")
@Api("生产计划登记")
public class JsProducePlanController {

    @Autowired
    private IJsProducePlanService producePlanService;

    @ApiOperation("生产计划登记添加")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody JsProducePlan producePlan){
        return producePlanService.add(producePlan);
    }

    @ApiOperation("生产计划登记修改")
    @PostMapping("/edit")
    public AjaxResult edit(@RequestBody JsProducePlan producePlan){
        return producePlanService.edit(producePlan);
    }

    @ApiOperation("生产计划登记删除")
    @PostMapping("/delete")
    public AjaxResult delete(@RequestBody Map<String, String> paramsMap) {
        String ids = paramsMap.get("ids");
        return producePlanService.delete(ids);
    }

    @ApiOperation("生产计划登记列表")
    @PostMapping("/list")
    public AjaxResult listAll(){
        return producePlanService.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 = "allowSlaughterNo", required = false) String allowSlaughterNo) {
        return producePlanService.page(pageNum, pageSize, startTime,endTime,allowSlaughterNo);
    }

    @ApiOperation("生产计划登记详情")
    @GetMapping("/listById")
    public AjaxResult listById(JsProducePlan req){
        return success(producePlanService.getDetail(req));
    }

    @ApiOperation("获取最新生产计划")
    @GetMapping("/lastPlan")
    public AjaxResult lastPlan(){
        return success(producePlanService.lastPlan());
    }
}
