package cn.estsh.i3plus.ext.mes.pcn.apiservice.controller.busi;

import cn.estsh.i3plus.ext.mes.pcn.api.busi.IMesEmergencyLocationService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MesEmergencyLocationModel;
import cn.estsh.impp.framework.boot.exception.ImppBusiException;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description :应急件库位管理
 * @Reference :
 * @Author : junsheng.li
 * @CreateDate 2024/10/17 16:16
 * @Modify:
 **/
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/emergencyLocation")
public class MesEmergencyLocationController {

    @Autowired
    private IMesEmergencyLocationService mesEmergencyLocationService;

    @GetMapping("/query")
    @ApiOperation(value = "查询绑定信息")
    public ResultBean findMesRecyclablePackageBindingDetail(String organizeCode, String workCenterCode) {

        try {
            ValidatorBean.checkNotNull(workCenterCode, "产线代码不能为空");
            ValidatorBean.checkNotNull(organizeCode, "工厂代码不能为空");
            return ResultBean.success("查询成功").setResultList(mesEmergencyLocationService.findMesEmergencyLocationList(organizeCode, workCenterCode));
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }


    @PostMapping("/doAction")
    @ApiOperation(value = "操作")
    public ResultBean doAction(@RequestBody MesEmergencyLocationModel model) {

        try {
            ValidatorBean.checkNotNull(model.getWorkCenterCode(), "产线代码不能为空");
            ValidatorBean.checkNotNull(model.getOrganizeCode(), "工厂代码不能为空");
            ValidatorBean.checkNotNull(model.getType(), "操作类型不能为空");
            ValidatorBean.checkNotNull(model.getUserName(), "操作人不能为空");
            mesEmergencyLocationService.doAction(model);
            return ResultBean.success("操作成功");
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
