fix(用例管理): 修复用例评审详情模块树默认节点的构造

This commit is contained in:
guoyuqi 2024-02-01 20:15:59 +08:00 committed by 刘瑞斌
parent 0e6b6da459
commit 3d54e2186d
6 changed files with 54 additions and 7 deletions

View File

@ -0,0 +1,16 @@
package io.metersphere.functional.dto;
import io.metersphere.system.dto.sdk.OptionDTO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProjectOptionDTO extends OptionDTO {
@Schema(description = "是否是默认模板")
private String projectName;
}

View File

@ -1,6 +1,7 @@
package io.metersphere.functional.mapper; package io.metersphere.functional.mapper;
import io.metersphere.functional.dto.FunctionalCaseModuleDTO; import io.metersphere.functional.dto.FunctionalCaseModuleDTO;
import io.metersphere.functional.dto.ProjectOptionDTO;
import io.metersphere.project.dto.NodeSortQueryParam; import io.metersphere.project.dto.NodeSortQueryParam;
import io.metersphere.request.AssociateCaseModuleRequest; import io.metersphere.request.AssociateCaseModuleRequest;
import io.metersphere.system.dto.sdk.BaseModule; import io.metersphere.system.dto.sdk.BaseModule;
@ -14,6 +15,8 @@ public interface ExtFunctionalCaseModuleMapper {
List<FunctionalCaseModuleDTO> selectBaseByProjectIdAndReviewId(@Param("reviewId")String reviewId); List<FunctionalCaseModuleDTO> selectBaseByProjectIdAndReviewId(@Param("reviewId")String reviewId);
List<ProjectOptionDTO> selectFunRootIdByReviewId(@Param("reviewId")String reviewId);
List<BaseTreeNode> selectBaseByIds(@Param("ids") List<String> ids); List<BaseTreeNode> selectBaseByIds(@Param("ids") List<String> ids);
List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds); List<String> selectChildrenIdsByParentIds(@Param("ids") List<String> deleteIds);

View File

@ -7,6 +7,15 @@
WHERE project_id = #{projectId} WHERE project_id = #{projectId}
ORDER BY pos ORDER BY pos
</select> </select>
<select id="selectFunRootIdByReviewId" resultType="io.metersphere.functional.dto.ProjectOptionDTO">
SELECT fc.module_id as id, fc.project_id as name, p.name as projectName
FROM functional_case fc
LEFT JOIN case_review_functional_case crfc ON crfc.case_id = fc.id
LEFT JOIN project p ON fc.project_id = p.id
WHERE crfc.review_id = #{reviewId}
AND fc.deleted = false AND fc.module_id = 'root'
ORDER BY fc.pos
</select>
<select id="selectBaseByProjectIdAndReviewId" resultType="io.metersphere.functional.dto.FunctionalCaseModuleDTO"> <select id="selectBaseByProjectIdAndReviewId" resultType="io.metersphere.functional.dto.FunctionalCaseModuleDTO">
SELECT fcm.id, fcm.project_id, p.name as projectName SELECT fcm.id, fcm.project_id, p.name as projectName
FROM functional_case_module fcm FROM functional_case_module fcm

View File

