xiejun
2023-12-04 fefddc77b2e240d5754abf15f5e3e91e86d360fe
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -845,7 +845,7 @@
            }
            // 单次导入数量限制
            if(sheetDataSetList.get(i).getRowData().size() > IMPORT_DATA_LIMIT){
               throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过"+IMPORT_DATA_LIMIT+"条的数据");
               throw new ServiceException(StringUtil.format("为了保证系统的稳定性,请一次不要导入超过{}条的数据",IMPORT_DATA_LIMIT));
            }
            //历史导入的时候不处理编码
            //----逻辑内容----
@@ -1134,7 +1134,7 @@
         if(StringUtils.isNotBlank(excelFileName)) {
            codeImProtRusultVO.setFilePath(excelFileName);
            codeImProtRusultVO.setFileOid("");
            saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap)) );
            saveLogUtil.operateLog("历史数据导入",true, StringUtil.format("错误信息:{}",JSON.toJSONString(shetNameMap)));
         }else{
            saveLogUtil.operateLog("历史数据导入",false, StringUtil.format("导入到分类{}中,导入成功总数为:{}", JSON.toJSONString(classifyFullInfo),importCount.get(0)));
         }
@@ -1143,7 +1143,7 @@
         }
         return codeImProtRusultVO;
      }catch (Exception e){
         saveLogUtil.operateLog("历史数据导入",true,e.getMessage());
         saveLogUtil.operateLog("历史数据导入",true,e.toString());
         throw e;
      }
   }
@@ -1458,7 +1458,7 @@
         }
         saveLogUtil.operateLog("批量申请编码",false, StringUtil.format("批量导入申请成功共{}条数据,生成的码值如下【{}】",codeList.size(),codeList));
      }catch (Exception e){
         saveLogUtil.operateLog("批量申请编码",true,e.getMessage());
         saveLogUtil.operateLog("批量申请编码",true,e.toString());
         throw e;
      }
      return uuid;
