xiejun
2023-11-17 4208d7f9407ab7c9d6b756f5f8a7616b7686fc74
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmProductCodeServiceImpl.java
@@ -1,10 +1,10 @@
package com.vci.ubcs.code.service.impl;
import com.vci.ubcs.code.algorithm.CustomSerialEnum;
import com.vci.ubcs.code.dto.CodeCustomSerialDTO;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vci.ubcs.code.algorithm.CustomSerialEnum;
import com.vci.ubcs.code.bo.CodeClassifyFullInfoBO;
import com.vci.ubcs.code.dto.CodeCustomSerialDTO;
import com.vci.ubcs.code.dto.CodeOrderSecDTO;
import com.vci.ubcs.code.entity.CodeAllCode;
import com.vci.ubcs.code.entity.CodeClassifyValue;
@@ -114,7 +114,7 @@
            log.info("code:----->"+cbo.getId());
            //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
            String code = cbo.getId();
            List<String> serialUnitList = new ArrayList<>();
            List<String> serialUnitList = new CopyOnWriteArrayList<>();
            String seclenghStr=cbo.getData().get(CODE_SEC_LENGTH_FIELD);
            String[] secLengths = cbo.getData().get(CODE_SEC_LENGTH_FIELD).split("#");
            cbo.getData().remove(CODE_SEC_LENGTH_FIELD);//将此key除去
@@ -176,8 +176,6 @@
                     serialDb=subSecValue;
                  }else {
                     //左右填充的,我们需要
                     /*serialDb = VciBaseUtil.getDouble(killUnNumberChar(killFillChar(subSecValue,secVO.getCodeFillSeparator(),
                        OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType()))));*/
                     serialDb = killFillChar(subSecValue,secVO.getCodeFillSeparator(),
                        OsCodeFillTypeEnum.LEFT.getValue().equalsIgnoreCase(secVO.getCodeFillType()));
                  }
