refactor: 删除环境组时置空与之相关的场景环境组字段

This commit is contained in:
shiziyuan9527 2021-11-30 15:43:13 +08:00 committed by shiziyuan9527
parent 07f3572805
commit 08f7cb1bc2
4 changed files with 13 additions and 0 deletions

View File

@ -3043,4 +3043,8 @@ public class ApiAutomationService {
List<ApiScenarioFollow> follows = apiScenarioFollowMapper.selectByExample(example); List<ApiScenarioFollow> follows = apiScenarioFollowMapper.selectByExample(example);
return follows.stream().map(ApiScenarioFollow::getFollowId).distinct().collect(Collectors.toList()); return follows.stream().map(ApiScenarioFollow::getFollowId).distinct().collect(Collectors.toList());
} }
public void setScenarioEnvGroupIdNull(String envGroupId) {
extApiScenarioMapper.setScenarioEnvGroupIdNull(envGroupId);
}
} }

View File

@ -85,4 +85,6 @@ public interface ExtApiScenarioMapper {
List<RelationshipGraphData.Node> getTestCaseForGraph(@Param("ids") Set<String> ids); List<RelationshipGraphData.Node> getTestCaseForGraph(@Param("ids") Set<String> ids);
void setScenarioEnvGroupIdNull(@Param("environmentGroupId") String environmentGroupId);
} }

View File

@ -389,6 +389,9 @@
<update id="updateCustomNumByProjectId"> <update id="updateCustomNumByProjectId">
update api_scenario set custom_num = num where (custom_num is null or custom_num = '') and project_id = #{projectId} update api_scenario set custom_num = num where (custom_num is null or custom_num = '') and project_id = #{projectId}
</update> </update>
<update id="setScenarioEnvGroupIdNull">
update api_scenario set environment_group_id = null where environment_group_id = #{environmentGroupId}
</update>
<select id="countByProjectID" resultType="java.lang.Long"> <select id="countByProjectID" resultType="java.lang.Long">
SELECT COUNT(id) AS countNumber FROM api_scenario WHERE project_id = #{0} AND status != 'Trash' SELECT COUNT(id) AS countNumber FROM api_scenario WHERE project_id = #{0} AND status != 'Trash'

View File

@ -1,5 +1,6 @@
package io.metersphere.service; package io.metersphere.service;
import io.metersphere.api.service.ApiAutomationService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import io.metersphere.base.mapper.ApiTestEnvironmentMapper;
import io.metersphere.base.mapper.EnvironmentGroupMapper; import io.metersphere.base.mapper.EnvironmentGroupMapper;
@ -43,6 +44,8 @@ public class EnvironmentGroupService {
private ProjectMapper projectMapper; private ProjectMapper projectMapper;
@Resource @Resource
private ApiTestEnvironmentMapper apiTestEnvironmentMapper; private ApiTestEnvironmentMapper apiTestEnvironmentMapper;
@Resource
private ApiAutomationService apiAutomationService;
public EnvironmentGroup add(EnvironmentGroupRequest request) { public EnvironmentGroup add(EnvironmentGroupRequest request) {
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
@ -93,6 +96,7 @@ public class EnvironmentGroupService {
return; return;
} }
environmentGroupMapper.deleteByPrimaryKey(id); environmentGroupMapper.deleteByPrimaryKey(id);
apiAutomationService.setScenarioEnvGroupIdNull(id);
EnvironmentGroupProjectExample example = new EnvironmentGroupProjectExample(); EnvironmentGroupProjectExample example = new EnvironmentGroupProjectExample();
example.createCriteria().andEnvironmentGroupIdEqualTo(id); example.createCriteria().andEnvironmentGroupIdEqualTo(id);
environmentGroupProjectMapper.deleteByExample(example); environmentGroupProjectMapper.deleteByExample(example);