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.MillProductionResult;
import com.ruoyi.mill.service.IMillProductionService;
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/production")
public class MillProductionController extends BaseController {

    @Autowired
    private IMillProductionService productionService;

    @PreAuthorize("@ss.hasPermi('mill:production:list')")
    @GetMapping("/list")
    public TableDataInfo list(MillProductionResult query) {
        startPage();
        List<MillProductionResult> list = productionService.selectResultList(query);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('mill:production:query')")
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id) {
        return AjaxResult.success(productionService.selectResultById(id));
    }

    /** 录入产出结果并自动通过 UDP 上报 K12F03 */
    @PreAuthorize("@ss.hasPermi('mill:production:add')")
    @PostMapping
    public AjaxResult add(@RequestBody MillProductionResult result) {
        return toAjax(productionService.saveAndReport(result));
    }

    /** 删除计划钢卷并发送 K12F02 */
    @PreAuthorize("@ss.hasPermi('mill:production:delete')")
    @DeleteMapping("/coil")
    public AjaxResult deleteCoil(@RequestParam String planNo,
                                  @RequestParam Integer seqNo,
                                  @RequestParam String unitCode,
                                  @RequestParam String inMatNo,
                                  @RequestParam String causeDesc) {
        return toAjax(productionService.deleteCoilAndNotify(planNo, seqNo, unitCode, inMatNo, causeDesc));
    }
}
