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

import cn.estsh.i3plus.ext.mes.api.busi.ISxProductDataReportFormService;
import cn.estsh.i3plus.ext.mes.pojo.model.SxProductDataReportParamModel;
import cn.estsh.i3plus.ext.mes.pojo.model.SxProductDataReportResultModel;
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 SxProductDataReportFormController extends MesBaseController {

    @Autowired
    private ISxProductDataReportFormService productDataReportFormService;

    @GetMapping(value = "/product-data/query")
    @ApiOperation(value = "生产数据报表")
    public ResultBean queryProductDataReport(SxProductDataReportParamModel model, Pager pager) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.WORK_CENTER_CODE, model.getWorkCenterCode())
                    .notNull(MesExtConstWords.WORK_CELL_CODE, model.getWorkCellCode())
                    .notNull(MesExtConstWords.CREATE_DATE_TIME_START, model.getCreateDatetimeStart())
                    .notNull(MesExtConstWords.CREATE_DATE_TIME_END, model.getCreateDatetimeEnd());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            SxProductDataReportResultModel result = productDataReportFormService.queryProductDataReport(model, pager);
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultObject(result.getAttributeModelList()).setListPager(result.getListPager());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
