|
|
|
@ -5,13 +5,14 @@ import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
|
|
|
|
|
import com.anjiplus.template.gaea.business.code.ResponseCode;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.datasettransform.controller.dto.DataSetTransformDto;
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.datasettransform.service.TransformStrategy;
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import jdk.nashorn.api.scripting.ScriptObjectMirror;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import javax.script.Invocable;
|
|
|
|
|
import javax.script.ScriptEngine;
|
|
|
|
|
import javax.script.ScriptEngineManager;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -54,7 +55,20 @@ public class JsTransformServiceImpl implements TransformStrategy {
|
|
|
|
|
engine.eval(js);
|
|
|
|
|
if(engine instanceof Invocable){
|
|
|
|
|
Invocable invocable = (Invocable) engine;
|
|
|
|
|
return (List<JSONObject>) invocable.invokeFunction("dataTransform", data);
|
|
|
|
|
Object dataTransform = invocable.invokeFunction("dataTransform", data);
|
|
|
|
|
if (dataTransform instanceof List) {
|
|
|
|
|
return (List<JSONObject>) dataTransform;
|
|
|
|
|
}
|
|
|
|
|
//前端js自定义的数组[{"aa":"bb"}]解析后变成{"0":{"aa":"bb"}}
|
|
|
|
|
ScriptObjectMirror scriptObjectMirror = (ScriptObjectMirror) dataTransform;
|
|
|
|
|
List<JSONObject> result = new ArrayList<>();
|
|
|
|
|
scriptObjectMirror.forEach((key, value) -> {
|
|
|
|
|
ScriptObjectMirror valueObject = (ScriptObjectMirror) value;
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
|
|
jsonObject.putAll(valueObject);
|
|
|
|
|
result.add(jsonObject);
|
|
|
|
|
});
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|