Эх сурвалжийг харах

fix 承保规则中如果出现两个逗号则转化为或字

liub 1 сар өмнө
parent
commit
7d489965f7

+ 14 - 0
commons/src/main/java/com/jzg/commons/util/StringUtils.java

@@ -783,4 +783,18 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils
         StrSubstitutor strSubstitutor = new StrSubstitutor(valuesMap, "%", "%");
         return strSubstitutor.replace(content);
     }
+
+    /**
+     * 将字符串中两个及以上相邻的逗号(中文","或英文",")替换为"或"字
+     * 例如:"a,,b" -> "a或b";"a,,b" -> "a或b";"a,b"(单个逗号)保持原样
+     *
+     * @param str 原始字符串,可为null
+     * @return 替换后的字符串,若入参为null则返回null
+     */
+    public static String convertAdjacentCommaToOr(String str) {
+        if (str == null) {
+            return null;
+        }
+        return str.replaceAll("[,,]{2,}", "; 或 ");
+    }
 }

+ 3 - 4
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementCostServiceImpl.java

@@ -1,7 +1,6 @@
 package com.jzg.organization.service.impl;
 
 import cn.hutool.core.bean.BeanUtil;
-import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.json.JSONUtil;
@@ -45,9 +44,7 @@ import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
-import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -265,7 +262,7 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
                 if (StringUtils.isNotEmpty(ruleCondition.getMin()) && ruleCondition.getMin().contains(",")){
                     ruleCondition.setMinArray(Arrays.asList(ruleCondition.getMin().split(",")));
                 }else {
-                    ruleCondition.setMinArray(Arrays.asList(ruleCondition.getMin()));
+                    ruleCondition.setMinArray(Collections.singletonList(ruleCondition.getMin()));
                     //ruleCondition.setMinArray(Collections.singletonList(ruleCondition.getMin()));
                 }
 
@@ -412,6 +409,8 @@ public class PtlAgreementCostServiceImpl extends ServiceImpl<PtlAgreementCostMap
             if(item.getRuleDescription() != null && !item.getRuleDescription().isEmpty()){
                 item.setRuleDescription(item.getRuleDescription().substring(0,item.getRuleDescription().length()-1));
             }
+            // ruleDescription中出现两个相邻的","或","时,转换为"或"字
+            item.setRuleDescription(StringUtils.convertAdjacentCommaToOr(item.getRuleDescription()));
             item.setAuditPersonName(userName2Name.getOrDefault(item.getAuditPerson(),item.getAuditPerson()));
         });
         return HttpResult.ok(costManagementVoPage);

+ 7 - 1
tenant/organization/src/main/java/com/jzg/organization/service/impl/PtlAgreementUndwrtRulesServiceImpl.java

@@ -14,6 +14,7 @@ import com.jzg.commons.entity.po.*;
 import com.jzg.commons.entity.vo.AgreementRulesVo;
 import com.jzg.commons.entity.vo.CostListVo;
 import com.jzg.commons.exception.SystemException;
+import com.jzg.commons.util.StringUtils;
 import com.jzg.commons.util.idgen.IdGenerate;
 import com.jzg.organization.mapper.PtlAgreementUndwrtRulesAttrLinkMapper;
 import com.jzg.organization.mapper.PtlAgreementUndwrtRulesMapper;
@@ -80,6 +81,8 @@ public class PtlAgreementUndwrtRulesServiceImpl extends ServiceImpl<PtlAgreement
             }
             // 相同parentId的规则合并为一条,ruleDescription以","拼接
             rulesVos = mergeByParentId(rulesVos);
+            // ruleDescription中出现两个相邻的","或","时,转换为"或"字
+            rulesVos.forEach(vo -> vo.setRuleDescription(StringUtils.convertAdjacentCommaToOr(vo.getRuleDescription())));
             // 查询费用:对合并后的规则,匹配同一parentId下所有规则的费用
             for (AgreementRulesVo rulesVo : rulesVos) {
                 List<CostListVo> allCostVos = new ArrayList<>();
@@ -390,6 +393,8 @@ public class PtlAgreementUndwrtRulesServiceImpl extends ServiceImpl<PtlAgreement
                 String ruleDescription = CollUtil.isNotEmpty(andAttrLinks)
                         ? buildDesc(andAttrLinks, undwrtRulesAttrList)
                         : oldRuleDescription;
+                // 相邻的","或","转换为"或"字
+                ruleDescription = StringUtils.convertAdjacentCommaToOr(ruleDescription);
 
                 if (isExisting) {
                     // 使用 LambdaUpdateWrapper 显式指定更新字段,避免 updateById 将 null 字段写入 SQL
@@ -716,7 +721,8 @@ public class PtlAgreementUndwrtRulesServiceImpl extends ServiceImpl<PtlAgreement
                 }
             }
         }
-        return desc.toString();
+        // 相邻的","或","转换为"或"字
+        return StringUtils.convertAdjacentCommaToOr(desc.toString());
     }
 
     private String radioIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink ptlAgreementProductCostsAttrLink) {