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

import cn.estsh.i3plus.ext.mes.pcn.api.base.IMesWorkCellExtendCfgService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.constant.MesCommonConstant;
import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkCellExtendCfg;
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.*;

import java.util.List;

/**
 * @Description: 主子工位关系
 * @Author: gsz
 * @Date: 2024/6/17 15:16
 * @Modify:
 */
@RestController
@RequestMapping(MesCommonConstant.MES_YANFEN + "/mesWorkCellExtendCfg")
public class MesWorkCellExtendCfgController {
    @Autowired
    private IMesWorkCellExtendCfgService mesWorkCellExtendCfgService;

    @GetMapping("/query-pager")
    @ApiOperation(value = "分页查询主子工位关系")
    public ResultBean queryMesProdShiftRecordByPager(MesWorkCellExtendCfg workCellExtendCfg, Pager pager) {
        try {

            ListPager<MesWorkCellExtendCfg> mesWorkCellExtendCfgByPager = mesWorkCellExtendCfgService.queryMesWorkCellExtendCfgByPager(workCellExtendCfg, pager);
            return ResultBean.success("查询主子工位关系成功").setListPager(mesWorkCellExtendCfgByPager);
        } catch (ImppBusiException imppException) {
            return ResultBean.fail(imppException);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query")
    @ApiOperation(value = "查询主子工位关系")
    public ResultBean queryMesProdShiftRecord(MesWorkCellExtendCfg mesWorkCellExtendCfg) {
        try {
            // 数据校验
            ValidatorBean.checkNotNull(mesWorkCellExtendCfg.getAreaCode(), "区域不能为空");
            ValidatorBean.checkNotNull(mesWorkCellExtendCfg.getWorkCenterCode(), "产线不能为空");
            ValidatorBean.checkNotNull(mesWorkCellExtendCfg.getWorkCellCode(), "工位不能为空");
            //查询汇总工单数量
            List<MesWorkCellExtendCfg> mesWorkCellExtendCfgList= mesWorkCellExtendCfgService.queryMesWorkCellExtendCfg(mesWorkCellExtendCfg);
            return ResultBean.success("查询成功")
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()).setResultList(mesWorkCellExtendCfgList);
        } catch (ImppBusiException e) {
            return ResultBean.fail(e).build();
        } catch (Exception e) {
            return ResultBean.fail(e);
        }
    }

}
