Merge pull request 'fix : js 执行函数报错' (#86) from portal into master

Reviewed-on: http://git.feashow.cn/clay/fateverse/pulls/86
This commit is contained in:
clay
2024-04-29 14:08:00 +00:00
4 changed files with 32 additions and 6 deletions

View File

@@ -41,9 +41,15 @@ public class JavaScriptEngine {
* @return 返回结构
*/
public static Object execute(String script, String functionName, Object args) {
try {
Value executeFunction = getFunction(functionName, script);
Value result = executeFunction.execute(JSON.toJSONString(args));
Value javaObjectAsValue = Value.asValue(args);
Value result = executeFunction.execute(javaObjectAsValue);
return result.as(Object.class);
} catch (Exception e) {
remove(functionName);
throw new CustomException("运行失败!");
}
}
@@ -90,4 +96,12 @@ public class JavaScriptEngine {
}
private static void remove(String functionName) {
SegmentLock.lock(functionName, () -> {
functionMap.remove(functionName);
return null;
});
}
}

View File

@@ -36,6 +36,8 @@ public class PortalVo extends SimplePortalVo {
*/
private Boolean page;
private String url;
/**
* 条件映射
*/

View File

@@ -41,6 +41,9 @@ public class JavaEngineExecuteHandler implements EngineExecuteHandler {
@Override
public EngineResult mockExecute(DataAdapter dataAdapter, Object data) {
if (!DataAdapterType.JAVA.equals(dataAdapter.getType())) {
return null;
}
return javaCodeEngine.mockExecute(dataAdapter.getExecuteCode(), getClassName(dataAdapter),
"execute", new Object[]{data});
}

View File

@@ -129,8 +129,15 @@ public class PortalServiceImpl implements PortalService {
}
if (PortalEnum.LOCAL.equals(portal.getType())) {
UniQuery uniQuery = queryMapper.selectById(portal.getQueryId());
if (!ObjectUtils.isEmpty(uniQuery)) {
portalVo.setQueryType(uniQuery.getType());
}
} else {
PortalInterface portalInterface = portalInterfaceMapper.selectById(portal.getInterfaceId());
if (!ObjectUtils.isEmpty(portalInterface)) {
portalVo.setUrl(portalInterface.getUrl());
}
}
if (portal.getCreateDataAdapter()) {
DataAdapter dataAdapter = adapterMapper.selectById(portal.getAdapterId());
if (!ObjectUtils.isEmpty(dataAdapter)) {