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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.ep.IEpQmsHttpRequestService;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.impp.framework.base.controller.MesPcnBaseController;
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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @Author: wangjie
 * @CreateDate: 2021/01/19 15:37
 * @Description:
 **/
@RestController
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/sx-ep-qms")
@Api(tags = "EP-QMS-出货检验-http请求调用控制层")
public class EpQmsHttpRequestController extends MesPcnBaseController {

    @Autowired
    private IEpQmsHttpRequestService qmsHttpRequestService;

    @PostMapping(value = "/oqc-manage-data/query")
    @ApiOperation(value = "EP-QMS获取出货检验数据")
    public ResultBean queryEpQmsOqcManageData(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultObject(qmsHttpRequestService.queryEpQmsOqcManageData(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/window/work-order/query-list-page")
    @ApiOperation(value = "EP-QMS获取生产工单分页数据")
    public ResultBean queryEpQmsWindowWorkOrderExtListPage(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(qmsHttpRequestService.queryEpQmsWindowWorkOrderExtListPage(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/select/shift/query-list")
    @ApiOperation(value = "EP-QMS获取班次信息数据")
    public ResultBean queryEpQmsSelectShiftList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsSelectShiftList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/window/shift/query-list")
    @ApiOperation(value = "EP-QMS获取班次信息数据")
    public ResultBean queryEpQmsShiftList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsShiftList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/window/defect/query-list")
    @ApiOperation(value = "EP-QMS获取缺陷信息数据")
    public ResultBean queryEpQmsDefectList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsDefectList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/window/happen-station/query-list-page")
    @ApiOperation(value = "EP-QMS获取发生岗位分页数据")
    public ResultBean queryEpQmsWindowHappenStationListPage(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(qmsHttpRequestService.queryEpQmsWindowHappenStationListPage(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/window/work-cell/query-list-page")
    @ApiOperation(value = "EP-QMS获取工位分页数据")
    public ResultBean queryEpQmsWindowWorkCellListPage(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(qmsHttpRequestService.queryEpQmsWindowWorkCellListPage(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/engineering-bad/classify-statistics/bad-cell-detail/query-list")
    @ApiOperation(value = "EP-QMS获取工位不良明细信息数据")
    public ResultBean queryEpQmsBadCellDetailList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsBadCellDetailList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/engineering-quality/bad-statistics/repair-task/query-list")
    @ApiOperation(value = "EP-QMS获取维修作业单信息数据")
    public ResultBean queryEpQmsRepairTaskList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsRepairTaskList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/engineering-quality/bad-statistics/out-put-statistics/query-list")
    @ApiOperation(value = "EP-QMS获取产量信息数据")
    public ResultBean queryEpQmsOutPutStatisticsList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(qmsHttpRequestService.queryEpQmsOutPutStatisticsList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
