feat(测试跟踪): 测试计划列表增加进度列

This commit is contained in:
shiziyuan9527 2020-11-04 10:48:50 +08:00
parent 8cb881fe42
commit 12e86889f7
6 changed files with 55 additions and 46 deletions

View File

@ -8,7 +8,7 @@ import org.apache.ibatis.annotations.Param;
import java.util.List;
public interface ExtTestPlanMapper {
List<TestPlanDTO> list(@Param("request") QueryTestPlanRequest params);
List<TestPlanDTOWithMetric> list(@Param("request") QueryTestPlanRequest params);
List<TestPlanDTOWithMetric> listRelate(@Param("request") QueryTestPlanRequest params);

View File

@ -96,7 +96,7 @@
</if>
</sql>
<select id="list" resultMap="BaseResultMap"
<select id="list" resultType="io.metersphere.track.dto.TestPlanDTOWithMetric"
parameterType="io.metersphere.track.request.testcase.QueryTestPlanRequest">
select DISTINCT test_plan.*, user.name as user_name from test_plan
LEFT JOIN user ON user.id = test_plan.principal

View File

@ -8,7 +8,7 @@ import io.metersphere.base.mapper.ext.*;
import io.metersphere.commons.utils.SessionUtils;
import io.metersphere.dto.LoadTestDTO;
import io.metersphere.i18n.Translator;
import io.metersphere.track.dto.TestPlanDTO;
import io.metersphere.track.dto.TestPlanDTOWithMetric;
import io.metersphere.track.request.testplan.QueryTestPlanRequest;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
@ -81,7 +81,7 @@ public class CheckOwnerService {
io.metersphere.track.request.testcase.QueryTestPlanRequest request = new io.metersphere.track.request.testcase.QueryTestPlanRequest();
request.setWorkspaceId(workspaceId);
request.setId(planId);
List<TestPlanDTO> list = extTestPlanMapper.list(request);
List<TestPlanDTOWithMetric> list = extTestPlanMapper.list(request);
if (CollectionUtils.size(list) != 1) {
throw new UnauthorizedException(Translator.get("check_owner_plan"));
}

View File

@ -37,7 +37,7 @@ public class TestPlanController {
CheckOwnerService checkOwnerService;
@PostMapping("/list/{goPage}/{pageSize}")
public Pager<List<TestPlanDTO>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
public Pager<List<TestPlanDTOWithMetric>> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryTestPlanRequest request) {
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
request.setWorkspaceId(currentWorkspaceId);
Page<Object> page = PageHelper.startPage(goPage, pageSize, true);

View File

@ -279,9 +279,46 @@ public class TestPlanService {
testPlanTestCaseMapper.deleteByExample(testPlanTestCaseExample);
}
public List<TestPlanDTO> listTestPlan(QueryTestPlanRequest request) {
private void calcTestPlanRate(List<TestPlanDTOWithMetric> testPlans) {
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(SessionUtils.getCurrentWorkspaceId());
Map<String, List<TestPlanCaseDTO>> testCaseMap = new HashMap<>();
listTestCaseByProjectIds(projectIds).forEach(testCase -> {
List<TestPlanCaseDTO> list = testCaseMap.get(testCase.getPlanId());
if (list == null) {
list = new ArrayList<>();
list.add(testCase);
testCaseMap.put(testCase.getPlanId(), list);
} else {
list.add(testCase);
}
});
testPlans.forEach(testPlan -> {
List<TestPlanCaseDTO> testCases = testCaseMap.get(testPlan.getId());
testPlan.setTested(0);
testPlan.setPassed(0);
testPlan.setTotal(0);
if (testCases != null) {
testPlan.setTotal(testCases.size());
testCases.forEach(testCase -> {
if (!StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Prepare.name())
&& !StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Underway.name())) {
testPlan.setTested(testPlan.getTested() + 1);
if (StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Pass.name())) {
testPlan.setPassed(testPlan.getPassed() + 1);
}
}
});
}
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested()));
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
});
}
public List<TestPlanDTOWithMetric> listTestPlan(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
return extTestPlanMapper.list(request);
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.list(request);
calcTestPlanRate(testPlans);
return testPlans;
}
public List<TestPlanDTO> listTestPlanByProject(QueryTestPlanRequest request) {
@ -359,49 +396,12 @@ public class TestPlanService {
public List<TestPlanDTOWithMetric> listRelateAllPlan() {
SessionUser user = SessionUtils.getUser();
QueryTestPlanRequest request = new QueryTestPlanRequest();
request.setPrincipal(user.getId());
request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId());
request.setPlanIds(extTestPlanTestCaseMapper.findRelateTestPlanId(user.getId(), SessionUtils.getCurrentWorkspaceId()));
List<String> projectIds = extProjectMapper.getProjectIdByWorkspaceId(SessionUtils.getCurrentWorkspaceId());
List<TestPlanDTOWithMetric> testPlans = extTestPlanMapper.listRelate(request);
Map<String, List<TestPlanCaseDTO>> testCaseMap = new HashMap<>();
listTestCaseByProjectIds(projectIds).forEach(testCase -> {
List<TestPlanCaseDTO> list = testCaseMap.get(testCase.getPlanId());
if (list == null) {
list = new ArrayList<>();
list.add(testCase);
testCaseMap.put(testCase.getPlanId(), list);
} else {
list.add(testCase);
}
});
testPlans.forEach(testPlan -> {
List<TestPlanCaseDTO> testCases = testCaseMap.get(testPlan.getId());
testPlan.setTested(0);
testPlan.setPassed(0);
testPlan.setTotal(0);
if (testCases != null) {
testPlan.setTotal(testCases.size());
testCases.forEach(testCase -> {
if (!StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Prepare.name())
&& !StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Underway.name())) {
testPlan.setTested(testPlan.getTested() + 1);
if (StringUtils.equals(testCase.getStatus(), TestPlanTestCaseStatus.Pass.name())) {
testPlan.setPassed(testPlan.getPassed() + 1);
}
}
});
}
testPlan.setPassRate(MathUtils.getPercentWithDecimal(testPlan.getTested() == 0 ? 0 : testPlan.getPassed() * 1.0 / testPlan.getTested()));
testPlan.setTestRate(MathUtils.getPercentWithDecimal(testPlan.getTotal() == 0 ? 0 : testPlan.getTested() * 1.0 / testPlan.getTotal()));
});
calcTestPlanRate(testPlans);
return testPlans;
}
@ -528,7 +528,7 @@ public class TestPlanService {
for (Project project : projects) {
stringBuilder.append(project.getName()).append("");
}
projectName = stringBuilder.toString().substring(0, stringBuilder.length() - 1);
projectName = stringBuilder.substring(0, stringBuilder.length() - 1);
}
return projectName;

View File

@ -63,6 +63,15 @@
<plan-stage-table-item :stage="scope.row.stage"/>
</template>
</el-table-column>
<el-table-column
prop="projectName"
:label="$t('test_track.home.test_rate')"
min-width="100"
show-overflow-tooltip>
<template v-slot:default="scope">
<el-progress :percentage="scope.row.testRate"></el-progress>
</template>
</el-table-column>
<el-table-column
prop="projectName"
:label="$t('test_track.plan.plan_project')"