package cn.estsh.i3plus.ext.mes.pcn.apiservice.serviceimpl.job;

import cn.estsh.i3plus.ext.mes.pcn.api.base.IPartExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.IProdPackExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxPcnHttpService;
import cn.estsh.i3plus.ext.mes.pcn.api.base.ISxWorkOrderExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IProduceSnExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IProductEncodeCfgExtService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.ISxNumberRulePackAttributeService;
import cn.estsh.i3plus.ext.mes.pcn.api.busi.IWorkOrderCreateSnErrorRecordService;
import cn.estsh.i3plus.ext.mes.pcn.api.job.ISxWorkOrderAutoCreateSnService;
import cn.estsh.i3plus.ext.mes.pcn.pojo.bean.*;
import cn.estsh.i3plus.ext.mes.pcn.pojo.model.MatchRuleCodeModel;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesPackageExtRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesProduceSnExtRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.repository.MesWorkOrderExtRepository;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.ConvertBeanExt;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtConstWords;
import cn.estsh.i3plus.ext.mes.pcn.pojo.util.MesPcnExtEnumUtil;
import cn.estsh.i3plus.mes.pcn.api.iservice.busi.ISyncFuncService;
import cn.estsh.i3plus.mes.pcn.util.PcnHttpUtil;
import cn.estsh.i3plus.platform.common.convert.ConvertBean;
import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
import cn.estsh.i3plus.platform.common.tool.MathOperation;
import cn.estsh.i3plus.pojo.base.bean.BaseResultBean;
import cn.estsh.i3plus.pojo.base.bean.DdlPackBean;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.MesPcnEnumUtil;
import cn.estsh.i3plus.pojo.base.tool.DdlPreparedPack;
import cn.estsh.i3plus.pojo.mes.bean.MesWorkOrder;
import cn.estsh.i3plus.pojo.mes.model.GenSerialNoModel;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author: wangjie
 * @CreateDate: 2019/8/23 1:16 PM
 * @Description: Pcn处理工单自动批量生成条码
 **/
@Slf4j
@Service
public class SxWorkOrderAutoCreateSnService implements ISxWorkOrderAutoCreateSnService {

    @Autowired
    private MesWorkOrderExtRepository workOrderExtRepository;

    @Autowired
    private MesProduceSnExtRepository produceSnExtRepository;

    @Autowired
    private IProduceSnExtService produceSnExtService;

    @Autowired
    private ISxWorkOrderExtService workOrderExtService;

    @Autowired
    private IPartExtService partExtService;

    @Autowired
    private IProdPackExtService prodPackExtService;

    @Autowired
    private IProductEncodeCfgExtService productEncodeCfgExtService;

    @Autowired
    private ISxNumberRulePackAttributeService numberRulePackAttributeService;

    @Autowired
    private ISyncFuncService syncFuncService;

    @Autowired
    private MesPackageExtRepository packageExtRepository;

    @Autowired
    private IWorkOrderCreateSnErrorRecordService workOrderCreateSnErrorRecordService;

    @Autowired
    private ISxPcnHttpService pcnHttpService;