@ -18,7 +18,6 @@ import io.metersphere.project.mapper.ExtBaseProjectVersionMapper;
import io.metersphere.project.mapper.ProjectApplicationMapper; import io.metersphere.project.mapper.ProjectApplicationMapper;
import io.metersphere.provider.BaseCaseProvider; import io.metersphere.provider.BaseCaseProvider;
import io.metersphere.sdk.constants.InternalUserRole; import io.metersphere.sdk.constants.InternalUserRole;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.ProjectApplicationType; import io.metersphere.sdk.constants.ProjectApplicationType;
import io.metersphere.sdk.constants.UserRoleScope; import io.metersphere.sdk.constants.UserRoleScope;
import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.exception.MSException;
@ -35,6 +34,7 @@ import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.utils.ServiceUtils; import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSession;
@ -611,15 +611,25 @@ public class CaseReviewFunctionalCaseService {
public List<BaseTreeNode> getTree(String reviewId) { public List<BaseTreeNode> getTree(String reviewId) {
List<BaseTreeNode> returnList = new ArrayList<>(); List<BaseTreeNode> returnList = new ArrayList<>();
List<ProjectOptionDTO> rootIds = extFunctionalCaseModuleMapper.selectFunRootIdByReviewId(reviewId);
Map<String, List<ProjectOptionDTO>> projectRootMap = rootIds.stream().collect(Collectors.groupingBy(ProjectOptionDTO::getName));
List<FunctionalCaseModuleDTO> functionalModuleIds = extFunctionalCaseModuleMapper.selectBaseByProjectIdAndReviewId(reviewId); List<FunctionalCaseModuleDTO> functionalModuleIds = extFunctionalCaseModuleMapper.selectBaseByProjectIdAndReviewId(reviewId);
Map<String, List<FunctionalCaseModuleDTO>> projectModuleMap = functionalModuleIds.stream().collect(Collectors.groupingBy(FunctionalCaseModule::getProjectId)); Map<String, List<FunctionalCaseModuleDTO>> projectModuleMap = functionalModuleIds.stream().collect(Collectors.groupingBy(FunctionalCaseModule::getProjectId));
if (MapUtils.isEmpty(projectModuleMap)) {
projectRootMap.forEach((projectId,projectOptionDTOList)->{
BaseTreeNode projectNode = new BaseTreeNode(projectId, projectOptionDTOList.get(0).getProjectName(), Project.class.getName());
returnList.add(projectNode);
BaseTreeNode defaultNode = functionalCaseModuleService.getDefaultModule(Translator.get("default.module"));
projectNode.addChild(defaultNode);
});
return returnList;
}
projectModuleMap.forEach((projectId,moduleList)->{ projectModuleMap.forEach((projectId,moduleList)->{
BaseTreeNode projectNode = new BaseTreeNode(projectId, moduleList.get(0).getProjectName(), Project.class.getName()); BaseTreeNode projectNode = new BaseTreeNode(projectId, moduleList.get(0).getProjectName(), Project.class.getName());
returnList.add(projectNode); returnList.add(projectNode);
List<String> projectModuleIds = moduleList.stream().map(FunctionalCaseModule::getId).toList(); List<String> projectModuleIds = moduleList.stream().map(FunctionalCaseModule::getId).toList();
List<BaseTreeNode> nodeByNodeIds = functionalCaseModuleService.getNodeByNodeIds(projectModuleIds); List<BaseTreeNode> nodeByNodeIds = functionalCaseModuleService.getNodeByNodeIds(projectModuleIds);
List<BaseTreeNode> list = nodeByNodeIds.stream().filter(t -> StringUtils.equalsIgnoreCase(t.getParentId(), ModuleConstants.DEFAULT_NODE_ID)).toList(); boolean haveVirtualRootNode = CollectionUtils.isEmpty(projectRootMap.get(projectId));
boolean haveVirtualRootNode = list.isEmpty();
List<BaseTreeNode> baseTreeNodes = functionalCaseModuleService.buildTreeAndCountResource(nodeByNodeIds, !haveVirtualRootNode, Translator.get("default.module")); List<BaseTreeNode> baseTreeNodes = functionalCaseModuleService.buildTreeAndCountResource(nodeByNodeIds, !haveVirtualRootNode, Translator.get("default.module"));
for (BaseTreeNode baseTreeNode : baseTreeNodes) { for (BaseTreeNode baseTreeNode : baseTreeNodes) {
projectNode.addChild(baseTreeNode); projectNode.addChild(baseTreeNode);

View File

@ -144,6 +144,9 @@ public class CaseReviewFunctionalCaseControllerTests extends BaseTest {
@Test @Test
@Order(4) @Order(4)
public void emptyDataTest() throws Exception { public void emptyDataTest() throws Exception {
List<BaseTreeNode> treeNodeDefaults = this.getCaseReviewModuleTreeNode("wx_test_project","wx_review_id_5");
String jsonStringD = JSON.toJSONString(treeNodeDefaults);
System.out.println(jsonStringD);
List<BaseTreeNode> treeNodes = this.getCaseReviewModuleTreeNode("wx_test_project","wx_review_id_2"); List<BaseTreeNode> treeNodes = this.getCaseReviewModuleTreeNode("wx_test_project","wx_review_id_2");
String jsonString = JSON.toJSONString(treeNodes); String jsonString = JSON.toJSONString(treeNodes);
System.out.println(jsonString); System.out.println(jsonString);

View File

@ -17,7 +17,8 @@ VALUES ('gyq_case_id_5', 102, 'TEST_MODULE_ID', 'wx_test_project', '100001', '
('gyq_case_id_9', 104, 'TEST_MODULE_ID_COUNT_four', 'wx_test_project_review_two', '100001', '测试模块2-1', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_9', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_9', 104, 'TEST_MODULE_ID_COUNT_four', 'wx_test_project_review_two', '100001', '测试模块2-1', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_9', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_a', 105, 'TEST_MODULE_ID_COUNT_five', 'wx_test_project_review_two', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_a', 105, 'TEST_MODULE_ID_COUNT_five', 'wx_test_project_review_two', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_b', 105, 'TEST_MODULE_ID_COUNT_six', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL), ('gyq_case_id_b', 105, 'TEST_MODULE_ID_COUNT_six', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_c', 105, 'TEST_MODULE_ID_COUNT_seven', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL); ('gyq_case_id_c', 105, 'TEST_MODULE_ID_COUNT_seven', 'wx_test_project_review_one', '100001', '测试模块2-2', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_a', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL),
('gyq_case_id_d', 105, 'root', 'wx_test_project_review_one', '100001', '测试默认模块', 'UN_REVIEWED', '["测试标签_1"]', 'STEP', 0, 'v1.0.0', 'gyq_case_id_d', 'UN_EXECUTED', b'0', b'0', b'1', 'admin', 'admin', '', 1698058347559, 1698058347559, NULL);
INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time) INSERT INTO functional_case(id, num, module_id, project_id, template_id, name, review_status, tags, case_edit_type, pos, version_id, ref_id, last_execute_result, deleted, public_case, latest, create_user, update_user, delete_user, create_time, update_time, delete_time)
@ -47,7 +48,10 @@ INSERT INTO case_review(id, num, name, module_id, project_id, status, review_pas
VALUES ('wx_review_id_1',10001,'wx1', 'wx_module_1', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), VALUES ('wx_review_id_1',10001,'wx1', 'wx_module_1', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_2',10002,'wx2', 'wx_module_2', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), ('wx_review_id_2',10002,'wx2', 'wx_module_2', 'wx_test_project', 'COMPLETED', 'SINGLE', 001, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_3',10003,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'), ('wx_review_id_3',10003,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_4',10004,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'); ('wx_review_id_4',10004,'wx3', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin'),
('wx_review_id_5',10004,'gyq5', 'wx_module_3', 'wx_test_project', 'COMPLETED', 'MULTIPLE', 003, null, null, 1,100.00,null,null,1698058347559,'admin',1698058347559,'admin');
;
INSERT INTO case_review_functional_case(id, review_id, case_id, status, create_time, create_user, update_time, pos) INSERT INTO case_review_functional_case(id, review_id, case_id, status, create_time, create_user, update_time, pos)
VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 1000), VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 1000),
@ -68,7 +72,8 @@ VALUES ('wx_test_1', 'wx_review_id_1', 'wx_case_id_1', 'PASS', 1698058347559,'ad
('wx_test_7', 'wx_review_id_3', 'wx_case_id_3', 'PASS', 1698058347559,'admin',1698058347559, 3000), ('wx_test_7', 'wx_review_id_3', 'wx_case_id_3', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_8', 'wx_review_id_4', 'wx_case_id_4', 'PASS', 1698058347559,'admin',1698058347559, 3000), ('wx_test_8', 'wx_review_id_4', 'wx_case_id_4', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_9', 'wx_review_id_4', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 3000), ('wx_test_9', 'wx_review_id_4', 'wx_case_id_1', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_10', 'wx_review_id_4', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000); ('wx_test_10', 'wx_review_id_4', 'wx_case_id_2', 'PASS', 1698058347559,'admin',1698058347559, 3000),
('wx_test_11', 'wx_review_id_5', 'gyq_case_id_d', 'PASS', 1698058347559,'admin',1698058347559, 3000);
INSERT INTO case_review_functional_case_user(case_id, review_id, user_id) INSERT INTO case_review_functional_case_user(case_id, review_id, user_id)
VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'), VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'),
@ -83,7 +88,8 @@ VALUES ('wx_case_id_1', 'wx_review_id_1', 'admin'),
('wx_case_id_1', 'wx_review_id_4', '123'), ('wx_case_id_1', 'wx_review_id_4', '123'),
('wx_case_id_1', 'wx_review_id_4', 'admin'), ('wx_case_id_1', 'wx_review_id_4', 'admin'),
('wx_case_id_2', 'wx_review_id_4', '123'), ('wx_case_id_2', 'wx_review_id_4', '123'),
('wx_case_id_2', 'wx_review_id_4', 'admin'); ('wx_case_id_2', 'wx_review_id_4', 'admin'),
('gyq_case_id_d', 'wx_review_id_5', 'admin');