fix(测试跟踪): 首页重构

This commit is contained in:
shiziyuan9527 2021-03-15 17:24:14 +08:00
parent 84a989db63
commit 19d284a399
7 changed files with 101 additions and 41 deletions

View File

@ -71,5 +71,10 @@ public interface ExtTestCaseMapper {
List<TrackCountResult> countRelevanceMaintainer(@Param("projectId") String projectId); List<TrackCountResult> countRelevanceMaintainer(@Param("projectId") String projectId);
int getTestPlanBug(@Param("planId") String planId);
int getTestPlanCase(@Param("planId") String planId);
int getTestPlanPassCase(@Param("planId") String planId);
} }

View File

@ -342,8 +342,9 @@
</select> </select>
<select id="countCoverage" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countCoverage" resultType="io.metersphere.track.response.TrackCountResult">
SELECT count(test_case.id) AS countNumber, if(test_case.test_id is null,"uncoverage","coverage") AS groupField SELECT count(test_case.id) AS countNumber,
FROM test_case WHERE test_case.project_id=#{projectId} GROUP BY groupField if(test_case.test_id is null,"uncoverage","coverage") AS groupField
FROM test_case WHERE test_case.project_id=#{projectId} and test_case.type != 'functional' GROUP BY groupField
</select> </select>
<select id="countFuncMaintainer" resultType="io.metersphere.track.response.TrackCountResult"> <select id="countFuncMaintainer" resultType="io.metersphere.track.response.TrackCountResult">
select count(tc.id) as countNumber, user.name as groupField from test_case tc right join user on tc.maintainer = user.id select count(tc.id) as countNumber, user.name as groupField from test_case tc right join user on tc.maintainer = user.id
@ -355,6 +356,50 @@
where tc.project_id = #{projectId} and tc.test_id is not null where tc.project_id = #{projectId} and tc.test_id is not null
group by tc.maintainer group by tc.maintainer
</select> </select>
<select id="getTestPlanBug" resultType="int">
select count(tci.issues_id) from test_plan_test_case tptc join test_case_issues tci on tptc.case_id = tci.test_case_id
where tptc.plan_id = #{planId};
</select>
<select id="getTestPlanCase" resultType="int">
select count(s)
from (
select id as s
from test_plan_test_case tptc
where tptc.plan_id = #{planId}
union all
select id as s
from test_plan_api_scenario tpas
where tpas.test_plan_id = #{planId}
union all
select id as s
from test_plan_api_case tpac
where tpac.test_plan_id = #{planId}
union all
select id as s
from test_plan_load_case tplc
where tplc.test_plan_id = #{planId}
) as temp
</select>
<select id="getTestPlanPassCase" resultType="int">
select count(s)
from (
select id as s
from test_plan_test_case tptc
where tptc.plan_id = #{planId} and tptc.status = 'Pass'
union all
select id as s
from test_plan_api_scenario tpas
where tpas.test_plan_id = #{planId} and tpas.last_result = 'Success'
union all
select id as s
from test_plan_api_case tpac
where tpac.test_plan_id = #{planId} and tpac.status = 'success'
union all
select id as s
from test_plan_load_case tplc
where tplc.test_plan_id = #{planId} and tplc.status = 'success'
) as temp
</select>
</mapper> </mapper>

View File

@ -87,7 +87,7 @@ public class TrackController {
} }
@GetMapping("/bug/count/{projectId}") @GetMapping("/bug/count/{projectId}")
public BugStatustics getBugStatustics(@PathVariable String projectId) { public BugStatustics getBugStatistics(@PathVariable String projectId) {
return trackService.getBugStatustics(projectId); return trackService.getBugStatistics(projectId);
} }
} }

View File

