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

import cn.estsh.i3plus.ext.mes.api.busi.ep.IEpQmsGetDataStatisticsService;
import cn.estsh.i3plus.ext.mes.pojo.model.ep.EpOutPutStatisticsModel;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
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.*;

/**
 * @PROJECT_NAME: i3plus-mes-panasonic
 * @DESCRIPTION:
 * @USER: xinwang.yi
 * @DATE: 2022-04-06 16:35
 */
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES+"/ep/data-statistics")
@Api(tags = "Qms 获取数据统计")
public class QmsGetDataStatisticsController {
    @Autowired
    private IEpQmsGetDataStatisticsService epMesOutPutStatisticsService;

    @GetMapping(value = "/output-statistics/query")
    @ApiOperation(value = "获取产量统计数据")
    public ResultBean queryMesOutPutStatisticsByTimeAndWorkOrderType(String organizeCode, String startTime, String endTime, Integer workOrderType) {
        try {
            return ResultBean.success("查询成功").setResultList(epMesOutPutStatisticsService.queryMesOutPutStatisticsByTimeAndWorkOrderType(organizeCode, startTime, endTime, workOrderType))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/repair-task/query")
    @ApiOperation(value = "获取返修数据")
    public ResultBean queryMesRepairTaskStatistics(String organizeCode, String startTime, String endTime) {
        try {
            return ResultBean.success("查询成功").setResultList(epMesOutPutStatisticsService.queryMesRepairTaskStatistics(organizeCode, startTime, endTime))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/output-statistics-is-oqc/query")
    @ApiOperation(value = "获取需要出货检验的产量统计数据")
    public ResultBean queryOutPutStatisticsByTimeAndIsOqc(String organizeCode, String startTime, String endTime, Integer workOrderType) {
        try {
            return ResultBean.success("查询成功").setResultList(epMesOutPutStatisticsService.queryOutPutStatisticsByTimeAndIsOqc(organizeCode, startTime, endTime, workOrderType))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/output-statistics-by-work-order-no/query")
    @ApiOperation(value = "获取产量统计数据")
    public ResultBean queryMesOutPutStatisticsByWorkOrderNo(@RequestBody EpOutPutStatisticsModel model) {
        try {
            return ResultBean.success("查询成功").setResultList(epMesOutPutStatisticsService.queryMesOutPutStatisticsByWorkOrderNoList(model))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }
}