    @Override
    public void doWorkOrderAutoCreateSn(String organizeCode) {
        //SEQ正序获取所有下达状态,条码未生成状态的工单集合
        List<MesWorkOrderExt> workOrderList = getWorkOrderList(organizeCode);
        if (CollectionUtils.isEmpty(workOrderList)) {
            log.info("Pcn处理工单自动批量生成条码JOB,未获取到需要自动生成条码的工单");
            return;
        }

        log.info("Pcn处理工单自动批量生成条码JOB,查询工单状态下达的数据量为:[{}],包含{}",
                workOrderList.size(), workOrderList.stream().filter(o -> null != o).map(MesWorkOrder::getOrderNo).collect(Collectors.toList()).toString());

        List<MesWorkOrderCreateSnErrorRecord> recordList = workOrderCreateSnErrorRecordService.getWorkOrderCreateSnErrorRecordList(organizeCode);
        if (!CollectionUtils.isEmpty(recordList)) {
            List<String> workOrderNoList = recordList.stream().filter(o -> null != o).map(MesWorkOrderCreateSnErrorRecord::getWorkOrderNo).collect(Collectors.toList());
            workOrderList = CollectionUtils.isEmpty(workOrderNoList) ? workOrderList :
                    workOrderList.stream().filter(o -> (null != o && !workOrderNoList.contains(o.getOrderNo()))).collect(Collectors.toList());
        }

        if (CollectionUtils.isEmpty(workOrderList)) {
            log.info("Pcn处理工单自动批量生成条码JOB,排除已执行出现异常的工单,剩余可执行数据量为:[0]");
            return;
        }

        log.info("Pcn处理工单自动批量生成条码JOB,排除已执行出现异常的工单,剩余可执行数据量为:[{}],包含{}",
                workOrderList.size(), workOrderList.stream().filter(o -> null != o).map(MesWorkOrder::getOrderNo).collect(Collectors.toList()).toString());

        for (MesWorkOrderExt workOrder : workOrderList) {
            if (null == workOrder) {
                continue;
            }
            log.info("Pcn处理工单自动批量生成条码JOB,生成条码开始,工单号[{}]", workOrder.getOrderNo());

            // 已绑定条码数量（手动绑定条码）
            int produceSnNum = getProduceSnNum(workOrder);

            String msg;
            if (!checkWorkOrderStatus(workOrder, produceSnNum)) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单号[{}],工单类型[%s],条码生产状态[%s],工单生成条码执行失败", workOrder.getOrderNo(),
                        MesPcnExtEnumUtil.WORK_ORDER_TYPE.valueOfDescription(workOrder.getWorkOrderType()), MesPcnExtEnumUtil.WORK_ORDER_SN_CREATE_STATUS.valueOfDescription(workOrder.getSnCreateStatus()));
                log.info(msg);
                insertWorkOrderCreateSnErrorRecord(workOrder, msg);
                continue;
            }
            MesPartExt partDb = partExtService.getPartExt(workOrder.getOrganizeCode(), workOrder.getPartNo());
            msg = doCheckWorkOrderIsExistSn(workOrder, partDb);
            if (!StringUtils.isEmpty(msg)) {
                insertWorkOrderCreateSnErrorRecord(workOrder, msg);
                continue;
            }
            MesProdPackExt prodPackDb = prodPackExtService.getProdPackExt(organizeCode, partDb.getPartNo(), partDb.getPptCode());
            if (null == prodPackDb || StringUtils.isEmpty(prodPackDb.getProcessLabelTemplate())) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]未在产品包装关系中维护过程标签模板", workOrder.getOrderNo(), workOrder.getPartNo());
                log.info(msg);
                insertWorkOrderCreateSnErrorRecord(workOrder, msg);
                continue;
            }
            msg = doAutoCreateSn(workOrder, partDb, prodPackDb, produceSnNum);
            if (StringUtils.isEmpty(msg)) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]未在产品包装关系中维护过程标签模板", workOrder.getOrderNo(), workOrder.getPartNo());
                workOrderExtService.saveSnCreateStatus(workOrder, MesPcnExtConstWords.JOB, MesPcnExtEnumUtil.WORK_ORDER_SN_CREATE_STATUS.CREATED.getValue());
                break;
            } else {
                log.info(msg);
                insertWorkOrderCreateSnErrorRecord(workOrder, msg);
            }
        }
    }

    private int getProduceSnNum(MesWorkOrderExt workOrder) {

        String requestUrl = pcnHttpService.getRequestUrl(workOrder.getOrganizeCode(), MesPcnExtConstWords.GET_PRODUCE_SN_NUM);
        log.info("getProduceSnNum --- 获取URL：{}",requestUrl);
        Map<String, String> params = new HashMap<>();
        params.put(MesPcnExtConstWords.WORK_ORDER_NO, workOrder.getOrderNo());
        params.put(MesPcnExtConstWords.ORGANIZE_CODE, workOrder.getOrganizeCode());
        String data = PcnHttpUtil.doPost(requestUrl, params);
        BaseResultBean baseResultBean = null;
        if (!StringUtils.isEmpty(data)) {
            baseResultBean = JsonUtilTool.decode(data, BaseResultBean.class);
        } else {
            log.error("getProduceSnNum --- HTTP[{}]调用主接口失败", requestUrl);
        }

        int produceSnNum = 0;
        if (null != baseResultBean && baseResultBean.success) {
            produceSnNum = (int)baseResultBean.getResultObject();
        } else {
            log.error("getProduceSnNum --- HTTP[{}]调用主接口失败 baseResultBean:{}", requestUrl, baseResultBean);
        }
        log.error("getProduceSnNum --- workOrderNo:{}; produceSnNum:{}", workOrder.getOrderNo(), produceSnNum);
        return produceSnNum;
    }

    private String doAutoCreateSn(MesWorkOrderExt workOrder, MesPartExt partDb, MesProdPackExt prodPackDb, int produceSnNum) {
        String msg = null;
        List<MatchRuleCodeModel> codeTypeList = getCodeType(workOrder, produceSnNum);
        for (MatchRuleCodeModel model : codeTypeList) {
            if (null == model) {
                continue;
            }
            String ruleCode;
            try {
                ruleCode = productEncodeCfgExtService.getRuleCodeByMatchType(workOrder.getOrganizeCode(), model.getCodeType(), partDb, workOrder.getWorkCenterCode());
            } catch (Exception e) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]:%s", workOrder.getOrderNo(), e.getMessage());
                log.info(msg);
                return msg;
            }

            GenSerialNoModel genSerialNoModel = doPackGenSerialNoModel(workOrder, ruleCode, partDb, workOrder.getStartTime());
            if (null == genSerialNoModel) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,编码规则封装入参属性失败,工单[%s]:%s", workOrder.getOrderNo());
                log.info(msg);
                return msg;
            }
            if (StringUtils.isEmpty(model.getCount()) || model.getCount().compareTo(0) <= 0) {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,请检查工单[%s]数量", workOrder.getOrderNo());
                log.info(msg);
                return msg;
            }
            BaseResultBean<String> resultBean = syncFuncService.syncSerialNo(genSerialNoModel, MesPcnExtConstWords.JOB, workOrder.getOrganizeCode(), model.getCount());
            if (resultBean != null && resultBean.isSuccess()) {
                log.info("Pcn处理工单自动批量生成条码JOB,生成[{}]条码成功,数量[{}],工单号[{}]", MesPcnExtEnumUtil.ENCODE_CODE_TYPE.valueOfDescription(model.getCodeType()), model.getCount(), workOrder.getOrderNo());
                if (CollectionUtils.isEmpty(resultBean.getResultList())) {
                    msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]批量生成过程条码成功,但没有返回过程条码集合", workOrder.getOrderNo());
                    log.info(msg);
                    return msg;
                }
                log.info("Pcn处理工单自动批量生成条码JOB,生成[{}]条码成功,工单号[{}],数量[{}],条码区间[{}~{}]", MesPcnExtEnumUtil.ENCODE_CODE_TYPE.valueOfDescription(model.getCodeType()),
                        workOrder.getOrderNo(), model.getCount(), resultBean.getResultList().get(0), resultBean.getResultList().get(resultBean.getResultList().size() - 1));
                try {
                    insertProduceSnExt(resultBean.getResultList(), workOrder, partDb, model.getCodeType(), prodPackDb, MesPcnExtConstWords.JOB);
                } catch (Exception e) {
                    msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]插入产品条码出错:%s", workOrder.getOrderNo(), e.getMessage());
                    log.info(msg);
                    return msg;
                }
            } else {
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]批量生成过程条码失败", workOrder.getOrderNo());
                log.info(msg);
                return msg;
            }
        }
        return msg;
    }

    @Override
    public GenSerialNoModel doPackGenSerialNoModel(MesWorkOrderExt workOrderExt, String ruleCode, MesPartExt partDb, String workOrderStartTime) {
        Map<String, Object> map = new HashMap<>();
        map.put(MesPcnExtConstWords.ORGANIZE_CODE, workOrderExt.getOrganizeCode());
        map.put(MesPcnExtConstWords.RULE_CODE, ruleCode);
        map.put(MesPcnExtConstWords.PART_EXT, partDb);
        map.put(MesPcnExtConstWords.START_TIME, workOrderStartTime);
        map.put(MesPcnExtConstWords.WORK_ORDER, workOrderExt);
        return numberRulePackAttributeService.doPackGenSerialNoModel(map);
    }

    @Override
    public void insertPackage(List<String> packageNoList, MesWorkOrderExt workOrder, MesPartExt partDb, Integer codeType, MesProdPackExt prodPackDb,Double num, String userInfo) {
        //物料设置的包装数量
        Double qty2 = partDb.getQty2();
        for (String o : packageNoList) {
            MesPackageExt pack = new MesPackageExt();
            pack.setPackageNo(o);
            pack.setWorkOrderNo(workOrder.getOrderNo());
            pack.setLastWorkOrderNo(workOrder.getOrderNo());
            pack.setPartNo(partDb.getPartNo());
            pack.setPartNameRdd(partDb.getPartName());
            if(o.equals(packageNoList.get(packageNoList.size()-1))){
                if(num!=0){
                    pack.setQty(num);
                }else{
                    pack.setQty(qty2);
                }
            }else{
                pack.setQty(qty2);
            }
            pack.setPackSpec(prodPackDb.getPackSpec());
            pack.setPackSpecQty(qty2);
            pack.setPackageLabelTemplate(prodPackDb.getPackLabelTemplate());
            pack.setUnit(partDb.getUnit());
            pack.setIsSealed(MesPcnEnumUtil.PACKAGE_IS_SEALED.UNSEALED.getValue());
            pack.setPrintStatus(MesPcnEnumUtil.PACKAGE_PRINT_STATUS.UNPRINTED.getValue());
            pack.setPackLevel(MesPcnEnumUtil.PACKAGE_PACKLEVEL.FIRST.getValue());
            pack.setWorkCenterCode(workOrder.getWorkCenterCode());
            pack.setOrganizeCode(workOrder.getOrganizeCode());
            ConvertBean.serviceModelInitialize(pack, userInfo);
            pack.setSystemSyncStatus(MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
            new ConvertBeanExt(pack).convertBean(pack);
            packageExtRepository.insert(pack);
        }
    }

    @Override
    public void insertProduceSnExt(List<String> serialNumberList, MesWorkOrderExt workOrder, MesPartExt partDb, Integer codeType, MesProdPackExt prodPackDb, String userInfo) {
        serialNumberList.forEach(o -> {
            MesProduceSnExt produceSnExt = new MesProduceSnExt();
            produceSnExt.setSerialNumber(o);
            produceSnExt.setProductSn(o);
            produceSnExt.setWorkOrderNo(workOrder.getOrderNo());
            produceSnExt.setLastWorkOrderNo(workOrder.getOrderNo());
            produceSnExt.setPartNo(partDb.getPartNo());
            produceSnExt.setPartNameRdd(partDb.getPartName());
            produceSnExt.setProcessLabelTemplate(prodPackDb.getProcessLabelTemplate());
            produceSnExt.setQualityAssureTemplate(prodPackDb.getQualityAssureTemplate());
            produceSnExt.setBigProcessLabelTemplate(prodPackDb.getBigProcessLabelTemplate());
            produceSnExt.setCustCode(workOrder.getCustCode());
            produceSnExt.setPrintStatus(MesPcnExtEnumUtil.PRODUCE_SN_PRINT_STATUS.UNPRINT.getValue());
            produceSnExt.setPrintCount(0);
            produceSnExt.setSnStatus(MesPcnExtEnumUtil.PRODUCE_SN_STATUS.CREATE.getValue());
            produceSnExt.setQcStatus(MesPcnExtEnumUtil.PRODUCE_SN_QC_STATUS.QUALIFIED.getValue());
            produceSnExt.setSnType(codeType);
            produceSnExt.setQty(1d);
            produceSnExt.setWorkCenterCode(workOrder.getWorkCenterCode());
            produceSnExt.setOrganizeCode(workOrder.getOrganizeCode());
            ConvertBean.serviceModelInitialize(produceSnExt, userInfo);
            produceSnExt.setSystemSyncStatus(MesPcnExtEnumUtil.IF_SYNC_STATUS.NO_SYNC.getValue());
            new ConvertBeanExt(produceSnExt).convertBean(produceSnExt);
            produceSnExtRepository.insert(produceSnExt);
        });
    }

    @Override
    public List<MatchRuleCodeModel> getCodeType(MesWorkOrderExt workOrder, int produceSnNum) {
        List<MatchRuleCodeModel> codeTypeList = new ArrayList<>();
        switch (MesPcnExtEnumUtil.WORK_ORDER_TYPE.getByValue(workOrder.getWorkOrderType())) {
            case ATTEMPT_ORDER:
                codeTypeList.add(new MatchRuleCodeModel(MesPcnExtEnumUtil.ENCODE_CODE_TYPE.ATTEMPT_SERIAL_SN.getValue(), workOrder.getQty().intValue()));
                break;
            case STANDARD_ORDER:
                if (!StringUtils.isEmpty(workOrder.getPlanQty()) && MathOperation.compareTo(workOrder.getPlanQty(), new Double(0)) > 0) {
                    Double standardQty = MathOperation.sub(MathOperation.sub(workOrder.getQty(), workOrder.getPlanQty()), produceSnNum);
                    codeTypeList.add(new MatchRuleCodeModel(MesPcnExtEnumUtil.ENCODE_CODE_TYPE.REWORK_SERIAL_SN.getValue(), workOrder.getPlanQty().intValue()));
                    if (standardQty.compareTo(new Double(0)) > 0) {
                        codeTypeList.add(new MatchRuleCodeModel(MesPcnExtEnumUtil.ENCODE_CODE_TYPE.STANDARD_SERIAL_SN.getValue(), standardQty.intValue()));
                    }
                } else {
                    double sub = MathOperation.sub(workOrder.getQty(), produceSnNum);
                    codeTypeList.add(new MatchRuleCodeModel(MesPcnExtEnumUtil.ENCODE_CODE_TYPE.STANDARD_SERIAL_SN.getValue(), (int) sub));
                }
                break;
            default:
                break;
        }
        return codeTypeList;
    }

    private boolean checkWorkOrderStatus(MesWorkOrderExt workOrder, int produceSnNum) {
        if (MesPcnExtEnumUtil.WORK_ORDER_TYPE.REWORK_ORDER.getValue() == workOrder.getWorkOrderType()) {
            return false;
        }
        if (MesPcnExtEnumUtil.WORK_ORDER_SN_CREATE_STATUS.NO_CREATE.getValue() == workOrder.getSnCreateStatus() ||
                MesPcnExtEnumUtil.WORK_ORDER_SN_CREATE_STATUS.CREATED.getValue() == workOrder.getSnCreateStatus()) {
            return false;
        }

        if (produceSnNum == (workOrder.getQty() - workOrder.getPlanQty())) {
            return false;
        }
        return true;
    }

    private String doCheckWorkOrderIsExistSn(MesWorkOrderExt workOrder, MesPartExt partDb) {
        String msg = null;
        if (null == partDb) {
            msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]无效", workOrder.getOrderNo(), workOrder.getPartNo());
            log.error(msg);
            return msg;
        }
        if (StringUtils.isEmpty(partDb.getIsCreateSn())) {
            msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]未维护是否生成条码标识", workOrder.getOrderNo(), workOrder.getPartNo());
            log.error(msg);
            return msg;
        }
        if (CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue() == partDb.getIsCreateSn()) {
            msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]已配置不生成条码", workOrder.getOrderNo(), workOrder.getPartNo());
            log.error(msg);
            return msg;
        }
        List<MesProduceSnExt> produceSnExtList = produceSnExtService.getProduceSnExtListByOrderNo(workOrder.getOrganizeCode(), workOrder.getOrderNo());
        if (!CollectionUtils.isEmpty(produceSnExtList)) {
            if (produceSnExtList.size() == workOrder.getQty().intValue()) {
                workOrderExtService.saveSnCreateStatus(workOrder, MesPcnExtConstWords.JOB, MesPcnExtEnumUtil.WORK_ORDER_SN_CREATE_STATUS.CREATED.getValue());
                msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]已经生成过条码,且生成的条码数量[{}]与工单数量[{}]一致",
                        workOrder.getOrderNo(), produceSnExtList.size(), workOrder.getQty());
                log.error(msg);
                return msg;
            }
            //else {
            //    msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]已经生成过条码,但是生成的条码数量[%s]与工单数量[%s]不一致",
            //            workOrder.getOrderNo(), produceSnExtList.size(), workOrder.getQty());
            //    log.error(msg);
            //}

        }
        if (StringUtils.isEmpty(partDb.getProcessMatchType())) {
            msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]未维护过程编码匹配类型", workOrder.getOrderNo(), workOrder.getPartNo());
            log.error(msg);
            return msg;
        }
        if (null == MesPcnExtEnumUtil.ENCODE_MATCH_TYPE.getByValue(partDb.getProcessMatchType())) {
            msg = String.format("Pcn处理工单自动批量生成条码JOB,工单[%s]关联的物料号[%s]未维护有效的过程编码匹配类型", workOrder.getOrderNo(), workOrder.getPartNo());
            log.error(msg);
            return msg;
        }
        return msg;
    }

    private List<MesWorkOrderExt> getWorkOrderList(String organizeCode) {
        DdlPackBean packBean = DdlPackBean.getDdlPackBean(organizeCode);
        DdlPreparedPack.getNumEqualPack(MesPcnExtEnumUtil.WORK_ORDER_STATUS.LANDED.getValue(), MesPcnExtConstWords.WORK_ORDER_STATUS, packBean);
        DdlPreparedPack.getOrderByPack(new Object[]{CommonEnumUtil.ASC_OR_DESC.ASC.getValue()}, new String[]{MesPcnExtConstWords.SEQ}, packBean);
        return workOrderExtRepository.findByHqlWhere(packBean);
    }

    private void insertWorkOrderCreateSnErrorRecord(MesWorkOrderExt workOrder, String msg) {
        MesWorkOrderCreateSnErrorRecord record = new MesWorkOrderCreateSnErrorRecord();
        record.setWorkOrderNo(workOrder.getOrderNo());
        record.setWorkCenterCode(workOrder.getWorkCenterCode());
        record.setPartNo(workOrder.getPartNo());
        record.setPartNameRdd(workOrder.getPartNameRdd());
        record.setMessage(msg);
        record.setOrganizeCode(workOrder.getOrganizeCode());
        ConvertBean.serviceModelInitialize(record, MesPcnExtConstWords.JOB);
        workOrderCreateSnErrorRecordService.insertWorkOrderCreateSnErrorRecordNoRollback(record);
    }
}
