Raod 3 years ago
parent 0dffccd895
commit 0162467aed

@ -0,0 +1,62 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller;
import com.anji.plus.gaea.bean.ResponseBean;
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.param.DataSetParamParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.param.DataSetParamValidationParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity.DataSetParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.service.DataSetParamService;
import com.anjiplus.template.gaea.business.modules.data.dataSource.controller.param.ConnectionParam;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @desc controller
* @website https://gitee.com/anji-plus/gaea
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@RestController
@Api(tags = "数据集动态参数管理")
@RequestMapping("/dataSetParam")
public class DataSetParamController extends GaeaBaseController<DataSetParamParam, DataSetParam, DataSetParamDto> {
@Autowired
private DataSetParamService dataSetParamService;
@Override
public GaeaBaseService<DataSetParamParam, DataSetParam> getService() {
return dataSetParamService;
}
@Override
public DataSetParam getEntity() {
return new DataSetParam();
}
@Override
public DataSetParamDto getDTO() {
return new DataSetParamDto();
}
/**
*
* @param param
* @return
*/
@PostMapping("/verification")
public ResponseBean verification(@Validated @RequestBody DataSetParamValidationParam param) {
DataSetParamDto dto = new DataSetParamDto();
dto.setSampleItem(param.getSampleItem());
dto.setValidationRules(param.getValidationRules());
return responseSuccessWithData(dataSetParamService.verification(dto));
}
}

@ -0,0 +1,48 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import lombok.Data;
import java.io.Serializable;
/**
*
* @description dto
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@Data
public class DataSetParamDto extends GaeaBaseDTO implements Serializable {
/** 数据集编码 */
private String setCode;
/** 参数名 */
private String paramName;
/** 参数描述 */
private String paramDesc;
/** 参数类型,字典= */
private String paramType;
/** 参数示例项 */
private String sampleItem;
/** 0--非必填 1--必填 DIC_NAME=REQUIRED_FLAG */
private Integer requiredFlag;
/** js校验字段值规则满足校验返回 true */
private String validationRules;
/** 排序 */
private Integer orderNum;
/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
private Integer enableFlag;
/** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
private Integer deleteFlag;
}

@ -0,0 +1,17 @@
/**/
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.param;
import com.anji.plus.gaea.curd.params.PageParam;
import lombok.Data;
import java.io.Serializable;
/**
* @desc DataSetParam
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@Data
public class DataSetParamParam extends PageParam implements Serializable{
}

@ -0,0 +1,22 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.param;
import lombok.Data;
import javax.validation.constraints.NotBlank;
import java.io.Serializable;
/**
* Created by raodeming on 2021/3/24.
*/
@Data
public class DataSetParamValidationParam implements Serializable {
/** 参数示例项 */
@NotBlank(message = "sampleItem not empty")
private String sampleItem;
/** js校验字段值规则满足校验返回 true */
@NotBlank(message = "validationRules not empty")
private String validationRules;
}

@ -0,0 +1,15 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity.DataSetParam;
import org.apache.ibatis.annotations.Mapper;
/**
* DataSetParam Mapper
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@Mapper
public interface DataSetParamMapper extends GaeaBaseMapper<DataSetParam> {
}

@ -0,0 +1,48 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description entity
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@TableName(value="gaea_report_data_set_param")
@Data
public class DataSetParam extends GaeaBaseEntity {
@ApiModelProperty(value = "数据集编码")
private String setCode;
@ApiModelProperty(value = "参数名")
private String paramName;
@ApiModelProperty(value = "参数描述")
private String paramDesc;
@ApiModelProperty(value = "参数类型,字典=")
private String paramType;
@ApiModelProperty(value = "参数示例项")
private String sampleItem;
@ApiModelProperty(value = "0--非必填 1--必填 DIC_NAME=REQUIRED_FLAG")
private Integer requiredFlag;
@ApiModelProperty(value = "js校验字段值规则满足校验返回 true")
private String validationRules;
@ApiModelProperty(value = "排序")
private Integer orderNum;
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
private Integer enableFlag;
@ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG")
private Integer deleteFlag;
}

@ -0,0 +1,52 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.service;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.dataSet.controller.dto.DataSetDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.param.DataSetParamParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity.DataSetParam;
import java.util.List;
import java.util.Map;
/**
* @author Raod
* @desc DataSetParam
* @date 2021-03-18 12:12:33.108033200
**/
public interface DataSetParamService extends GaeaBaseService<DataSetParamParam, DataSetParam> {
/**
*
*
* @param contextData
* @param dynSentence
* @return
*/
String transform(Map<String, Object> contextData, String dynSentence);
/**
*
*
* @param dataSetParamDtoList
* @param dynSentence
* @return
*/
String transform(List<DataSetParamDto> dataSetParamDtoList, String dynSentence);
/**
* js
* @param dataSetParamDto
* @return
*/
boolean verification(DataSetParamDto dataSetParamDto);
/**
* js
*
* @param dataSetParamDtoList
* @return
*/
boolean verification(List<DataSetParamDto> dataSetParamDtoList, Map<String, Object> contextData);
}