@@ -3863,6 +3863,7 @@
                  } else {
                     Map<String, String> classifyDataMap = VciBaseUtil.objectToMapString(classifyVO);
                     String value = classifyDataMap.getOrDefault(attrVO.getClassifyInvokeAttr(), "");
                     log.error("================================当前分类注入的value值为:==========================",value);
                     cbo.setAttributeValue(attrId, value);
                  }
               } catch (Throwable e) {
@@ -4612,7 +4613,7 @@
    * @return
    */
   @Override
   public String exportGroupCodeExcel(String codeClassifyOid) {
   public String exportGroupCodeExcel(String codeClassifyOid) throws ServiceException {
      VciBaseUtil.alertNotNull(codeClassifyOid,"主题库分类的主键");
      CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid);
      CodeClassifyVO codeClassifyVO= classifyFullInfo.getCurrentClassifyVO();
@@ -4623,9 +4624,12 @@
      ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO();
      createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//组织数据
      if(!CollectionUtils.isEmpty(execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS())){
         throw new ServiceException("集团属性映射未配置");
      }
      fieldList=execGroupCodePortDataDTO.getFieldList();
      List<Map<String,String>>dataList=new ArrayList<>();
      getDatas(classifyFullInfo,templateVO,fieldList,dataList);
      getDatas(classifyFullInfo,templateVO,fieldList,dataList,null);
      execGroupCodePortDataDTO.setDataList(dataList);//放数据
      execGroupCodePortDataDTO.setSheetName(codeClassifyVO.getName()+"集团码导入模板");
      String tempFolder = LocalFileUtil.getDefaultTempFolder();
@@ -4714,8 +4718,91 @@
      log.info("文件路径"+excelName);
      return excelName;
   }
   /***
    * 导入集团码
    * @param codeClassifyOid
    * @param file
    * @return
    */
   public String improtGroupCode(String codeClassifyOid, File file) throws ServiceException {
      VciBaseUtil.alertNotNull(codeClassifyOid,"分类的主键");
      ReadExcelOption reo = new ReadExcelOption();
      reo.setReadAllSheet(true);
      List<SheetDataSet> sheetDataSetList = ExcelUtil.readDataObjectFromExcel(file,null,reo);
      if (sheetDataSetList.size() > LIMIT + 1) {
         throw new ServiceException("为了保证系统的稳定性,请一次不要导入超过1万条的数据");
      }
      CodeClassifyFullInfoBO classifyFullInfo = classifyService.getClassifyFullInfo(codeClassifyOid);
      CodeClassifyTemplateVO templateVO = new CodeClassifyTemplateVO();
      //除去默认的属性.还有只有表单显示的字段才导入
      List<CodeClassifyTemplateAttrVO> attrVOS = templateVO.getAttributes().stream().filter(s ->!DEFAULT_SYNC_ATTR_LIST.contains(s.getId()) && VciBaseUtil.getBoolean(s.getFormDisplayFlag())
      ).collect(Collectors.toList());
      ExecGroupCodePortDataDTO execGroupCodePortDataDTO=new ExecGroupCodePortDataDTO();
      createExportGroupCodeMapConfig(templateVO,execGroupCodePortDataDTO);//组织数据
      List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS=execGroupCodePortDataDTO.getCodeAttrMapGroupAttrDTOS();
      if(!CollectionUtils.isEmpty(codeAttrMapGroupAttrDTOS)){
         throw new ServiceException("集团属性映射未配置");
      }
      Map<String, CodeAndGroupCodeAttrMappingDTO> codeSystemObjectMap = codeAttrMapGroupAttrDTOS.stream().filter(codeAttrMappingDTO -> codeAttrMappingDTO != null && StringUtils.isNotBlank(codeAttrMappingDTO.getSourceAttrName())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getSourceAttrName(), t -> t));
      SheetDataSet dataSet= sheetDataSetList.get(0);
      List<String> titleRowData = dataSet.getColName();
      Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap = new HashMap<>();
      getGroupCodeFieldIndexMap(titleRowData,codeAttrMapGroupAttrDTOS,fieldIndexMap);
      //需要判断是否所有的属性都在模板上了
      List<CodeClassifyTemplateAttrVO> unExistAttrVOs = attrVOS.stream().filter(s -> !fieldIndexMap.containsValue(s.getId().toLowerCase(Locale.ROOT))
         && com.alibaba.cloud.commons.lang.StringUtils.isBlank(s.getComponentRule()) && com.alibaba.cloud.commons.lang.StringUtils.isBlank(s.getClassifyInvokeAttr())//组合规则和分类注入确实没给用户导出去
      ).collect(Collectors.toList());
      if(!CollectionUtils.isEmpty(unExistAttrVOs)){
         String message=unExistAttrVOs.stream().map(CodeClassifyTemplateAttrVO::getName).collect(Collectors.joining(SERIAL_UNIT_SPACE));
         throw new VciBaseException("【" + message + "】这些属性在excel中没有找到");
      }
      List<ClientBusinessObject> cboList = new ArrayList<>();
      List<SheetRowData> rowDataList = dataSet.getRowData();
      getExportGroupCodeDatas(fieldIndexMap,rowDataList,cboList);//构建数据对象
      List<String> codeList= cboList.stream().map(ClientBusinessObject::getId).collect(Collectors.toList());
      List<Map<String,String>>dataList=new ArrayList<>();
      getDatas(classifyFullInfo,templateVO,execGroupCodePortDataDTO.getFieldList(),dataList,codeList);
      //查询系统中存在
      if(!CollectionUtils.isEmpty(dataList)){
      }
      return "";
   }
   /**
    *
    * @param fieldIndexMap
    * @param rowDataList
    * @param cboList
    */
   private void getExportGroupCodeDatas(Map<Integer,String> fieldIndexMap,List<SheetRowData> rowDataList,List<ClientBusinessObject>cboList){
      rowDataList.stream().forEach(sheetRowData -> {
         sheetRowData.getData().forEach((index,value)->{
            ClientBusinessObject cbo=new ClientBusinessObject();
            String field = fieldIndexMap.get(index);
            if (StringUtils.isBlank(field)) {
               throw new VciBaseException("第" + (index + 1) + "列的标题在系统中不存在");
            }
            try {
               cbo.setAttributeValueWithNoCheck(field, value);
               if (WebUtil.isDefaultField(field)) {
                  WebUtil.setValueToField(field, cbo, value);
               }
            } catch (VciBaseException e) {
               log.error("设置属性的值错误", e);
            }
            cboList.add(cbo);
         });
      });
   }
   /***
    * 集团导出模板属性映射信息获取
    * @param templateVO
    * @param execGroupCodePortDataDTO
    */
   private void createExportGroupCodeMapConfig(CodeClassifyTemplateVO templateVO,ExecGroupCodePortDataDTO execGroupCodePortDataDTO){
      String classOid=templateVO.getCodeclassifyoid();
@@ -4746,23 +4833,53 @@
         execGroupCodePortDataDTO.setColName(colNameList);
      }
   }
   /***
    * 查询数据
    * 集团码属性转换
    * @param titleRowData
    * @param codeAttrMapGroupAttrDTOS
    * @param fieldIndexMap
    */
   private void getGroupCodeFieldIndexMap(List<String> titleRowData,List<CodeAndGroupCodeAttrMappingDTO> codeAttrMapGroupAttrDTOS,Map<Integer/**列号**/,String/**字段的名称**/> fieldIndexMap){
      Map<String, CodeAndGroupCodeAttrMappingDTO> codeSystemObjectMap = codeAttrMapGroupAttrDTOS.stream().filter(codeAttrMappingDTO -> codeAttrMappingDTO != null && StringUtils.isNotBlank(codeAttrMappingDTO.getSourceAttrName())).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getSourceAttrName(), t -> t));
      for (int i = 0; i < titleRowData.size(); i++) {
         String title = titleRowData.get(i);
         CodeAndGroupCodeAttrMappingDTO codeAndGroupCodeAttrMappingDTO =codeSystemObjectMap.get(title.replace(KEY_ATTR_CHAR,"").replace(REQUIRED_CHAR,""));
         String id=codeAndGroupCodeAttrMappingDTO.getTargetAttrKey();
         if(com.alibaba.cloud.commons.lang.StringUtils.isBlank(id) && "集团码".equalsIgnoreCase(title)){
            id = CODE_GROUP_FIELD;
         }
         if(com.alibaba.cloud.commons.lang.StringUtils.isBlank(id) && "企业编码".equalsIgnoreCase(title)){
            id = CODE_FIELD;
         }
         if(com.alibaba.cloud.commons.lang.StringUtils.isNotBlank(id)){
            fieldIndexMap.put(i,id);
         }
      }
   }
   /***
    * 查询未有集团码的数据
    * @param classifyFullInfo
    * @param templateVO
    * @param selectFieldList
    * @param dataList
    */
   private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList){
   private void getDatas(CodeClassifyFullInfoBO classifyFullInfo,CodeClassifyTemplateVO templateVO,LinkedList<String> selectFieldList,List<Map<String,String>>dataList,List<String> codeList ){
      //先查询数据
      String btmTypeId = classifyFullInfo.getTopClassifyVO().getBtmTypeId();
      String codeClassifyOid=classifyFullInfo.getCurrentClassifyVO().getOid();
      Map<String, String> conditionMap = new HashMap<>();
      Map<String, String> conditionMap=new HashMap<>();
      if(conditionMap == null){
         conditionMap = new HashMap<>();
      }
      if(conditionMap.containsKey(VciQueryWrapperForDO.OID_FIELD)){
         conditionMap.put(VciQueryWrapperForDO.OID_FIELD,QueryOptionConstant.IN + "(" + VciBaseUtil.toInSql(conditionMap.get(VciQueryWrapperForDO.OID_FIELD)) + ")");
      }
      if(!CollectionUtils.isEmpty(codeList)){
         conditionMap.put("id_in",VciBaseUtil.array2String(codeList.toArray(new String[]{})));
      }
      conditionMap.put("codeclsfpath","*" + codeClassifyOid + "*");
      conditionMap.put("groupcode_null", "null");
      conditionMap.put("lastr", "1");