Przeglądaj źródła

fix 费用规则出现 两个晋c问题

liub 2 tygodni temu
rodzic
commit
b42c4fa0b7

+ 21 - 22
tenant/organization/src/main/java/com/jzg/organization/component/BuildDescUtils.java

@@ -41,14 +41,13 @@ public class BuildDescUtils {
                 desc.append(radioIdentifying(ptlAgreementUndwrtRulesAttr, link)).append(";\t\t");
             } else if ("checkbox".equals(attrType) || "select".equals(attrType)) {
                 if (link.getMinArray() != null && link.getMinArray().length > 0) {
-                    desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含");
-                    for (PtlAgreementUndwrtRulesDictLabal labal : link.getDictLabal()) {
-                        if (Arrays.asList(link.getMinArray()).contains(labal.getCode())) {
-                            desc.append(null != labal ? labal.getName() : "").append(",");
-                        }
-                    }
-                    // 条件描述后补充一个分号
-                    desc.append(",");
+                    // minArray 转 Set,避免循环内反复创建 List 做 contains 查找
+                    Set<String> minCodes = Arrays.stream(link.getMinArray()).collect(Collectors.toSet());
+                    String names = Optional.ofNullable(link.getDictLabal()).orElse(Collections.emptyList()).stream()
+                            .filter(labal -> minCodes.contains(labal.getCode()))
+                            .map(PtlAgreementUndwrtRulesDictLabal::getName)
+                            .collect(Collectors.joining(","));
+                    desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(names).append(";\t\t");
                 } else {
                     desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(link.getMin()).append(";\t\t");
                 }
@@ -142,29 +141,29 @@ public class BuildDescUtils {
         return ptlAgreementUndwrtRulesAttr.getAttrName() + "为" + ptlAgreementUndwrtRulesDictLabal.getName();
     }
 
-    public static String selectIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink ptlAgreementProductCostsAttrLink) {
+    public static String selectIdentifying(PtlAgreementUndwrtRulesAttr undwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink link) {
         StringBuilder returnMsg = new StringBuilder();
-        returnMsg.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("为");
         // 兼容 min 逗号分隔存储,保证 minArray 有值
-        if (ptlAgreementProductCostsAttrLink.getMinArray() == null) {
-            String minStr = ptlAgreementProductCostsAttrLink.getMin();
+        if (link.getMinArray() == null) {
+            String minStr = link.getMin();
             if (minStr != null && !minStr.isEmpty()) {
-                ptlAgreementProductCostsAttrLink.setMinArray(minStr.split(","));
+                link.setMinArray(minStr.split(","));
             }
         }
 
         // 优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
-        List<PtlAgreementUndwrtRulesDictLabal> dictLabalList = getDictLabalList(ptlAgreementUndwrtRulesAttr, ptlAgreementProductCostsAttrLink);
+        List<PtlAgreementUndwrtRulesDictLabal> dictLabalList = getDictLabalList(undwrtRulesAttr, link);
 
         // 用字典标签的 code 匹配 minArray 中的每一项
-        if (ptlAgreementProductCostsAttrLink.getMinArray() != null) {
-            for (String item : ptlAgreementProductCostsAttrLink.getMinArray()) {
-                PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = dictLabalList.stream()
-                        .filter(x -> x.getCode() != null && x.getCode().equals(item)).findAny().orElse(null);
-                if (ptlAgreementUndwrtRulesDictLabal != null) {
-                    returnMsg.append(ptlAgreementUndwrtRulesDictLabal.getName()).append(",");
-                }
-            }
+        if (link.getMinArray() != null && link.getMinArray().length > 0) {
+            // minArray 转 Set,避免循环内反复创建 List 做 contains 查找
+            Set<String> minCodes = Arrays.stream(link.getMinArray()).collect(Collectors.toSet());
+            String names = Optional.ofNullable(dictLabalList).orElse(Collections.emptyList()).stream()
+                    .filter(labal -> minCodes.contains(labal.getCode()))
+                    .map(PtlAgreementUndwrtRulesDictLabal::getName)
+                    .collect(Collectors.joining(","));
+            returnMsg.append(undwrtRulesAttr.getAttrName()).append("包含").append(names).append(",");
+
         }
         return returnMsg.toString();
     }