diff --git a/README.md b/README.md index e3ee59cb..1ed6c0e2 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ magic-api 是一个基于Java的接口快速开发框架,编写接口将通过 org.ssssssss magic-api-spring-boot-starter - 1.4.0 + 1.4.1 ``` ## 修改application.properties diff --git a/magic-api-spring-boot-starter/pom.xml b/magic-api-spring-boot-starter/pom.xml index 87cd3685..bf2337d5 100644 --- a/magic-api-spring-boot-starter/pom.xml +++ b/magic-api-spring-boot-starter/pom.xml @@ -6,7 +6,7 @@ org.ssssssss magic-api-parent - 1.4.0 + 1.4.1 magic-api-spring-boot-starter jar diff --git a/magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java b/magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java index 1257e7df..e0c8eea1 100644 --- a/magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java +++ b/magic-api-spring-boot-starter/src/main/java/org/ssssssss/magicapi/spring/boot/starter/MagicAPIAutoConfiguration.java @@ -617,9 +617,11 @@ public boolean supports(Class clazz) { @Override public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) { String web = properties.getWeb(); + MagicNotifyService magicNotifyService = magicNotifyServiceProvider.getObject(); + WebSocketSessionManager.setMagicNotifyService(magicNotifyService); if (web != null && !registerWebsocket) { registerWebsocket = true; - MagicWebSocketDispatcher dispatcher = new MagicWebSocketDispatcher(properties.getClusterConfig().getInstanceId(), magicNotifyServiceProvider.getObject(), Arrays.asList( + MagicWebSocketDispatcher dispatcher = new MagicWebSocketDispatcher(properties.getClusterConfig().getInstanceId(), magicNotifyService, Arrays.asList( new MagicDebugHandler(), new MagicWorkbenchHandler(authorizationInterceptorProvider.getIfAvailable(this::createAuthorizationInterceptor)) )); diff --git a/magic-api/pom.xml b/magic-api/pom.xml index d0e77464..9940cbfa 100644 --- a/magic-api/pom.xml +++ b/magic-api/pom.xml @@ -6,7 +6,7 @@ org.ssssssss magic-api-parent - 1.4.0 + 1.4.1 magic-api jar diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java b/magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java index deb4d5d8..c9be6e3a 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/config/MagicFunctionManager.java @@ -136,6 +136,10 @@ public List getFunctionInfos() { return mappings.values().stream().distinct().collect(Collectors.toList()); } + public FunctionInfo getFunctionInfo(String path) { + return mappings.get(path); + } + private boolean hasConflict(TreeNode group, String newPath) { // 获取要移动的接口 List infos = mappings.values().stream() diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/config/WebSocketSessionManager.java b/magic-api/src/main/java/org/ssssssss/magicapi/config/WebSocketSessionManager.java index 2fd648d2..1eb1961b 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/config/WebSocketSessionManager.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/config/WebSocketSessionManager.java @@ -42,12 +42,11 @@ public static void remove(String sessionId) { public static void sendToAll(MessageType messageType, Object... values) { String content = buildMessage(messageType, values); sendToAll(content); - // 通知其他机器去发送消息 - magicNotifyService.sendNotify(new MagicNotify(instanceId, Constants.NOTIFY_WS_S_C, null, content)); } private static void sendToAll(String content) { SESSION.values().stream().filter(MagicConsoleSession::writeable).forEach(session -> sendBySession(session, content)); + sendToOther(null, content); } public static void sendBySessionId(String sessionId, MessageType messageType, Object... values) { @@ -55,7 +54,13 @@ public static void sendBySessionId(String sessionId, MessageType messageType, Ob String content = buildMessage(messageType, values); if (session != null && session.writeable()) { sendBySession(session, content); - } else if (magicNotifyService != null) { + } else { + sendToOther(sessionId, content); + } + } + + private static void sendToOther(String sessionId, String content){ + if (magicNotifyService != null) { // 通知其他机器去发送消息 magicNotifyService.sendNotify(new MagicNotify(instanceId, Constants.NOTIFY_WS_S_C, sessionId, content)); } diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicAPIController.java b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicAPIController.java index a4842b3c..e001b137 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicAPIController.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicAPIController.java @@ -9,11 +9,9 @@ import org.ssssssss.magicapi.model.ApiInfo; import org.ssssssss.magicapi.model.Backup; import org.ssssssss.magicapi.model.JsonBean; -import org.ssssssss.magicapi.provider.ApiServiceProvider; -import org.ssssssss.magicapi.provider.MagicAPIService; -import org.ssssssss.magicapi.provider.MagicBackupService; import javax.servlet.http.HttpServletRequest; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -74,7 +72,10 @@ public JsonBean get(HttpServletRequest request, String id) { @ResponseBody public JsonBean> backupList(HttpServletRequest request, String id) { isTrue(allowVisit(request, Authorization.VIEW, getApiInfo(id)), PERMISSION_INVALID); - return new JsonBean<>(magicBackupService.backupById(id)); + return new JsonBean<>(magicBackupService.backupById(id) + .stream() + .sorted(Comparator.comparing(Backup::getCreateDate).reversed()) + .collect(Collectors.toList())); } /** diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicFunctionController.java b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicFunctionController.java index 5c3a86d6..93498bd6 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicFunctionController.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/controller/MagicFunctionController.java @@ -9,11 +9,9 @@ import org.ssssssss.magicapi.model.Backup; import org.ssssssss.magicapi.model.FunctionInfo; import org.ssssssss.magicapi.model.JsonBean; -import org.ssssssss.magicapi.provider.FunctionServiceProvider; -import org.ssssssss.magicapi.provider.MagicAPIService; -import org.ssssssss.magicapi.provider.MagicBackupService; import javax.servlet.http.HttpServletRequest; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; @@ -52,7 +50,10 @@ public JsonBean backups(HttpServletRequest request, String id, Long time @ResponseBody public JsonBean> backupList(HttpServletRequest request, String id) { isTrue(allowVisit(request, Authorization.VIEW, getFunctionInfo(id)), PERMISSION_INVALID); - return new JsonBean<>(magicBackupService.backupById(id)); + return new JsonBean<>(magicBackupService.backupById(id) + .stream() + .sorted(Comparator.comparing(Backup::getCreateDate).reversed()) + .collect(Collectors.toList())); } @RequestMapping("/function/move") diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/model/Backup.java b/magic-api/src/main/java/org/ssssssss/magicapi/model/Backup.java index 5c48f853..b191bedc 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/model/Backup.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/model/Backup.java @@ -12,7 +12,7 @@ public class Backup { /** * 备份时间 */ - private long createDate; + private Long createDate = 0L; /** * 标签,只允许有一个 @@ -58,11 +58,11 @@ public void setType(String type) { this.type = type; } - public long getCreateDate() { + public Long getCreateDate() { return createDate; } - public void setCreateDate(long createDate) { + public void setCreateDate(Long createDate) { this.createDate = createDate; } diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java b/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java index 2488fa21..46d39d1c 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/modules/table/NamedTable.java @@ -19,7 +19,7 @@ public class NamedTable { String logicDeleteColumn; - String logicDeleteValue; + Object logicDeleteValue; Map columns = new HashMap<>(); @@ -46,7 +46,19 @@ public NamedTable(String tableName, SQLModule sqlModule, Function 2){ + this.logicDeleteValue = deleteValue.substring(1,deleteValue.length() - 1); + }else{ + try { + this.logicDeleteValue = Integer.parseInt(deleteValue); + } catch (NumberFormatException e) { + this.logicDeleteValue = deleteValue; + } + } + } } @Comment("使用逻辑删除") diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/provider/MagicAPIService.java b/magic-api/src/main/java/org/ssssssss/magicapi/provider/MagicAPIService.java index dd8675e8..65d7ab29 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/provider/MagicAPIService.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/provider/MagicAPIService.java @@ -19,7 +19,7 @@ public interface MagicAPIService extends MagicModule { * * @param method 请求方法 * @param path 请求路径 - * @param context 请求上下文,主要给脚本中使用 + * @param context 变量信息 */ Object execute(String method, String path, Map context); @@ -28,10 +28,18 @@ public interface MagicAPIService extends MagicModule { * * @param method 请求方法 * @param path 请求路径 - * @param context 请求上下文,主要给脚本中使用 + * @param context 变量信息 */ Object call(String method, String path, Map context); + /** + * 执行MagicAPI中的函数 + * + * @param path 函数路径 + * @param context 变量信息 + */ + Object invoke(String path, Map context); + /** * 保存接口 * diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java b/magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java index b8321cc0..2fa72da0 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/provider/impl/DefaultMagicAPIService.java @@ -180,6 +180,19 @@ public Object call(String method, String path, Map context) { } } + @Override + public Object invoke(String path, Map context) { + FunctionInfo functionInfo = magicFunctionManager.getFunctionInfo(path); + if (functionInfo == null) { + throw new MagicServiceException(String.format("找不到对应函数 [%s]", path)); + } + MagicScriptContext scriptContext = new MagicScriptContext(context); + scriptContext.putMapIntoContext(context); + SimpleScriptContext simpleScriptContext = new SimpleScriptContext(); + simpleScriptContext.setAttribute(MagicScript.CONTEXT_ROOT, scriptContext, ScriptContext.ENGINE_SCOPE); + return ((MagicScript) ScriptManager.compile("MagicScript", functionInfo.getScript())).eval(simpleScriptContext); + } + @Override public String saveApi(ApiInfo info) { // 非空验证 diff --git a/magic-api/src/main/java/org/ssssssss/magicapi/utils/JsonUtils.java b/magic-api/src/main/java/org/ssssssss/magicapi/utils/JsonUtils.java index 1e031c3d..984c69b6 100644 --- a/magic-api/src/main/java/org/ssssssss/magicapi/utils/JsonUtils.java +++ b/magic-api/src/main/java/org/ssssssss/magicapi/utils/JsonUtils.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JavaType; import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -18,6 +19,7 @@ public class JsonUtils { static { mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } public static String toJsonString(Object target) { diff --git a/magic-editor/pom.xml b/magic-editor/pom.xml index b1557599..538dd142 100644 --- a/magic-editor/pom.xml +++ b/magic-editor/pom.xml @@ -6,7 +6,7 @@ org.ssssssss magic-api-parent - 1.4.0 + 1.4.1 magic-editor jar diff --git a/magic-editor/src/console/package.json b/magic-editor/src/console/package.json index be83aec9..cdfae08c 100644 --- a/magic-editor/src/console/package.json +++ b/magic-editor/src/console/package.json @@ -1,6 +1,6 @@ { "name": "magic-editor", - "version": "1.4.0", + "version": "1.4.1", "private": false, "description": "magic-editor for magic-api", "main": "dist/magic-editor.umd.min.js", diff --git a/magic-editor/src/console/src/components/common/magic-structure-array.vue b/magic-editor/src/console/src/components/common/magic-structure-array.vue index ef50d116..43950745 100644 --- a/magic-editor/src/console/src/components/common/magic-structure-array.vue +++ b/magic-editor/src/console/src/components/common/magic-structure-array.vue @@ -26,6 +26,7 @@ "{{value.replace(/"/g, "\"")}}" {{value}} {{value}} + null {{value}} diff --git a/magic-editor/src/console/src/components/common/magic-structure-object.vue b/magic-editor/src/console/src/components/common/magic-structure-object.vue index 28867037..acaab255 100644 --- a/magic-editor/src/console/src/components/common/magic-structure-object.vue +++ b/magic-editor/src/console/src/components/common/magic-structure-object.vue @@ -12,6 +12,7 @@ "{{value.replace(/"/g, "\"")}}" {{value}} {{value}} + null {{value}} } @@ -28,6 +29,7 @@ "{{value.replace(/"/g, "\"")}}" {{value}} {{value}} + null {{value}} diff --git a/magic-editor/src/console/src/components/common/magic-structure.vue b/magic-editor/src/console/src/components/common/magic-structure.vue index 15cfad9e..87b2d2c7 100644 --- a/magic-editor/src/console/src/components/common/magic-structure.vue +++ b/magic-editor/src/console/src/components/common/magic-structure.vue @@ -1,6 +1,7 @@