xiejun
2025-01-22 d9183aa80ae17d36b79dda48c6b1d7fa22a80ee3
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -3,6 +3,7 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.common.utils.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.google.protobuf.ServiceException;
import com.vci.ubcs.code.applyjtcodeservice.feign.IMdmInterJtClient;
@@ -430,6 +431,7 @@
               throw new VciBaseException("模板没有配置属性");
            }
         }
         //剔除掉默认的属性,以及表单不显示的属性
         List<CodeClassifyTemplateAttrVO> templateAttrVOS = codeClassifyTemplateAttrVOList.stream().filter(s ->
            !DEFAULT_ATTR_LIST.contains(s.getId())
               && StringUtils.isBlank(s.getComponentRule())
@@ -1246,19 +1248,21 @@
               //我们需要先查询一下,内容是否已经存在
               if (!CollectionUtils.isEmpty(thisCbos)) {
                  List<String> existIds = new ArrayList<>();
                  // TODO: 2024/12/3 Ludc 这儿查询做了修改改成组成一句sql查询,而不是分批次查询
                  LambdaQueryWrapper<CodeAllCode> wrapper =  Wrappers.<CodeAllCode>query().lambda()
                     .eq(CodeAllCode::getCodeRuleOid, ruleOid);
                  VciBaseUtil.switchCollectionForOracleIn(thisCbos).stream().forEach(cbos -> {
                     List<CodeAllCode> codeAllCodeList = codeAllCodeService.selectByWrapper(Wrappers.<CodeAllCode>query().lambda().eq(CodeAllCode::getCodeRuleOid, ruleOid)
                        .notIn(CodeAllCode::getId, cbos.stream().map(s -> s.getId()).collect(Collectors.toSet()).toArray(new String[0]))
                        .notIn(CodeAllCode::getLcStatus, CodeAllCodeLC.TASK_BACK.getValue() + "','" + CodeAllCodeLC.OBSOLETED.getValue())
                     );
                     existIds.addAll(Optional.ofNullable(codeAllCodeList).orElseGet(() -> new ArrayList<>()).stream().map(s -> {
                        String id = s.getId();
                        if (StringUtils.isBlank(id)) {
                           id = s.getId();
                        }
                        return id;
                     }).collect(Collectors.toList()));
                     wrapper.notIn(CodeAllCode::getId, cbos.stream().map(s -> s.getId()).collect(Collectors.toSet()).toArray(new String[0]));
                  });
                  wrapper.notIn(CodeAllCode::getLcStatus, CodeAllCodeLC.TASK_BACK.getValue() + "','" + CodeAllCodeLC.OBSOLETED.getValue());
                  List<CodeAllCode> codeAllCodeList = codeAllCodeService.selectByWrapper(wrapper);
                  existIds.addAll(Optional.ofNullable(codeAllCodeList).orElseGet(() -> new ArrayList<>()).stream().map(s -> {
                     String id = s.getId();
                     if (StringUtils.isBlank(id)) {
                        id = s.getId();
                     }
                     return id;
                  }).collect(Collectors.toList()));
                  List<String> existIdCbos = thisCbos.stream().filter(s -> {
                     String id = s.getId();
                     if (StringUtils.isBlank(id)) {
@@ -2424,7 +2428,7 @@
      //都转换完了。需要批量检查
      //如果出错了,我们依然执行有效的数据,无效的数据写回到excel中
      Map<String, String> errorKeyMap = new HashMap<>();
      Map<String, String> errorKeyMap = new ConcurrentHashMap<>();
      //1.分类注入
      batchSwitchClassifyAttrOnOrder(attrVOS, cboList, classifyFullInfo, false);
      //boolean
@@ -2447,6 +2451,7 @@
      batchSwitchComponentAttrOnOrder(attrVOS, cboList);
      //3.判断关键属性
      CodeImportResultVO keyResultVO = batchCheckKeyAttrOnOrder(classifyFullInfo, templateVO, cboList, false, errorKeyMap);
      log.info("================查重后的errorKeyMap错误信息================="+JSON.toJSONString(errorKeyMap));
      Set<String> selfRepeatRowIndexList = keyResultVO.getSelfRepeatRowIndexList();
      Set<String> keyAttrRepeatRowIndexList = keyResultVO.getKeyAttrRepeatRowIndexList();
@@ -2688,7 +2693,6 @@
         }
      }
   }
   /***
@@ -3372,10 +3376,16 @@
   private void getCodeOrderDTOs(CodeClassifyVO codeClassifyVO, CodeClassifyTemplateVO templateVO, Map<String, RowDatas> codeDataMap, Map<String, ClientBusinessObject> codeSystemObjectMap, List<CodeOrderDTO> codeOrderDTOList, Map<String, String> errorMap, boolean isCodeOrGroupCode) {
      codeSystemObjectMap.keySet().forEach(code -> {
         ClientBusinessObject sysDataObject = codeSystemObjectMap.get(code);
         if (isCodeOrGroupCode) {
            code = sysDataObject.getAttributeValue("GROUPCODE");
         /*if (isCodeOrGroupCode) {
         //   code = sysDataObject.getAttributeValue("GROUPCODE");
            if (StringUtils.isBlank(code)) {
               code = sysDataObject.getId();
            }
         }*/
         if(isCodeOrGroupCode){
            String groupCode=sysDataObject.getAttributeValue("GROUPCODE");
            if(codeDataMap.containsKey(groupCode)){
               code=groupCode;
            }
         }
         CodeOrderDTO orderDTO = new CodeOrderDTO();
@@ -4117,7 +4127,8 @@
         StringBuffer sb = new StringBuffer();
         sb.append(" select id from ");
         sb.append(finalTableName);
         sb.append(" where 1=1 ");
         //sb.append(" where 1 = 1");
         sb.append(" where lastr = 1 and lastv = 1"); //TODO:涉及到已升版的数据也应该排除掉,否则会报重
         sb.append(" and id in (");
         sb.append(VciBaseUtil.toInSql(cbos.stream().map(s -> s.getId()).collect(Collectors.toSet()).toArray(new String[0])));
         sb.append(")");
@@ -4423,9 +4434,11 @@
    * @param classifyFullInfo 分类的全部信息
    * @param templateVO       模板的内容,必须包含模板属性
    * @param cboList          批量的数据
    */
    * @param isEdit          是否是修改
    * @param errorMap          必须必须必须是线程安全的集合
    * */
   private CodeImportResultVO batchCheckKeyAttrOnOrder(CodeClassifyFullInfoBO classifyFullInfo, CodeClassifyTemplateVO templateVO,
                                          List<ClientBusinessObject> cboList, boolean isEdit, Map<String, String> errorMap) {
                                          List<ClientBusinessObject> cboList, boolean isEdit, Map<String, String> errorMap/*必须要是线程安全的集合*/) {
      //与MdmEngineServiceImpl里的checkKeyAttrOnOrder相似
      //先获取关键属性的规则,也利用继承的方式
      CodeKeyAttrRepeatVO keyRuleVO = keyRuleService.getRuleByClassifyFullInfo(classifyFullInfo);
@@ -4454,7 +4467,7 @@
      if (Func.isNotEmpty(codeSynonymMaps)) {
         codeSynonymMaps.keySet().stream().forEach(item -> {
            synonymResString.append(item);
            synonymResString.append(",");
            synonymResString.append(",");
         });
      }
      resultVO.setSynonymRuleInfo(Func.isEmpty(codeSynonymMaps) ? "" : String.format("以下[%s]被设置了近义词查询规则的关键属性,中出现了重复:", synonymResString));
@@ -4478,8 +4491,8 @@
      // TODO:Thread limit exceeded replacing blocked 异常是这部分代码抛出的
      //  ,所以暂时将parallelStream改成了stream,改成了stream之后发现巨慢
      // customForkJoinPool控制并发度
      List<ClientBusinessObject> finalCboList = cboList;
      Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps;
      final List<ClientBusinessObject> finalCboList = cboList;
      final Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps;
      List<ClientBusinessObject> repeatDataMap = (List<ClientBusinessObject>) customForkJoinPool.submit(() -> {
         finalCboList.parallelStream().filter(cbo -> {
            //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示
@@ -4522,6 +4535,7 @@
                  });
                  // 添加错误值
                  String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
                  log.info("=============关键属性查询重复的============="+JSON.toJSONString(repeatData));
                  errorMap.put(rowIndex, "重复的记录编号为:" + repeatData.stream().collect(Collectors.joining(",")));
                  if (!CollectionUtils.isEmpty(newCboList)) {
                     indexTODataMap.put(cbo.getAttributeValue(IMPORT_ROW_INDEX), newCboList);
@@ -4947,7 +4961,7 @@
      }
   }
   /******
   /**
    * 根据编码规则缓存数据
    * @param uuid
    * @param codeImprotDataVOs
@@ -4991,7 +5005,7 @@
      });
   }
   /****
   /**
    * 数据相似项数据校验redis缓存
    * @param codeClassifyOid
    * @param templateVO
@@ -5365,7 +5379,7 @@
      List<String> codeList = cboList.stream().map(ClientBusinessObject::getId).collect(Collectors.toList());
      List<Map<String, String>> dataList = new ArrayList<>();
      Map<String, String> errorMap = new HashMap<>();
      Map<String, String> errorMap = new ConcurrentHashMap<>();
      batchSwitchCheckExist(errorMap, cboList, classifyFullInfo, templateVO, execGroupCodePortDataDTO, fieldIndexMap);
      //判断必输项
      batchCheckRequiredAttrOnOrder(templateVO, cboList, errorMap);