田源
2024-03-01 02b3d584d201ca7cb8a024fd151fe6eddbf43def
Source/UBCS/ubcs-service/ubcs-code/src/main/java/com/vci/ubcs/code/service/impl/MdmEngineServiceImpl.java
@@ -177,6 +177,11 @@
   private MdmProductCodeService productCodeService;
   /**
    * 近义词规则查询服务
    */
   @Autowired ICodeSynonymService codeSynonymService;
   /**
    * 可输可选的服务
    */
   @Resource
@@ -358,7 +363,6 @@
    */
   @Autowired
   private SaveLogUtil saveLogUtil;
   /**
    * 使用分类的主键获取可以使用的模板对象
@@ -755,27 +759,36 @@
      //注意的是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 = "";
         }
         wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
         wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
      });
      //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可
      if (!CollectionUtils.isEmpty(conditionMap)) {
         // TODO: 同一个库判重不需要区分分类oid
         // conditionMap.put("CODETEMPLATEOID","'" + orderDTO.getTemplateOid() + "'");
//         final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " t where 1 = 1 "};
         // final String[] sql = {"select count(*) from " + VciBaseUtil.getTableName(classifyFullInfo.getTopClassifyVO().getBtmtypeid()) + " t where 1 = 1 "};
         R<List<BtmTypeVO>> listR = btmTypeClient.selectByIdCollection(Collections.singletonList(classifyFullInfo.getTopClassifyVO().getBtmTypeId()));
//            String referTable = VciBaseUtil.getTableName(referVO.getReferType());
         // String referTable = VciBaseUtil.getTableName(referVO.getReferType());
         if (!listR.isSuccess() || listR.getData().size() == 0) {
            throw new VciBaseException("传入业务类型未查询到相应表单,请检查!");
         }
@@ -800,7 +813,7 @@
         if (Func.isNotEmpty(isParticipateCheckOids)) {
            sql[0] += " and codeclsfid not in(" + isParticipateCheckOids + ")";
         }
//         if (boService.queryCountBySql(sql[0], new HashMap<>()) > 0) {
         // if (boService.queryCountBySql(sql[0], new HashMap<>()) > 0) {
         List<String> repeatData = commonsMapper.selectList(sql[0]);
         if (!repeatData.isEmpty()) {
            String ruleInfoMsg = keyRuleVO == null ? "" : "查询规则:去除空格--{0},忽略大小写--{1},忽略全半角--{2},忽略全部空格--{3}";
@@ -825,18 +838,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 = "";
         }
         wrapperKeyAttrConditionMap(value, keyRuleVO, attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
         wrapperKeyAttrConditionMap(value, keyRuleVO, finalCodeSynonymMaps.get(attrId), attrId, trim, ignoreCase, ignoreWidth, trimAll, conditionMap);
      });
      //没有限制分类,但是一个模板只可能在一个业务类型里面,所以直接查询这个业务类型即可
@@ -927,7 +949,7 @@
      }
      //是否系列
      if (!codeBZApplyDTO.isSeries()) {
         boolean isSeriesValue = codeBZApplyDTO.getData().get(isSeries).equals("true") ? true : false;
         boolean isSeriesValue = Func.toBoolean(codeBZApplyDTO.getData().get(isSeries));
         codeBZApplyDTO.setSeries(isSeriesValue);
      }
      //原标准号
@@ -947,7 +969,7 @@
      }
      //是否变更系列
      if (!codeBZApplyDTO.isEditSeries()) {
         boolean isEditSeriesValue = codeBZApplyDTO.getData().get(isEditSeries).equals("true") ? true : false;
         boolean isEditSeriesValue = Func.toBoolean(codeBZApplyDTO.getData().get(isEditSeries));
         codeBZApplyDTO.setEditSeries(isEditSeriesValue);
      }
      VciBaseUtil.alertNotNull(codeBZApplyDTO.getOperationType(), "操作类型",
@@ -965,7 +987,7 @@
      } else if (codeBZApplyDTO.getOperationType().equals(CodeBZOperationTypeEnum.CODE_BZ_DISABLE.getValue())) {//作废
         code = amendmentDataBZ(codeBZApplyDTO, authUser);
         createChangeOder(code, codeBZApplyDTO, authUser);
      } else if (codeBZApplyDTO.getOperationType().equals(CodeBZOperationTypeEnum.CODE_BZ_AMENDMENT.getValue())) {//备查
      } else if (codeBZApplyDTO.getOperationType().equals(CodeBZOperationTypeEnum.CODE_BZ_FOR_REFERENCE.getValue())) {//备查
         code = amendmentDataBZ(codeBZApplyDTO, authUser);
         createChangeOder(code, codeBZApplyDTO, authUser);
      }
@@ -1235,14 +1257,18 @@
    * @param conditionMap 查询条件
    */
   @Override
   public void wrapperKeyAttrConditionMap(String value, CodeKeyAttrRepeatVO keyRuleVO, String attrId,
   public void wrapperKeyAttrConditionMap(String value, CodeKeyAttrRepeatVO keyRuleVO,
                                 List<CodeSynonym> codeSynonymMaps, String attrId,
                                 boolean trim, boolean ignoreCase, boolean ignoreWidth,
                                 boolean trimAll, Map<String, String> conditionMap) {
      boolean ignoreSpace = trim || trimAll;
      if (StringUtils.isBlank(value)) {
         //为空的时候,不能用QueryOperation.ISNULL,平台不知道啥时候不处理这种了
         //值为空的时候,不能用QueryOperation.ISNULL,平台不知道啥时候不处理这种了
         conditionMap.put("t." + attrId, QueryOptionConstant.ISNULL);
      } else {
         //近义词查询规则valu值转换
         value = this.getValueToSynony(codeSynonymMaps, value);
         if (keyRuleVO != null) {
            String queryKey = "";
            String queryValue = "";
@@ -1278,7 +1304,7 @@
            conditionMap.put(queryKey, queryValue);
         } else {
            if (StringUtils.isNotBlank(value)) {
               //为空的时候不代表不校验,只是不去除相关的信息
               //关键属性查重规则为空的时候不代表不校验,只是不去除相关的信息
               conditionMap.put("nvl(" + "t." + attrId + ",'/')", "'" + SpecialCharacterConverter.escapeSpecialCharacters(value) + "'");
            } else {
               conditionMap.put("t." + attrId, QueryOptionConstant.ISNULL);
@@ -1288,17 +1314,20 @@
   }
   /**
    * 封装近义词查询规则属性的查询语句
    * @param value 当前的值
    * @param keyRuleVO 属性的编号
    * @param attrId
    * @param conditionMap 查询条件
    * 近义词查询规则转换
    * @param codeSynonymMaps
    * @param value
    * @return
    */
   @Override
   public void wrapperSynonymAttrConditionMap(String value, CodeKeyAttrRepeatVO keyRuleVO, String attrId, Map<String, String> conditionMap) {
      // map构造思路:1、先完成正向替换sql值
      // 2、再完成反向替换sql值
   public String getValueToSynony(/*近义词查询规则*/List<CodeSynonym> codeSynonymMaps,String value){
      // 获取并判断是否配置了近义词查询规则
      // TODO:近义词替换成源值(源值是正确的值,近义词是相当于输错笔误的字符)
      if(!codeSynonymMaps.isEmpty()){
         for (int i = 0; i < codeSynonymMaps.size(); i++) {
            value = value.replace(codeSynonymMaps.get(i).getSynonymValue(),codeSynonymMaps.get(i).getSourceValue());
         }
      }
      return value;
   }
   /**