package com.ruoyi.mill.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.mill.domain.MillPlan;
import com.ruoyi.mill.service.IMillPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mill/plan")
public class MillPlanController extends BaseController {

    @Autowired
    private IMillPlanService millPlanService;

    @PreAuthorize("@ss.hasPermi('mill:plan:list')")
    @GetMapping("/list")
    public TableDataInfo list(MillPlan query) {
        startPage();
        List<MillPlan> list = millPlanService.selectMillPlanList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('mill:plan:query')")
    @GetMapping("/{planNo}")
    public AjaxResult getInfo(@PathVariable String planNo) {
        return AjaxResult.success(millPlanService.selectMillPlanByPlanNo(planNo));
    }

    @PreAuthorize("@ss.hasPermi('mill:plan:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MillPlan plan) {
        return toAjax(millPlanService.insertMillPlan(plan));
    }

    @PreAuthorize("@ss.hasPermi('mill:plan:edit')")
    @PutMapping
    public AjaxResult edit(@RequestBody MillPlan plan) {
        return toAjax(millPlanService.updateMillPlan(plan));
    }

    @PreAuthorize("@ss.hasPermi('mill:plan:cancel')")
    @PutMapping("/cancel/{planNo}/{matSeqNo}")
    public AjaxResult cancel(@PathVariable String planNo, @PathVariable String matSeqNo) {
        return toAjax(millPlanService.cancelMillPlan(planNo, matSeqNo));
    }
}
