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

import cn.estsh.i3plus.ext.mes.api.busi.IProjectBadRateService;
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 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年06月16日 10:12
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES)
@Api(tags = "工程不良率")
public class ProjectBadRateController extends MesBaseController {

    @Autowired
    private IProjectBadRateService projectBadRateService;

    @GetMapping(value = "/project-bad-rate/query")
    @ApiOperation(value = "工程不良率")
    public ResultBean queryProjectBadRate(String organizeCode) {
        try {

            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryProjectBadRate(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/ep/project-bad-rate/query")
    @ApiOperation(value = "EP工程不良率")
    public ResultBean queryEpProjectBadRate(String organizeCode) {
        try {

            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryEpProjectBadRate(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/month-or-project-bad-rate/query")
    @ApiOperation(value = "月度能率与工程不良率")
    public ResultBean queryProjectBadRate(String organizeCode,String workCenterCode) {
        try {

            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryProjectBadRateByMonth(workCenterCode,organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/board-produce-qty/query")
    @ApiOperation(value = "看板-产量")
    public ResultBean queryBoardProduceQty(String organizeCode) {
        try {

            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryBoardProduceQty(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/ep/board-produce-qty/query")
    @ApiOperation(value = "EP看板-产量")
    public ResultBean queryEpBoardProduceQty(String organizeCode) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryEpBoardProduceQty(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/board-work-center-data/query")
    @ApiOperation(value = "PMC-制造管理 返回相应产线的计划数量、生产数量、综合能率、生产达成率、标准生产达成率")
    public ResultBean queryBoardWorkCenterData(String organizeCode) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(projectBadRateService.queryBoardWorkCenterData(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
