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

import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxRepairWorkService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxSyncBusiService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IWorkCenterExtService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesBadCellDetail;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesProdBindRecordExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.MesRepairRecordExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.RepairRequestModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.pojo.base.common.Pager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.mes.bean.MesDefect;
import cn.estsh.i3plus.pojo.mes.bean.MesDefectCause;
import cn.estsh.i3plus.pojo.mes.bean.MesRepair;
import cn.estsh.i3plus.pojo.mes.model.DefectModel;
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.LocaleUtils;
import cn.estsh.impp.framework.boot.util.ResultBean;
import cn.estsh.impp.framework.boot.util.ValidatorBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.util.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: xiangming.liao
 * @CreateDate: 2021/02/26
 * @Description:
 **/
@RestController
@Api(tags = "返修作业")
@RequestMapping(CommonConstWords.BASE_URL_MES_PCN + "/module-repair-data")
public class SxRepairWorkController extends MesPcnBaseController {

    @Autowired
    private ISxRepairWorkService sxRepairWorkService;

    @Autowired
    private IWorkCenterExtService workCenterExtService;

    @Autowired
    private ISxSyncBusiService sxSyncBusiService;

    @GetMapping(value = "/query-producesn-frozen")
    @ApiOperation(value = "本体返修-提交-查询产品条码", notes = "本体返修-提交-查询产品条码")
    public ResultBean queryProducrsnFrozen(String serialNumber, String organizeCode) {
        try {
            if (StringUtils.isEmpty(serialNumber) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少产品条码[%s]组织代码[%s]", serialNumber, organizeCode)
                        .build();
            }
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultObject(sxRepairWorkService.getProduceSnFrozenBySn(serialNumber, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-defect-record")
    @ApiOperation(value = "本体返修-提交-查询不良明细", notes = "本体返修-提交-查询不良明细")
    public ResultBean queryMesDefectRecord(String serialNumber, String organizeCode) {
        try {
            if (StringUtils.isEmpty(serialNumber) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少产品条码[%s]组织代码[%s]", serialNumber, organizeCode)
                        .build();
            }
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(sxRepairWorkService.getMesBadCellDetailBySerialNumber(serialNumber, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-repair-record")
    @ApiOperation(value = "本体返修-提交-查询维修明细", notes = "本体返修-提交-查询维修明细")
    public ResultBean queryMesRepairRecord(String serialNumber, String organizeCode) {
        try {
            if (StringUtils.isEmpty(serialNumber) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少产品条码[%s]组织代码[%s]", serialNumber, organizeCode)
                        .build();
            }
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(sxRepairWorkService.getMesRepairRecordBySerialNumber(serialNumber, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-work-center")
    @ApiOperation(value = "组件返修-查询组件产线")
    public ResultBean queryWorkCenter(String organizeCode) {
        try {
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(sxRepairWorkService.queryWorkCenter(organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/work-order/by-center/query")
    @ApiOperation(value = "组件返修-选择生产线-加载工单信息", notes = "组件返修-选择生产线-加载工单信息")
    public ResultBean queryWorkOrderByCenter(String workCenterCode, String organizeCode) {
        try {
            if (StringUtils.isEmpty(workCenterCode) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少生产线代码[%s]组织代码[%s]", workCenterCode, organizeCode)
                        .build();
            }
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(sxRepairWorkService.queryWorkOrderByCenter(workCenterCode, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/defect-record/by-work-order-no/query")
    @ApiOperation(value = "组件返修-选择生产线-查询不良明细", notes = "组件返修-选择生产线-查询不良明细")
    public ResultBean queryMesDefectRecordByWorkOrderNo(String workOrderNo, String organizeCode) {
        try {
            if (StringUtils.isEmpty(workOrderNo) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少工单编码[%s]组织代码[%s]", workOrderNo, organizeCode)
                        .build();
            }
            return ResultBean.success(LocaleUtils.getLocaleRes("操作成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(sxRepairWorkService.getMesBadCellDetailByWorkOrderNo(workOrderNo, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-repair-by-order")
    @ApiOperation(value = "组件返修-选择生产线-查询维修明细")
    public ResultBean getMesRepairRecordByOrderNo(String workOrderNo, String organizeCode) {
        try {
            if (StringUtils.isEmpty(workOrderNo) || StringUtils.isEmpty(organizeCode)) {
                throw ImppExceptionBuilder.newInstance()
                        .setSystemID(CommonEnumUtil.SOFT_TYPE.MES_PCN.getCode())
                        .setErrorCode(ImppExceptionEnum.VARIFY_EXCEPTION.getCode())
                        .setErrorDetail("入参缺少工单编码[%s]组织代码[%s]", workOrderNo, organizeCode)
                        .build();
            }
            List<MesRepairRecordExt> mesRepairRecordList = sxRepairWorkService.getMesRepairRecordByOrderNo(workOrderNo, organizeCode);
            return ResultBean.success(LocaleUtils.getLocaleRes("操作成功")).setResultList(mesRepairRecordList)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-defect")
    @ApiOperation(value = "本体/组件返修-查询缺陷列表", notes = "本体/组件返修-查询缺陷列表")
    public ResultBean queryMesDefect(String organizeCode) {
        try {
            List<DefectModel> mesDefectList = sxRepairWorkService.getMesDefect(organizeCode);
            return ResultBean.success(LocaleUtils.getLocaleRes("操作成功")).setResultList(mesDefectList)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-defect-bycode-name")
    @ApiOperation(value = "本体/组件返修-选中缺陷列表数据", notes = "本体/组件返修-选中缺陷列表数据")
    public ResultBean queryMesDefectByCodeAndName(String defectCode, String defectName, String organizeCode) {
        try {
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultObject(sxRepairWorkService.getMesDefect(defectCode, defectName, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-cells-by-center")
    @ApiOperation(value = "本体/组件返修-不良明细-新增/一步操作-根据生产线查询工位集合", notes = "本体/组件返修-不良明细-新增/一步操作-根据生产线查询工位集合")
    public ResultBean queryCellsByCenter(String workCenterCode, String organizeCode) {
        try {
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setResultList(workCenterExtService.queryCellsByCenter(workCenterCode, organizeCode));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/insert-defect-records")
    @ApiOperation(value = "本体/组件返修-不良明细-新增", notes = "本体/组件返修-不良明细-新增")
    public ResultBean insertMesDefectRecord(@RequestBody MesBadCellDetail mesDefectRecord) {
        List<MesDefect> mesDefectList = mesDefectRecord.getMesDefectList();
        if (CollectionUtils.isEmpty(mesDefectList)) {
            return ResultBean.fail("入参缺失缺陷集合");
        }
        try {
            ValidatorBean.beginValid(mesDefectRecord)
                    .notNull(MesPcnExtConstWords.PART_NO, mesDefectRecord.getPartNo())
                    .notNull(MesPcnExtConstWords.WORK_CENTER_CODE, mesDefectRecord.getWorkCenterCode())
                    .notNull(MesPcnExtConstWords.WORK_CELL_CODE, mesDefectRecord.getWorkCellCode());
            for (MesDefect mesDefect : mesDefectList) {
                ValidatorBean.beginValid(mesDefect)
                        .notNull(MesPcnExtConstWords.DEFECT_CODE, mesDefect.getDefectCode())
                        .notNull(MesPcnExtConstWords.DEFECT_NAME, mesDefect.getDefectName());
            }
            sxSyncBusiService.doRepairOrQualityDecision(mesDefectRecord, 2);
            return ResultBean.success(LocaleUtils.getLocaleRes("新增成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/insert-repair-record")
    @ApiOperation(value = "本体/组件返修-维修明细-新增", notes = "本体/组件返修-维修明细-新增")
    public ResultBean insertMesRepairRecord(MesRepairRecordExt mesRepairRecord) {
        try {
            ValidatorBean.beginValid(mesRepairRecord)
                    .notNull(MesPcnExtConstWords.PART_NO, mesRepairRecord.getPartNo())
                    .notNull(MesPcnExtConstWords.PART_NAME, mesRepairRecord.getPartName())
                    .notNull(MesPcnExtConstWords.DEFECT_CODE, mesRepairRecord.getDefectCode())
                    .notNull(MesPcnExtConstWords.DEFECT_NAME, mesRepairRecord.getDefectName())
                    .notNull(MesPcnExtConstWords.REPAIR_CODE, mesRepairRecord.getRepairCode())
                    .notNull(MesPcnExtConstWords.REPAIR_JUDGE_CODE, mesRepairRecord.getRepairJudgeCode())
                    .notNull(MesPcnExtConstWords.REPAIR_JUDGE_NAME, mesRepairRecord.getRepairJudgeName())
                    .notNull(MesPcnExtConstWords.REPAIR_NAME, mesRepairRecord.getRepairName())
                    .notNull(MesPcnExtConstWords.DEFECT_RECORD_ID, mesRepairRecord.getDefectRecordId())
                    .notNull(MesPcnExtConstWords.WORK_CELL_CODE, mesRepairRecord.getWorkCellCode())
                    .notNull(MesPcnExtConstWords.QTY, mesRepairRecord.getQty());
            sxRepairWorkService.insertMesRepairRecord(mesRepairRecord);
            return ResultBean.success(LocaleUtils.getLocaleRes(LocaleUtils.getLocaleRes("操作成功")))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping(value = "/update-repair-record")
    @ApiOperation(value = "本体/组件返修-维修明细-修改", notes = "本体/组件返修-维修明细-修改")
    public ResultBean updateMesRepairRecord(@RequestBody MesRepairRecordExt mesRepairRecord) {
        try {
            ValidatorBean.beginValid(mesRepairRecord)
                    .notNull(MesPcnExtConstWords.ID, mesRepairRecord.getId())
                    .notNull(MesPcnExtConstWords.PART_NO, mesRepairRecord.getPartNo())
                    .notNull(MesPcnExtConstWords.PART_NAME, mesRepairRecord.getPartName())
                    .notNull(MesPcnExtConstWords.DEFECT_CODE, mesRepairRecord.getDefectCode())
                    .notNull(MesPcnExtConstWords.DEFECT_NAME, mesRepairRecord.getDefectName())
                    .notNull(MesPcnExtConstWords.REPAIR_CODE, mesRepairRecord.getRepairCode())
                    .notNull(MesPcnExtConstWords.REPAIR_JUDGE_CODE, mesRepairRecord.getRepairJudgeCode())
                    .notNull(MesPcnExtConstWords.REPAIR_JUDGE_NAME, mesRepairRecord.getRepairJudgeName())
                    .notNull(MesPcnExtConstWords.REPAIR_NAME, mesRepairRecord.getRepairName())
                    .notNull(MesPcnExtConstWords.DEFECT_RECORD_ID, mesRepairRecord.getDefectRecordId())
                    .notNull(MesPcnExtConstWords.WORK_CELL_CODE, mesRepairRecord.getWorkCellCode())
                    .notNull(MesPcnExtConstWords.QTY, mesRepairRecord.getQty());
            sxRepairWorkService.updateMesRepairRecord(mesRepairRecord);
            return ResultBean.success(LocaleUtils.getLocaleRes("修改成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-defect-cause")
    @ApiOperation(value = "本体/组件返修-查询缺陷原因", notes = "本体/组件返修-查询缺陷原因")
    public ResultBean queryMesDefectCause(MesDefectCause mesDefectCause, Pager pager) {
        try {
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(sxRepairWorkService.getMesDefectCause(mesDefectCause, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/query-repair")
    @ApiOperation(value = "本体/组件返修-查询措施代码", notes = "本体/组件返修-查询措施代码")
    public ResultBean queryMesRepair(MesRepair mesRepair, Pager pager) {
        try {
            return ResultBean.success(LocaleUtils.getLocaleRes("查询成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
                    .setListPager(sxRepairWorkService.getMesRepair(mesRepair, pager));
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PostMapping(value = "/insert-repair-defect-record")
    @ApiOperation(value = "本体/组件返修-一步操作", notes = "本体/组件返修-一步操作")
    public ResultBean insertMesRepairDefectRecord(@RequestBody RepairRequestModel requestModel) {
        List<MesBadCellDetail> mesDefectRecordList = requestModel.getMesDefectRecordList();
        if (CollectionUtils.isEmpty(mesDefectRecordList)) {
            return ResultBean.fail("请求必要参数信息为空");
        }
        List<MesRepairRecordExt> mesRepairRecordList = requestModel.getMesRepairRecordList();
        if (CollectionUtils.isEmpty(mesRepairRecordList)) {
            return ResultBean.fail("请求必要参数信息为空");
        }
        try {
            ValidatorBean.beginValid(requestModel)
                    .notNull(MesPcnExtConstWords.ORGANIZE_CODE, requestModel.getOrganizeCode())
                    .notNull(MesPcnExtConstWords.MODIFY_USER, requestModel.getModifyUser())
                    .notNull(MesPcnExtConstWords.WORK_CELL_CODE, requestModel.getWorkCellCode());
            for (MesBadCellDetail mesDefectRecord : mesDefectRecordList) {
                ValidatorBean.beginValid(mesDefectRecord)
                        .notNull(MesPcnExtConstWords.PART_NO, mesDefectRecord.getPartNo())
                        .notNull(MesPcnExtConstWords.DEFECT_CODE, mesDefectRecord.getDefectCode())
                        .notNull(MesPcnExtConstWords.DEFECT_NAME, mesDefectRecord.getDefectName())
                        .notNull(MesPcnExtConstWords.WORK_CENTER_CODE, mesDefectRecord.getWorkCenterCode());
            }
            for (MesRepairRecordExt mesRepairRecord : mesRepairRecordList) {
                ValidatorBean.beginValid(mesRepairRecord)
                        .notNull(MesPcnExtConstWords.PART_NO, mesRepairRecord.getPartNo())
                        .notNull(MesPcnExtConstWords.PART_NAME, mesRepairRecord.getPartName())
                        .notNull(MesPcnExtConstWords.DEFECT_CODE, mesRepairRecord.getDefectCode())
                        .notNull(MesPcnExtConstWords.DEFECT_NAME, mesRepairRecord.getDefectName())
                        .notNull(MesPcnExtConstWords.WORK_CENTER_CODE, mesRepairRecord.getWorkCenterCode())
                        .notNull(MesPcnExtConstWords.REPAIR_JUDGE_CODE, mesRepairRecord.getRepairJudgeCode())
                        .notNull(MesPcnExtConstWords.REPAIR_JUDGE_NAME, mesRepairRecord.getRepairJudgeName())
                        .notNull(MesPcnExtConstWords.REPAIR_CODE, mesRepairRecord.getRepairCode())
                        .notNull(MesPcnExtConstWords.REPAIR_NAME, mesRepairRecord.getRepairName())
                        .notNull(MesPcnExtConstWords.QTY, mesRepairRecord.getQty());
            }
            sxSyncBusiService.doRepairOrQualityDecision(requestModel, 3);
            return ResultBean.success(LocaleUtils.getLocaleRes(LocaleUtils.getLocaleRes("操作成功")))
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping(value = "/update-repair-complete")
    @ApiOperation(value = "本体返修-维修完成", notes = "本体返修-维修完成")
    public ResultBean updateRepairComplete(String serialNumber, String organizeCode, String modifyUser) {
        try {
            sxRepairWorkService.updateRepairComplete(serialNumber, organizeCode, modifyUser);
            return ResultBean.success(LocaleUtils.getLocaleRes("操作成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping(value = "/update-batch-repair-complete")
    @ApiOperation(value = "组件返修-维修完成", notes = "组件返修-维修完成")
    public ResultBean updateRepairBatchComplete(String workOrderNo, Double defectQty, String organizeCode, String modifyUser) {
        try {
            sxRepairWorkService.updateRepairBatchComplete(workOrderNo, defectQty, organizeCode, modifyUser);
            return ResultBean.success(LocaleUtils.getLocaleRes("操作成功")).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @GetMapping(value = "/replace-key-task/by-sn/query")
    @ApiOperation(value = "本体返修-换件作业查询", notes = "本体返修-换件作业查询")
    public ResultBean repairKeyTaskQuery(String serialNumber, String organizeCode) {
        try {
            List<MesProdBindRecordExt> prodBindRecordList = sxRepairWorkService.getBindRecordData(serialNumber, organizeCode);
            return ResultBean.success("操作成功").setResultList(prodBindRecordList)
                    .setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

    @PutMapping(value = "/insert-prod-bind-record")
    @ApiOperation(value = "本体返修-换件作业确认替换", notes = "本体返修-换件作业确认替换")
    public ResultBean updateMesProdBindRecord(Long id, String serialNumber, String keyBarCode, String organizeCode, String modifyUser, String itemPartNo) {
        try {
            sxRepairWorkService.insertProdBindRecord(id, serialNumber, keyBarCode, organizeCode, modifyUser, itemPartNo);
            return ResultBean.success("绑定成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
        } catch (ImppBusiException busExcep) {
            return ResultBean.fail(busExcep);
        } catch (Exception e) {
            return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
        }
    }

}
