fix(测试计划): 测试计划的各种操作增加归档相关的逻辑判断

This commit is contained in:
Jianguo-Genius 2024-05-21 19:04:43 +08:00 committed by Craftsman
parent 2983288864
commit 0d4fea5a7c
10 changed files with 47 additions and 11 deletions

View File

@ -94,4 +94,5 @@ test_plan_report_name.not_blank=测试计划报告名称不能为空
test_plan_not_exist=测试计划不存在
test_plan.report_id.not_blank=测试计划报告ID不能为空
test_plan.report.share_id.not_blank=测试计划报告分享ID不能为空
no_plan_to_archive=没有可归档的计划/计划组
no_plan_to_archive=没有可归档的计划/计划组
test_plan.is.archived=测试计划已归档

View File

@ -106,4 +106,5 @@ run_functional_case=Run functional case
test_plan_not_exist=The test plan does not exist
test_plan.report_id.not_blank=The test plan report ID cannot be empty
test_plan.report.share_id.not_blank=The test plan report share ID cannot be empty
no_plan_to_archive=No plans/plan groups to archive
no_plan_to_archive=No plans/plan groups to archive
test_plan.is.archived=Test plan has been archived

View File

@ -106,4 +106,5 @@ run_functional_case=执行功能用例
test_plan_not_exist=测试计划不存在
test_plan.report_id.not_blank=测试计划报告ID不能为空
test_plan.report.share_id.not_blank=测试计划报告分享ID不能为空
no_plan_to_archive=没有可归档的计划/计划组
no_plan_to_archive=没有可归档的计划/计划组
test_plan.is.archived=测试计划已归档

View File

@ -106,4 +106,5 @@ run_functional_case=執行功能用例
test_plan_not_exist=測試計劃不存在
test_plan.report_id.not_blank=測試計劃報告ID不能爲空
test_plan.report.share_id.not_blank=測試計劃報告分享ID不能爲空
no_plan_to_archive=沒有可歸檔的計劃/計劃組
no_plan_to_archive=沒有可歸檔的計劃/計劃組
test_plan.is.archived=測試計劃已歸檔

View File

