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

import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxBadStatisticsReportFormService;
import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxBomPendingPartService;
import cn.estsh.i3plus.ext.mes.api.busi.jx.IJxProductReportService;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesBomPendingPart;
import cn.estsh.i3plus.ext.mes.pojo.bean.MesProdBindRecordExt;
import cn.estsh.i3plus.ext.mes.pojo.model.BadStatisticsReportParamModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
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.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;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic-jx
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2023-11-13 17:18
 */
@RestController
@RequestMapping(MesExtConstWords.BASE_URL_MES_JX + "/report")
@Api(tags = "嘉兴报表")
public class JxReportController extends MesBaseController {

    @Autowired
    private IJxProductReportService productReportService;

    @Autowired
    private IJxBadStatisticsReportFormService badStatisticsReportFormService;

    @Autowired
    private IJxBomPendingPartService bomPendingPartService;

    @GetMapping(value = "/mes-prod-bind-record/query")
    @ApiOperation(value = "按条件分页查询MES物料绑定记录数据")
    public ResultBean queryMesProdBindRecord(MesProdBindRecordExt prodBindRecordExt, Pager pager) {
        try {
            prodBindRecordExt.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            ListPager listPager = productReportService.queryMesProdBindRecordByPager(prodBindRecordExt, pager);
            return ResultBean.success("操作成功").setListPager(listPager)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/project-bad-performance/query")
    @ApiOperation(value = "工程不良实绩报表")
    public ResultBean queryProjectBadPerformance(BadStatisticsReportParamModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.DIMENSION, model.getDimension());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultObject(badStatisticsReportFormService.queryProjectBadPerformance(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/bom-pending-part/query")
    @ApiOperation(value = "待BOM生效成品报表")
    public ResultBean query(MesBomPendingPart bomPendingPart, Pager pager) {
        try {
            bomPendingPart.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(bomPendingPartService.queryBomPendingPartByPager(bomPendingPart, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
