|
|
@@ -0,0 +1,231 @@
|
|
|
+package com.jzg.organization.component;
|
|
|
+
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesAttr;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesAttrLink;
|
|
|
+import com.jzg.commons.entity.po.PtlAgreementUndwrtRulesDictLabal;
|
|
|
+import com.jzg.commons.util.StringUtils;
|
|
|
+
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
+public class BuildDescUtils {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 遍历费用属性描述文字
|
|
|
+ *
|
|
|
+ * @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()));
|
|
|
+ // 这里进行排序,保证生成的承保规则描述是有序的
|
|
|
+ linkList = linkList.stream().sorted(Comparator.comparing(PtlAgreementUndwrtRulesAttr::getAttrCode)).toList();
|
|
|
+ List<PtlAgreementUndwrtRulesAttr> sortedLinks = new ArrayList<>(linkList);
|
|
|
+
|
|
|
+ for (PtlAgreementUndwrtRulesAttr link : sortedLinks) {
|
|
|
+ PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr = attrMap.get(link.getAttrCode());
|
|
|
+ if (ptlAgreementUndwrtRulesAttr == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ String attrType = ptlAgreementUndwrtRulesAttr.getAttrType();
|
|
|
+
|
|
|
+ if ("inputNumber".equals(attrType)) {
|
|
|
+ desc.append(inputNumberIdentifying(ptlAgreementUndwrtRulesAttr, link)).append(";\t\t");
|
|
|
+ } else if ("radio".equals(attrType)) {
|
|
|
+ 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 (int k=0 ; k<link.getMinArray().length; k++){
|
|
|
+ PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = null;
|
|
|
+ for (PtlAgreementUndwrtRulesDictLabal x : link.getDictLabal()) {
|
|
|
+ if (Arrays.asList(link.getMinArray()).contains(x.getCode())) {
|
|
|
+ ptlAgreementUndwrtRulesDictLabal = x;
|
|
|
+ link.getMinArray()[k] = null;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ desc.append(null != ptlAgreementUndwrtRulesDictLabal ? ptlAgreementUndwrtRulesDictLabal.getName() : "").append(",");
|
|
|
+ }
|
|
|
+ // 条件描述后补充一个分号
|
|
|
+ desc.append(",");
|
|
|
+ }else {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(link.getMin()).append(";\t\t");
|
|
|
+ }
|
|
|
+ } else if ("inputTag".equals(attrType)) {
|
|
|
+ if (link.getOperator() != null && "1".equals(link.getOperator())) {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(link.getMin()).append(";\t\t");
|
|
|
+ } else {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("不包含").append(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() + "未知操作符";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 遍历承保规则属性描述文字
|
|
|
+ *
|
|
|
+ * @param linkList
|
|
|
+ * @param undwrtRulesAttrList
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static String buildDesc(List<PtlAgreementUndwrtRulesAttrLink> linkList, List<PtlAgreementUndwrtRulesAttr> undwrtRulesAttrList) {
|
|
|
+ StringBuilder desc = new StringBuilder();
|
|
|
+ // 这里进行排序,保证生成的承保规则描述是有序的
|
|
|
+ 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();
|
|
|
+
|
|
|
+ //数值范围判断
|
|
|
+
|
|
|
+ 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)));
|
|
|
+ }
|
|
|
+ if ("inputTag".equals(ptlAgreementUndwrtRulesAttr.getAttrType())) {
|
|
|
+ if (sortedLinks.get(i).getOperator() != null && sortedLinks.get(i).getOperator().equals("1")) {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("包含").append(sortedLinks.get(i).getMin()).append(",");
|
|
|
+ } else {
|
|
|
+ desc.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("不包含").append(sortedLinks.get(i).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 ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink ptlAgreementProductCostsAttrLink) {
|
|
|
+ StringBuilder returnMsg = new StringBuilder();
|
|
|
+ returnMsg.append(ptlAgreementUndwrtRulesAttr.getAttrName()).append("为");
|
|
|
+ // 兼容 min 逗号分隔存储,保证 minArray 有值
|
|
|
+ if (ptlAgreementProductCostsAttrLink.getMinArray() == null) {
|
|
|
+ String minStr = ptlAgreementProductCostsAttrLink.getMin();
|
|
|
+ if (minStr != null && !minStr.isEmpty()) {
|
|
|
+ ptlAgreementProductCostsAttrLink.setMinArray(minStr.split(","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
|
|
|
+ List<PtlAgreementUndwrtRulesDictLabal> dictLabalList = getDictLabalList(ptlAgreementUndwrtRulesAttr, ptlAgreementProductCostsAttrLink);
|
|
|
+
|
|
|
+ // 用字典标签的 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(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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(","));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ 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));
|
|
|
+ for (String code : linkList.getMinArray()) {
|
|
|
+ PtlAgreementUndwrtRulesDictLabal ptlAgreementUndwrtRulesDictLabal = dictLabalMap.get(code);
|
|
|
+ returnMsg.append(ptlAgreementUndwrtRulesDictLabal != null ? ptlAgreementUndwrtRulesDictLabal.getName() : "").append(",");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return returnMsg.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取字典标签列表:优先取 link 上的字典标签列表(JSONArray -> List),为空时回退到属性自带字典
|
|
|
+ */
|
|
|
+ private static List<PtlAgreementUndwrtRulesDictLabal> getDictLabalList(PtlAgreementUndwrtRulesAttr ptlAgreementUndwrtRulesAttr, PtlAgreementUndwrtRulesAttrLink link) {
|
|
|
+ if (link.getDictLabal() != null && !link.getDictLabal().isEmpty()) {
|
|
|
+ return link.getDictLabal().toJavaList(PtlAgreementUndwrtRulesDictLabal.class);
|
|
|
+ }
|
|
|
+ if (ptlAgreementUndwrtRulesAttr.getDictLabal() != null) {
|
|
|
+ return ptlAgreementUndwrtRulesAttr.getDictLabal();
|
|
|
+ }
|
|
|
+ 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 "";
|
|
|
+ }
|
|
|
+
|
|
|
+}
|