@@ -261,8 +259,8 @@
            // TODO 历史数据导入的时候这儿偶尔会触发空指针异常
            Map<String,List<CodeAllCode>> ruleGroup = allCodeDOList.stream().collect(Collectors.groupingBy(s -> s.getCodeRuleOid()));
            Map<String, CodeAllCode> codeDOMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getCodeRuleOid() + "${SEP}" + s.getId(), t -> t));
            List<CodeAllCode> addCodeDOs = new ArrayList<>();
            List<CodeAllCode> editCodeDOs = new ArrayList<>();
            List<CodeAllCode> addCodeDOs = new CopyOnWriteArrayList<>();
            List<CodeAllCode> editCodeDOs = new CopyOnWriteArrayList<>();
            ruleGroup.forEach((ruleOid,allCodeDOS)->{
               VciBaseUtil.switchCollectionForOracleIn(allCodeDOS).stream().forEach(codeDOs->{
                  QueryWrapper<CodeAllCode> allCodeWrapper = new QueryWrapper<>();
@@ -320,7 +318,7 @@
               List<CodeAllCode> codeAllCodes = codeAllCodeService.selectByWrapper(wrapper);
               List<CodeAllCode> takeBack = codeAllCodes.stream().filter(e -> e.getLcStatus().equals("TakeBack")).collect(Collectors.toList());
               if(codeAllCodes.size()>takeBack.size()){
                  throw new ServiceException("生成编码数据ID已有历史记录,请确认如下生成的ID数据:"+ codeAllCodes.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
                  throw new ServiceException("生成编码数据ID已有历史记录,请确认如下生成的ID数据:"+ addCodeDOs.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
               }
               for (CodeAllCode codeAllCode : takeBack) {
                  codeAllCode.setTs(new Date());
@@ -332,7 +330,8 @@
                     if(codeAllCode.getId().equals(next.getId())){
                        codeAllCode.setCreateCodeOid(next.getCreateCodeOid());
                        codeAllCode.setLcStatus(next.getLcStatus());
                        iterator.remove();
                        // TODO: 这儿先暂时注释掉,没看懂这儿为什么要这样做,导致报错
                        //iterator.remove();
                     }
                  }
               }
@@ -345,6 +344,13 @@
//            try {
            mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
               // 提交事务
               //transactionTemplate.getTransactionManager().commit(status);
//            }catch (Exception e){
//               // 出现异常时回滚事务
//               transactionTemplate.getTransactionManager().rollback(status);
//            }
         }
         return codeList;
      }else {
@@ -407,10 +413,14 @@
            allCodeDOList.stream().forEach(
               allCode -> {DefaultAttrAssimtUtil.addDefaultAttrAssimt(allCode,"codeallcode");allCode.setLctid("codeAllCodeLC");}
            );
            Map<String, String> statusMap = allCodeDOList.stream().collect(Collectors.toMap(s -> s.getOid(), s -> s.getLcStatus()));
            allCodeDOList.stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmname())).forEach(s -> {
            s.setLcStatus(statusMap.get(s.getOid()));
            });
            //通过ID来进行去重
            List<CodeAllCode> distinctCodeAllCOdes = allCodeDOList.stream().collect(Collectors
               .collectingAndThen(
@@ -425,7 +435,7 @@
            List<CodeAllCode> codeAllCodes = codeAllCodeService.selectByWrapper(wrapper);
            List<CodeAllCode> takeBack = codeAllCodes.stream().filter(e -> e.getLcStatus().equals("TakeBack")).collect(Collectors.toList());
            if(codeAllCodes.size()>takeBack.size()){
               throw new ServiceException("生成编码数据ID已有历史记录,请确认如下生成的ID数据:"+ codeAllCodes.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
            throw new ServiceException("生成编码数据ID已有历史记录,请确认如下生成的ID数据:"+ allCodeDOList.stream().map(CodeAllCode::getId).collect(Collectors.toList()));
            }
            for (CodeAllCode codeAllCode : takeBack) {
@@ -438,23 +448,16 @@
                  if(codeAllCode.getId().equals(next.getId())){
                     codeAllCode.setCreateCodeOid(next.getCreateCodeOid());
                     codeAllCode.setLcStatus(next.getLcStatus());
                     iterator.remove();
                  //iterator.remove();
                  }
               }
            }
            mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(), dataCBOList);
            if(takeBack.size()>0){
               codeAllCodeService.updateBatchById(takeBack);
            }
            codeAllCodeService.saveBatch(allCodeDOList);
//            iCodeWupinService.saveBatch(dataCBOList);
            // 提交事务
         //   transactionTemplate.getTransactionManager().commit(status);
         //}catch (Exception e){
            // 出现异常时回滚事务
         //   transactionTemplate.getTransactionManager().rollback(status);
         //   throw e;
         //}
         mdmEngineService.insertBatchByType(dataCBOList.get(0).getBtmname(),dataCBOList);
//         batchCBO.getCreateCbos().stream().filter(s -> StringUtils.equalsIgnoreCase("codeallcode",s.getBtmName())).forEach(s -> {
//            s.setLcStatus(statusMap.get(s.getOid()));
//            try {
@@ -529,7 +532,6 @@
                             CodeRuleVO ruleVO,String serialUnitString,
                             Map<String/**码段的主键**/,Map<String/**流水依据**/,CodeSerialValue>> maxSerialValueMap,List<String> thisSecValueList,
                             Map<String/**码段的主键**/,Map<String/**流水依据**/, String>> lastMaxSerialValueMap,boolean firstData){
      if (!CollectionUtils.isEmpty(serialSecVOList)) {
         Map<String,String> secIdserialValueMap=new LinkedHashMap<>();
         for (int j = 0; j < serialSecVOList.size(); j++) {
@@ -625,6 +627,7 @@
         }
      }
   }
    private String customCodeSerial(String className, CodeCustomSerialDTO codeCustomSerialDTO){
      String result = "";
      try {
@@ -648,6 +651,7 @@
      }
      return result;
   }
   /**
    * 转换码值的内容
    * @param secVO 码段的内容