feat(测试计划): 测试计划详情用例脑图批量关联缺陷

This commit is contained in:
WangXu10 2024-08-29 17:53:57 +08:00 committed by Craftsman
parent ca8d95f9a6
commit 11fe18e5d0
8 changed files with 79 additions and 52 deletions

View File

@ -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<MultipartFile> 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());
}
}

View File

@ -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})

View File

@ -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}")

View File

@ -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<String> minderModuleIds;

View File

@ -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<TestPlanResourceExecResultDTO> selectDistinctExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
Collection<String> selectIdsByProjectIds(@Param("request") TestPlanCaseMinderBatchAddBugRequest request);
Collection<String> selectIdsByProjectIds(@Param("request") TestPlanCaseMinderRequest request);
List<FunctionalCaseModule> selectProjectByModuleIds(@Param("moduleIds") List<String> moduleIds);
Collection<String> selectIdsByModuleIds(@Param("request") TestPlanCaseMinderBatchAddBugRequest request, @Param("minderModuleIds") List<String> minderModuleIds);
Collection<String> selectIdsByModuleIds(@Param("request") TestPlanCaseMinderRequest request, @Param("minderModuleIds") List<String> minderModuleIds);
}

View File

@ -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<String> ids = getMinderSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
SubListUtils.dealForSubList(ids, 500, (subList) -> {
Map<String, String> caseMap = testPlanFunctionalCaseService.getCaseMap(subList);
List<BugRelationCase> 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<String> getMinderSelectIds(TestPlanCaseMinderBatchAddBugRequest request) {
private List<String> getMinderSelectIds(TestPlanCaseMinderRequest request) {
if (request.isSelectAll()) {
//全选
List<String> ids = extTestPlanFunctionalCaseMapper.getIds(request, false);
@ -124,4 +109,17 @@ public class TestPlanFunctionalCaseMinderService {
}
/**
* 脑图批量关联缺陷
*
* @param request
* @param userId
*/
public void batchAssociateBugByIds(TestPlanCaseBatchAssociateBugRequest request, String userId) {
List<String> ids = getMinderSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
testPlanFunctionalCaseService.handleAssociateBugByIds(ids, request, userId);
}
}
}

View File

@ -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<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
Map<String, String> caseMap = getCaseMap(ids);
handleAssociateBug(ids, userId, bugId, request.getTestPlanId());
}
}
public void handleAssociateBug(List<String> ids, String userId, String bugId, String testPlanId) {
SubListUtils.dealForSubList(ids, 500, (subList) -> {
Map<String, String> caseMap = getCaseMap(subList);
List<BugRelationCase> 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<String, String> getCaseMap(List<String> ids) {
@ -980,23 +988,30 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
public void batchAssociateBugByIds(TestPlanCaseBatchAssociateBugRequest request, String userId) {
List<String> ids = doSelectIds(request);
if (CollectionUtils.isNotEmpty(ids)) {
handleAssociateBugByIds(ids, request, userId);
}
}
public void handleAssociateBugByIds(List<String> 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<BugRelationCase> bugRelationCases = bugRelationCaseMapper.selectByExample(example);
Map<String, List<String>> bugMap = bugRelationCases.stream()
.collect(Collectors.groupingBy(
BugRelationCase::getTestPlanCaseId,
Collectors.mapping(BugRelationCase::getBugId, Collectors.toList())
));
Map<String, String> caseMap = getCaseMap(ids);
Map<String, String> caseMap = getCaseMap(subList);
List<BugRelationCase> 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<String, List<String>> bugMap, List<BugRelationCase> list, TestPlanCaseBatchAssociateBugRequest request, Map<String, String> caseMap, String userId) {

View File

@ -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<MockMultipartFile> files = new ArrayList<>();
LinkedMultiValueMap<String, Object> 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);
}
}