diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/TestPlanConstants.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/TestPlanConstants.java index abf4cf860c..988caf55a6 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/TestPlanConstants.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/TestPlanConstants.java @@ -13,7 +13,6 @@ public class TestPlanConstants { //测试计划状态-未开始 public static final String TEST_PLAN_STATUS_PREPARED = "PREPARED"; - //测试计划状态-进行中 public static final String TEST_PLAN_STATUS_UNDERWAY = "UNDERWAY"; //测试计划状态-已完成 diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java index a547c9f981..a0e1d35b8e 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanTableRequest.java @@ -23,6 +23,8 @@ public class TestPlanTableRequest extends BasePageRequest { @NotBlank(message = "{test_plan.type.not_blank}") private String type; + @Schema(description = "通过Keyword过滤出的测试子计划的测试计划组id") + private List keywordFilterIds; public String getSortString() { if (StringUtils.isEmpty(super.getSortString())) { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java index 02ea07a0ab..585a1b838c 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.java @@ -62,4 +62,6 @@ public interface ExtTestPlanMapper { List selectRightfulIdsForExecute(@Param("ids") List ids); List listHis(@Param("request")TestPlanExecuteHisPageRequest request); + + List selectGroupIdByKeyword(@Param("projectId") String projectId, @Param("keyword") String keyword); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml index 95ac7c21f4..4220c17d1a 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanMapper.xml @@ -90,28 +90,20 @@ + and ( t.name like concat('%', #{request.keyword},'%') or t.num like concat('%', #{request.keyword},'%') or t.tags like concat('%', #{request.keyword}, '%') + + or t.id in + + #{id} + + ) - - - - and t.group_id = 'NONE' - - - and t.group_id = 'NONE' - and t.type = 'TEST_PLAN' - - - and t.group_id = 'NONE' - and t.type = 'GROUP' - - - AND @@ -472,6 +464,16 @@ where tpr.test_plan_id = #{request.testPlanId} + update test_plan diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java index 4153187b64..1a1b770c10 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanLogService.java @@ -185,6 +185,9 @@ public class TestPlanLogService { * @param typeKey 类型Key */ public void saveBatchLog(List plans, String operator, String requestUrl, String requestMethod, String requestType, String typeKey) { + if (CollectionUtils.isEmpty(plans)) { + return; + } Project project = projectMapper.selectByPrimaryKey(plans.get(0).getProjectId()); List list = new ArrayList<>(); for (TestPlan plan : plans) { diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java index 755aa085b9..a7e0e61916 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanManagementService.java @@ -26,9 +26,7 @@ import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.Collections; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; @Service @@ -48,6 +46,7 @@ public class TestPlanManagementService { private TestPlanMapper testPlanMapper; public Map moduleCount(TestPlanTableRequest request) { + this.initDefaultFilter(request); //查出每个模块节点下的资源数量。 不需要按照模块进行筛选 request.setModuleIds(null); List moduleCountDTOList = extTestPlanMapper.countModuleIdByConditions(request); @@ -64,11 +63,36 @@ public class TestPlanManagementService { * 测试计划列表查询 */ public Pager> page(TestPlanTableRequest request) { + this.initDefaultFilter(request); Page page = PageHelper.startPage(request.getCurrent(), request.getPageSize(), MapUtils.isEmpty(request.getSort()) ? "t.num desc" : request.getSortString()); return PageUtils.setPageInfo(page, this.list(request)); } + private void initDefaultFilter(TestPlanTableRequest request) { + if (request.getFilter() == null || !request.getFilter().containsKey("status")) { + List defaultStatusList = new ArrayList<>(); + defaultStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_PREPARED); + defaultStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_UNDERWAY); + defaultStatusList.add(TestPlanConstants.TEST_PLAN_STATUS_COMPLETED); + if (request.getFilter() == null) { + request.setFilter(new HashMap<>() {{ + this.put("status", defaultStatusList); + }}); + } else { + request.getFilter().put("status", defaultStatusList); + } + } + + if (StringUtils.isNotBlank(request.getKeyword())) { + List groupIdList = extTestPlanMapper.selectGroupIdByKeyword(request.getProjectId(), request.getKeyword()); + if (CollectionUtils.isNotEmpty(groupIdList)) { + request.setKeywordFilterIds(groupIdList); + } + + } + } + public List list(TestPlanTableRequest request) { List testPlanResponses = extTestPlanMapper.selectByConditions(request); handChildren(testPlanResponses,request.getProjectId()); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java index d897d3b776..a286d1df16 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanService.java @@ -433,7 +433,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { ).collect(Collectors.toList()); archivedPlanList.forEach(item -> this.archived(item.getId(), currentUser)); //日志 - testPlanLogService.saveBatchLog(archivedPlanList, currentUser, "/test-plan/batch-archived", HttpMethodConstants.POST.name(), OperationLogType.UPDATE.name(), "archive"); + testPlanLogService.saveBatchLog(archivedPlanList, currentUser, "/test-plan/batch-archived", HttpMethodConstants.POST.name(), OperationLogType.ARCHIVED.name(), "archive"); } } @@ -601,7 +601,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { //日志 if (CollectionUtils.isNotEmpty(copyTestPlanList)) { copyCount = testPlanBatchOperationService.batchCopy(copyTestPlanList, request.getTargetId(), request.getMoveType(), userId); - testPlanLogService.saveBatchLog(copyTestPlanList, userId, url, method, OperationLogType.COPY.name(), "copy"); + testPlanLogService.saveBatchLog(copyTestPlanList, userId, url, method, OperationLogType.ADD.name(), "copy"); } } @@ -814,7 +814,7 @@ public class TestPlanService extends TestPlanBaseUtilsService { } } TestPlanExample testPlanExample = new TestPlanExample(); - testPlanExample.createCriteria().andIdEqualTo(testPlanGroupId).andStatusNotEqualTo(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED); + testPlanExample.createCriteria().andIdEqualTo(testPlanGroupId); TestPlan updateGroupPlan = new TestPlan(); updateGroupPlan.setStatus(groupStatus); testPlanMapper.updateByExampleSelective(updateGroupPlan, testPlanExample); diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java index a350d24dc3..852a5bdba5 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanTests.java @@ -951,7 +951,6 @@ public class TestPlanTests extends BaseTest { groupRequest.setType(TestPlanConstants.TEST_PLAN_TYPE_GROUP); onlyPlanRequest.setType(TestPlanConstants.TEST_PLAN_TYPE_PLAN); - BaseTreeNode a1Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a1"); BaseTreeNode a2Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a2"); BaseTreeNode a3Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a3"); @@ -959,17 +958,27 @@ public class TestPlanTests extends BaseTest { BaseTreeNode a1b1Node = TestPlanTestUtils.getNodeByName(preliminaryTreeNodes, "a1-b1"); assert a1Node != null & a2Node != null & a3Node != null & a1a1Node != null & a1b1Node != null; + //此时有一个归档的 testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, dataRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(), dataRequest.getPageSize(), - 1010); + 1010 - 1); + //查询归档的 + dataRequest.setFilter(new HashMap<>() {{ + this.put("status", Collections.singletonList(TestPlanConstants.TEST_PLAN_STATUS_ARCHIVED)); + }}); + testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( + URL_POST_TEST_PLAN_PAGE, dataRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), + dataRequest.getCurrent(), + dataRequest.getPageSize(), + 1); //只查询组 testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, groupRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(), dataRequest.getPageSize(), - 3); + 3 - 1); //只查询计划 testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, onlyPlanRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), @@ -981,11 +990,12 @@ public class TestPlanTests extends BaseTest { dataRequest.setSort(new HashMap<>() {{ this.put("name", "desc"); }}); + dataRequest.setFilter(null); testPlanTestService.checkTestPlanPage(this.requestPostWithOkAndReturn( URL_POST_TEST_PLAN_PAGE, dataRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(), dataRequest.getPageSize(), - 1010); + 1010 - 1); //指定模块ID查询 (查询count时,不会因为选择了模块而更改了总量 @@ -998,7 +1008,7 @@ public class TestPlanTests extends BaseTest { URL_POST_TEST_PLAN_PAGE, dataRequest).getResponse().getContentAsString(StandardCharsets.UTF_8), dataRequest.getCurrent(), dataRequest.getPageSize(), - 910); + 910 - 1); //测试根据名称模糊查询: Plan_2 预期结果: a1Node下有11条(testPlan_2,testPlan_20~testPlan_29), a1b1Node下有100条(testPlan_200~testPlan_299) dataRequest.setModuleIds(null);