RulesMergeStrUtils.java 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. package com.ydtech.modules.protocol.utils;
  2. import com.ydtech.modules.protocol.constants.DispatchTypeConstants;
  3. import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesAttr;
  4. import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesAttrLink;
  5. import com.ydtech.modules.protocols.entity.po.PtlAgreementDispatchRulesDictLabal;
  6. import org.apache.commons.lang3.StringUtils;
  7. import java.math.BigDecimal;
  8. import java.util.List;
  9. import java.util.Objects;
  10. /**
  11. * @version
  12. * @author: hxl
  13. * @Date: 2024/5/24 9:54
  14. * @Description: 将规则列表合并成一句话
  15. */
  16. public class RulesMergeStrUtils {
  17. /**
  18. * @version
  19. * @author: hxl
  20. * @Date: 2024/5/24 10:41
  21. * @Description: 将规则合成一句描述
  22. */
  23. public static String getRulesMergeStr(List<PtlAgreementDispatchRulesAttrLink> v, List<PtlAgreementDispatchRulesAttr> attrList) {
  24. String desc = "";
  25. for (int i = 0; i < v.size(); i++) {
  26. int finalI = i;
  27. if(v.get(i).getMinArray() != null && v.get(i).getMinArray().length > 0){
  28. v.get(i).setMin(String.join(",",v.get(i).getMinArray()));
  29. }
  30. //处理中文逗号
  31. if(v.get(i).getMin() != null && v.get(i).getMin().contains(",")) {
  32. v.get(i).setMin(v.get(i).getMin().replace(",",","));
  33. }
  34. PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr = attrList.stream().filter(x -> x.getAttrCode().equals(v.get(finalI).getAttrCode())).findAny().orElse(new PtlAgreementDispatchRulesAttr());
  35. //数值范围判断
  36. if ("inputNumber".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  37. if((v.get(i).getMin()!=null && !"0".equals(v.get(i).getMin())) || (v.get(i).getMax()!=null && !"0".equals(v.get(i).getMax()))){
  38. desc += inputNumberIdentifying(ptlAgreementDispatchRulesAttr, v.get(i)) + "\n";
  39. }
  40. }
  41. if ("radio".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  42. if(v.get(i).getMin()!=null && !"".equals(v.get(i).getMin())){
  43. desc += radioIdentifying(ptlAgreementDispatchRulesAttr, v.get(i)) + "\n";
  44. }
  45. }
  46. if ("checkbox".equals(ptlAgreementDispatchRulesAttr.getAttrType()) || "select".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  47. if(v.get(i).getMin()!=null && !"".equals(v.get(i).getMin())) {
  48. desc += ptlAgreementDispatchRulesAttr.getAttrName() + "包含" + v.get(i).getMin() + "\n";
  49. }
  50. }
  51. }
  52. return desc;
  53. }
  54. /**
  55. * @version
  56. * @author: hxl
  57. * @Date: 2024/5/24 10:38
  58. * @Description: 单选框
  59. */
  60. private static String radioIdentifying(PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr, PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink) {
  61. PtlAgreementDispatchRulesDictLabal ptlAgreementDispatchRulesDictLabal = ptlAgreementDispatchRulesAttr.getDictLabal().stream().filter(x ->
  62. x.getCode().equals(ptlAgreementDispatchRulesAttrLink.getMin())).findAny().orElse(new PtlAgreementDispatchRulesDictLabal());
  63. return ptlAgreementDispatchRulesAttr.getAttrName() + "为" + Objects.requireNonNull(ptlAgreementDispatchRulesDictLabal).getName();
  64. }
  65. /**
  66. * @version
  67. * @author: hxl
  68. * @Date: 2024/5/24 10:38
  69. * @Description: 数值范围
  70. */
  71. private static String inputNumberIdentifying(PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr, PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink) {
  72. if ("1".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) {
  73. return ptlAgreementDispatchRulesAttr.getAttrName() + "范围值" + ptlAgreementDispatchRulesAttrLink.getMin() + "到" + ptlAgreementDispatchRulesAttrLink.getMax();
  74. } else if ("2".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) {
  75. return ptlAgreementDispatchRulesAttr.getAttrName() + "小于" + ptlAgreementDispatchRulesAttrLink.getMin();
  76. } else if ("3".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) {
  77. return ptlAgreementDispatchRulesAttr.getAttrName() + "小于等于" + ptlAgreementDispatchRulesAttrLink.getMin();
  78. } else if ("4".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) {
  79. return ptlAgreementDispatchRulesAttr.getAttrName() + "大于" + ptlAgreementDispatchRulesAttrLink.getMax();
  80. } else if ("5".equals(ptlAgreementDispatchRulesAttrLink.getOperator())) {
  81. return ptlAgreementDispatchRulesAttr.getAttrName() + "大于等于" + ptlAgreementDispatchRulesAttrLink.getMax();
  82. }
  83. return "";
  84. }
  85. /**
  86. * @version
  87. * @author: hxl
  88. * @Date: 2024/5/24 15:08
  89. * @Description: 判断值知否在范围内
  90. */
  91. public static Boolean judgeVal(List<PtlAgreementDispatchRulesAttrLink> list, String val, String code, List<PtlAgreementDispatchRulesAttr> dispatchRulesAttrList) {
  92. //查询定义的规则表
  93. PtlAgreementDispatchRulesAttrLink ptlAgreementDispatchRulesAttrLink = list.stream().filter(y -> y.getAttrCode().equals(code)).findFirst().orElse(new PtlAgreementDispatchRulesAttrLink());
  94. PtlAgreementDispatchRulesAttr ptlAgreementDispatchRulesAttr = dispatchRulesAttrList.stream().filter(y -> y.getAttrCode().equals(code)).findFirst().orElse(new PtlAgreementDispatchRulesAttr());
  95. Boolean resultFlag=false;
  96. if ("inputNumber".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  97. if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin()) || StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMax()) ) {
  98. //三者险为null为不投保情况 或者新车购置价为空 直接返回false
  99. if((DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_8.getCode().equals(code) || DispatchTypeConstants.DISPATCH_TYPE_CONSTANTS_10.getCode().equals(code)) && val==null){
  100. resultFlag=false;
  101. }else{
  102. //取符号做判断
  103. resultFlag = judgeValInputNumber(ptlAgreementDispatchRulesAttrLink.getOperator(), ptlAgreementDispatchRulesAttrLink.getMin(), ptlAgreementDispatchRulesAttrLink.getMax(), val);
  104. }
  105. }else{
  106. //等于空 不验证
  107. resultFlag=true;
  108. }
  109. }
  110. if ("radio".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  111. //相等
  112. if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin())){
  113. if(val.equals(ptlAgreementDispatchRulesAttrLink.getMin())) {
  114. resultFlag= true;
  115. }
  116. //等于空 不验证
  117. }else{
  118. resultFlag=true;
  119. }
  120. }
  121. if ("checkbox".equals(ptlAgreementDispatchRulesAttr.getAttrType()) || "select".equals(ptlAgreementDispatchRulesAttr.getAttrType())) {
  122. //包含
  123. if(StringUtils.isNotBlank(ptlAgreementDispatchRulesAttrLink.getMin())){
  124. if(ptlAgreementDispatchRulesAttrLink.getMin().contains(val)){
  125. resultFlag= true;
  126. }
  127. //等于空 不验证
  128. }else{
  129. resultFlag=true;
  130. }
  131. }
  132. return resultFlag;
  133. }
  134. /**
  135. * @version
  136. * @author: hxl
  137. * @Date: 2024/5/24 15:09
  138. * @Description: 判断运算符号
  139. */
  140. private static Boolean judgeValInputNumber(String operatorType,String min,String max,String val) {
  141. BigDecimal bigMin=new BigDecimal(min==null?"0":min);
  142. BigDecimal bigMax=new BigDecimal(max==null?"0":max);
  143. BigDecimal bigVal=new BigDecimal(val==null?"0":val);
  144. if ("1".equals(operatorType)) {
  145. //范围值
  146. return isInRange(bigVal,bigMin,bigMax);
  147. } else if ("2".equals(operatorType)) {
  148. //小于
  149. return bigVal.compareTo(bigMin) < 0;
  150. } else if ("3".equals(operatorType)) {
  151. //小于等于
  152. return bigVal.compareTo(bigMin) <= 0;
  153. } else if ("4".equals(operatorType)) {
  154. //大于
  155. return bigVal.compareTo(bigMax) > 0;
  156. } else if ("5".equals(operatorType)) {
  157. //大于等于
  158. return bigVal.compareTo(bigMax) >= 0;
  159. }
  160. return null;
  161. }
  162. /**
  163. * @version
  164. * @author: hxl
  165. * @Date: 2024/5/24 15:15
  166. * @Description: 判断是否在范围值之内
  167. */
  168. public static boolean isInRange(BigDecimal value, BigDecimal min, BigDecimal max) {
  169. return min.compareTo(value) <= 0 && max.compareTo(value) >= 0;
  170. }
  171. }