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

import cn.estsh.i3plus.ext.mes.api.busi.bu3.ISxCloudApiBusiService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu3.SxProdDataToStatisticsOutPutParamModel;
import cn.estsh.i3plus.ext.mes.pojo.util.MesExtConstWords;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesBaseController;
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.*;

/**
 * @author yebu
 * @description 微服接口业务控制层
 * @date 2023/7/20 18:02
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES+"/cloud-api-busi")
@Api(tags = "微服接口业务控制层")
public class SxCloudApiBusiController extends MesBaseController {

    @Autowired
    private ISxCloudApiBusiService sxCloudApiBusiService;

    @PostMapping(value = "/prod-data-to-monthly-statistics/query")
    @ApiOperation(value = "生产数据月度统计查询")
    public ResultBean queryProdDataToMonthlyStatistics(@RequestBody SxProdDataToStatisticsOutPutParamModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.ORGANIZE_CODE, model.getOrganizeCode())
                    .notNull(MesExtConstWords.DATA_KEY, model.getDataKey())
                    .notNull(MesExtConstWords.STATISTICS_DATE, model.getStatisticsDate());
            return ResultBean.success("操作成功").setResultList(sxCloudApiBusiService.queryProdDataToMonthlyStatistics(model)).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/normal-prod-and-unnormal-prod-record/query")
    @ApiOperation(value = "常规生产停开机记录和非常规生产停开机查询")
    public ResultBean queryNormalProdAndUnnormalProdShiftProdCenterRecord(@RequestParam("workTimeStart") String workTimeStart, @RequestParam("workTimeEnd") String workTimeEnd, @RequestParam(value = "workCenterCode", required = false) String workCenterCode, @RequestParam("organizeCode") String organizeCode) {
        try {
            return ResultBean.success("操作成功").setResultList(sxCloudApiBusiService.queryNormalProdAndUnnormalProdShiftProdCenterRecord(workTimeStart, workTimeEnd, workCenterCode, organizeCode)).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