@ -0,0 +1,136 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.service.impl;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.controller.dto.DataSetParamDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.DataSetParamMapper;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.dao.entity.DataSetParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.service.DataSetParamService;
import com.anjiplus.template.gaea.business.modules.data.dataSetParam.util.ParamsResolverHelper;
import com.anjiplus.template.gaea.common.RespCommonCode;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @desc DataSetParam
* @author Raod
* @date 2021-03-18 12:12:33.108033200
**/
@Service
//@RequiredArgsConstructor
@Slf4j
public class DataSetParamServiceImpl implements DataSetParamService {
private ScriptEngine engine;
{
ScriptEngineManager manager = new ScriptEngineManager();
engine = manager.getEngineByName("JavaScript");
}
@Autowired
private DataSetParamMapper dataSetParamMapper;
@Override
public GaeaBaseMapper<DataSetParam> getMapper() {
return dataSetParamMapper;
}
/**
*
*
* @param contextData
* @param dynSentence
* @return
*/
@Override
public String transform(Map<String, Object> contextData, String dynSentence) {
if (StringUtils.isBlank(dynSentence)) {
return dynSentence;
}
if (dynSentence.contains("${")) {
dynSentence = ParamsResolverHelper.resolveParams(contextData, dynSentence);
}
if (dynSentence.contains("${")) {
throw BusinessExceptionBuilder.build(RespCommonCode.INCOMPLETE_PARAMETER_REPLACEMENT_VALUES, dynSentence);
}
return dynSentence;
}
/**
*
*
* @param dataSetParamDtoList
* @param dynSentence
* @return
*/
@Override
public String transform(List<DataSetParamDto> dataSetParamDtoList, String dynSentence) {
Map<String, Object> contextData = new HashMap<>();
if (null == dataSetParamDtoList || dataSetParamDtoList.size() <= 0) {
return dynSentence;
}
dataSetParamDtoList.forEach(dataSetParamDto -> {
contextData.put(dataSetParamDto.getParamName(), dataSetParamDto.getSampleItem());
});
return transform(contextData, dynSentence);
}
/**
* js
*
* @param dataSetParamDto
* @return
*/
@Override
public boolean verification(DataSetParamDto dataSetParamDto) {
String sampleItem = dataSetParamDto.getSampleItem();
String validationRules = dataSetParamDto.getValidationRules();
if (StringUtils.isNotBlank(validationRules)) {
validationRules = validationRules + "\nvar result = verification('" + sampleItem + "');";
try {
engine.eval(validationRules);
return Boolean.parseBoolean(engine.get("result").toString());
} catch (Exception ex) {
throw BusinessExceptionBuilder.build(RespCommonCode.EXECUTE_JS_ERROR, ex.getMessage());
}
}
return true;
}
/**
* js
*
* @param dataSetParamDtoList
* @return
*/
@Override
public boolean verification(List<DataSetParamDto> dataSetParamDtoList, Map<String, Object> contextData) {
if (null == dataSetParamDtoList || dataSetParamDtoList.size() == 0) {
return true;
}
for (DataSetParamDto dataSetParamDto : dataSetParamDtoList) {
if (null != contextData) {
String value = contextData.getOrDefault(dataSetParamDto.getParamName(), "").toString();
dataSetParamDto.setSampleItem(value);
}
if (!verification(dataSetParamDto)) {
return false;
}
}
return true;
}
}

