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

import cn.estsh.i3plus.ext.mes.api.busi.bu.ISxStandardWorkReportFormService;
import cn.estsh.i3plus.ext.mes.pojo.model.bu.SxStandardWorkReportModel;
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.i3plus.pojo.mes.bean.MesShift;
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 SxStandardWorkReportFormController extends MesBaseController {

    @Autowired
    private ISxStandardWorkReportFormService reportFormService;

    @GetMapping(value = "/query-single-shift")
    @ApiOperation(value = "仅班次信息")
    public ResultBean querySingleShiftList() {
        try {
            return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultMap(reportFormService.querySingleShiftList(AuthUtil.getOrganize().getOrganizeCode()));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/standard-work/query")
    @ApiOperation(value = "机种别工数报表")
    public ResultBean queryStandardWorkReportForm(SxStandardWorkReportModel model) {
        try {
            ValidatorBean.beginValid(model)
                    .notNull(MesExtConstWords.DIMENSION, model.getDimension())
                    .notNull(MesExtConstWords.DIMENSION_1, model.getDimension1())
                    .notNull(MesExtConstWords.WORK_TIME_START, model.getWorkTimeStart())
                    .notNull(MesExtConstWords.WORK_TIME_END, model.getWorkTimeEnd());
            model.setOrganizeCode(AuthUtil.getOrganize().getOrganizeCode());
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(reportFormService.queryStandardWorkReportForm(model));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }


}
