fix(测试计划): 测试计划统计中已通过的测试计划增加阈值对比
This commit is contained in:
parent
ccc10bacc2
commit
714f8644d3
|
@ -22,4 +22,16 @@ public class CalculateUtils {
|
||||||
return passRate + "%";
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,5 +83,5 @@ public interface ExtTestPlanApiCaseMapper {
|
||||||
|
|
||||||
Integer countByPlanIds(@Param("planIds") List<String> planIds);
|
Integer countByPlanIds(@Param("planIds") List<String> planIds);
|
||||||
|
|
||||||
List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
|
List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -893,9 +893,9 @@
|
||||||
AND test_plan.status != 'ARCHIVED'
|
AND test_plan.status != 'ARCHIVED'
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="selectDistinctLastExecResultByTestPlanIds"
|
<select id="selectLastExecResultByTestPlanIds"
|
||||||
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
||||||
select distinct resource.test_plan_id AS testPlanId,
|
select resource.test_plan_id AS testPlanId,
|
||||||
CASE
|
CASE
|
||||||
WHEN resource.last_exec_result is null
|
WHEN resource.last_exec_result is null
|
||||||
THEN 'PENDING'
|
THEN 'PENDING'
|
||||||
|
|
|
@ -80,5 +80,5 @@ public interface ExtTestPlanApiScenarioMapper {
|
||||||
|
|
||||||
Integer countByPlanIds(@Param("planIds") List<String> planIds);
|
Integer countByPlanIds(@Param("planIds") List<String> planIds);
|
||||||
|
|
||||||
List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
|
List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(@Param("testPlanIds") List<String> testPlanIds);
|
||||||
}
|
}
|
||||||
|
|
|
@ -663,9 +663,9 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
<select id="selectDistinctLastExecResultByTestPlanIds"
|
<select id="selectLastExecResultByTestPlanIds"
|
||||||
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
||||||
select distinct resource.test_plan_id AS testPlanId,
|
select resource.test_plan_id AS testPlanId,
|
||||||
CASE
|
CASE
|
||||||
WHEN resource.last_exec_result is null
|
WHEN resource.last_exec_result is null
|
||||||
THEN 'PENDING'
|
THEN 'PENDING'
|
||||||
|
|
|
@ -88,5 +88,5 @@ public interface ExtTestPlanFunctionalCaseMapper {
|
||||||
|
|
||||||
Collection<String> selectIdsByRootIds(@Param("rootIds") List<String> rootIds, @Param("testPlanId") String testPlanId);
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -780,9 +780,9 @@
|
||||||
</foreach>
|
</foreach>
|
||||||
and functional_case.module_id = 'root'
|
and functional_case.module_id = 'root'
|
||||||
</select>
|
</select>
|
||||||
<select id="selectDistinctLastExecResultByTestPlanIds"
|
<select id="selectLastExecResultByTestPlanIds"
|
||||||
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
resultType="io.metersphere.plan.dto.TestPlanResourceExecResultDTO">
|
||||||
select distinct resource.test_plan_id AS testPlanId,
|
select resource.test_plan_id AS testPlanId,
|
||||||
CASE
|
CASE
|
||||||
WHEN resource.last_exec_result is null
|
WHEN resource.last_exec_result is null
|
||||||
THEN 'PENDING'
|
THEN 'PENDING'
|
||||||
|
|
|
@ -146,8 +146,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
||||||
return extTestPlanApiCaseMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
|
return extTestPlanApiCaseMapper.selectLastExecResultByTestPlanIds(testPlanIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -134,8 +134,8 @@ public class TestPlanApiScenarioService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
||||||
return extTestPlanApiScenarioMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
|
return extTestPlanApiScenarioMapper.selectLastExecResultByTestPlanIds(testPlanIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class TestPlanBugService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
||||||
return List.of();
|
return List.of();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -144,8 +144,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<TestPlanResourceExecResultDTO> selectDistinctLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
public List<TestPlanResourceExecResultDTO> selectLastExecResultByTestPlanIds(List<String> testPlanIds) {
|
||||||
return extTestPlanFunctionalCaseMapper.selectDistinctLastExecResultByTestPlanIds(testPlanIds);
|
return extTestPlanFunctionalCaseMapper.selectLastExecResultByTestPlanIds(testPlanIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -107,7 +107,7 @@ public abstract class TestPlanResourceService extends TestPlanSortService {
|
||||||
|
|
||||||
public abstract List<TestPlanResourceExecResultDTO> selectDistinctExecResultByTestPlanIds(List<String> testPlanIds);
|
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())));
|
associateBugs.forEach(bug -> bug.setStatus(statusMap.get(bug.getStatus())));
|
||||||
return associateBugs.stream().collect(Collectors.groupingBy(TestPlanCaseBugDTO::getPlanCaseRefId));
|
return associateBugs.stream().collect(Collectors.groupingBy(TestPlanCaseBugDTO::getPlanCaseRefId));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,10 +16,7 @@ import io.metersphere.project.request.ProjectApplicationRequest;
|
||||||
import io.metersphere.project.service.ProjectApplicationService;
|
import io.metersphere.project.service.ProjectApplicationService;
|
||||||
import io.metersphere.sdk.constants.*;
|
import io.metersphere.sdk.constants.*;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.*;
|
||||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
|
||||||
import io.metersphere.sdk.util.SubListUtils;
|
|
||||||
import io.metersphere.sdk.util.Translator;
|
|
||||||
import io.metersphere.system.domain.ScheduleExample;
|
import io.metersphere.system.domain.ScheduleExample;
|
||||||
import io.metersphere.system.domain.TestPlanModule;
|
import io.metersphere.system.domain.TestPlanModule;
|
||||||
import io.metersphere.system.domain.TestPlanModuleExample;
|
import io.metersphere.system.domain.TestPlanModuleExample;
|
||||||
|
@ -1029,16 +1026,31 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
||||||
// 批量处理
|
// 批量处理
|
||||||
SubListUtils.dealForSubList(notArchivedList, SubListUtils.DEFAULT_BATCH_SIZE, dealList -> {
|
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<>();
|
List<TestPlanResourceExecResultDTO> execResults = new ArrayList<>();
|
||||||
beansOfType.forEach((k, v) -> execResults.addAll(v.selectDistinctLastExecResultByTestPlanIds(dealList)));
|
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())));
|
Map<String, List<String>> testPlanExecResultMap = execResults.stream().collect(
|
||||||
|
Collectors.groupingBy(TestPlanResourceExecResultDTO::getTestPlanId, Collectors.mapping(TestPlanResourceExecResultDTO::getExecResult, Collectors.toList())));
|
||||||
|
|
||||||
for (String testPlanId : dealList) {
|
for (String testPlanId : dealList) {
|
||||||
List<String> executeResultList = testPlanExecResultMap.get(testPlanId);
|
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)) {
|
if (CollectionUtils.isEmpty(executeResultList)) {
|
||||||
// 未运行
|
// 未运行
|
||||||
returnDTO.notStartedAutoIncrement();
|
returnDTO.notStartedAutoIncrement();
|
||||||
} else {
|
} 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();
|
List<String> calculateList = executeResultList.stream().distinct().toList();
|
||||||
//目前只有三个状态。如果同时包含多种状态(进行中/未开始、进行中/已完成、已完成/未开始、进行中/未开始/已完成),根据算法可得测试计划都会是进行中
|
//目前只有三个状态。如果同时包含多种状态(进行中/未开始、进行中/已完成、已完成/未开始、进行中/未开始/已完成),根据算法可得测试计划都会是进行中
|
||||||
if (calculateList.size() == 1) {
|
if (calculateList.size() == 1) {
|
||||||
|
@ -1050,7 +1062,9 @@ public class TestPlanService extends TestPlanBaseUtilsService {
|
||||||
returnDTO.unSuccessAutoIncrement();
|
returnDTO.unSuccessAutoIncrement();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (calculateList.contains(ExecStatus.PENDING.name())) {
|
if (passphrase > executeRage) {
|
||||||
|
returnDTO.successAutoIncrement();
|
||||||
|
} else if (calculateList.contains(ExecStatus.PENDING.name())) {
|
||||||
// 存在还未完成的用例,测试计划为进行中
|
// 存在还未完成的用例,测试计划为进行中
|
||||||
returnDTO.testPlanRunningAutoIncrement();
|
returnDTO.testPlanRunningAutoIncrement();
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue