|
|
@@ -3,7 +3,6 @@ package org.jeecg.modules.medical.ruleengine;
|
|
|
import cn.hutool.core.collection.CollectionUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.poi.ss.formula.functions.Even;
|
|
|
import org.jeecg.modules.medical.ColumnTypeEnum;
|
|
|
import org.jeecg.modules.medical.entity.EventAttr;
|
|
|
import org.jeecg.modules.medical.entity.FactorCondRela;
|
|
|
@@ -17,6 +16,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
import java.lang.reflect.Method;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
@@ -49,7 +49,7 @@ public class SPELUtil {
|
|
|
//A包含B == B存在于A
|
|
|
ColumnTypeEnum eventColumnTypeEnum = ColumnTypeEnum.getType(eventAttr.getDispType());
|
|
|
ColumnTypeEnum refEventColumnTypeEnum = ColumnTypeEnum.STRING;
|
|
|
- if(2 == factorCondRela.getRefAttrType()) {
|
|
|
+ if (2 == factorCondRela.getRefAttrType()) {
|
|
|
refEventColumnTypeEnum = ColumnTypeEnum.getType(refEventAttr.getDispType());
|
|
|
}
|
|
|
if (OperaterEnum.MEMBER == operaterEnum) {
|
|
|
@@ -57,17 +57,22 @@ public class SPELUtil {
|
|
|
String inKey = eventAttr.getDispArgs();
|
|
|
String outKey = refEventAttr.getDispArgs();
|
|
|
if (ColumnTypeEnum.ARRAY_MAP == eventColumnTypeEnum) {
|
|
|
+// if (ColumnTypeEnum.ARRAY == refEventColumnTypeEnum) {
|
|
|
+// spelStr = "#isMemberLeftListObject(#" + eventAttr.getEnName() + ",#" + refEventAttr.getEnName() + ")";
|
|
|
+// }else
|
|
|
if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
- spelStr = "isMemberLeftMapAndRightListMap(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "','" + inKey + "')";
|
|
|
+ spelStr = "#isMemberLeftMapAndRightListMap(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "','" + inKey + "')";
|
|
|
} else {
|
|
|
- spelStr = "isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
+ spelStr = "#isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
}
|
|
|
|
|
|
} else if (ColumnTypeEnum.ARRAY == eventColumnTypeEnum) {
|
|
|
- if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
- spelStr = "isMemberLeftMapRightListObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "')";
|
|
|
+ if (ColumnTypeEnum.ARRAY == refEventColumnTypeEnum) {
|
|
|
+ spelStr = "#isMemberListAndList(#" + eventAttr.getEnName() + ",#" + refEventAttr.getEnName() + ")";
|
|
|
+ } else if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
+ spelStr = "#isMemberLeftMapRightListObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "')";
|
|
|
} else {
|
|
|
- spelStr = "isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
+ spelStr = "#isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
}
|
|
|
} else {
|
|
|
log.error("factorCondRelaId:{} 配置的包含关系使用了不恰当的要素类型", factorCondRela.getId());
|
|
|
@@ -77,27 +82,32 @@ public class SPELUtil {
|
|
|
String inKey = eventAttr.getDispArgs();
|
|
|
String outKey = refEventAttr.getDispArgs();
|
|
|
if (ColumnTypeEnum.ARRAY_MAP == eventColumnTypeEnum) {
|
|
|
+// if (ColumnTypeEnum.ARRAY == refEventColumnTypeEnum) {
|
|
|
+// spelStr = "!#isMemberLeftListObject(#" + eventAttr.getEnName() + ",#" + refEventAttr.getEnName() + ")";
|
|
|
+// }
|
|
|
if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
- spelStr = "!isMemberLeftMapAndRightListMap(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "','" + inKey + "')";
|
|
|
+ spelStr = "!#isMemberLeftMapAndRightListMap(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "','" + inKey + "')";
|
|
|
} else {
|
|
|
- spelStr = "!isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
+ spelStr = "!#isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
}
|
|
|
|
|
|
} else if (ColumnTypeEnum.ARRAY == eventColumnTypeEnum) {
|
|
|
- if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
- spelStr = "!isMemberLeftMapRightListObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "')";
|
|
|
+ if (ColumnTypeEnum.ARRAY == refEventColumnTypeEnum) {
|
|
|
+ spelStr = "!#isMemberListAndList(#" + eventAttr.getEnName() + ",#" + refEventAttr.getEnName() + ")";
|
|
|
+ }else if (ColumnTypeEnum.MAP == refEventColumnTypeEnum) {
|
|
|
+ spelStr = "!#isMemberLeftMapRightListObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ",'" + outKey + "')";
|
|
|
} else {
|
|
|
- spelStr = "!isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
+ spelStr = "!#isMemberLeftObject(#" + refEventAttr.getEnName() + ",#" + eventAttr.getEnName() + ")";
|
|
|
}
|
|
|
} else {
|
|
|
log.error("factorCondRelaId:{} 配置的包含关系使用了不恰当的要素类型", factorCondRela.getId());
|
|
|
}
|
|
|
} else {
|
|
|
- if(1 == factorCondRela.getRefAttrType()){
|
|
|
+ if (1 == factorCondRela.getRefAttrType()) {
|
|
|
|
|
|
spelStr = "#" + eventAttr.getEnName() + operaterEnum.getOperaterStr() + factorCondRela.getExtAttr1();
|
|
|
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
spelStr = "#" + eventAttr.getEnName() + operaterEnum.getOperaterStr() + "#" + refEventAttr.getEnName();
|
|
|
}
|
|
|
}
|
|
|
@@ -110,6 +120,7 @@ public class SPELUtil {
|
|
|
StandardEvaluationContext ctx = new StandardEvaluationContext();
|
|
|
Method[] methods = this.getClass().getMethods();
|
|
|
for (Method method : methods) {
|
|
|
+ log.info("methodName:{} method:{}", method.getName(), method);
|
|
|
if (!"runSpelExpression".equals(method.getName())) {
|
|
|
ctx.registerFunction(method.getName(), method);
|
|
|
}
|
|
|
@@ -117,13 +128,13 @@ public class SPELUtil {
|
|
|
ctx.setVariables(contentMap);
|
|
|
Expression expression = parser.parseExpression(condStr);
|
|
|
Object defResult = expression.getValue(ctx);
|
|
|
-
|
|
|
+// Object defResult = expression.getValue(ctx, Object.class);
|
|
|
|
|
|
return defResult;
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Boolean isMemberLeftString(String inValue, List<String> memberList) {
|
|
|
+ public static Boolean isMemberLeftString(String inValue, List<String> memberList) {
|
|
|
if (StringUtils.isNotBlank(inValue) && CollectionUtil.isNotEmpty(memberList)) {
|
|
|
if (memberList.contains(inValue)) {
|
|
|
return true;
|
|
|
@@ -140,7 +151,7 @@ public class SPELUtil {
|
|
|
* @param key
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean isMemberLeftObjectAndRightListMap(Object inStr, List<Map<String, Object>> memberList, String key) {
|
|
|
+ public static Boolean isMemberLeftObjectAndRightListMap(Object inStr, List<Map<String, Object>> memberList, String key) {
|
|
|
if (null != inStr && CollectionUtil.isNotEmpty(memberList) && StringUtils.isNotBlank(key)) {
|
|
|
List<String> itemValueList = new ArrayList<>();
|
|
|
for (Map<String, Object> itemMap : memberList) {
|
|
|
@@ -163,7 +174,7 @@ public class SPELUtil {
|
|
|
* @param listKey
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean isMemberLeftMapAndRightListMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String mapKey, String listKey) {
|
|
|
+ public static Boolean isMemberLeftMapAndRightListMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String mapKey, String listKey) {
|
|
|
if (null != inMap && CollectionUtil.isNotEmpty(memberList) && StringUtils.isNotBlank(mapKey) && StringUtils.isNotBlank(listKey)) {
|
|
|
List<String> itemValueList = new ArrayList<>();
|
|
|
Object inStr = inMap.get(mapKey);
|
|
|
@@ -178,7 +189,7 @@ public class SPELUtil {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public Boolean isMemberLeftInt(Integer inValue, List<Integer> memberList) {
|
|
|
+ public static Boolean isMemberLeftInt(Integer inValue, List<Integer> memberList) {
|
|
|
if (null != inValue && CollectionUtil.isNotEmpty(memberList)) {
|
|
|
if (memberList.contains(inValue)) {
|
|
|
return true;
|
|
|
@@ -196,7 +207,7 @@ public class SPELUtil {
|
|
|
* @param keyArr
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean isMemberLeftMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String[] keyArr) {
|
|
|
+ public static Boolean isMemberLeftMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String[] keyArr) {
|
|
|
if (CollectionUtil.isNotEmpty(inMap) && CollectionUtil.isNotEmpty(memberList) && null != keyArr && keyArr.length > 0) {
|
|
|
List<Object> inObjectList = new ArrayList<>();
|
|
|
for (String key : keyArr) {
|
|
|
@@ -226,7 +237,7 @@ public class SPELUtil {
|
|
|
* @param key
|
|
|
* @return
|
|
|
*/
|
|
|
- public Boolean isMemberLeftListObject(List<Object> inList, List<Map<String, Object>> memberList, String key) {
|
|
|
+ public static Boolean isMemberLeftListObject(List<Object> inList, List<Map<String, Object>> memberList, String key) {
|
|
|
if (CollectionUtil.isNotEmpty(inList) && CollectionUtil.isNotEmpty(memberList) && StringUtils.isNotBlank(key)) {
|
|
|
List<String> memberValueList = new ArrayList<>();
|
|
|
for (Map<String, Object> itemMap : memberList) {
|
|
|
@@ -242,7 +253,7 @@ public class SPELUtil {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public Boolean isMemberLeftMapRightListObject(Map<String, Object> inMap, List<Object> memberList, String inKey) {
|
|
|
+ public static Boolean isMemberLeftMapRightListObject(Map<String, Object> inMap, List<Object> memberList, String inKey) {
|
|
|
if (CollectionUtil.isNotEmpty(inMap) && CollectionUtil.isNotEmpty(memberList) && null != inKey) {
|
|
|
Object mapObject = inMap.get(inKey);
|
|
|
for (Object paramObject : memberList) {
|
|
|
@@ -256,11 +267,11 @@ public class SPELUtil {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public Boolean isNotMemberLeftMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String[] keyArr) {
|
|
|
+ public static Boolean isNotMemberLeftMap(Map<String, Object> inMap, List<Map<String, Object>> memberList, String[] keyArr) {
|
|
|
return !isMemberLeftMap(inMap, memberList, keyArr);
|
|
|
}
|
|
|
|
|
|
- public Boolean isMemberLeftLong(Long inValue, List<Long> memberList) {
|
|
|
+ public static Boolean isMemberLeftLong(Long inValue, List<Long> memberList) {
|
|
|
if (null != inValue && CollectionUtil.isNotEmpty(memberList)) {
|
|
|
if (memberList.contains(inValue)) {
|
|
|
return true;
|
|
|
@@ -269,11 +280,11 @@ public class SPELUtil {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public Boolean isNotMemberLeftObject(Object inValue, List<Object> memberList) {
|
|
|
+ public static Boolean isNotMemberLeftObject(Object inValue, List<Object> memberList) {
|
|
|
return !isMemberLeftObject(inValue, memberList);
|
|
|
}
|
|
|
|
|
|
- public Boolean isMemberLeftObject(Object inValue, List<Object> memberList) {
|
|
|
+ public static Boolean isMemberLeftObject(Object inValue, List<Object> memberList) {
|
|
|
if (null != inValue && CollectionUtil.isNotEmpty(memberList)) {
|
|
|
if (memberList.contains(inValue)) {
|
|
|
return true;
|
|
|
@@ -282,6 +293,18 @@ public class SPELUtil {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ public static Boolean isMemberListAndList(List<Object> lList, List<Object> rList) {
|
|
|
+ for (Object value : rList) {
|
|
|
+ boolean flag = isMemberLeftObject(value, lList);
|
|
|
+ if (flag) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
public static void main(String[] args) {
|
|
|
SPELUtil spelUtil = new SPELUtil();
|
|
|
Map<String, Object> inMap = new HashMap<>();
|
|
|
@@ -299,5 +322,12 @@ public class SPELUtil {
|
|
|
lList.add(1L);
|
|
|
lList.add(2L);
|
|
|
System.out.println(spelUtil.isMemberLeftLong(3L, lList));
|
|
|
+// String condStr = "isMemberLeftObject(#medical_diagnose_code,#medical_ins_medicalDiagnoseCodeList) && #change_class<>#medical_ins_changeClass";
|
|
|
+ String condStr = "#isMemberListAndList(#medical_diagnose_code,#medical_ins_medicalDiagnoseCodeList) ";
|
|
|
+
|
|
|
+ Map<String, Object> itemMap1 = new HashMap<>();
|
|
|
+ itemMap1.put("medical_diagnose_code", Arrays.asList("1", "2", "3"));
|
|
|
+ itemMap1.put("medical_ins_medicalDiagnoseCodeList", Arrays.asList("3", "5", "6"));
|
|
|
+ System.out.println(spelUtil.runSpelExpression(itemMap1, condStr));
|
|
|
}
|
|
|
}
|