diff --git a/src/main/java/aiyh/utils/ScriptUtil.java b/src/main/java/aiyh/utils/ScriptUtil.java index 6c53d1d..9e59a3d 100644 --- a/src/main/java/aiyh/utils/ScriptUtil.java +++ b/src/main/java/aiyh/utils/ScriptUtil.java @@ -1,5 +1,6 @@ package aiyh.utils; +import aiyh.utils.interfaces.script_util.CusScriptFunInterface; import aiyh.utils.tool.org.apache.commons.jexl3.*; import java.util.Map; @@ -13,9 +14,16 @@ import java.util.Map; */ public class ScriptUtil { private static final JexlEngine JEXL = new JexlBuilder().create(); - + public static Object invokeScript(String script, Map params) { + return invokeScript(script, params, null); + } + + public static Object invokeScript(String script, Map params, CusScriptFunInterface scriptFunInterface) { JexlContext jc = new MapContext(); + if(null != scriptFunInterface){ + jc.set(scriptFunInterface.getClass().getSimpleName(), scriptFunInterface); + } for (Map.Entry entry : params.entrySet()) { jc.set(entry.getKey(), entry.getValue()); } diff --git a/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java b/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java index 7926f48..827640d 100644 --- a/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java +++ b/src/test/java/xuanran/wang/xk_hospital/test/XkHospitalTest.java @@ -117,4 +117,12 @@ public class XkHospitalTest extends BaseTest { Util.null2DefaultStr(null,""); service.async("4bce0693734d","common", map); } + + @Test + public void testD(){ + String json = "{\"data\":[{\"ID\":\"2\",\"GroupID\":\"test_yl_01\",\"Wards\":[]},{\"ID\":\"1\",\"GroupID\":\"test_yl_01\",\"Wards\":[{\"ID\":\"1\",\"WardCode\":\"bq_01\",\"WardName\":\"病区名称01_1\"},{\"ID\":\"2\",\"WardCode\":\"bq_02\",\"WardName\":\"病区名称01_2\"},{\"ID\":\"3\",\"WardCode\":\"bq_03\",\"WardName\":\"病区名称0_2_3\"},{\"ID\":\"4\",\"WardCode\":\"bq_04\",\"WardName\":\"病区名称02_1_3\"}]}]}\n"; + System.out.println(json); + Map map = JSONObject.parseObject(json, Map.class); + service.async("testarr","common", map); + } }