@ -140,6 +140,7 @@ public class TestPlanController {
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void delete(@Validated @RequestBody TestPlanBatchProcessRequest request) throws Exception {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.filterArchivedIds(request);
testPlanService.batchDelete(request, SessionUtils.getUserId(), "/test-plan/batch-delete", HttpMethodConstants.POST.name());
}
@ -149,6 +150,7 @@ public class TestPlanController {
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void batchCopy(@Validated @RequestBody TestPlanBatchRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.filterArchivedIds(request);
testPlanService.batchCopy(request, SessionUtils.getUserId(), "/test-plan/batch-copy", HttpMethodConstants.POST.name());
}
@ -158,6 +160,7 @@ public class TestPlanController {
@CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project")
public void batchMove(@Validated @RequestBody TestPlanBatchRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.filterArchivedIds(request);
testPlanService.batchMove(request, SessionUtils.getUserId(), "/test-plan/batch-move", HttpMethodConstants.POST.name());
}
@ -176,6 +179,7 @@ public class TestPlanController {
@CheckOwner(resourceId = "#request.getTestPlanId()", resourceType = "test_plan")
public void association(@Validated @RequestBody TestPlanAssociationRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getTestPlanId(), TestPlanResourceConfig.CHECK_TYPE_TEST_PLAN, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN_FUNCTIONAL_CASE));
testPlanService.checkTestPlanNotArchived(request.getTestPlanId());
testPlanService.association(request);
}
@ -186,6 +190,7 @@ public class TestPlanController {
@Log(type = OperationLogType.UPDATE, expression = "#msClass.batchEditLog(#request)", msClass = TestPlanLogService.class)
public void batchEdit(@Validated @RequestBody TestPlanBatchEditRequest request) {
testPlanManagementService.checkModuleIsOpen(request.getProjectId(), TestPlanResourceConfig.CHECK_TYPE_PROJECT, Collections.singletonList(TestPlanResourceConfig.CONFIG_TEST_PLAN));
testPlanService.filterArchivedIds(request);
testPlanService.batchEdit(request, SessionUtils.getUserId());
}
}

View File

@ -38,4 +38,6 @@ public interface ExtTestPlanMapper {
void batchUpdate(@Param("testPlan") TestPlan testPlan, @Param("ids") List<String> ids);
List<String> selectIdByProjectId(String projectId);
List<String> selectNotArchivedIds(@Param("ids") List<String> selectIds);
}

View File

@ -392,6 +392,13 @@
FROM test_plan
WHERE project_id = #{0}
</select>
<select id="selectNotArchivedIds" resultType="java.lang.String">
SELECT id FROM test_plan WHERE id IN
<foreach collection="ids" item="id" open="(" separator="," close=")">
#{id}
</foreach>
AND status != 'ARCHIVED'
</select>
<update id="batchUpdate">

View File

@ -39,6 +39,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import java.util.stream.Collectors;
import static io.metersphere.sdk.constants.TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED;
@Service
@Transactional(rollbackFor = Exception.class)
public class TestPlanService extends TestPlanBaseUtilsService {
@ -104,7 +106,6 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private TestPlan savePlanDTO(TestPlanCreateRequest createOrCopyRequest, String operator, String id) {
//检查模块的合法性
checkModule(createOrCopyRequest.getModuleId());
TestPlan createTestPlan = new TestPlan();
BeanUtils.copyBean(createTestPlan, createOrCopyRequest);
// 5.21查询需求文档测试用例测试计划名称允许重复
@ -148,6 +149,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
* @param requestMethod
*/
public void delete(String id, String operator, String requestUrl, String requestMethod) {
this.checkTestPlanNotArchived(id);
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(id);
if (StringUtils.equals(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
// 计划组的删除暂时预留
@ -287,6 +289,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
* @return
*/
public TestPlan update(TestPlanUpdateRequest request, String userId, String requestUrl, String requestMethod) {
this.checkTestPlanNotArchived(request.getId());
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getId());
if (!ObjectUtils.allNull(request.getName(), request.getModuleId(), request.getTags(), request.getPlannedEndTime(), request.getPlannedStartTime(), request.getDescription(), request.getTestPlanGroupId())) {
TestPlan updateTestPlan = new TestPlan();
@ -358,9 +361,9 @@ public class TestPlanService extends TestPlanBaseUtilsService {
if (StringUtils.equalsAnyIgnoreCase(testPlan.getType(), TestPlanConstants.TEST_PLAN_TYPE_GROUP)) {
//测试计划组归档
updateGroupStatus(testPlan.getId(), userId);
} else {
} else if (StringUtils.equals(testPlan.getStatus(), TestPlanConstants.TEST_PLAN_STATUS_COMPLETED)) {
//测试计划
testPlan.setStatus(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED);
testPlan.setStatus(TEST_PLAN_STATUS_ARCHIVED);
testPlan.setUpdateUser(userId);
testPlan.setUpdateTime(System.currentTimeMillis());
testPlanMapper.updateByPrimaryKeySelective(testPlan);
@ -378,7 +381,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
List<String> batchArchivedIds = request.getSelectIds();
if (CollectionUtils.isNotEmpty(batchArchivedIds)) {
TestPlanExample example = new TestPlanExample();
example.createCriteria().andIdIn(batchArchivedIds);
example.createCriteria().andIdIn(batchArchivedIds).andStatusEqualTo(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED);
List<TestPlan> archivedPlanList = testPlanMapper.selectByExample(example);
Map<String, List<TestPlan>> plans = archivedPlanList.stream().collect(Collectors.groupingBy(TestPlan::getType));
testPlanBatchArchivedService.batchArchived(plans, request, currentUser);
@ -404,7 +407,7 @@ public class TestPlanService extends TestPlanBaseUtilsService {
if (CollectionUtils.isEmpty(ids)) {
throw new MSException(Translator.get("test_plan.group.not_plan"));
}
extTestPlanMapper.batchUpdateStatus(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED, userId, System.currentTimeMillis(), ids);
extTestPlanMapper.batchUpdateStatus(TEST_PLAN_STATUS_ARCHIVED, userId, System.currentTimeMillis(), ids);
}
/**
@ -664,4 +667,19 @@ public class TestPlanService extends TestPlanBaseUtilsService {
this.deleteByList(testPlanIdList);
});
}
// 过滤掉已归档的测试计划
public void filterArchivedIds(TestPlanBatchProcessRequest request) {
if (CollectionUtils.isNotEmpty(request.getSelectIds())) {
request.setSelectIds(extTestPlanMapper.selectNotArchivedIds(request.getSelectIds()));
}
}
public void checkTestPlanNotArchived(String testPlanId) {
TestPlanExample example = new TestPlanExample();
example.createCriteria().andIdEqualTo(testPlanId).andStatusEqualTo(TEST_PLAN_STATUS_ARCHIVED);
if (testPlanMapper.countByExample(example) > 0) {
throw new MSException(Translator.get("test_plan.is.archived"));
}
}
}

View File

@ -102,7 +102,7 @@
class="mb-[16px]"
allow-clear
/>
<a-spin class="w-full" :style="{ height: `calc(100vh - 298px)` }" :loading="loading">
<a-spin class="w-full" :loading="loading">
<MsTree
v-model:focus-node-key="focusNodeKey"
v-model:selected-keys="selectedKeys"

View File

@ -3,7 +3,7 @@
<MsSplitBox :size="300" :max="0.5">
<template #first>
<div class="flex flex-col">
<div class="p-[16px]">
<div class="p-[16px]" :style="{ height: `calc(100vh - 120px)` }">
<moduleTree
ref="moduleTreeRef"
:active-node-id="activeNodeId"