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

import cn.estsh.i3plus.ext.mes.api.busi.IProcedureOnSiteService;
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: Dominic
 * @CreateDate: 2022-05-26 16:33:33
 * @Description:
 **/
@RestController
@Api(tags = "过程巡检作业微服")
@RequestMapping(CommonConstWords.BASE_URL_MES + "/procedure")
public class ProcedureOnSiteController extends MesBaseController {

    @Autowired
    private IProcedureOnSiteService procedureOnSiteService;

    @ApiOperation("查询区域")
    @GetMapping("/find-area")
    public ResultBean findArea(String organizeCode) {
        try {
            return ResultBean.success("查询成功")
                    .setResultList(procedureOnSiteService.findArea(organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation("查询产线")
    @GetMapping("/find-work-center")
    public ResultBean findWorkCenter(String organizeCode, String areaCode) {
        try {
            return ResultBean.success("查询成功")
                    .setResultList(procedureOnSiteService.findWorkCenter(organizeCode, areaCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation("获取启动状态的工单信息")
    @GetMapping("/find-work-order/by-status")
    public ResultBean findWorkOrderByStatus(String organizeCode, String workCenterCode) {
        try {
            return ResultBean.success("查询成功")
                    .setResultList(procedureOnSiteService.findWorkOrderByStatus(organizeCode, workCenterCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @ApiOperation("获取物料名称")
    @GetMapping("/get-part-name")
    public ResultBean getPartName(String organizeCode, String partNo) {
        try {
            return ResultBean.success("查询成功")
                    .setResultObject(procedureOnSiteService.getPartName(organizeCode, partNo))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/mes-defect/query")
    @ApiOperation("按条件分页查询MES不良信息资料数据")
    public ResultBean queryMesDefectByPager(String organizeCode) {
        try {
            return ResultBean.success("操作成功").setResultList(procedureOnSiteService.queryMesDefectByPager(organizeCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException var4) {
            return ResultBean.fail(var4);
        } catch (Exception var5) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(var5);
        }
    }

    @GetMapping(value = "/generate-serial-number")
    @ApiOperation("生成条码")
    public ResultBean generateSerialNumber(String organizeCode, String userName, String ruleCode) {
        try {
            return ResultBean.success("操作成功").setResultObject(procedureOnSiteService.generateSerialNumber(organizeCode, userName, ruleCode))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException var4) {
            return ResultBean.fail(var4);
        } catch (Exception var5) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(var5);
        }
    }
}
