mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-03 04:28:51 +08:00
fix(测试计划): 报告用例明细列表跨项目用例所属模块展示问题
--bug=1044294 --user=宋昌昌 【测试计划】测试计划中关联了跨项目的接口用例-执行该计划-报告中的接口明细-所属模块列表信息获取错误 https://www.tapd.cn/55049933/s/1553888
This commit is contained in:
parent
16177fedb6
commit
47eba6f6a9
@ -43,7 +43,7 @@ public class BugRelateCaseController {
|
|||||||
private BugRelateCaseCommonService bugRelateCaseCommonService;
|
private BugRelateCaseCommonService bugRelateCaseCommonService;
|
||||||
|
|
||||||
@PostMapping("/un-relate/page")
|
@PostMapping("/un-relate/page")
|
||||||
@Operation(description = "缺陷管理-关联用例-未关联用例-列表分页")
|
@Operation(summary = "缺陷管理-关联用例-未关联用例-列表分页")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
||||||
public Pager<List<TestCaseProviderDTO>> unRelatedPage(@Validated @RequestBody TestCasePageProviderRequest request) {
|
public Pager<List<TestCaseProviderDTO>> unRelatedPage(@Validated @RequestBody TestCasePageProviderRequest request) {
|
||||||
bugRelateCaseCommonService.checkCaseTypeParamIllegal(request.getSourceType());
|
bugRelateCaseCommonService.checkCaseTypeParamIllegal(request.getSourceType());
|
||||||
@ -77,7 +77,7 @@ public class BugRelateCaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/page")
|
@PostMapping("/page")
|
||||||
@Operation(description = "缺陷管理-关联用例-列表分页查询")
|
@Operation(summary = "缺陷管理-关联用例-列表分页查询")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_READ)
|
||||||
public Pager<List<BugRelateCaseDTO>> page(@Validated @RequestBody BugRelatedCasePageRequest request) {
|
public Pager<List<BugRelateCaseDTO>> page(@Validated @RequestBody BugRelatedCasePageRequest request) {
|
||||||
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
Page<Object> page = PageHelper.startPage(request.getCurrent(), request.getPageSize());
|
||||||
@ -85,7 +85,7 @@ public class BugRelateCaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/un-relate/{id}")
|
@GetMapping("/un-relate/{id}")
|
||||||
@Operation(description = "缺陷管理-关联用例-取消关联用例")
|
@Operation(summary = "缺陷管理-关联用例-取消关联用例")
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE)
|
||||||
@Parameter(name = "id", description = "ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
@Parameter(name = "id", description = "ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
@Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.getRelateLog(#id)", msClass = BugRelateCaseLogService.class)
|
@Log(type = OperationLogType.DISASSOCIATE, expression = "#msClass.getRelateLog(#id)", msClass = BugRelateCaseLogService.class)
|
||||||
@ -94,7 +94,7 @@ public class BugRelateCaseController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/check-permission/{projectId}/{caseType}")
|
@GetMapping("/check-permission/{projectId}/{caseType}")
|
||||||
@Operation(description = "缺陷管理-关联用例-查看用例权限校验")
|
@Operation(summary = "缺陷管理-关联用例-查看用例权限校验")
|
||||||
@Parameters({
|
@Parameters({
|
||||||
@Parameter(name = "projectId", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)),
|
@Parameter(name = "projectId", description = "项目ID", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED)),
|
||||||
@Parameter(name = "caseType", description = "关联用例类型(FUNCTIONAL, API, SCENARIO)", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
@Parameter(name = "caseType", description = "关联用例类型(FUNCTIONAL, API, SCENARIO)", schema = @Schema(requiredMode = Schema.RequiredMode.REQUIRED))
|
||||||
|
@ -8,6 +8,7 @@ import io.metersphere.system.dto.sdk.request.PosRequest;
|
|||||||
import jakarta.validation.ConstraintViolation;
|
import jakarta.validation.ConstraintViolation;
|
||||||
import jakarta.validation.Validator;
|
import jakarta.validation.Validator;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -120,6 +121,9 @@ public class ServiceUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String compressName(String name, int maxSize) {
|
public static String compressName(String name, int maxSize) {
|
||||||
|
if (StringUtils.isBlank(name)) {
|
||||||
|
return StringUtils.EMPTY;
|
||||||
|
}
|
||||||
String newName = name;
|
String newName = name;
|
||||||
// 限制名称长度 (数据库里最大的长度是255,这里判断超过250时截取到200附近)
|
// 限制名称长度 (数据库里最大的长度是255,这里判断超过250时截取到200附近)
|
||||||
if (newName.length() > maxSize) {
|
if (newName.length() > maxSize) {
|
||||||
|
@ -27,10 +27,10 @@ public interface ExtTestPlanReportApiCaseMapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下接口用例所属模块集合
|
* 获取项目下接口用例所属模块集合
|
||||||
* @param projectId 计划ID
|
* @param ids 模块ID集合
|
||||||
* @return 模块集合
|
* @return 模块集合
|
||||||
*/
|
*/
|
||||||
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("id") String projectId);
|
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询报告关联的用例
|
* 分页查询报告关联的用例
|
||||||
|
@ -20,8 +20,11 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
||||||
select adm.id, adm.name, adm.parent_id as parentId from api_definition_module adm
|
select adm.id, adm.name from api_definition_module adm
|
||||||
where adm.project_id = #{id}
|
where adm.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="list" resultType="io.metersphere.plan.dto.ReportDetailCasePageDTO">
|
<select id="list" resultType="io.metersphere.plan.dto.ReportDetailCasePageDTO">
|
||||||
|
@ -27,10 +27,10 @@ public interface ExtTestPlanReportApiScenarioMapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下场景用例所属模块集合
|
* 获取项目下场景用例所属模块集合
|
||||||
* @param projectId 计划ID
|
* @param ids 模块ID集合
|
||||||
* @return 模块集合
|
* @return 模块集合
|
||||||
*/
|
*/
|
||||||
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("id") String projectId);
|
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询报告关联的用例
|
* 分页查询报告关联的用例
|
||||||
|
@ -19,8 +19,11 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
||||||
select asm.id, asm.name, asm.parent_id as parentId from api_scenario_module asm
|
select asm.id, asm.name from api_scenario_module asm
|
||||||
where asm.project_id = #{id}
|
where asm.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" close=")" separator=",">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="list" resultType="io.metersphere.plan.dto.ReportDetailCasePageDTO">
|
<select id="list" resultType="io.metersphere.plan.dto.ReportDetailCasePageDTO">
|
||||||
|
@ -21,10 +21,10 @@ public interface ExtTestPlanReportFunctionalCaseMapper {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取项目下功能用例所属模块集合
|
* 获取项目下功能用例所属模块集合
|
||||||
* @param projectId 计划ID
|
* @param ids 模块ID集合
|
||||||
* @return 模块集合
|
* @return 模块集合
|
||||||
*/
|
*/
|
||||||
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("id") String projectId);
|
List<TestPlanBaseModule> getPlanExecuteCaseModules(@Param("ids") List<String> ids);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用例等级
|
* 获取用例等级
|
||||||
|
@ -14,8 +14,11 @@
|
|||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
<select id="getPlanExecuteCaseModules" resultType="io.metersphere.plan.dto.TestPlanBaseModule">
|
||||||
select fcm.id, fcm.name, fcm.parent_id as parentId from functional_case_module fcm
|
select fcm.id, fcm.name from functional_case_module fcm
|
||||||
where fcm.project_id = #{id}
|
where fcm.id in
|
||||||
|
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getCasePriorityByIds" resultType="io.metersphere.plugin.platform.dto.SelectOption">
|
<select id="getCasePriorityByIds" resultType="io.metersphere.plugin.platform.dto.SelectOption">
|
||||||
|
@ -12,7 +12,6 @@ import io.metersphere.plan.dto.response.TestPlanReportPageResponse;
|
|||||||
import io.metersphere.plan.enums.TestPlanReportAttachmentSourceType;
|
import io.metersphere.plan.enums.TestPlanReportAttachmentSourceType;
|
||||||
import io.metersphere.plan.mapper.*;
|
import io.metersphere.plan.mapper.*;
|
||||||
import io.metersphere.plan.utils.CountUtils;
|
import io.metersphere.plan.utils.CountUtils;
|
||||||
import io.metersphere.plan.utils.ModuleTreeUtils;
|
|
||||||
import io.metersphere.plan.utils.RateCalculateUtils;
|
import io.metersphere.plan.utils.RateCalculateUtils;
|
||||||
import io.metersphere.plugin.platform.dto.SelectOption;
|
import io.metersphere.plugin.platform.dto.SelectOption;
|
||||||
import io.metersphere.project.service.FileService;
|
import io.metersphere.project.service.FileService;
|
||||||
@ -304,8 +303,6 @@ public class TestPlanReportService {
|
|||||||
try {
|
try {
|
||||||
// 所有计划
|
// 所有计划
|
||||||
List<TestPlan> plans = getPlans(request.getTestPlanId());
|
List<TestPlan> plans = getPlans(request.getTestPlanId());
|
||||||
// 模块参数
|
|
||||||
TestPlanReportModuleParam moduleParam = getModuleParam(request.getProjectId());
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* 1. 准备报告生成参数
|
* 1. 准备报告生成参数
|
||||||
@ -326,7 +323,7 @@ public class TestPlanReportService {
|
|||||||
genPreParam.setUseManual(manual);
|
genPreParam.setUseManual(manual);
|
||||||
//如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
//如果是测试计划的独立报告,使用参数中的预生成的报告id。否则只有测试计划组报告使用该id
|
||||||
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
String prepareItemReportId = isGroupReports ? IDGenerator.nextStr() : prepareReportId;
|
||||||
TestPlanReport preReport = preGenReport(prepareItemReportId, genPreParam, currentUser, moduleParam, childPlanIds, reportManualParam);
|
TestPlanReport preReport = preGenReport(prepareItemReportId, genPreParam, currentUser, childPlanIds, reportManualParam);
|
||||||
if (manual) {
|
if (manual) {
|
||||||
// 汇总
|
// 汇总
|
||||||
if (genPreParam.getIntegrated()) {
|
if (genPreParam.getIntegrated()) {
|
||||||
@ -357,8 +354,8 @@ public class TestPlanReportService {
|
|||||||
*
|
*
|
||||||
* @return 报告
|
* @return 报告
|
||||||
*/
|
*/
|
||||||
public TestPlanReport preGenReport(String prepareId, TestPlanReportGenPreParam genParam, String currentUser, TestPlanReportModuleParam moduleParam,
|
public TestPlanReport preGenReport(String prepareId, TestPlanReportGenPreParam genParam, String currentUser, List<String> childPlanIds,
|
||||||
List<String> childPlanIds, TestPlanReportManualParam reportManualParam) {
|
TestPlanReportManualParam reportManualParam) {
|
||||||
// 计划配置
|
// 计划配置
|
||||||
TestPlanConfig config = testPlanConfigMapper.selectByPrimaryKey(genParam.getTestPlanId());
|
TestPlanConfig config = testPlanConfigMapper.selectByPrimaryKey(genParam.getTestPlanId());
|
||||||
|
|
||||||
@ -383,7 +380,7 @@ public class TestPlanReportService {
|
|||||||
TestPlanReportDetailCaseDTO reportCaseDetail;
|
TestPlanReportDetailCaseDTO reportCaseDetail;
|
||||||
if (!genParam.getIntegrated()) {
|
if (!genParam.getIntegrated()) {
|
||||||
// 生成独立报告的关联数据
|
// 生成独立报告的关联数据
|
||||||
reportCaseDetail = genReportDetail(genParam, moduleParam, report);
|
reportCaseDetail = genReportDetail(genParam, report);
|
||||||
} else {
|
} else {
|
||||||
// 计划组报告暂不统计各用例类型, 汇总时再入库
|
// 计划组报告暂不统计各用例类型, 汇总时再入库
|
||||||
reportCaseDetail = TestPlanReportDetailCaseDTO.builder().build();
|
reportCaseDetail = TestPlanReportDetailCaseDTO.builder().build();
|
||||||
@ -408,10 +405,9 @@ public class TestPlanReportService {
|
|||||||
* 生成独立报告的关联数据
|
* 生成独立报告的关联数据
|
||||||
*
|
*
|
||||||
* @param genParam 报告生成的参数
|
* @param genParam 报告生成的参数
|
||||||
* @param moduleParam 模块参数
|
|
||||||
* @param report 报告
|
* @param report 报告
|
||||||
*/
|
*/
|
||||||
private TestPlanReportDetailCaseDTO genReportDetail(TestPlanReportGenPreParam genParam, TestPlanReportModuleParam moduleParam, TestPlanReport report) {
|
private TestPlanReportDetailCaseDTO genReportDetail(TestPlanReportGenPreParam genParam, TestPlanReport report) {
|
||||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||||
// 功能用例
|
// 功能用例
|
||||||
List<TestPlanReportFunctionCase> reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
List<TestPlanReportFunctionCase> reportFunctionCases = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
||||||
@ -420,6 +416,13 @@ public class TestPlanReportService {
|
|||||||
List<String> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
|
List<String> ids = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseId).distinct().toList();
|
||||||
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
|
List<SelectOption> options = extTestPlanReportFunctionalCaseMapper.getCasePriorityByIds(ids);
|
||||||
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
Map<String, String> casePriorityMap = options.stream().collect(Collectors.toMap(SelectOption::getValue, SelectOption::getText));
|
||||||
|
// 用例模块
|
||||||
|
List<String> moduleIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getFunctionCaseModule).filter(Objects::nonNull).toList();
|
||||||
|
Map<String, String> moduleMap = new HashMap<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(moduleIds)) {
|
||||||
|
List<TestPlanBaseModule> modules = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCaseModules(moduleIds);
|
||||||
|
moduleMap = modules.stream().collect(Collectors.toMap(TestPlanBaseModule::getId, TestPlanBaseModule::getName));
|
||||||
|
}
|
||||||
// 关联的功能用例最新一次执行历史
|
// 关联的功能用例最新一次执行历史
|
||||||
List<String> relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList();
|
List<String> relateIds = reportFunctionCases.stream().map(TestPlanReportFunctionCase::getTestPlanFunctionCaseId).toList();
|
||||||
TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample();
|
TestPlanCaseExecuteHistoryExample example = new TestPlanCaseExecuteHistoryExample();
|
||||||
@ -427,13 +430,11 @@ public class TestPlanReportService {
|
|||||||
List<TestPlanCaseExecuteHistory> functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example);
|
List<TestPlanCaseExecuteHistory> functionalExecHisList = testPlanCaseExecuteHistoryMapper.selectByExample(example);
|
||||||
Map<String, List<TestPlanCaseExecuteHistory>> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId));
|
Map<String, List<TestPlanCaseExecuteHistory>> functionalExecMap = functionalExecHisList.stream().collect(Collectors.groupingBy(TestPlanCaseExecuteHistory::getTestPlanCaseId));
|
||||||
|
|
||||||
|
for (TestPlanReportFunctionCase reportFunctionalCase : reportFunctionCases) {
|
||||||
reportFunctionCases.forEach(reportFunctionalCase -> {
|
|
||||||
reportFunctionalCase.setId(IDGenerator.nextStr());
|
reportFunctionalCase.setId(IDGenerator.nextStr());
|
||||||
reportFunctionalCase.setTestPlanReportId(report.getId());
|
reportFunctionalCase.setTestPlanReportId(report.getId());
|
||||||
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
|
reportFunctionalCase.setTestPlanName(genParam.getTestPlanName());
|
||||||
reportFunctionalCase.setFunctionCaseModule(moduleParam.getFunctionalModuleMap().getOrDefault(reportFunctionalCase.getFunctionCaseModule(),
|
reportFunctionalCase.setFunctionCaseModule(moduleMap.getOrDefault(reportFunctionalCase.getFunctionCaseModule(), reportFunctionalCase.getFunctionCaseModule()));
|
||||||
ModuleTreeUtils.MODULE_PATH_PREFIX + reportFunctionalCase.getFunctionCaseModule()));
|
|
||||||
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
|
reportFunctionalCase.setFunctionCasePriority(casePriorityMap.get(reportFunctionalCase.getFunctionCaseId()));
|
||||||
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
|
List<TestPlanCaseExecuteHistory> hisList = functionalExecMap.get(reportFunctionalCase.getTestPlanFunctionCaseId());
|
||||||
if (CollectionUtils.isNotEmpty(hisList)) {
|
if (CollectionUtils.isNotEmpty(hisList)) {
|
||||||
@ -442,7 +443,8 @@ public class TestPlanReportService {
|
|||||||
} else {
|
} else {
|
||||||
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
|
reportFunctionalCase.setFunctionCaseExecuteReportId(null);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
|
|
||||||
// 插入计划功能用例关联数据 -> 报告内容
|
// 插入计划功能用例关联数据 -> 报告内容
|
||||||
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
|
TestPlanReportFunctionCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportFunctionCaseMapper.class);
|
||||||
batchMapper.batchInsert(reportFunctionCases);
|
batchMapper.batchInsert(reportFunctionCases);
|
||||||
@ -451,12 +453,19 @@ public class TestPlanReportService {
|
|||||||
// 接口用例
|
// 接口用例
|
||||||
List<TestPlanReportApiCase> reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
List<TestPlanReportApiCase> reportApiCases = extTestPlanReportApiCaseMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
||||||
if (CollectionUtils.isNotEmpty(reportApiCases)) {
|
if (CollectionUtils.isNotEmpty(reportApiCases)) {
|
||||||
reportApiCases.forEach(reportApiCase -> {
|
// 用例模块
|
||||||
|
List<String> moduleIds = reportApiCases.stream().map(TestPlanReportApiCase::getApiCaseModule).filter(Objects::nonNull).toList();
|
||||||
|
Map<String, String> moduleMap = new HashMap<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(moduleIds)) {
|
||||||
|
List<TestPlanBaseModule> modules = extTestPlanReportApiCaseMapper.getPlanExecuteCaseModules(moduleIds);
|
||||||
|
moduleMap = modules.stream().collect(Collectors.toMap(TestPlanBaseModule::getId, TestPlanBaseModule::getName));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TestPlanReportApiCase reportApiCase : reportApiCases) {
|
||||||
reportApiCase.setId(IDGenerator.nextStr());
|
reportApiCase.setId(IDGenerator.nextStr());
|
||||||
reportApiCase.setTestPlanReportId(report.getId());
|
reportApiCase.setTestPlanReportId(report.getId());
|
||||||
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
reportApiCase.setTestPlanName(genParam.getTestPlanName());
|
||||||
reportApiCase.setApiCaseModule(moduleParam.getApiModuleMap().getOrDefault(reportApiCase.getApiCaseModule(),
|
reportApiCase.setApiCaseModule(moduleMap.getOrDefault(reportApiCase.getApiCaseModule(), reportApiCase.getApiCaseModule()));
|
||||||
ModuleTreeUtils.MODULE_PATH_PREFIX + reportApiCase.getApiCaseModule()));
|
|
||||||
//根据不超过数据库字段最大长度压缩模块名
|
//根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
reportApiCase.setApiCaseModule(ServiceUtils.compressName(reportApiCase.getApiCaseModule(), 450));
|
||||||
if (!genParam.getUseManual()) {
|
if (!genParam.getUseManual()) {
|
||||||
@ -465,7 +474,7 @@ public class TestPlanReportService {
|
|||||||
reportApiCase.setApiCaseExecuteUser(null);
|
reportApiCase.setApiCaseExecuteUser(null);
|
||||||
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
|
reportApiCase.setApiCaseExecuteReportId(IDGenerator.nextStr());
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
// 插入计划接口用例关联数据 -> 报告内容
|
// 插入计划接口用例关联数据 -> 报告内容
|
||||||
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
|
TestPlanReportApiCaseMapper batchMapper = sqlSession.getMapper(TestPlanReportApiCaseMapper.class);
|
||||||
batchMapper.batchInsert(reportApiCases);
|
batchMapper.batchInsert(reportApiCases);
|
||||||
@ -474,12 +483,19 @@ public class TestPlanReportService {
|
|||||||
// 场景用例
|
// 场景用例
|
||||||
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
List<TestPlanReportApiScenario> reportApiScenarios = extTestPlanReportApiScenarioMapper.getPlanExecuteCases(genParam.getTestPlanId());
|
||||||
if (CollectionUtils.isNotEmpty(reportApiScenarios)) {
|
if (CollectionUtils.isNotEmpty(reportApiScenarios)) {
|
||||||
reportApiScenarios.forEach(reportApiScenario -> {
|
// 用例模块
|
||||||
|
List<String> moduleIds = reportApiScenarios.stream().map(TestPlanReportApiScenario::getApiScenarioModule).filter(Objects::nonNull).toList();
|
||||||
|
Map<String, String> moduleMap = new HashMap<>();
|
||||||
|
if (CollectionUtils.isNotEmpty(moduleIds)) {
|
||||||
|
List<TestPlanBaseModule> modules = extTestPlanReportApiScenarioMapper.getPlanExecuteCaseModules(moduleIds);
|
||||||
|
moduleMap = modules.stream().collect(Collectors.toMap(TestPlanBaseModule::getId, TestPlanBaseModule::getName));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (TestPlanReportApiScenario reportApiScenario : reportApiScenarios) {
|
||||||
reportApiScenario.setId(IDGenerator.nextStr());
|
reportApiScenario.setId(IDGenerator.nextStr());
|
||||||
reportApiScenario.setTestPlanReportId(report.getId());
|
reportApiScenario.setTestPlanReportId(report.getId());
|
||||||
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
reportApiScenario.setTestPlanName(genParam.getTestPlanName());
|
||||||
reportApiScenario.setApiScenarioModule(moduleParam.getScenarioModuleMap().getOrDefault(reportApiScenario.getApiScenarioModule(),
|
reportApiScenario.setApiScenarioModule(moduleMap.getOrDefault(reportApiScenario.getApiScenarioModule(), reportApiScenario.getApiScenarioModule()));
|
||||||
ModuleTreeUtils.MODULE_PATH_PREFIX + reportApiScenario.getApiScenarioModule()));
|
|
||||||
//根据不超过数据库字段最大长度压缩模块名
|
//根据不超过数据库字段最大长度压缩模块名
|
||||||
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
reportApiScenario.setApiScenarioModule(ServiceUtils.compressName(reportApiScenario.getApiScenarioModule(), 450));
|
||||||
if (!genParam.getUseManual()) {
|
if (!genParam.getUseManual()) {
|
||||||
@ -488,7 +504,7 @@ public class TestPlanReportService {
|
|||||||
reportApiScenario.setApiScenarioExecuteUser(null);
|
reportApiScenario.setApiScenarioExecuteUser(null);
|
||||||
reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr());
|
reportApiScenario.setApiScenarioExecuteReportId(IDGenerator.nextStr());
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
// 插入计划场景用例关联数据 -> 报告内容
|
// 插入计划场景用例关联数据 -> 报告内容
|
||||||
TestPlanReportApiScenarioMapper batchMapper = sqlSession.getMapper(TestPlanReportApiScenarioMapper.class);
|
TestPlanReportApiScenarioMapper batchMapper = sqlSession.getMapper(TestPlanReportApiScenarioMapper.class);
|
||||||
batchMapper.batchInsert(reportApiScenarios);
|
batchMapper.batchInsert(reportApiScenarios);
|
||||||
@ -1062,26 +1078,6 @@ public class TestPlanReportService {
|
|||||||
return plans;
|
return plans;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 获取项目下的模块参数
|
|
||||||
*
|
|
||||||
* @param projectId 项目ID
|
|
||||||
* @return 模块参数
|
|
||||||
*/
|
|
||||||
private TestPlanReportModuleParam getModuleParam(String projectId) {
|
|
||||||
// 模块树 {功能, 接口, 场景}
|
|
||||||
List<TestPlanBaseModule> functionalModules = extTestPlanReportFunctionalCaseMapper.getPlanExecuteCaseModules(projectId);
|
|
||||||
Map<String, String> functionalModuleMap = new HashMap<>(functionalModules.size());
|
|
||||||
ModuleTreeUtils.genPathMap(functionalModules, functionalModuleMap, new ArrayList<>());
|
|
||||||
List<TestPlanBaseModule> apiModules = extTestPlanReportApiCaseMapper.getPlanExecuteCaseModules(projectId);
|
|
||||||
Map<String, String> apiModuleMap = new HashMap<>(apiModules.size());
|
|
||||||
ModuleTreeUtils.genPathMap(apiModules, apiModuleMap, new ArrayList<>());
|
|
||||||
List<TestPlanBaseModule> scenarioModules = extTestPlanReportApiScenarioMapper.getPlanExecuteCaseModules(projectId);
|
|
||||||
Map<String, String> scenarioModuleMap = new HashMap<>(apiModules.size());
|
|
||||||
ModuleTreeUtils.genPathMap(scenarioModules, scenarioModuleMap, new ArrayList<>());
|
|
||||||
return TestPlanReportModuleParam.builder().functionalModuleMap(functionalModuleMap).apiModuleMap(apiModuleMap).scenarioModuleMap(scenarioModuleMap).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户集合
|
* 获取用户集合
|
||||||
*
|
*
|
||||||
|
@ -1,61 +0,0 @@
|
|||||||
package io.metersphere.plan.utils;
|
|
||||||
|
|
||||||
import io.metersphere.plan.dto.TestPlanBaseModule;
|
|
||||||
import lombok.experimental.UtilityClass;
|
|
||||||
import org.apache.commons.collections4.CollectionUtils;
|
|
||||||
import org.apache.commons.collections4.MapUtils;
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 模块树解析相关的工具类
|
|
||||||
*/
|
|
||||||
@UtilityClass
|
|
||||||
public class ModuleTreeUtils {
|
|
||||||
|
|
||||||
public static final String MODULE_PATH_PREFIX = "/";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析并返回模块的全路径
|
|
||||||
* @param filterNodes 模块集合
|
|
||||||
* @param nodePathMap 树节点路径集合
|
|
||||||
*/
|
|
||||||
private static void realGenPathMap(List<TestPlanBaseModule> filterNodes, Map<String, String> nodePathMap, List<String> scanIds) {
|
|
||||||
int lastLoopSize = nodePathMap.size();
|
|
||||||
if (MapUtils.isEmpty(nodePathMap)) {
|
|
||||||
// 根节点遍历
|
|
||||||
List<TestPlanBaseModule> rootNodes = filterNodes.stream().filter(node ->
|
|
||||||
StringUtils.isBlank(node.getParentId()) || StringUtils.equals(node.getParentId(), "NONE")).toList();
|
|
||||||
rootNodes.forEach(node -> nodePathMap.put(node.getId(), MODULE_PATH_PREFIX + node.getName()));
|
|
||||||
// 下一级父节点
|
|
||||||
scanIds = rootNodes.stream().map(TestPlanBaseModule::getId).toList();
|
|
||||||
filterNodes.removeAll(rootNodes);
|
|
||||||
} else {
|
|
||||||
// 非根节点遍历
|
|
||||||
List<String> finalScanIds = scanIds;
|
|
||||||
List<TestPlanBaseModule> scanNodes = filterNodes.stream().filter(node -> finalScanIds.contains(node.getParentId())).toList();
|
|
||||||
scanNodes.forEach(node -> nodePathMap.put(node.getId(), nodePathMap.getOrDefault(node.getParentId(), StringUtils.EMPTY) + MODULE_PATH_PREFIX + node.getName()));
|
|
||||||
// 下一级父节点
|
|
||||||
scanIds = scanNodes.stream().map(TestPlanBaseModule::getId).toList();
|
|
||||||
// 每次过滤的数据
|
|
||||||
filterNodes.removeAll(scanNodes);
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isEmpty(scanIds)) {
|
|
||||||
// 叶子节点不存在, 跳出
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (lastLoopSize == nodePathMap.size()) {
|
|
||||||
// 处理前后无新数据产生, 无效的迭代, 跳出;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
realGenPathMap(filterNodes, nodePathMap, scanIds);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void genPathMap(List<TestPlanBaseModule> allNodes, Map<String, String> nodePathMap, List<String> scanIds) {
|
|
||||||
// 过滤掉一些不好的数据
|
|
||||||
allNodes.removeIf(node -> StringUtils.equals(node.getId(), "NONE") || StringUtils.equals(node.getId(), node.getParentId()));
|
|
||||||
realGenPathMap(allNodes, nodePathMap, scanIds);
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user