package com.ydtech.modules.protocol.utils; import com.ydtech.modules.protocol.constants.DispatchTypeConstants; import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesAttr; import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesAttrLink; import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesDictLabal; import org.apache.commons.lang3.StringUtils; import java.math.BigDecimal; import java.util.List; import java.util.Objects; /** * @version * @author: hxl * @Date: 2024/5/24 9:54 * @Description: 将规则列表合并成一句话 */ public class RulesMergeStrUtils { /** * @version * @author: hxl * @Date: 2024/5/24 10:41 * @Description: 将规则合成一句描述 */ public static String getRulesMergeStr(List v, List attrList) { String desc = ""; for (int i = 0; i < v.size(); i++) { int finalI = i; if(v.get(i).getMinArray() != null && v.get(i).getMinArray().length > 0){ v.get(i).setMin(String.join(",",v.get(i).getMinArray())); } //处理中文逗号 if(v.get(i).getMin() != null && v.get(i).getMin().contains(",")) { v.get(i).setMin(v.get(i).getMin().replace(",",",")); } PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr = attrList.stream().filter(x -> x.getAttrCode().equals(v.get(finalI).getAttrCode())).findAny().orElse(new PtlAgreementDispatchRulesAttr()); //数值范围判断 if ("inputNumber".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { if((v.get(i).getMin()!=null && !"0".equals(v.get(i).getMin())) || (v.get(i).getMax()!=null && !"0".equals(v.get(i).getMax()))){ desc += inputNumberIdentifying(ptlAgreementDispatchRulesAttr, v.get(i)) + "\n"; } } if ("radio".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { if(v.get(i).getMin()!=null && !"".equals(v.get(i).getMin())){ desc += radioIdentifying(ptlAgreementDispatchRulesAttr, v.get(i)) + "\n"; } } if ("checkbox".equals(ptlAgreementDispatchRulesAttr.getAttrType()) || "select".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { if(v.get(i).getMin()!=null && !"".equals(v.get(i).getMin())) { desc += ptlAgreementDispatchRulesAttr.getAttrName() + "包含" + v.get(i).getMin() + "\n"; } } } return desc; } /** * @version * @author: hxl * @Date: 2024/5/24 10:38 * @Description: 单选框 */ private static String radioIdentifying(PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr, PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink) { PtlAgreementDispatchRulesDictLabal ptlAgreementDispatchRulesDictLabal = ptlAgreementDispatchRulesAttr.getDictLabal().stream().filter(x -> x.getCode().equals(ptlAgreementDispatchRulesAttrLink.getMin())).findAny().orElse(new PtlAgreementDispatchRulesDictLabal()); return ptlAgreementDispatchRulesAttr.getAttrName() + "为" + Objects.requireNonNull(ptlAgreementDispatchRulesDictLabal).getName(); } /** * @version * @author: hxl * @Date: 2024/5/24 10:38 * @Description: 数值范围 */ private static String inputNumberIdentifying(PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr, PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink) { if ("1".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) { return ptlAgreementDispatchRulesAttr.getAttrName() + "范围值" + ptlAgreementDispatchRulesAttrLink.getMin() + "到" + ptlAgreementDispatchRulesAttrLink.getMax(); } else if ("2".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) { return ptlAgreementDispatchRulesAttr.getAttrName() + "小于" + ptlAgreementDispatchRulesAttrLink.getMin(); } else if ("3".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) { return ptlAgreementDispatchRulesAttr.getAttrName() + "小于等于" + ptlAgreementDispatchRulesAttrLink.getMin(); } else if ("4".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) { return ptlAgreementDispatchRulesAttr.getAttrName() + "大于" + ptlAgreementDispatchRulesAttrLink.getMax(); } else if ("5".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) { return ptlAgreementDispatchRulesAttr.getAttrName() + "大于等于" + ptlAgreementDispatchRulesAttrLink.getMax(); } return ""; } /** * @version * @author: hxl * @Date: 2024/5/24 15:08 * @Description: 判断值知否在范围内 */ public static Boolean judgeVal(List list, String val, String code, List dispatchRulesAttrList) { //查询定义的规则表 PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink = list.stream().filter(y -> y.getAttrCode().equals(code)).findFirst().orElse(new PtlAgreementDispatchRulesAttrLink()); PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr = dispatchRulesAttrList.stream().filter(y -> y.getAttrCode().equals(code)).findFirst().orElse(new PtlAgreementDispatchRulesAttr()); Boolean resultFlag=false; if ("inputNumber".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin()) || StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMax()) ) { //三者险为null为不投保情况 或者新车购置价为空 直接返回false if((DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode().equals(code) || DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode().equals(code)) && val==null){ resultFlag=false; }else{ //取符号做判断 resultFlag = judgeValInputNumber(ptlAgreementDispatchRulesAttrLink.getOperator(), ptlAgreementDispatchRulesAttrLink.getMin(), ptlAgreementDispatchRulesAttrLink.getMax(), val); } }else{ //等于空 不验证 resultFlag=true; } } if ("radio".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { //相等 if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin())){ if(val.equals(ptlAgreementDispatchRulesAttrLink.getMin())) { resultFlag= true; } //等于空 不验证 }else{ resultFlag=true; } } if ("checkbox".equals(ptlAgreementDispatchRulesAttr.getAttrType()) || "select".equals(ptlAgreementDispatchRulesAttr.getAttrType())) { //包含 if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin())){ if(ptlAgreementDispatchRulesAttrLink.getMin().contains(val)){ resultFlag= true; } //等于空 不验证 }else{ resultFlag=true; } } return resultFlag; } /** * @version * @author: hxl * @Date: 2024/5/24 15:09 * @Description: 判断运算符号 */ private static Boolean judgeValInputNumber(String operatorType,String min,String max,String val) { BigDecimal bigMin=new BigDecimal(min==null?"0":min); BigDecimal bigMax=new BigDecimal(max==null?"0":max); BigDecimal bigVal=new BigDecimal(val==null?"0":val); if ("1".equals(operatorType)) { //范围值 return isInRange(bigVal,bigMin,bigMax); } else if ("2".equals(operatorType)) { //小于 return bigVal.compareTo(bigMin) < 0; } else if ("3".equals(operatorType)) { //小于等于 return bigVal.compareTo(bigMin) <= 0; } else if ("4".equals(operatorType)) { //大于 return bigVal.compareTo(bigMax) > 0; } else if ("5".equals(operatorType)) { //大于等于 return bigVal.compareTo(bigMax) >= 0; } return null; } /** * @version * @author: hxl * @Date: 2024/5/24 15:15 * @Description: 判断是否在范围值之内 */ public static boolean isInRange(BigDecimal value, BigDecimal min, BigDecimal max) { return min.compareTo(value) <= 0 && max.compareTo(value) >= 0; } }