|
@@ -1,6 +1,8 @@
|
|
|
package com.scbfkj.uni.service;
|
|
|
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.jayway.jsonpath.JsonPath;
|
|
|
+import com.scbfkj.uni.dtos.Expression;
|
|
|
import com.scbfkj.uni.library.DataAliasGetUtil;
|
|
|
import com.scbfkj.uni.library.DataFormatUtil;
|
|
|
import com.scbfkj.uni.library.UniReturnUtil;
|
|
@@ -111,20 +113,30 @@ public class DataProcessService {
|
|
|
source.put("args", resource);
|
|
|
source.put("algorithm", algorithmLibrary);
|
|
|
// 计算前置算法
|
|
|
- if (Objects.nonNull(preConditions)) {
|
|
|
+ List<Map<String, Object>> preScriptExpressions = DATA_BASE.query(Config.getCenterConnectionStr(), "select * from scriptexpression where algorithmlibraryid=?", algorithmlibraryid);
|
|
|
+ Map<String, Object> eval = null;
|
|
|
+
|
|
|
+
|
|
|
+ if (!preScriptExpressions.isEmpty()) {
|
|
|
+ List<String> expressions = preScriptExpressions.stream().map(DataFormatUtil::toString).map(it -> {
|
|
|
+ try {
|
|
|
+ return DataFormatUtil.getObjectMapper().readValue(it, Expression.class);
|
|
|
+ } catch (JsonProcessingException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }).map(Expression::toScript).toList();
|
|
|
+ String preExpression = String.join("\n", expressions);
|
|
|
+ eval = JsScriptEngineUtil.eval(preExpression, resource);
|
|
|
+ } else if (Objects.nonNull(preConditions)) {
|
|
|
+ eval = JsScriptEngineUtil.eval(preConditions.toString(), resource);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Objects.nonNull(eval)) {
|
|
|
HashMap<String, Object> preData = new HashMap<>();
|
|
|
preResource.add(preData);
|
|
|
|
|
|
preData.put("algorithmlibraryid", algorithmlibraryid);
|
|
|
-
|
|
|
-
|
|
|
String preCode;
|
|
|
-// 前置算法参数
|
|
|
-// List<Object> params = new ArrayList<>(getParams(Optional.ofNullable(preparameterset).map(DataFormatUtil::toString).orElse(null), source));
|
|
|
-
|
|
|
-// params.add(0, DataFormatUtil.toString(preConditions));
|
|
|
- Map<String, Object> eval = JsScriptEngineUtil.eval(preConditions.toString(), resource);
|
|
|
-
|
|
|
preData.put("preResult", eval);
|
|
|
if (!Objects.equals(eval.get("code"), "0")) {
|
|
|
throw new RuntimeException(eval.get("message").toString());
|