@ -0,0 +1,36 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetParam.util;
import org.springframework.util.PropertyPlaceholderHelper;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created by raodeming on 2021/3/23.
*/
public class ParamsResolverHelper {
private static String placeholderPrefix = "${";
private static String placeholderSuffix = "}";
private static PropertyPlaceholderHelper helper =
new PropertyPlaceholderHelper(placeholderPrefix, placeholderSuffix);
public static String resolveParams(final Map<String, Object> param, String con) {
con = helper.replacePlaceholders(con, (key -> param.get(key) + ""));
return con;
}
private static Pattern key = Pattern.compile("\\$\\{(.*?)\\}");
public static List<String> findParamKeys(String con) {
Matcher m = key.matcher(con);
List ret = new ArrayList();
while (m.find()) {
ret.add(m.group(1));
}
return ret;
}
}

@ -0,0 +1,44 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller;
import com.anji.plus.gaea.curd.controller.GaeaBaseController;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.param.DataSetTransformParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity.DataSetTransform;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.DataSetTransformService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* @desc controller
* @website https://gitee.com/anji-plus/gaea
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@RestController
@Api(tags = "数据集数据转换管理")
@RequestMapping("/dataSetTransform")
public class DataSetTransformController extends GaeaBaseController<DataSetTransformParam, DataSetTransform, DataSetTransformDto> {
@Autowired
private DataSetTransformService dataSetTransformService;
@Override
public GaeaBaseService<DataSetTransformParam, DataSetTransform> getService() {
return dataSetTransformService;
}
@Override
public DataSetTransform getEntity() {
return new DataSetTransform();
}
@Override
public DataSetTransformDto getDTO() {
return new DataSetTransformDto();
}
}

@ -0,0 +1,36 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto;
import com.anji.plus.gaea.curd.dto.GaeaBaseDTO;
import lombok.Data;
import java.io.Serializable;
/**
*
* @description dto
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@Data
public class DataSetTransformDto extends GaeaBaseDTO implements Serializable {
/** 数据集编码 */
private String setCode;
/** 数据转换类型DIC_NAME=TRANSFORM_TYPE; jsjavaBean字典转换 */
private String transformType;
/** 数据转换script,处理逻辑 */
private String transformScript;
/** 排序,执行数据转换顺序 */
private Integer orderNum;
/** 0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG */
private Integer enableFlag;
/** 0--未删除 1--已删除 DIC_NAME=DELETE_FLAG */
private Integer deleteFlag;
}

@ -0,0 +1,17 @@
/**/
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.param;
import com.anji.plus.gaea.curd.params.PageParam;
import lombok.Data;
import java.io.Serializable;
/**
* @desc DataSetTransform
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@Data
public class DataSetTransformParam extends PageParam implements Serializable{
}

@ -0,0 +1,15 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity.DataSetTransform;
import org.apache.ibatis.annotations.Mapper;
/**
* DataSetTransform Mapper
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@Mapper
public interface DataSetTransformMapper extends GaeaBaseMapper<DataSetTransform> {
}

@ -0,0 +1,36 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity;
import com.anji.plus.gaea.curd.entity.GaeaBaseEntity;
import com.baomidou.mybatisplus.annotation.TableName;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @description entity
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@TableName(value="gaea_report_data_set_transform")
@Data
public class DataSetTransform extends GaeaBaseEntity {
@ApiModelProperty(value = "数据集编码")
private String setCode;
@ApiModelProperty(value = "数据转换类型DIC_NAME=TRANSFORM_TYPE; jsjavaBean字典转换")
private String transformType;
@ApiModelProperty(value = "数据转换script,处理逻辑")
private String transformScript;
@ApiModelProperty(value = "排序,执行数据转换顺序")
private Integer orderNum;
@ApiModelProperty(value = "0--已禁用 1--已启用 DIC_NAME=ENABLE_FLAG")
private Integer enableFlag;
@ApiModelProperty(value = "0--未删除 1--已删除 DIC_NAME=DELETE_FLAG")
private Integer deleteFlag;
}

@ -0,0 +1,21 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.curd.service.GaeaBaseService;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.param.DataSetTransformParam;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity.DataSetTransform;
import java.util.List;
/**
* @desc DataSetTransform
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
public interface DataSetTransformService extends GaeaBaseService<DataSetTransformParam, DataSetTransform> {
List<JSONObject> transform(List<DataSetTransformDto> dataSetTransformDtoList, List<JSONObject> data);
}

@ -0,0 +1,25 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import java.util.List;
/**
* Created by raodeming on 2021/3/23.
*/
public interface TransformStrategy {
/**
*
* @return
*/
String type();
/***
*
* @param def
* @param data
* @return
*/
List<JSONObject> transform(DataSetTransformDto def, List<JSONObject> data);
}

