|
|
@@ -14,160 +14,179 @@ public class BuildDescUtils {
|
|
|
/**
|
|
|
* 遍历费用属性描述文字
|
|
|
*
|
|
|
- * @param linkList
|
|
|
- * @param undwrtRulesAttrList
|
|
|
+ * @param linkList 属性记录列表
|
|
|
+ * @param undwrtRulesAttrList 属性定义列表
|
|
|
* @return
|
|
|
*/
|
|
|
public static String buildDesc(String companyId, List<PtlAgreementUndwrtRulesAttr> linkList, List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList) {
|
|
|
StringBuilder desc = new StringBuilder();
|
|
|
- Map<String, PtlAgreementUndwrtRulesAttr> attrMap = undwrtRulesAttrList.stream().filter(attr -> "all".equals(attr.getCompanyIds()) || (attr.getCompanyIds() != null && attr.getCompanyIds().equals(companyId))).collect(Collectors.toMap(PtlAgreementUndwrtRulesAttr::getAttrCode, Function.identity()));
|
|
|
+ // 仅保留当前主体可用(all 或匹配 companyId)的属性定义
|
|
|
+ Map<String, PtlAgreementUndwrtRulesAttr> attrMap = undwrtRulesAttrList.stream()
|
|
|
+ .filter(attr -> "all".equals(attr.getCompanyIds()) || Objects.equals(attr.getCompanyIds(), companyId))
|
|
|
+ .collect(Collectors.toMap(PtlAgreementUndwrtRulesAttr::getAttrCode, Function.identity()));
|
|
|
// 这里进行排序,保证生成的承保规则描述是有序的
|
|
|
- linkList = linkList.stream().sorted(Comparator.comparing(PtlAgreementUndwrtRulesAttr::getAttrCode)).toList();
|
|
|
- List<PtlAgreementUndwrtRulesAttr> sortedLinks = new ArrayList<>(linkList);
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> sortedLinks = linkList.stream()
|
|
|
+ .sorted(Comparator.comparing(PtlAgreementUndwrtRulesAttr::getAttrCode))
|
|
|
+ .toList();
|
|
|
|
|
|
for (PtlAgreementUndwrtRulesAttr link : sortedLinks) {
|
|
|
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = attrMap.get(link.getAttrCode());
|
|
|
- if (ptlAgreementUndwrtRulesAttr == null) {
|
|
|
+ PtlAgreementUndwrtRulesAttr attr = attrMap.get(link.getAttrCode());
|
|
|
+ if (attr == null) {
|
|
|
continue;
|
|
|
}
|
|
|
-
|
|
|
- String attrType = ptlAgreementUndwrtRulesAttr.getAttrType();
|
|
|
-
|
|
|
+ String attrType = attr.getAttrType();
|
|
|
if ("inputNumber".equals(attrType)) {
|
|
|
- desc.append(inputNumberIdentifying(ptlAgreementUndwrtRulesAttr, link)).append(";\t\t");
|
|
|
+ desc.append(inputNumberDesc(attr.getAttrName(), link.getOperator(), link.getMin(), link.getMax())).append(";\t\t");
|
|
|
} else if ("radio".equals(attrType)) {
|
|
|
- desc.append(radioIdentifying(ptlAgreementUndwrtRulesAttr, link)).append(";\t\t");
|
|
|
+ desc.append(radioDesc(attr, link.getMin())).append(";\t\t");
|
|
|
} else if ("checkbox".equals(attrType) || "select".equals(attrType)) {
|
|
|
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(link.getDictLabal()).orElse(Collections.emptyList()).stream().filter(labal -> minCodes.contains(labal.getCode())).map(PtlAgreementUndwrtRulesDictLabal::getName).collect(Collectors.joining(","));
|
|
|
- desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append((link.getOperator() != null && "1".equals(link.getOperator())) ? "包含" : "不包含").append(names).append(";\t\t");
|
|
|
+ String names = joinDictNames(link.getDictLabal(), minCodes, ",");
|
|
|
+ desc.append(containDesc(attr.getAttrName(), link.getOperator(), names)).append(";\t\t");
|
|
|
} else {
|
|
|
- desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append((link.getOperator() != null && "1".equals(link.getOperator())) ? "包含" : "不包含").append(link.getMin()).append(";\t\t");
|
|
|
+ desc.append(containDesc(attr.getAttrName(), link.getOperator(), link.getMin())).append(";\t\t");
|
|
|
}
|
|
|
} else if ("inputTag".equals(attrType)) {
|
|
|
- desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append((link.getOperator() != null && "1".equals(link.getOperator())) ? "包含" : "不包含").append(link.getMin()).append(";\t\t");
|
|
|
+ desc.append(containDesc(attr.getAttrName(), link.getOperator(), link.getMin())).append(";\t\t");
|
|
|
}
|
|
|
}
|
|
|
- return desc.toString();
|
|
|
- }
|
|
|
-
|
|
|
- private static String radioIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttr link) {
|
|
|
- Optional<PtlAgreementUndwrtRulesDictLabal> dictLabel = Optional.ofNullable(ptlAgreementUndwrtRulesAttr.getDictLabal()).flatMap(list -> list.stream().filter(x -> x.getCode().equals(link.getMin())).findFirst());
|
|
|
-
|
|
|
- return dictLabel.map(dl -> ptlAgreementUndwrtRulesAttr.getAttrName() + "为" + dl.getName()).orElse("");
|
|
|
- }
|
|
|
-
|
|
|
- private static String inputNumberIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttr link) {
|
|
|
- String operator = link.getOperator();
|
|
|
- switch (operator) {
|
|
|
- case "1":
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "范围值" + link.getMin() + "到" + link.getMax();
|
|
|
- case "2":
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于" + link.getMin();
|
|
|
- case "3":
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于等于" + link.getMin();
|
|
|
- case "4":
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于" + link.getMax();
|
|
|
- case "5":
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于等于" + link.getMax();
|
|
|
- default:
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "未知操作符";
|
|
|
- }
|
|
|
+ // buildDesc返回的条件间以相邻双逗号分隔,此处合并为单个分号
|
|
|
+ return StringUtils.mergeAdjacentComma(desc.toString());
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 遍历承保规则属性描述文字
|
|
|
*
|
|
|
- * @param linkList
|
|
|
- * @param undwrtRulesAttrList
|
|
|
+ * @param linkList 规则因子关联记录列表
|
|
|
+ * @param undwrtRulesAttrList 属性定义列表
|
|
|
* @return
|
|
|
*/
|
|
|
public static String buildDesc(List<PtlAgreementUndwrtRulesAttrLink> linkList, List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList) {
|
|
|
StringBuilder desc = new StringBuilder();
|
|
|
+ // 属性定义按 attrCode 建索引,避免循环内逐条 stream 查找
|
|
|
+ Map<String, PtlAgreementUndwrtRulesAttr> attrMap = undwrtRulesAttrList.stream()
|
|
|
+ .collect(Collectors.toMap(PtlAgreementUndwrtRulesAttr::getAttrCode, Function.identity(), (oldItem, newItem) -> newItem));
|
|
|
// 这里进行排序,保证生成的承保规则描述是有序的
|
|
|
- linkList = linkList.stream().sorted(Comparator.comparing(PtlAgreementUndwrtRulesAttrLink::getAttrCode)).toList();
|
|
|
- List<PtlAgreementUndwrtRulesAttrLink> sortedLinks = new ArrayList<>(linkList);
|
|
|
-
|
|
|
- for (int i = 0; i < sortedLinks.size(); i++) {
|
|
|
- int finalI = i;
|
|
|
- PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = undwrtRulesAttrList.stream().filter(x -> x.getAttrCode().equals(sortedLinks.get(finalI).getAttrCode())).findAny().get();
|
|
|
+ List<PtlAgreementUndwrtRulesAttrLink> sortedLinks = linkList.stream()
|
|
|
+ .sorted(Comparator.comparing(PtlAgreementUndwrtRulesAttrLink::getAttrCode))
|
|
|
+ .toList();
|
|
|
|
|
|
- //数值范围判断
|
|
|
-
|
|
|
- if ("inputNumber".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
- desc.append(inputNumberIdentifying(ptlAgreementUndwrtRulesAttr, sortedLinks.get(i))).append(",");
|
|
|
- }
|
|
|
- if ("radio".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
- desc.append(radioIdentifying(ptlAgreementUndwrtRulesAttr, sortedLinks.get(i))).append(",");
|
|
|
- }
|
|
|
- if ("select".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
- desc.append(selectIdentifying(ptlAgreementUndwrtRulesAttr, sortedLinks.get(i)));
|
|
|
- }
|
|
|
- if ("checkbox".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
- desc.append(checkBoxIdentifying(ptlAgreementUndwrtRulesAttr, sortedLinks.get(i)));
|
|
|
+ for (PtlAgreementUndwrtRulesAttrLink link : sortedLinks) {
|
|
|
+ PtlAgreementUndwrtRulesAttr attr = attrMap.get(link.getAttrCode());
|
|
|
+ if (attr == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- if ("inputTag".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
- desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append((sortedLinks.get(i).getOperator() != null && sortedLinks.get(i).getOperator().equals("1")) ? "包含" : "不包含").append(sortedLinks.get(i).getMin()).append(",");
|
|
|
+ String attrType = attr.getAttrType();
|
|
|
+ if ("inputNumber".equals(attrType)) {
|
|
|
+ desc.append(inputNumberDesc(attr.getAttrName(), link.getOperator(), link.getMin(), link.getMax())).append(",");
|
|
|
+ } else if ("radio".equals(attrType)) {
|
|
|
+ desc.append(radioDesc(attr, link.getMin())).append(",");
|
|
|
+ } else if ("select".equals(attrType)) {
|
|
|
+ desc.append(selectIdentifying(attr, link));
|
|
|
+ } else if ("checkbox".equals(attrType)) {
|
|
|
+ desc.append(checkBoxIdentifying(attr, link));
|
|
|
+ } else if ("inputTag".equals(attrType)) {
|
|
|
+ desc.append(containDesc(attr.getAttrName(), link.getOperator(), link.getMin())).append(",");
|
|
|
}
|
|
|
}
|
|
|
// 相邻的","或","转换为"或"字
|
|
|
return StringUtils.convertAdjacentCommaToOr(desc.toString());
|
|
|
}
|
|
|
|
|
|
- public static String radioIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink ptlAgreementProductCostsAttrLink) {
|
|
|
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = ptlAgreementUndwrtRulesAttr.getDictLabal().stream().filter(x -> x.getCode().equals(ptlAgreementProductCostsAttrLink.getMin())).findAny().get();
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "为" + ptlAgreementUndwrtRulesDictLabal.getName();
|
|
|
- }
|
|
|
-
|
|
|
public static String selectIdentifying(PtlAgreementUndwrtRulesAttr undwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink link) {
|
|
|
StringBuilder returnMsg = new StringBuilder();
|
|
|
- // 兼容 min 逗号分隔存储,保证 minArray 有值
|
|
|
- if (link.getMinArray() == null) {
|
|
|
- String minStr = link.getMin();
|
|
|
- if (minStr != null && !minStr.isEmpty()) {
|
|
|
- link.setMinArray(minStr.split(","));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
+ ensureMinArray(link);
|
|
|
// 优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
|
|
|
List<PtlAgreementUndwrtRulesDictLabal> dictLabalList = getDictLabalList(undwrtRulesAttr, link);
|
|
|
-
|
|
|
// 用字典标签的 code 匹配 minArray 中的每一项
|
|
|
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((link.getOperator() != null && "1".equals(link.getOperator())) ? "包含" : "不包含").append(names).append(",");
|
|
|
+ String names = joinDictNames(dictLabalList, minCodes, ",");
|
|
|
+ returnMsg.append(containDesc(undwrtRulesAttr.getAttrName(), link.getOperator(), names)).append(",");
|
|
|
}
|
|
|
return returnMsg.toString();
|
|
|
}
|
|
|
|
|
|
public static String checkBoxIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink linkList) {
|
|
|
- StringBuilder returnMsg = new StringBuilder();
|
|
|
- returnMsg.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("为");
|
|
|
- // 兼容 min 逗号分隔存储,保证 minArray 有值
|
|
|
- if (linkList.getMinArray() == null) {
|
|
|
- String minStr = linkList.getMin();
|
|
|
- if (minStr != null && !minStr.isEmpty()) {
|
|
|
- linkList.setMinArray(minStr.split(","));
|
|
|
- }
|
|
|
- }
|
|
|
+ StringBuilder returnMsg = new StringBuilder(ptlAgreementUndwrtRulesAttr.getAttrName()).append("为");
|
|
|
+ ensureMinArray(linkList);
|
|
|
if (linkList.getMinArray() != null) {
|
|
|
// 优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
|
|
|
List<PtlAgreementUndwrtRulesDictLabal> dictLabalList = getDictLabalList(ptlAgreementUndwrtRulesAttr, linkList);
|
|
|
// code -> 字典标签 映射,避免 O(n²) 循环匹配
|
|
|
- Map<String, PtlAgreementUndwrtRulesDictLabal> dictLabalMap = dictLabalList.stream().filter(x -> x.getCode() != null).collect(Collectors.toMap(PtlAgreementUndwrtRulesDictLabal::getCode, Function.identity(), (oldItem, newItem) -> newItem));
|
|
|
+ Map<String, PtlAgreementUndwrtRulesDictLabal> dictLabalMap = dictLabalList.stream()
|
|
|
+ .filter(dictLabal -> dictLabal.getCode() != null)
|
|
|
+ .collect(Collectors.toMap(PtlAgreementUndwrtRulesDictLabal::getCode, Function.identity(), (oldItem, newItem) -> newItem));
|
|
|
for (String code : linkList.getMinArray()) {
|
|
|
- PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = dictLabalMap.get(code);
|
|
|
- returnMsg.append(ptlAgreementUndwrtRulesDictLabal != null ? ptlAgreementUndwrtRulesDictLabal.getName() : "").append(",");
|
|
|
+ PtlAgreementUndwrtRulesDictLabal dictLabal = dictLabalMap.get(code);
|
|
|
+ returnMsg.append(dictLabal != null ? dictLabal.getName() : "").append(",");
|
|
|
}
|
|
|
}
|
|
|
return returnMsg.toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 拼接"属性名 + 包含/不包含 + 值"
|
|
|
+ */
|
|
|
+ private static String containDesc(String attrName, String operator, String value) {
|
|
|
+ return attrName + ("1".equals(operator) ? "包含" : "不包含") + value;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 数值操作符描述拼接(operator: 1区间 2小于 3小于等于 4大于 5大于等于)
|
|
|
+ */
|
|
|
+ private static String inputNumberDesc(String attrName, String operator, String min, String max) {
|
|
|
+ if ("1".equals(operator)) {
|
|
|
+ return attrName + "范围值" + min + "到" + max;
|
|
|
+ } else if ("2".equals(operator)) {
|
|
|
+ return attrName + "小于" + min;
|
|
|
+ } else if ("3".equals(operator)) {
|
|
|
+ return attrName + "小于等于" + min;
|
|
|
+ } else if ("4".equals(operator)) {
|
|
|
+ return attrName + "大于" + max;
|
|
|
+ } else if ("5".equals(operator)) {
|
|
|
+ return attrName + "大于等于" + max;
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单选字典描述拼接:属性名为 + 字典名称
|
|
|
+ */
|
|
|
+ private static String radioDesc(PtlAgreementUndwrtRulesAttr attr, String code) {
|
|
|
+ return Optional.ofNullable(attr.getDictLabal()).orElse(Collections.emptyList()).stream()
|
|
|
+ .filter(dictLabal -> Objects.equals(dictLabal.getCode(), code))
|
|
|
+ .map(PtlAgreementUndwrtRulesDictLabal::getName)
|
|
|
+ .findFirst()
|
|
|
+ .map(name -> attr.getAttrName() + "为" + name)
|
|
|
+ .orElse("");
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将字典 code 集合对应的名称按 separator 拼接为字符串
|
|
|
+ */
|
|
|
+ private static String joinDictNames(List<PtlAgreementUndwrtRulesDictLabal> dictLabalList, Set<String> codes, String separator) {
|
|
|
+ return Optional.ofNullable(dictLabalList).orElse(Collections.emptyList()).stream()
|
|
|
+ .filter(dictLabal -> codes.contains(dictLabal.getCode()))
|
|
|
+ .map(PtlAgreementUndwrtRulesDictLabal::getName)
|
|
|
+ .collect(Collectors.joining(separator));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 兼容 min 逗号分隔存储:minArray 为空时将 min 按逗号拆分填充
|
|
|
+ */
|
|
|
+ private static void ensureMinArray(PtlAgreementUndwrtRulesAttrLink link) {
|
|
|
+ if (link.getMinArray() == null) {
|
|
|
+ String minStr = link.getMin();
|
|
|
+ if (minStr != null && !minStr.isEmpty()) {
|
|
|
+ link.setMinArray(minStr.split(","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取字典标签列表:优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
|
|
|
*/
|
|
|
@@ -181,19 +200,4 @@ public class BuildDescUtils {
|
|
|
return Collections.emptyList();
|
|
|
}
|
|
|
|
|
|
- private static String inputNumberIdentifying(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink ptlAgreementProductCostsAttrLink) {
|
|
|
- if ("1".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "范围值" + ptlAgreementProductCostsAttrLink.getMin() + "到" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
- } else if ("2".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于" + ptlAgreementProductCostsAttrLink.getMin();
|
|
|
- } else if ("3".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "小于等于" + ptlAgreementProductCostsAttrLink.getMin();
|
|
|
- } else if ("4".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
- } else if ("5".equals(ptlAgreementProductCostsAttrLink.getOperator())) {
|
|
|
- return ptlAgreementUndwrtRulesAttr.getAttrName() + "大于等于" + ptlAgreementProductCostsAttrLink.getMax();
|
|
|
- }
|
|
|
- return "";
|
|
|
- }
|
|
|
-
|
|
|
}
|