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

import cn.estsh.i3plus.ext.mes.pcn.api.busi.bu.IBuQmsHttpRequestService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MissPartConfirmModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.bu.BuOutPutStatisticsModel;
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.List;
import java.util.Map;

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

    @Autowired
    private IBuQmsHttpRequestService httpRequestService;

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

    @PostMapping("/oqc-project-check/miss-part-info")
    @ApiOperation(value = "Qms 调取缺件信息")
    public ResultBean queryMissingPart(@RequestBody Map<String, Object> params) {
        try {
            MissPartConfirmModel missPartConfirm = httpRequestService.getMissingPartAndWorkOrderBySn(params);
            return ResultBean.success("查询成功").setResultObject(missPartConfirm)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping("/oqc-project-check/out-put-statistics/query")
    @ApiOperation(value = "Qms 出货检验根据产线代码、物料号、工单号、班次 调取MES出货检验数据")
    public ResultBean queryOutPutStatisticsList(@RequestBody Map<String, Object> params) {
        try {
            List<BuOutPutStatisticsModel> outPutStatisticsModels = httpRequestService.queryOutPutStatisticsList(params);
            return ResultBean.success("查询成功").setResultList(outPutStatisticsModels)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/part-category/query-list")
    @ApiOperation(value = "BU-QMS获取物料分类数据")
    public ResultBean queryPartCategoryList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(httpRequestService.queryPartCategoryList(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping("/oqc-last-check-detail/out-put-statistics-qty/query")
    @ApiOperation(value = "BU产量统计班次完工数量")
    public ResultBean queryOutPutStatisticsQtyList(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(httpRequestService.queryOutPutStatisticsQtyList(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 = "BU-QMS获取生产工单分页数据(默认以修改时间倒序排序)")
    public ResultBean queryEpQmsWindowWorkOrderExtListPage(@RequestBody Map<String, Object> params) {
        try {
            return ResultBean.success("查询成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(httpRequestService.queryBuQmsWindowWorkOrderExtListPage(params));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
