From 14a6ec47b1c6f6429f4ab4869f441e8b3e78d19b Mon Sep 17 00:00:00 2001 From: WangXu10 Date: Tue, 24 Sep 2024 14:27:29 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92):=20?= =?UTF-8?q?=E8=84=91=E5=9B=BE=E5=85=B3=E8=81=94=E7=94=A8=E4=BE=8B=E9=87=8D?= =?UTF-8?q?=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1046647 --user=王旭 【测试计划】-脑图执行时,可以为用例重复关联相同的缺陷 https://www.tapd.cn/55049933/s/1584592 --- .../plan/service/TestPlanResourceService.java | 23 +++++++++++++++---- .../TestPlanCaseControllerTests.java | 2 ++ 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java index a068f18627..f834807723 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanResourceService.java @@ -164,6 +164,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService { /** * 获取待关联的缺陷列表 + * * @param request 请求参数 * @return 缺陷列表 */ @@ -173,13 +174,16 @@ public abstract class TestPlanResourceService extends TestPlanSortService { /** * 用例关联缺陷(单条用例) - * @param request 请求参数 - * @param userId 用户ID + * + * @param request 请求参数 + * @param userId 用户ID * @param caseType 用例类型 */ public void associateBug(TestPlanCaseAssociateBugRequest request, String userId, String caseType) { List ids = baseAssociateBugProvider.getSelectBugs(request, false); - if (org.apache.commons.collections.CollectionUtils.isNotEmpty(ids)) { + if (CollectionUtils.isNotEmpty(ids)) { + List bugIds = getCaseBugIds(request); + ids.removeAll(bugIds); SubListUtils.dealForSubList(ids, 100, subList -> { List list = new ArrayList<>(); subList.forEach(id -> { @@ -201,8 +205,17 @@ public abstract class TestPlanResourceService extends TestPlanSortService { } } + private List getCaseBugIds(TestPlanCaseAssociateBugRequest request) { + BugRelationCaseExample example = new BugRelationCaseExample(); + example.createCriteria().andTestPlanCaseIdEqualTo(request.getTestPlanCaseId()).andCaseIdEqualTo(request.getCaseId()).andTestPlanIdEqualTo(request.getTestPlanId()); + List bugRelationCases = bugRelationCaseMapper.selectByExample(example); + return bugRelationCases.stream().map(BugRelationCase::getBugId).toList(); + } + + /** * 取消关联缺陷 + * * @param id 关系ID */ public void disassociateBug(String id) { @@ -211,6 +224,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService { /** * 取消关联缺陷日志 + * * @param id 关系ID * @return 日志 */ @@ -236,7 +250,8 @@ public abstract class TestPlanResourceService extends TestPlanSortService { /** * 查询(计划关联)用例关联的缺陷 - * @param ids 关联用例关系ID集合 + * + * @param ids 关联用例关系ID集合 * @param projectId 项目ID * @return 缺陷集合 */ diff --git a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java index 5abe10582c..5a8057b497 100644 --- a/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java +++ b/backend/services/test-plan/src/test/java/io/metersphere/plan/controller/TestPlanCaseControllerTests.java @@ -209,6 +209,8 @@ public class TestPlanCaseControllerTests extends BaseTest { associateBugPageRequest.setPageSize(10); associateBugPageRequest.setTestPlanCaseId("relate_case_1"); this.requestPostWithOkAndReturn("/test-plan/functional/case/has/associate/bug/page", associateBugPageRequest); + ids.add("bug_5"); + this.requestPostWithOkAndReturn("/test-plan/functional/case/associate/bug", request); }