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

import cn.estsh.i3plus.ext.mes.api.base.IMesAccidentDateService;
import cn.estsh.i3plus.ext.mes.api.base.IMesNumberOfSafeOperationDaysService;
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.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 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 xiangming.liao
 * @date 2021年07月01日 15:33
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES+"/operation-days-board")
@Api(tags = "看板-安全运行天数")
public class MesNumberOfSafeOperationDaysBoardController extends MesBaseController {
    @Autowired
    private IMesNumberOfSafeOperationDaysService numberOfSafeOperationDaysService;
    @Autowired
    private IMesAccidentDateService accidentDateService;

    @GetMapping(value = "safe-days/query")
    @ApiOperation(value = "EP查询初始安全运行天数")
    public ResultBean queryNumberOfSafeOperationDaysBoard() {
        try {
            return ResultBean.success("查询成功").setResultObject(numberOfSafeOperationDaysService.queryNumberOfSafeOperationDaysBoard(AuthUtil.getOrganize().getOrganizeCode()))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/bu/safe-days/query")
    @ApiOperation(value = "BU查询初始安全运行天数")
    public ResultBean queryBuNumberOfSafeOperationDaysBoard() {
        try {
            return ResultBean.success("查询成功").setResultObject(numberOfSafeOperationDaysService.queryBuNumberOfSafeOperationDaysBoard(AuthUtil.getOrganize().getOrganizeCode()))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * @Description: 查询事故日期分页
     * @Param []
     * @return cn.estsh.impp.framework.boot.util.ResultBean
     * @Date 2021/7/1 15:47
     **/
    @GetMapping(value = "/accident-days/query")
    @ApiOperation(value = "EP查询当年累计事故总数")
    public ResultBean queryAccidentDaysBoard() {
        try {
            return ResultBean.success("查询事故日期成功").setResultObject(accidentDateService.queryAccidentDaysBoard(AuthUtil.getOrganize().getOrganizeCode()))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    /**
     * @Description: 查询事故日期分页
     * @Param []
     * @return cn.estsh.impp.framework.boot.util.ResultBean
     * @Date 2021/7/1 15:47
     **/
    @GetMapping(value = "/bu/accident-days/query")
    @ApiOperation(value = "BU查询当年累计事故总数")
    public ResultBean queryBuAccidentDaysBoard() {
        try {
            return ResultBean.success("查询事故日期成功").setResultObject(accidentDateService.queryBuAccidentDaysBoard(AuthUtil.getOrganize().getOrganizeCode()))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
