From ac94d86261b316ccb5ceb98c2fe96251bec393ea Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Wed, 1 Dec 2021 15:55:00 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E7=8E=AF=E5=A2=83=E7=BB=84):=20?= =?UTF-8?q?=E5=AF=B9=E7=8E=AF=E5=A2=83=E7=BB=84=E9=80=89=E9=A1=B9=E8=BF=9B?= =?UTF-8?q?=E8=A1=8C=E8=BF=87=E6=BB=A4=E5=88=86=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1008140 --user=lyh 【环境组】-项目不属于环境组可见环境组选项 和需求不一致 https://www.tapd.cn/55049933/s/1076963 --- .../EnvironmentGroupController.java | 6 + .../request/EnvironmentGroupRequest.java | 1 + .../metersphere/dto/EnvironmentGroupDTO.java | 11 ++ .../service/EnvironmentGroupService.java | 26 ++++ .../automation/scenario/EditApiScenario.vue | 2 +- .../api/automation/scenario/EnvGroup.vue | 4 - .../scenario/EnvGroupWithOption.vue | 137 ++++++++++++++++++ .../api/automation/scenario/EnvPopover.vue | 31 +++- .../scenario/maximize/ScenarioHeader.vue | 2 +- 9 files changed, 207 insertions(+), 13 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/dto/EnvironmentGroupDTO.java create mode 100644 frontend/src/business/components/api/automation/scenario/EnvGroupWithOption.vue diff --git a/backend/src/main/java/io/metersphere/controller/EnvironmentGroupController.java b/backend/src/main/java/io/metersphere/controller/EnvironmentGroupController.java index 612f669081..0d3a08577b 100644 --- a/backend/src/main/java/io/metersphere/controller/EnvironmentGroupController.java +++ b/backend/src/main/java/io/metersphere/controller/EnvironmentGroupController.java @@ -7,6 +7,7 @@ import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.EnvironmentGroupRequest; +import io.metersphere.dto.EnvironmentGroupDTO; import io.metersphere.service.EnvironmentGroupService; import org.springframework.web.bind.annotation.*; @@ -71,4 +72,9 @@ public class EnvironmentGroupController { public void copy(@PathVariable String id) { environmentGroupService.copy(id); } + + @PostMapping("/get/option") + public List getEnvOptionGroup(@RequestBody EnvironmentGroupRequest request) { + return environmentGroupService.getEnvOptionGroup(request.getProjectIds()); + } } diff --git a/backend/src/main/java/io/metersphere/controller/request/EnvironmentGroupRequest.java b/backend/src/main/java/io/metersphere/controller/request/EnvironmentGroupRequest.java index a0a0d42a27..4383a8bbd6 100644 --- a/backend/src/main/java/io/metersphere/controller/request/EnvironmentGroupRequest.java +++ b/backend/src/main/java/io/metersphere/controller/request/EnvironmentGroupRequest.java @@ -19,4 +19,5 @@ public class EnvironmentGroupRequest extends EnvironmentGroup { */ private Map map; private List groupIds; + private List projectIds; } diff --git a/backend/src/main/java/io/metersphere/dto/EnvironmentGroupDTO.java b/backend/src/main/java/io/metersphere/dto/EnvironmentGroupDTO.java new file mode 100644 index 0000000000..40ed8b138c --- /dev/null +++ b/backend/src/main/java/io/metersphere/dto/EnvironmentGroupDTO.java @@ -0,0 +1,11 @@ +package io.metersphere.dto; + +import io.metersphere.base.domain.EnvironmentGroup; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class EnvironmentGroupDTO extends EnvironmentGroup { + private Boolean disabled = false; +} diff --git a/backend/src/main/java/io/metersphere/service/EnvironmentGroupService.java b/backend/src/main/java/io/metersphere/service/EnvironmentGroupService.java index 1146823d0d..39b6b6f532 100644 --- a/backend/src/main/java/io/metersphere/service/EnvironmentGroupService.java +++ b/backend/src/main/java/io/metersphere/service/EnvironmentGroupService.java @@ -10,15 +10,19 @@ import io.metersphere.base.mapper.ext.ExtEnvironmentGroupMapper; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.SessionUtils; import io.metersphere.controller.request.EnvironmentGroupRequest; +import io.metersphere.dto.EnvironmentGroupDTO; import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; +import org.springframework.beans.BeanUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.UUID; @@ -46,6 +50,8 @@ public class EnvironmentGroupService { private ApiTestEnvironmentMapper apiTestEnvironmentMapper; @Resource private ApiAutomationService apiAutomationService; + @Resource + private EnvironmentGroupProjectService environmentGroupProjectService; public EnvironmentGroup add(EnvironmentGroupRequest request) { request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); @@ -246,4 +252,24 @@ public class EnvironmentGroupService { } sqlSession.flushStatements(); } + + public List getEnvOptionGroup(List projectIds) { + EnvironmentGroupExample example = new EnvironmentGroupExample(); + example.createCriteria().andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId()); + List result = new ArrayList<>(); + List groups = environmentGroupMapper.selectByExample(example); + for (EnvironmentGroup group : groups) { + Map envMap = environmentGroupProjectService.getEnvMap(group.getId()); + EnvironmentGroupDTO dto = new EnvironmentGroupDTO(); + BeanUtils.copyProperties(group, dto); + if (CollectionUtils.isNotEmpty(projectIds)) { + boolean b = envMap.keySet().containsAll(projectIds); + if (BooleanUtils.isFalse(b)) { + dto.setDisabled(true); + } + } + result.add(dto); + } + return result; + } } diff --git a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue index 4bf7b8380e..cb617d84f1 100644 --- a/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue +++ b/frontend/src/business/components/api/automation/scenario/EditApiScenario.vue @@ -137,7 +137,7 @@ :group-id="envGroupId" :project-list="projectList" :show-config-button-with-out-permission="showConfigButtonWithOutPermission" @setProjectEnvMap="setProjectEnvMap" @setEnvGroup="setEnvGroup" - @showPopover="showPopover" + @showPopover="showPopover" :has-option-group="true" ref="envPopover" class="ms-message-right"/> diff --git a/frontend/src/business/components/api/automation/scenario/EnvGroup.vue b/frontend/src/business/components/api/automation/scenario/EnvGroup.vue index c21492a182..c13efb9320 100644 --- a/frontend/src/business/components/api/automation/scenario/EnvGroup.vue +++ b/frontend/src/business/components/api/automation/scenario/EnvGroup.vue @@ -2,7 +2,6 @@
- @@ -23,7 +22,6 @@ + + diff --git a/frontend/src/business/components/api/automation/scenario/EnvPopover.vue b/frontend/src/business/components/api/automation/scenario/EnvPopover.vue index f037a24110..aaf7f2979b 100644 --- a/frontend/src/business/components/api/automation/scenario/EnvPopover.vue +++ b/frontend/src/business/components/api/automation/scenario/EnvPopover.vue @@ -19,9 +19,13 @@ @setProjectEnvMap="setProjectEnvMap" v-show="!radio || radio === ENV_TYPE.JSON" ref="envSelect"/> - - + + {{ $t('api_test.definition.request.run_env') }} @@ -33,15 +37,16 @@ import EnvSelect from "@/business/components/api/automation/scenario/EnvSelect"; import {ENV_TYPE} from "@/common/js/constants"; import EnvGroup from "@/business/components/api/automation/scenario/EnvGroup"; +import EnvGroupWithOption from "@/business/components/api/automation/scenario/EnvGroupWithOption"; export default { name: "EnvPopover", - components: {EnvGroup, EnvSelect}, + components: {EnvGroup, EnvSelect, EnvGroupWithOption}, props: { envMap: Map, projectIds: Set, projectList: Array, - showConfigButtonWithOutPermission:{ + showConfigButtonWithOutPermission: { type: Boolean, default() { return true; @@ -77,6 +82,12 @@ export default { default() { return "bottom"; } + }, + hasOptionGroup: { + type: Boolean, + default() { + return false; + } } }, data() { @@ -105,8 +116,13 @@ export default { }, openEnvSelect() { this.$refs.envSelect.open(); - this.$refs.envGroup.init(); - this.$refs.envGroup.open(); + if (!this.hasOptionGroup) { + this.$refs.envGroup.init(); + this.$refs.envGroup.open(); + } else { + this.$refs.envOptionGroup.init(); + this.$refs.envOptionGroup.open(); + } }, setProjectEnvMap(map) { this.$emit("setProjectEnvMap", map); @@ -123,7 +139,8 @@ export default { let res = this.$refs.envSelect.checkEnv(data); resolve(res); } else if (this.environmentType === ENV_TYPE.GROUP) { - let res = this.$refs.envGroup.checkEnv(); + let res = !this.hasOptionGroup ? this.$refs.envGroup.checkEnv() : + this.$refs.envOptionGroup.checkEnv(); res.then(r => { resolve(r); }) diff --git a/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue b/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue index 3b4ee83e69..9f775b19d1 100644 --- a/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue +++ b/frontend/src/business/components/api/automation/scenario/maximize/ScenarioHeader.vue @@ -28,7 +28,7 @@