ludc
2024-02-29 8ef9e366be48dc5e8e52617ea8ed48b37a0e1f74
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmIOServiceImpl.java
@@ -12,6 +12,7 @@
import com.vci.ubcs.code.bo.CodeTemplateAttrSqlBO;
import com.vci.ubcs.code.dto.*;
import com.vci.ubcs.code.entity.CodeAllCode;
import com.vci.ubcs.code.entity.CodeSynonym;
import com.vci.ubcs.code.enumpack.*;
import com.vci.ubcs.code.lifecycle.CodeAllCodeLC;
import com.vci.ubcs.code.mapper.CommonsMapper;
@@ -67,6 +68,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import javax.xml.bind.ValidationEvent;
import java.beans.BeanInfo;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
@@ -96,7 +98,6 @@
@Service
@Slf4j
public class MdmIOServiceImpl implements MdmIOService {
   /**
    * 字段
@@ -142,7 +143,7 @@
    * 模板的服务
    */
   @Resource
   private CodeClstemplateServiceImpl templateService;
   private ICodeClstemplateService templateService;
   /**
    * 主数据引擎的服务
@@ -165,35 +166,47 @@
   private ICodeKeyAttrRepeatService keyRuleService;
   /**
    * 近义词规则查询服务
    */
   @Autowired ICodeSynonymService codeSynonymService;
   /**
    * 公式的服务
    */
   @Autowired
   private FormulaServiceImpl formulaService;
   /**
    * 规则的服务
    */
   @Autowired
   private ICodeRuleService ruleService;
   /**
    * 业务类型的服务
    */
   @Autowired
   private IBtmTypeClient btmTypeClient;
   /***
    * 申请集团编码服务
    */
   @Resource
   private IMdmInterJtClient mdmInterJtClient;
   /***
    * 密级服务
    */
   @Resource
   private IWebSecretClient secretService;
   /**
    * 日志保存工具类
    */
   @Autowired
   private SaveLogUtil saveLogUtil;
   /**
    * 客户现场excel为老版本,导出的总数限制为65535
@@ -959,9 +972,7 @@
         //最后弄组合规则
         batchSwitchComponentAttrOnOrder(attrVOS,allCboList);
         Map<String, ClientBusinessObject> rowIndexCboMap = allCboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t));
         List<ClientBusinessObject> needSaveCboList = allCboList.stream().filter(cbo -> {
            String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
@@ -971,6 +982,7 @@
         Map<String,String>resembleMap=new HashMap<>();
         List<DataResembleVO> dataResembleVOS=new ArrayList<>();
         String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId();
         //相似项查询规则
         bathcResembleQuery(codeClassifyOid,templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
         if(resembleMap.size()>0) {
            if(!CollectionUtils.isEmpty(dataResembleVOS)) {
@@ -1280,6 +1292,7 @@
            Map<String, String> resembleMap = new HashMap<>();
            List<DataResembleVO> dataResembleVOS = new ArrayList<>();
            String btmtypeid = classifyFullInfo.getTopClassifyVO().getBtmTypeId();
            // 相似项查询
            bathcResembleQuery(templateVO.getCodeclassifyoid(), templateVO, needSaveCboList, resembleMap, btmtypeid, dataResembleVOS);
            if (resembleMap.size() > 0) {
               if (!CollectionUtils.isEmpty(dataResembleVOS)) {
@@ -1287,6 +1300,7 @@
                  createRedisDatas(uuid + "-resemble", templateVO, rowIndexCboMap, dataSet, fieldIndexMap, resembleMap, false);
               }
            }
            //生成class缓存
            Map<String, String> rowIndexClsOidMap = cboList.stream().filter(cbo -> cbo != null).collect(Collectors.toList()).stream().collect(Collectors.toMap(s -> s.getAttributeValue((IMPORT_ROW_INDEX)), t -> t.getAttributeValue(CODE_CLASSIFY_OID_FIELD)));
            createRedisByCodeClassify(uuid + "-class",templateVO,dataSet,fieldIndexMap,true);
@@ -1759,6 +1773,7 @@
         Map<String,String>resembleMap=new HashMap<>();
         List<DataResembleVO> dataResembleVOS=new ArrayList<>();
         String btmtypeid= classifyFullInfo.getTopClassifyVO().getBtmTypeId();
         //相似项查询
         bathcResembleQuery(orderDTO.getCodeClassifyOid(),templateVO,needSaveCboList,resembleMap,btmtypeid,dataResembleVOS);
         if(resembleMap.size()>0) {
            isCreateUUid=true;
@@ -3083,18 +3098,27 @@
      //注意的是keyRuleVO可能为空,表示不使用规则控制
      //获取所有的关键属性
      Map<String, CodeClassifyTemplateAttrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
      // TODO:2024-02-01 先获取配置了近义词查询规则的属性,不同于关键属性,设置了近义词查询规则的属性可能是多条不同的近义词查询规则
      Map<String, CodeClassifyTemplateAttrVO> sysonymAttrMaps = templateVO.getAttributes().stream().filter(item -> Func.isNotBlank(item.getSysonymRuleOids())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
      // 获取是否有配置近义词查询规则属性
      Map<String, List<CodeSynonym>> codeSynonymMaps = new HashMap<>();
      if(!sysonymAttrMaps.isEmpty()){
         // 查询近义词规则,存储方式key:属性id,value近义词查询规则列表
         codeSynonymMaps = codeSynonymService.getCodeSynonymByOids(sysonymAttrMaps);
      }
      Map<String, String> conditionMap = new HashMap<>();
      boolean trimAll = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag());
      //全部去空的优先级大于去空
      boolean trim = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorespaceflag());
      boolean ignoreCase = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorecaseflag());
      boolean ignoreWidth = keyRuleVO == null ? false : VciBaseUtil.getBoolean(keyRuleVO.getIgnorewidthflag());
      Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps;
      ketAttrMap.forEach((attrId, attrVO) -> {
         String value = getValueFromOrderDTO(orderDTO, attrId);
         if (value == null) {
            value = "";
         }
         engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
         engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
      });
      //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可
@@ -4370,7 +4394,7 @@
      }
   }
   /**
    * 校验关键属性
    * 校验关键属性,和近义词查询规则
    * @param classifyFullInfo 分类的全部信息
    * @param templateVO 模板的内容,必须包含模板属性
    * @param cboList 批量的数据
@@ -4382,7 +4406,16 @@
      CodeKeyAttrRepeatVO keyRuleVO = keyRuleService.getRuleByClassifyFullInfo(classifyFullInfo);
      //注意的是keyRuleVO可能为空,表示不使用规则控制
      //获取所有的关键属性
      Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
      Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> keyAttrMap = templateVO.getAttributes().stream().filter(s -> VciBaseUtil.getBoolean(s.getKeyAttrFlag())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
      // TODO:2024-02-01 先获取配置了近义词查询规则的属性,不同于关键属性,设置了近义词查询规则的属性可能是多条不同的近义词查询规则
      Map<String, CodeClassifyTemplateAttrVO> sysonymAttrMaps = templateVO.getAttributes().stream().filter(item -> Func.isNotBlank(item.getSysonymRuleOids())).collect(Collectors.toMap(s -> s.getId().toLowerCase(Locale.ROOT), t -> t));
      // 获取是否有配置近义词查询规则属性
      Map<String, List<CodeSynonym>> codeSynonymMaps = new HashMap<>();
      if(!sysonymAttrMaps.isEmpty()){
         // 查询近义词规则,存储方式key:属性id,value近义词查询规则列表
         codeSynonymMaps = codeSynonymService.getCodeSynonymByOids(sysonymAttrMaps);
      }
      boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag());
      //全部去空的优先级大于去空
@@ -4394,15 +4427,18 @@
      CodeImportResultVO resultVO = new CodeImportResultVO();
      resultVO.setKeyAttrRuleInfo(String.format(keyRuleVO ==null?"":"查询规则:去除空格--{0},忽略大小写--{1},忽略全半角--{2},忽略全部空格--{3}",
         new String[]{trim?"是":"否",ignoreCase?"是":"否",ignoreWidth?"是":"否",trimAll?"是":"否"}));
      //resultVO.setSelfRepeatRowIndexList(getSelfRepeatRowIndex(ketAttrMap,cboList,keyRuleVO));
      getSelfRepeatRowIndex(ketAttrMap,cboList,keyRuleVO,resultVO);
      //resultVO.setSelfRepeatRowIndexList(getSelfRepeatRowIndex(keyAttrMap,cboList,keyRuleVO));
      // 先在表格中查询关键属性和近义词转换后重复的列
      getSelfRepeatRowIndex(keyAttrMap,cboList,keyRuleVO,codeSynonymMaps,resultVO);
      // 再在表格中查询近义词查询规则的列
      //getSelfRepeatSysnomRowIndex(sysonymAttrMaps,cboList,codeSynonymMaps,resultVO);
      if(!CollectionUtils.isEmpty(resultVO.getSelfRepeatRowIndexList())){
         //我们移除本身重复的数据
         cboList = cboList.stream().filter(s->!resultVO.getSelfRepeatRowIndexList().contains(s.getAttributeValue(IMPORT_ROW_INDEX))).collect(Collectors.toList());
      }
      //2.判断关键属性在系统里是否重复
      //因为数据量很大,所以得想办法并行
      //SessionInfo sessionInfo = VciBaseUtil.getCurrentUserSessionInfo();
      Map<String,List<BaseModel>> indexTODataMap=new ConcurrentHashMap<>();
      // 查询不需要参与关键属性校验的除自己以外的所有分类oid
      final String isParticipateCheckOids = classifyService.selectLeafByParentClassifyOid(classifyFullInfo.getTopClassifyVO().getOid(), classifyFullInfo.getCurrentClassifyVO().getOid());
@@ -4411,25 +4447,29 @@
      //  ,所以暂时将parallelStream改成了stream,改成了stream之后发现巨慢
      // customForkJoinPool控制并发度
      List<ClientBusinessObject> finalCboList = cboList;
      Map<String, List<CodeSynonym>> finalCodeSynonymMaps = codeSynonymMaps;
      List<ClientBusinessObject> repeatDataMap = (List<ClientBusinessObject>) customForkJoinPool.submit(()->{
         finalCboList.parallelStream().filter(cbo -> {
            //每行都得查询.如果其中出现了错误,我们就直接抛出异常,其余的显示
            //VciBaseUtil.setCurrentUserSessionInfo(sessionInfo);
            Map<String, String> conditionMap = new HashMap<>();
            ketAttrMap.forEach((attrId, attrVO) -> {
            keyAttrMap.forEach((attrId, attrVO) -> {
               String value =cbo.getAttributeValue(attrId.toLowerCase(Locale.ROOT));
               if (value == null) {
                  value = "";
               }
               value= value.replace(REQUIRED_CHAR,SPECIAL_CHAR);
               engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
               // 关键属性查询条件map获取
               engineService.wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
            });
            if (!CollectionUtils.isEmpty(ketAttrMap)) {
            if (!CollectionUtils.isEmpty(keyAttrMap)) {
               // 添加不参与关键属性校验的分类oid判断
               if(Func.isNotBlank(isParticipateCheckOids)){
                  conditionMap.put("t.codeclsfid",QueryOptionConstant.NOTIN+isParticipateCheckOids);
               }
               if(isEdit){//如果是更改则需排除系统本身
               //如果是更改则需排除系统本身
               if(isEdit){
                  conditionMap.put("t.id",QueryOptionConstant.NOTEQUAL+cbo.getId());
               }
               conditionMap.put("t.lastr", "1");
@@ -4574,14 +4614,14 @@
   }
   /**
    * 获取导入的内容中关键属性重复的行号
    * 获取导入的内容中关键属性近义词转换后重复的行号
    * @param ketAttrMap 关键属性的映射
    * @param dataList 导入的数据
    * @param keyRuleVO 关键属性控制规则
    * @return 重复的行号
    */
   private void getSelfRepeatRowIndex(Map<String/**属性的编号**/, CodeClassifyTemplateAttrVO> ketAttrMap,
                              List<ClientBusinessObject> dataList,CodeKeyAttrRepeatVO keyRuleVO,CodeImportResultVO resultVO){
                              List<ClientBusinessObject> dataList,CodeKeyAttrRepeatVO keyRuleVO,/*近义词查询规则*/Map<String,List<CodeSynonym>> codeSynonymMaps, CodeImportResultVO resultVO){
      Set<String> selfRepeatRowIndexList = new CopyOnWriteArraySet<>();
      Map<String,List<String>> keyAttrOkOidTORepeatOidMap=new HashMap<>();
      boolean trimAll =keyRuleVO ==null?false: VciBaseUtil.getBoolean(keyRuleVO.getIgnoreallspaceflag());
@@ -4597,9 +4637,10 @@
         String rowIndex = cbo.getAttributeValue(IMPORT_ROW_INDEX);
         String oid=cbo.getOid();
         StringBuilder sb = new StringBuilder();
         for (int i = 0; i < attrVOList.size(); i++) {
            CodeClassifyTemplateAttrVO attrVO = attrVOList.get(i);
            String attrId = attrVO.getId().toLowerCase(Locale.ROOT);
         // TODO: 2024-02-25改造实现近义词查询规则功能;关键属性重复校验值处理
         attrVOList.stream().forEach(item->{
            String attrId = item.getId().toLowerCase(Locale.ROOT);
            String value = cbo.getAttributeValue( attrId);
            if (value == null) {
               value = "";
@@ -4616,8 +4657,9 @@
            if(ignoreWidth){
               value = VciBaseUtil.toDBC(value);
            }
            value = mdmEngineService.getValueToSynony(codeSynonymMaps.get(attrId),value);
            sb.append(value).append("${ks}");
         }
         });
         String keyString = sb.toString();
         if(rowIndexKeyStringMap.containsValue(keyString) && StringUtils.isNotBlank(keyString)){
            selfRepeatRowIndexList.add(rowIndex);
@@ -4628,7 +4670,6 @@
               if(keyAttrOkOidTORepeatOidMap.containsKey(okOid)){
                  List<String> oldOidList = keyAttrOkOidTORepeatOidMap.get(okOid);
                  newOidList.addAll(oldOidList);
               }
               keyAttrOkOidTORepeatOidMap.put(okOid,newOidList);
            }
@@ -4667,6 +4708,7 @@
         }
      }
   }
   private List<ClientBusinessObject> ChangeMapTOClientBusinessObjects(List<Map<String,String>> oldDataMap){
      List<ClientBusinessObject> clientBusinessObjectList=new ArrayList<>();
      DefaultAttrAssimtUtil.mapToLowerCase(oldDataMap,true);