diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseMinderController.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseMinderController.java index 86b1fe0aa6..427534bd71 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseMinderController.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/controller/TestPlanFunctionalCaseMinderController.java @@ -3,7 +3,8 @@ package io.metersphere.plan.controller; import io.metersphere.bug.domain.Bug; import io.metersphere.bug.dto.request.BugEditRequest; import io.metersphere.bug.service.BugService; -import io.metersphere.plan.dto.request.TestPlanCaseMinderBatchAddBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseBatchAddBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseBatchAssociateBugRequest; import io.metersphere.plan.service.TestPlanFunctionalCaseMinderService; import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.util.BeanUtils; @@ -14,10 +15,7 @@ import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.annotation.Resource; import org.apache.shiro.authz.annotation.RequiresPermissions; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestPart; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -36,11 +34,19 @@ public class TestPlanFunctionalCaseMinderController { @Operation(summary = "测试计划-功能用例-脑图-批量添加缺陷") @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") - public void minderBatchAddBug(@Validated @RequestPart("request") TestPlanCaseMinderBatchAddBugRequest request, + public void minderBatchAddBug(@Validated @RequestPart("request") TestPlanCaseBatchAddBugRequest request, @RequestPart(value = "files", required = false) List files) { BugEditRequest bugEditRequest = new BugEditRequest(); BeanUtils.copyBean(bugEditRequest, request); Bug bug = bugService.addOrUpdate(bugEditRequest, files, SessionUtils.getUserId(), SessionUtils.getCurrentOrganizationId(), false); testPlanFunctionalCaseMinderService.minderBatchAssociateBug(request, bug.getId(), SessionUtils.getUserId()); } + + @PostMapping("/batch/associate-bug") + @Operation(summary = "测试计划-计划详情-功能用例-脑图-批量关联缺陷") + @RequiresPermissions(PermissionConstants.TEST_PLAN_READ_EXECUTE) + @CheckOwner(resourceId = "#request.getProjectId()", resourceType = "project") + public void batchAssociateBug(@Validated @RequestBody TestPlanCaseBatchAssociateBugRequest request) { + testPlanFunctionalCaseMinderService.batchAssociateBugByIds(request, SessionUtils.getUserId()); + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAddBugRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAddBugRequest.java index ec662ed6a5..707aa5ada5 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAddBugRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAddBugRequest.java @@ -16,7 +16,7 @@ import java.util.List; * @author wx */ @Data -public class TestPlanCaseBatchAddBugRequest extends BasePlanCaseBatchRequest { +public class TestPlanCaseBatchAddBugRequest extends TestPlanCaseMinderRequest { @Schema(description = "ID", requiredMode = Schema.RequiredMode.REQUIRED) @NotBlank(message = "{bug.id.not_blank}", groups = {Updated.class}) diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAssociateBugRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAssociateBugRequest.java index 94dc4842f8..8c938d9946 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAssociateBugRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseBatchAssociateBugRequest.java @@ -10,7 +10,7 @@ import java.util.List; * @author wx */ @Data -public class TestPlanCaseBatchAssociateBugRequest extends BasePlanCaseBatchRequest { +public class TestPlanCaseBatchAssociateBugRequest extends TestPlanCaseMinderRequest { @Schema(description = "缺陷ID集合", requiredMode = Schema.RequiredMode.REQUIRED) @NotEmpty(message = "{bug.id.not_blank}") diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderBatchAddBugRequest.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderRequest.java similarity index 83% rename from backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderBatchAddBugRequest.java rename to backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderRequest.java index 7059ea2286..e93e86e040 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderBatchAddBugRequest.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/dto/request/TestPlanCaseMinderRequest.java @@ -9,7 +9,7 @@ import java.util.List; * @author wx */ @Data -public class TestPlanCaseMinderBatchAddBugRequest extends TestPlanCaseBatchAddBugRequest { +public class TestPlanCaseMinderRequest extends BasePlanCaseBatchRequest { @Schema(description = "脑图选中的模块id集合") private List minderModuleIds; diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java index e81db2e868..b6c06889b2 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/mapper/ExtTestPlanFunctionalCaseMapper.java @@ -9,7 +9,7 @@ import io.metersphere.plan.dto.ResourceSelectParam; import io.metersphere.plan.dto.TestPlanCaseRunResultCount; import io.metersphere.plan.dto.TestPlanResourceExecResultDTO; import io.metersphere.plan.dto.request.BasePlanCaseBatchRequest; -import io.metersphere.plan.dto.request.TestPlanCaseMinderBatchAddBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseMinderRequest; import io.metersphere.plan.dto.request.TestPlanCaseModuleRequest; import io.metersphere.plan.dto.request.TestPlanCaseRequest; import io.metersphere.plan.dto.response.TestPlanCasePageResponse; @@ -77,9 +77,9 @@ public interface ExtTestPlanFunctionalCaseMapper { List selectDistinctExecResultByTestPlanIds(@Param("testPlanIds") List testPlanIds); - Collection selectIdsByProjectIds(@Param("request") TestPlanCaseMinderBatchAddBugRequest request); + Collection selectIdsByProjectIds(@Param("request") TestPlanCaseMinderRequest request); List selectProjectByModuleIds(@Param("moduleIds") List moduleIds); - Collection selectIdsByModuleIds(@Param("request") TestPlanCaseMinderBatchAddBugRequest request, @Param("minderModuleIds") List minderModuleIds); + Collection selectIdsByModuleIds(@Param("request") TestPlanCaseMinderRequest request, @Param("minderModuleIds") List minderModuleIds); } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseMinderService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseMinderService.java index 03c8e33245..6c1e524c7d 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseMinderService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseMinderService.java @@ -1,15 +1,12 @@ package io.metersphere.plan.service; -import io.metersphere.bug.domain.BugRelationCase; -import io.metersphere.bug.mapper.BugRelationCaseMapper; import io.metersphere.functional.domain.FunctionalCaseModule; import io.metersphere.functional.service.FunctionalCaseModuleService; -import io.metersphere.plan.dto.request.TestPlanCaseMinderBatchAddBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseBatchAddBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseBatchAssociateBugRequest; +import io.metersphere.plan.dto.request.TestPlanCaseMinderRequest; import io.metersphere.plan.mapper.ExtTestPlanFunctionalCaseMapper; -import io.metersphere.sdk.constants.CaseType; -import io.metersphere.sdk.util.SubListUtils; import io.metersphere.system.dto.sdk.BaseTreeNode; -import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.apache.commons.collections.CollectionUtils; import org.springframework.stereotype.Service; @@ -31,36 +28,24 @@ public class TestPlanFunctionalCaseMinderService { private FunctionalCaseModuleService functionalCaseModuleService; @Resource private TestPlanFunctionalCaseService testPlanFunctionalCaseService; - @Resource - private BugRelationCaseMapper bugRelationCaseMapper; - public void minderBatchAssociateBug(TestPlanCaseMinderBatchAddBugRequest request, String bugId, String userId) { + /** + * 脑图批量添加缺陷 + * + * @param request + * @param bugId + * @param userId + */ + public void minderBatchAssociateBug(TestPlanCaseBatchAddBugRequest request, String bugId, String userId) { //获取脑图选中的用例id集合 List ids = getMinderSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { - SubListUtils.dealForSubList(ids, 500, (subList) -> { - Map caseMap = testPlanFunctionalCaseService.getCaseMap(subList); - List list = new ArrayList<>(); - subList.forEach(id -> { - BugRelationCase bugRelationCase = new BugRelationCase(); - bugRelationCase.setId(IDGenerator.nextStr()); - bugRelationCase.setBugId(bugId); - bugRelationCase.setCaseId(caseMap.get(id)); - bugRelationCase.setCaseType(CaseType.FUNCTIONAL_CASE.getKey()); - bugRelationCase.setCreateUser(userId); - bugRelationCase.setCreateTime(System.currentTimeMillis()); - bugRelationCase.setUpdateTime(System.currentTimeMillis()); - bugRelationCase.setTestPlanCaseId(id); - bugRelationCase.setTestPlanId(request.getTestPlanId()); - list.add(bugRelationCase); - }); - bugRelationCaseMapper.batchInsert(list); - }); + testPlanFunctionalCaseService.handleAssociateBug(ids, userId, bugId, request.getTestPlanId()); } } - private List getMinderSelectIds(TestPlanCaseMinderBatchAddBugRequest request) { + private List getMinderSelectIds(TestPlanCaseMinderRequest request) { if (request.isSelectAll()) { //全选 List ids = extTestPlanFunctionalCaseMapper.getIds(request, false); @@ -124,4 +109,17 @@ public class TestPlanFunctionalCaseMinderService { } + /** + * 脑图批量关联缺陷 + * + * @param request + * @param userId + */ + public void batchAssociateBugByIds(TestPlanCaseBatchAssociateBugRequest request, String userId) { + List ids = getMinderSelectIds(request); + if (CollectionUtils.isNotEmpty(ids)) { + testPlanFunctionalCaseService.handleAssociateBugByIds(ids, request, userId); + } + + } } diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index a0e46481ab..68eb2f1bb9 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -39,6 +39,7 @@ import io.metersphere.sdk.dto.AssociateCaseDTO; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; +import io.metersphere.sdk.util.SubListUtils; import io.metersphere.sdk.util.Translator; import io.metersphere.system.dto.LogInsertModule; import io.metersphere.system.dto.sdk.BaseTreeNode; @@ -950,9 +951,16 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { public void batchAssociateBug(TestPlanCaseBatchAddBugRequest request, String bugId, String userId) { List ids = doSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { - Map caseMap = getCaseMap(ids); + handleAssociateBug(ids, userId, bugId, request.getTestPlanId()); + + } + } + + public void handleAssociateBug(List ids, String userId, String bugId, String testPlanId) { + SubListUtils.dealForSubList(ids, 500, (subList) -> { + Map caseMap = getCaseMap(subList); List list = new ArrayList<>(); - ids.forEach(id -> { + subList.forEach(id -> { BugRelationCase bugRelationCase = new BugRelationCase(); bugRelationCase.setId(IDGenerator.nextStr()); bugRelationCase.setBugId(bugId); @@ -962,11 +970,11 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { bugRelationCase.setCreateTime(System.currentTimeMillis()); bugRelationCase.setUpdateTime(System.currentTimeMillis()); bugRelationCase.setTestPlanCaseId(id); - bugRelationCase.setTestPlanId(request.getTestPlanId()); + bugRelationCase.setTestPlanId(testPlanId); list.add(bugRelationCase); }); bugRelationCaseMapper.batchInsert(list); - } + }); } public Map getCaseMap(List ids) { @@ -980,23 +988,30 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { public void batchAssociateBugByIds(TestPlanCaseBatchAssociateBugRequest request, String userId) { List ids = doSelectIds(request); if (CollectionUtils.isNotEmpty(ids)) { + handleAssociateBugByIds(ids, request, userId); + } + } + + public void handleAssociateBugByIds(List ids, TestPlanCaseBatchAssociateBugRequest request, String userId) { + SubListUtils.dealForSubList(ids, 500, (subList) -> { BugRelationCaseExample example = new BugRelationCaseExample(); - example.createCriteria().andTestPlanCaseIdIn(ids).andTestPlanIdEqualTo(request.getTestPlanId()).andBugIdIn(request.getBugIds()); + example.createCriteria().andTestPlanCaseIdIn(subList).andTestPlanIdEqualTo(request.getTestPlanId()).andBugIdIn(request.getBugIds()); List bugRelationCases = bugRelationCaseMapper.selectByExample(example); Map> bugMap = bugRelationCases.stream() .collect(Collectors.groupingBy( BugRelationCase::getTestPlanCaseId, Collectors.mapping(BugRelationCase::getBugId, Collectors.toList()) )); - Map caseMap = getCaseMap(ids); + Map caseMap = getCaseMap(subList); List list = new ArrayList<>(); - ids.forEach(item -> { + subList.forEach(item -> { buildAssociateBugData(item, bugMap, list, request, caseMap, userId); }); if (CollectionUtils.isNotEmpty(list)) { bugRelationCaseMapper.batchInsert(list); } - } + }); + } private void buildAssociateBugData(String id, Map> bugMap, List list, TestPlanCaseBatchAssociateBugRequest request, Map caseMap, String userId) { 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 3fbff241c3..5abe10582c 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 @@ -22,7 +22,6 @@ import io.metersphere.plan.service.TestPlanFunctionalCaseService; import io.metersphere.provider.BaseAssociateBugProvider; import io.metersphere.request.AssociateBugPageRequest; import io.metersphere.request.BugPageProviderRequest; -import io.metersphere.sdk.util.BeanUtils; import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; @@ -71,6 +70,7 @@ public class TestPlanCaseControllerTests extends BaseTest { public static final String FUNCTIONAL_CASE_BATCH_ASSOCIATE_BUG_URL = "/test-plan/functional/case/batch/associate-bug"; public static final String FUNCTIONAL_CASE_MINDER_BATCH_ADD_BUG = "/test-plan/functional/case/minder/batch/add-bug"; + public static final String FUNCTIONAL_CASE_MINDER_BATCH_ASSOCIATE_BUG = "/test-plan/functional/case/minder/batch/associate-bug"; @Resource private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper; @Resource @@ -510,9 +510,7 @@ public class TestPlanCaseControllerTests extends BaseTest { @Test @Order(20) public void testMinderBatchAddBug() throws Exception { - TestPlanCaseMinderBatchAddBugRequest request = new TestPlanCaseMinderBatchAddBugRequest(); - TestPlanCaseBatchAddBugRequest bugRequest = buildRequest(false); - BeanUtils.copyBean(request, bugRequest); + TestPlanCaseBatchAddBugRequest request = buildRequest(false); request.setSelectAll(true); List files = new ArrayList<>(); LinkedMultiValueMap paramMap = new LinkedMultiValueMap<>(); @@ -535,4 +533,14 @@ public class TestPlanCaseControllerTests extends BaseTest { this.requestMultipartWithOkAndReturn(FUNCTIONAL_CASE_MINDER_BATCH_ADD_BUG, paramMap); } + @Test + @Order(21) + public void testMinderBatchAssociateBug() throws Exception { + TestPlanCaseBatchAssociateBugRequest request = new TestPlanCaseBatchAssociateBugRequest(); + request.setBugIds(Arrays.asList("123456")); + request.setTestPlanId("plan_1"); + this.requestPostWithOk(FUNCTIONAL_CASE_MINDER_BATCH_ASSOCIATE_BUG, request); + request.setSelectAll(true); + this.requestPostWithOk(FUNCTIONAL_CASE_MINDER_BATCH_ASSOCIATE_BUG, request); + } }