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

import cn.estsh.i3plus.ext.mes.api.busi.ISxOqcReportFormService;
import cn.estsh.i3plus.ext.mes.pojo.model.ErrorOffLineDetailModel;
import cn.estsh.i3plus.ext.mes.pojo.model.ErrorOffLineModel;
import cn.estsh.i3plus.ext.mes.pojo.model.OqcReportParamModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
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.base.controller.MesBaseController;
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.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES + "/sx/report-form")
@Api(tags = "出货检验报表")
public class SxOqcReportFormController extends MesBaseController {

    @Autowired
    private ISxOqcReportFormService oqcReportFormService;

    @GetMapping(value = "/oqc-last-check-detail/query-pager")
    @ApiOperation(value = "分页查询出货总检明细报表")
    public ResultBean queryOqcLastCheckDetailPager(OqcReportParamModel model, Pager pager) {
        try {
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(oqcReportFormService.queryOqcLastCheckDetailPager(model, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/oqc-check-detail/query-pager")
    @ApiOperation(value = "分页查询检验单明细报表")
    public ResultBean queryOqcCheckDetailPager(OqcReportParamModel model, Pager pager) {
        try {
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(oqcReportFormService.queryOqcCheckDetailPager(model, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/oqc-check-project-detail/query-pager")
    @ApiOperation(value = "分页查询检验单项目明细报表")
    public ResultBean queryOqcCheckProjectDetailPager(OqcReportParamModel model, Pager pager) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.OQC_NO, model.getOqcNo());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(oqcReportFormService.queryOqcCheckProjectDetailPager(model, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/oqc-check-statistics/query")
    @ApiOperation(value = "出货检验月报日报")
    public ResultBean queryOqcCheckStatistics(OqcReportParamModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.DIMENSION, model.getDimension())
                    .notNull(MesExtConstWords.DIMENSION_1, model.getDimension1());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(oqcReportFormService.queryOqcCheckStatistics(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/error-line-off/fre-confirm/query")
    @ApiOperation(value = "出货检验补件确认")
    public ResultBean queryErrorLineOffFreConfirm(ErrorOffLineModel model, Pager pager) {
        try {
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(oqcReportFormService.queryErrorLineOffFreConfirm(model, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/error-line-off/fre-confirm-detail/query")
    @ApiOperation(value = "出货检验补件确认明细")
    public ResultBean queryErrorLineOffFreConfirmDetail(ErrorOffLineDetailModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.ID, model.getId())
                    .notNull(MesExtConstWords.PART_NO, model.getPartNo())
                    .notNull(MesExtConstWords.PART_NAME, model.getPartName());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(oqcReportFormService.queryErrorLineOffFreConfirmDetail(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
