fix(测试计划): 测试计划统计中已通过的测试计划增加阈值对比

This commit is contained in:
Jianguo-Genius 2024-11-20 15:30:44 +08:00 committed by Craftsman
parent ccc10bacc2
commit 714f8644d3
13 changed files with 51 additions and 24 deletions

View File

@ -22,4 +22,16 @@ public class CalculateUtils {
return passRate + "%";
}
}
public static double percentage(int numerator, int denominator) {
if (denominator == 0) {
return 0;
}
DecimalFormat rateFormat = new DecimalFormat("#0.00");
rateFormat.setMinimumFractionDigits(2);
rateFormat.setMaximumFractionDigits(2);
return Double.parseDouble(rateFormat.format((double) numerator * 100 / (double) denominator));
}
}

View File

@ -83,5 +83,5 @@ public interface ExtTestPlanApiCaseMapper {
Integer countByPlanIds(@Param("planIds") List<String> planIds);
List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
}

View File

@ -893,9 +893,9 @@
AND test_plan.status != 'ARCHIVED'
</select>
<select id="selectDistinctLastExecResultByTestPlanIds"
<select id="selectLastExecResultByTestPlanIds"
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
select distinct resource.test_plan_id AS testPlanId,
select resource.test_plan_id AS testPlanId,
CASE
WHEN resource.last_exec_result is null
THEN 'PENDING'

View File

@ -80,5 +80,5 @@ public interface ExtTestPlanApiScenarioMapper {
Integer countByPlanIds(@Param("planIds") List<String> planIds);
List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
}

View File

@ -663,9 +663,9 @@
</foreach>
</where>
</select>
<select id="selectDistinctLastExecResultByTestPlanIds"
<select id="selectLastExecResultByTestPlanIds"
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
select distinct resource.test_plan_id AS testPlanId,
select resource.test_plan_id AS testPlanId,
CASE
WHEN resource.last_exec_result is null
THEN 'PENDING'

View File

@ -88,5 +88,5 @@ public interface ExtTestPlanFunctionalCaseMapper {
Collection<String> selectIdsByRootIds(@Param("rootIds") List<String> rootIds, @Param("testPlanId") String testPlanId);
List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
}

View File

@ -780,9 +780,9 @@
</foreach>
and functional_case.module_id = 'root'
</select>
<select id="selectDistinctLastExecResultByTestPlanIds"
<select id="selectLastExecResultByTestPlanIds"
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
select distinct resource.test_plan_id AS testPlanId,
select resource.test_plan_id AS testPlanId,
CASE
WHEN resource.last_exec_result is null
THEN 'PENDING'

View File

@ -146,8 +146,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
}
@Override
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanApiCaseMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanApiCaseMapper.selectLastExecResultByTestPlanIds(testPlanIds);
}
@Override

View File

@ -134,8 +134,8 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
}
@Override
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanApiScenarioMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanApiScenarioMapper.selectLastExecResultByTestPlanIds(testPlanIds);
}
@Override

View File

@ -74,7 +74,7 @@ public class TestPlanBugService extends TestPlanResourceService {
}
@Override
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
return List.of();
}

View File

@ -144,8 +144,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
}
@Override
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanFunctionalCaseMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
return extTestPlanFunctionalCaseMapper.selectLastExecResultByTestPlanIds(testPlanIds);
}
@Override

View File

@ -107,7 +107,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
public abstract List<TestPlanResourceExecResultDTO> selectDistinctExecResultByTestPlanIds(List<String> testPlanIds);
public abstract List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds);
public abstract List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds);
/**
* 关联用例
@ -268,4 +268,5 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
associateBugs.forEach(bug -> bug.setStatus(statusMap.get(bug.getStatus())));
return associateBugs.stream().collect(Collectors.groupingBy(TestPlanCaseBugDTO::getPlanCaseRefId));
}
}

View File

@ -16,10 +16,7 @@ import io.metersphere.project.request.ProjectApplicationRequest;
import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.BeanUtils;
import io.metersphere.sdk.util.CommonBeanFactory;
import io.metersphere.sdk.util.SubListUtils;
import io.metersphere.sdk.util.Translator;
import io.metersphere.sdk.util.*;
import io.metersphere.system.domain.ScheduleExample;
import io.metersphere.system.domain.TestPlanModule;
import io.metersphere.system.domain.TestPlanModuleExample;
@ -1029,16 +1026,31 @@ public class TestPlanService extends TestPlanBaseUtilsService {
// 批量处理
SubListUtils.dealForSubList(notArchivedList, SubListUtils.DEFAULT_BATCH_SIZE, dealList -> {
TestPlanConfigExample configExample = new TestPlanConfigExample();
configExample.createCriteria().andTestPlanIdIn(dealList);
List<TestPlanConfig> testPlanConfigList = testPlanConfigMapper.selectByExample(configExample);
Map<String, TestPlanConfig> testPlanConfigMap = testPlanConfigList.stream().collect(Collectors.toMap(TestPlanConfig::getTestPlanId, item -> item));
List<TestPlanResourceExecResultDTO> execResults = new ArrayList<>();
beansOfType.forEach((k, v) -> execResults.addAll(v.selectDistinctLastExecResultByTestPlanIds(dealList)));
Map<String, List<String>> testPlanExecResultMap = execResults.stream().collect(Collectors.groupingBy(TestPlanResourceExecResultDTO::getTestPlanId, Collectors.mapping(TestPlanResourceExecResultDTO::getExecResult, Collectors.toList())));
beansOfType.forEach((k, v) -> execResults.addAll(v.selectLastExecResultByTestPlanIds(dealList)));
Map<String, List<String>> testPlanExecResultMap = execResults.stream().collect(
Collectors.groupingBy(TestPlanResourceExecResultDTO::getTestPlanId, Collectors.mapping(TestPlanResourceExecResultDTO::getExecResult, Collectors.toList())));
for (String testPlanId : dealList) {
List<String> executeResultList = testPlanExecResultMap.get(testPlanId);
TestPlanConfig testPlanConfig = testPlanConfigMap.get(testPlanId);
double executeRage = testPlanConfig == null ? 100
: testPlanConfig.getPassThreshold() == null ? 100 : testPlanConfig.getPassThreshold();
if (CollectionUtils.isEmpty(executeResultList)) {
// 未运行
returnDTO.notStartedAutoIncrement();
} else {
double passphrase = CalculateUtils.percentage(
executeResultList.stream().filter(result -> StringUtils.equalsIgnoreCase(result, ResultStatus.SUCCESS.name())).toList().size(),
executeResultList.size()
);
List<String> calculateList = executeResultList.stream().distinct().toList();
//目前只有三个状态如果同时包含多种状态(进行中/未开始进行中/已完成已完成/未开始进行中/未开始/已完成),根据算法可得测试计划都会是进行中
if (calculateList.size() == 1) {
@ -1050,7 +1062,9 @@ public class TestPlanService extends TestPlanBaseUtilsService {
returnDTO.unSuccessAutoIncrement();
}
} else {
if (calculateList.contains(ExecStatus.PENDING.name())) {
if (passphrase > executeRage) {
returnDTO.successAutoIncrement();
} else if (calculateList.contains(ExecStatus.PENDING.name())) {
// 存在还未完成的用例测试计划为进行中
returnDTO.testPlanRunningAutoIncrement();
} else {