@ -0,0 +1,71 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.curd.mapper.GaeaBaseMapper;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.DataSetTransformMapper;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.dao.entity.DataSetTransform;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.DataSetTransformService;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.TransformStrategy;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @desc DataSetTransform
* @author Raod
* @date 2021-03-18 12:13:15.591309400
**/
@Service
//@RequiredArgsConstructor
public class DataSetTransformServiceImpl implements DataSetTransformService, InitializingBean, ApplicationContextAware {
private final Map<String, TransformStrategy> queryServiceImplMap = new HashMap<>();
private ApplicationContext applicationContext;
@Autowired
private DataSetTransformMapper dataSetTransformMapper;
@Override
public GaeaBaseMapper<DataSetTransform> getMapper() {
return dataSetTransformMapper;
}
public TransformStrategy getTarget(String type) {
return queryServiceImplMap.get(type);
}
@Override
public void afterPropertiesSet() {
Map<String, TransformStrategy> beanMap = applicationContext.getBeansOfType(TransformStrategy.class);
//遍历该接口的所有实现将其放入map中
for (TransformStrategy serviceImpl : beanMap.values()) {
queryServiceImplMap.put(serviceImpl.type(), serviceImpl);
}
}
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
@Override
public List<JSONObject> transform(List<DataSetTransformDto> dataSetTransformDtoList, List<JSONObject> data) {
if (dataSetTransformDtoList == null || dataSetTransformDtoList.size() <= 0) {
return data;
}
for (DataSetTransformDto dataSetTransformDto : dataSetTransformDtoList) {
data = getTarget(dataSetTransformDto.getTransformType()).transform(dataSetTransformDto, data);
}
return data;
}
}

@ -0,0 +1,56 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.TransformStrategy;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;
import java.util.List;
import java.util.Set;
/**
*
* Created by raodeming on 2021/3/29.
*/
@Component
@Slf4j
public class DictTransformServiceImpl implements TransformStrategy {
/**
*
*
* @return
*/
@Override
public String type() {
return "dict";
}
/***
*
* @param def
* @param data
* @return
*/
@Override
public List<JSONObject> transform(DataSetTransformDto def, List<JSONObject> data) {
String transformScript = def.getTransformScript();
if (StringUtils.isBlank(transformScript)) {
return data;
}
JSONObject jsonObject = JSONObject.parseObject(transformScript);
Set<String> keys = jsonObject.keySet();
data.forEach(dataDetail -> dataDetail.forEach((key, value) -> {
if (keys.contains(key)) {
String string = jsonObject.getJSONObject(key).getString(value.toString());
if (StringUtils.isNotBlank(string)) {
dataDetail.put(key, string);
}
}
}));
return data;
}
}

@ -0,0 +1,62 @@
package com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.impl;
import com.alibaba.fastjson.JSONObject;
import com.anji.plus.gaea.exception.BusinessExceptionBuilder;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.controller.dto.DataSetTransformDto;
import com.anjiplus.template.gaea.business.modules.data.dataSetTransform.service.TransformStrategy;
import com.anjiplus.template.gaea.common.RespCommonCode;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import java.util.List;
import java.util.stream.Collectors;
/**
* Created by raodeming on 2021/3/23.
*/
@Component
@Slf4j
public class JsTransformServiceImpl implements TransformStrategy {
private ScriptEngine engine;
{
ScriptEngineManager manager = new ScriptEngineManager();
engine = manager.getEngineByName("JavaScript");
}
/**
*
*
* @return
*/
@Override
public String type() {
return "js";
}
/***
*
* @param def
* @param data
* @return
*/
@Override
public List<JSONObject> transform(DataSetTransformDto def, List<JSONObject> data) {
return getValueFromJS(def,data);
}
private List<JSONObject> getValueFromJS(DataSetTransformDto def, List<JSONObject> data) {
String js = def.getTransformScript();
js = js + "\nvar result = dataTransform(eval(" + data.toString() + "));";
try {
engine.eval(js);
ScriptObjectMirror result = (ScriptObjectMirror) engine.get("result");
return result.values().stream().map(o -> JSONObject.parseObject(JSONObject.toJSONString(o))).collect(Collectors.toList());
} catch (Exception ex) {
throw BusinessExceptionBuilder.build(RespCommonCode.EXECUTE_JS_ERROR, ex.getMessage());
}
}
}
Loading…
Cancel
Save