From 446697379b15184b2acd20535284fc85d63f94e8 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 11 May 2021 16:13:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20ESB=E7=9A=843=E7=82=B9=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1.用户登陆接口定义页面,会自动选择这个角色上一次选择的接口类型;2.ESB接口编辑-请求参数表格,取消每一行后的确认按钮,改为在table最下方增加一个整体的确认按钮。按钮包含校验功能;3.接口导入时所属模块默认选择第一个 --- .../api/controller/ApiModuleController.java | 22 ++++++++-- .../ApiDefinitionDefaultApiTypeUtil.java | 43 +++++++++++++++++++ .../components/import/ApiImport.vue | 5 +++ .../components/module/ApiModule.vue | 11 ++++- 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionDefaultApiTypeUtil.java diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java index 8b37847748..3175fce687 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiModuleController.java @@ -5,6 +5,8 @@ import io.metersphere.api.dto.definition.DragModuleRequest; import io.metersphere.api.service.ApiModuleService; import io.metersphere.base.domain.ApiModule; import io.metersphere.commons.constants.RoleConstants; +import io.metersphere.commons.utils.ApiDefinitionDefaultApiTypeUtil; +import io.metersphere.commons.utils.SessionUtils; import io.metersphere.service.CheckPermissionService; import org.apache.shiro.authz.annotation.Logical; import org.apache.shiro.authz.annotation.RequiresRoles; @@ -26,13 +28,27 @@ public class ApiModuleController { @GetMapping("/list/{projectId}/{protocol}") public List getNodeByProjectId(@PathVariable String projectId,@PathVariable String protocol) { checkPermissionService.checkProjectOwner(projectId); - return apiModuleService.getNodeTreeByProjectId(projectId,protocol); + String userId = SessionUtils.getUserId(); + ApiDefinitionDefaultApiTypeUtil.addUserSelectApiType(userId, protocol); + return apiModuleService.getNodeTreeByProjectId(projectId, protocol); } @GetMapping("/getModuleByName/{projectId}/{protocol}") - public ApiModule getModuleByName(@PathVariable String projectId,@PathVariable String protocol) { + public ApiModule getModuleByName(@PathVariable String projectId, @PathVariable String protocol) { checkPermissionService.checkProjectOwner(projectId); - return apiModuleService.getModuleByName(projectId,protocol); + return apiModuleService.getModuleByName(projectId, protocol); + } + + @GetMapping("/getUserDefaultApiType") + public String getUserDefaultApiType() { + String returnStr = ApiDefinitionDefaultApiTypeUtil.HTTP; + try { + String userId = SessionUtils.getUserId(); + returnStr = ApiDefinitionDefaultApiTypeUtil.getUserSelectedApiType(userId); + } catch (Exception e) { + + } + return returnStr; } @GetMapping("/list/plan/{planId}/{protocol}") diff --git a/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionDefaultApiTypeUtil.java b/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionDefaultApiTypeUtil.java new file mode 100644 index 0000000000..4cb1726f7a --- /dev/null +++ b/backend/src/main/java/io/metersphere/commons/utils/ApiDefinitionDefaultApiTypeUtil.java @@ -0,0 +1,43 @@ +package io.metersphere.commons.utils; + +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; + +/** + * 获取用户进入接口定义页面 默认展示的接口类型 + * + * @author song.tianyang + * @Date 2021/5/11 10:52 上午 + * @Description + */ +public class ApiDefinitionDefaultApiTypeUtil { + public static final String HTTP = "HTTP"; + public static final String SQL = "SQL"; + public static final String DUBBO = "DUBBO"; + public static final String TCP = "TCP"; + + private static HashMap apiTypePerferenceMap; + + public synchronized static void addUserSelectApiType(String userId, String apiType) { + if (StringUtils.isNotEmpty(userId) && StringUtils.isNotEmpty(apiType)) { + if (apiTypePerferenceMap == null) { + apiTypePerferenceMap = new HashMap<>(); + } + apiTypePerferenceMap.put(userId, apiType); + } + } + + public synchronized static String getUserSelectedApiType(String userId) { + if (StringUtils.isEmpty(userId)) { + return HTTP; + } else { + String selectedApiType = apiTypePerferenceMap.get(userId); + if (StringUtils.equalsAny(selectedApiType, HTTP, SQL, DUBBO, TCP)) { + return selectedApiType; + } else { + return HTTP; + } + } + } +} diff --git a/frontend/src/business/components/api/definition/components/import/ApiImport.vue b/frontend/src/business/components/api/definition/components/import/ApiImport.vue index afdec45c36..c924eb4a85 100644 --- a/frontend/src/business/components/api/definition/components/import/ApiImport.vue +++ b/frontend/src/business/components/api/definition/components/import/ApiImport.vue @@ -201,6 +201,11 @@ this.selectedPlatform = this.platforms[0]; }, watch: { + moduleOptions() { + if (this.moduleOptions.length > 0) { + this.formData.moduleId = this.moduleOptions[0].id; + } + }, selectedPlatformValue() { for (let i in this.platforms) { if (this.platforms[i].value === this.selectedPlatformValue) { diff --git a/frontend/src/business/components/api/definition/components/module/ApiModule.vue b/frontend/src/business/components/api/definition/components/module/ApiModule.vue index 56c6e4c5fa..1ccbeba480 100644 --- a/frontend/src/business/components/api/definition/components/module/ApiModule.vue +++ b/frontend/src/business/components/api/definition/components/module/ApiModule.vue @@ -93,9 +93,9 @@ }, }, mounted() { - this.$emit('protocolChange', this.condition.protocol); - this.list(); + this.initProtocol(); }, + watch: { 'condition.filterText'(val) { this.$refs.nodeTree.filter(val); @@ -118,6 +118,13 @@ } }, methods: { + initProtocol() { + this.$get('/api/module//getUserDefaultApiType/', response => { + this.condition.protocol = response.data; + this.$emit('protocolChange', this.condition.protocol); + this.list(); + }); + }, list(projectId) { let url = undefined; if (this.isPlanModel) {