@ -8,7 +8,7 @@ import lombok.Setter;
public class TestPlanBugCount { public class TestPlanBugCount {
private int index; private int index;
private String planName; private String planName;
private long creatTime; private long createTime;
private String status; private String status;
private int caseSize; private int caseSize;
private int bugSize; private int bugSize;

View File

@ -144,20 +144,22 @@ public class TrackStatisticsDTO {
public void countRelevance(List<TrackCountResult> relevanceResults) { public void countRelevance(List<TrackCountResult> relevanceResults) {
for (TrackCountResult countResult : relevanceResults) { for (TrackCountResult countResult : relevanceResults) {
switch (countResult.getGroupField().toUpperCase()){ switch (countResult.getGroupField()){
case TrackCount.API: case TrackCount.API:
this.apiCaseCount += countResult.getCountNumber(); this.apiCaseCount += countResult.getCountNumber();
this.allRelevanceCaseCount += countResult.getCountNumber();
break; break;
case TrackCount.PERFORMANCE: case TrackCount.PERFORMANCE:
this.performanceCaseCount += countResult.getCountNumber(); this.performanceCaseCount += countResult.getCountNumber();
this.allRelevanceCaseCount += countResult.getCountNumber();
break; break;
case TrackCount.AUTOMATION: case TrackCount.AUTOMATION:
this.scenarioCaseCount += countResult.getCountNumber(); this.scenarioCaseCount += countResult.getCountNumber();
this.allRelevanceCaseCount += countResult.getCountNumber();
break; break;
default: default:
break; break;
} }
this.allRelevanceCaseCount += countResult.getCountNumber();
} }
} }

View File

@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
@ -110,59 +111,58 @@ public class TrackService {
return charts; return charts;
} }
public BugStatustics getBugStatustics(String projectId) { public BugStatustics getBugStatistics(String projectId) {
TestPlanExample example = new TestPlanExample(); TestPlanExample example = new TestPlanExample();
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
List<TestPlan> plans = testPlanMapper.selectByExample(example); List<TestPlan> plans = testPlanMapper.selectByExample(example);
List<TestPlanBugCount> list = new ArrayList<>(); List<TestPlanBugCount> list = new ArrayList<>();
BugStatustics bugStatustics = new BugStatustics(); BugStatustics bugStatustics = new BugStatustics();
int index = 1; int index = 1;
int totalBugSize = 0;
int totalCaseSize = 0;
for (TestPlan plan : plans) { for (TestPlan plan : plans) {
TestPlanBugCount testPlanBug = new TestPlanBugCount(); TestPlanBugCount testPlanBug = new TestPlanBugCount();
testPlanBug.setIndex(index++); testPlanBug.setIndex(index++);
testPlanBug.setPlanName(plan.getName()); testPlanBug.setPlanName(plan.getName());
testPlanBug.setCreatTime(plan.getCreateTime()); testPlanBug.setCreateTime(plan.getCreateTime());
testPlanBug.setStatus(plan.getStatus()); testPlanBug.setStatus(plan.getStatus());
testPlanBug.setCaseSize(getPlanCaseSize(plan.getId()));
testPlanBug.setBugSize(getPlanBugSize(plan.getId())); int planCaseSize = getPlanCaseSize(plan.getId());
testPlanBug.setPassRage(getPlanPassRage(plan.getId())); testPlanBug.setCaseSize(planCaseSize);
int planBugSize = getPlanBugSize(plan.getId());
testPlanBug.setBugSize(planBugSize);
testPlanBug.setPassRage(getPlanPassRage(plan.getId(), planCaseSize));
list.add(testPlanBug); list.add(testPlanBug);
totalBugSize += planBugSize;
totalCaseSize += planCaseSize;
} }
// todo
bugStatustics.setList(list); bugStatustics.setList(list);
bugStatustics.setRage("1"); float rage =totalCaseSize == 0 ? 0 : (float) totalBugSize * 100 / totalCaseSize;
bugStatustics.setBugTotalSize(2); DecimalFormat df = new DecimalFormat("0.0");
bugStatustics.setRage(df.format(rage) + "%");
bugStatustics.setBugTotalSize(totalBugSize);
return bugStatustics; return bugStatustics;
} }
private int getPlanCaseSize(String planId) { private int getPlanCaseSize(String planId) {
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); return extTestCaseMapper.getTestPlanCase(planId);
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(planId);
List<TestPlanTestCase> testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample);
TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample();
testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample);
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
example.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanLoadCase> testPlanLoadCases = testPlanLoadCaseMapper.selectByExample(example);
TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample();
testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(testPlanApiScenarioExample);
return testPlanTestCases.size() + testPlanApiCases.size() + testPlanLoadCases.size() + testPlanApiScenarios.size();
} }
private int getPlanBugSize(String planId) { private int getPlanBugSize(String planId) {
return 1; return extTestCaseMapper.getTestPlanBug(planId);
} }
private String getPlanPassRage(String planId) { private String getPlanPassRage(String planId, int totalSize) {
return "10%"; if (totalSize == 0) {
return "-";
}
int passSize = extTestCaseMapper.getTestPlanPassCase(planId);
float rage = (float) passSize * 100 / totalSize;
DecimalFormat df = new DecimalFormat("0.0");
return df.format(rage) + "%";
} }
} }

View File

@ -15,18 +15,19 @@
{{ $t('api_test.home_page.unit_of_measurement') }} {{ $t('api_test.home_page.unit_of_measurement') }}
</span> </span>
<div> <div>
占比: 占比
<el-link type="info" @click="redirectPage('thisWeekCount')" target="_blank" style="color: #000000">{{ rage }} <span class="rage">
</el-link> {{rage}}
</span>
</div> </div>
</div> </div>
</el-aside> </el-aside>
<el-table border :data="tableData" class="adjust-table table-content" height="300"> <el-table border :data="tableData" class="adjust-table table-content" height="300">
<el-table-column prop="index" label="序号" <el-table-column prop="index" label="序号"
width="100" show-overflow-tooltip/> width="60" show-overflow-tooltip/>
<el-table-column prop="planName" label="测试计划名称" <el-table-column prop="planName" label="测试计划名称"
width="130" show-overflow-tooltip/> width="130" show-overflow-tooltip/>
<el-table-column prop="createTime" :label="$t('commons.create_time')" width="130"> <el-table-column prop="createTime" :label="$t('commons.create_time')" width="180" show-overflow-tooltip>
<template v-slot:default="scope"> <template v-slot:default="scope">
<span>{{ scope.row.createTime | timestampFormatDate }}</span> <span>{{ scope.row.createTime | timestampFormatDate }}</span>
</template> </template>
@ -35,6 +36,7 @@
prop="status" prop="status"
column-key="status" column-key="status"
:label="$t('test_track.plan.plan_status')" :label="$t('test_track.plan.plan_status')"
width="100"
show-overflow-tooltip> show-overflow-tooltip>
<template v-slot:default="scope"> <template v-slot:default="scope">
<span @click.stop="clickt = 'stop'"> <span @click.stop="clickt = 'stop'">
@ -106,6 +108,12 @@ export default {
color: var(--count_number); color: var(--count_number);
} }
.rage {
font-family: 'ArialMT', 'Arial', sans-serif;
font-size: 18px;
color: var(--count_number);
}
.main-number-show { .main-number-show {
width: 100px; width: 100px;
height: 100px; height: 100px;