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

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxWorkCenterNotReachReasonService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesWorkCenterNotReachReason;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.boot.auth.AuthUtil;
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.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-dev
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-07-26 17:46
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES + "/ext/work-center-not-reach-reason")
@Api(tags = "产线未达成原因 控制层")
public class SxWorkCenterNotReachReasonController {

    @Autowired
    private ISxWorkCenterNotReachReasonService sxWorkCenterNotReachReasonService;

    @GetMapping(value = "/query")
    @ApiOperation(value = "分页查询 产线未达成原因")
    public ResultBean queryWorkCenterNotReachReasonByPager(MesWorkCenterNotReachReason notReachReason, Pager pager) {
        try {
            ValidatorBean.checkNotNull(notReachReason.getWorkTime(), "作业日期不能为空");
            notReachReason.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(sxWorkCenterNotReachReasonService.querySxWorkCenterNotReachReasonByPager(notReachReason, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/save")
    @ApiOperation(value = "保存产线未达成原因")
    public ResultBean doSaveWorkCenterNotReachReason(@RequestBody MesWorkCenterNotReachReason notReachReason) {
        try {
            ValidatorBean.checkNotNull(notReachReason.getWorkTime(), "作业日期不能为空");
            notReachReason.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            sxWorkCenterNotReachReasonService.doSaveSxWorkCenterNotReachReason(notReachReason);
            return ResultBean.success("修改成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
