From ef741fcb64d23e0482aeefe3ec9a8a6b68bd539b Mon Sep 17 00:00:00 2001 From: pfl <14579250+shadowman1@user.noreply.gitee.com> Date: Wed, 25 Jun 2025 13:50:21 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E6=B5=8B=E8=AF=95=E8=AE=A1=E5=88=92?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=8A=A5=E5=91=8A=E5=8F=8A=E6=8A=A5=E5=91=8A?= =?UTF-8?q?=E8=AF=A6=E6=83=85=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/test/test/domain/TestCaseLog.java | 8 +++ .../test/test/domain/vo/TestCaseReportVO.java | 18 ++++++ .../com/test/test/domain/vo/TestReportVo.java | 3 + .../test/test/mapper/TestCaseLogMapper.java | 9 +++ .../test/test/service/ITestReportService.java | 1 + .../service/impl/TestCaseServiceImpl.java | 2 + .../service/impl/TestReportServiceImpl.java | 31 +++++++++- .../mapper/test/TestCaseLogMapper.xml | 13 ++++ .../mapper/test/TestReportMapper.xml | 1 + .../test/testplan/caseReport/caseReport.vue | 1 + .../testplan/caseReport/platformReport.vue | 59 ++++++++++++++++--- 11 files changed, 138 insertions(+), 8 deletions(-) create mode 100644 test-test/src/main/java/com/test/test/domain/vo/TestCaseReportVO.java diff --git a/test-test/src/main/java/com/test/test/domain/TestCaseLog.java b/test-test/src/main/java/com/test/test/domain/TestCaseLog.java index 2a3c7d9..3306876 100644 --- a/test-test/src/main/java/com/test/test/domain/TestCaseLog.java +++ b/test-test/src/main/java/com/test/test/domain/TestCaseLog.java @@ -29,6 +29,14 @@ public class TestCaseLog extends BaseEntity @Excel(name = "用例id") private Long caseId; + /** 测试计划id */ + @Excel(name = "测试计划id") + private Long planId; + + /** 测试计划关联用例类型 */ + @Excel(name = "测试计划关联用例类型") + private Integer type; + /** 操作类别 */ @Excel(name = "操作类别") private String operType; diff --git a/test-test/src/main/java/com/test/test/domain/vo/TestCaseReportVO.java b/test-test/src/main/java/com/test/test/domain/vo/TestCaseReportVO.java new file mode 100644 index 0000000..c7b9cb7 --- /dev/null +++ b/test-test/src/main/java/com/test/test/domain/vo/TestCaseReportVO.java @@ -0,0 +1,18 @@ +package com.test.test.domain.vo; + +import java.io.Serializable; +import lombok.Data; + +@Data +public class TestCaseReportVO implements Serializable { + + private static final long serialVersionUID = 6972995415807958849L; + + private String name; + + private String result; + + private Integer caseNum; + + private Integer passNum; +} diff --git a/test-test/src/main/java/com/test/test/domain/vo/TestReportVo.java b/test-test/src/main/java/com/test/test/domain/vo/TestReportVo.java index e678393..8933c3d 100644 --- a/test-test/src/main/java/com/test/test/domain/vo/TestReportVo.java +++ b/test-test/src/main/java/com/test/test/domain/vo/TestReportVo.java @@ -17,6 +17,9 @@ public class TestReportVo extends BaseEntity { /** 测试结果(0,未通过,1,通过) */ private String result; + /** 测试报告(jason格式存储)*/ + private String report; + /** 测试用例类型(0,冒烟测试,1,功能测试,2,回归测试,3,准生产测试,4,生产验证) */ private Long type; diff --git a/test-test/src/main/java/com/test/test/mapper/TestCaseLogMapper.java b/test-test/src/main/java/com/test/test/mapper/TestCaseLogMapper.java index 33e7010..3c0bdc9 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestCaseLogMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestCaseLogMapper.java @@ -2,6 +2,7 @@ package com.test.test.mapper; import com.test.test.domain.TestCaseLog; +import com.test.test.domain.qo.TestReportAddQO; import java.util.List; /** @@ -28,6 +29,14 @@ public interface TestCaseLogMapper */ public List selectTestCaseLogList(TestCaseLog testCaseLog); + /** + * 查询用例日志列表 + * + * @param testCaseLog 用例日志 + * @return 用例日志集合 + */ + public String selectTestCaseLogCaseSid(TestReportAddQO testCaseLog); + /** * 新增用例日志 * diff --git a/test-test/src/main/java/com/test/test/service/ITestReportService.java b/test-test/src/main/java/com/test/test/service/ITestReportService.java index 1ce3241..dae99b2 100644 --- a/test-test/src/main/java/com/test/test/service/ITestReportService.java +++ b/test-test/src/main/java/com/test/test/service/ITestReportService.java @@ -1,5 +1,6 @@ package com.test.test.service; +import com.test.common.core.domain.AjaxResult; import com.test.test.domain.TestReport; import com.test.test.domain.qo.TestReportAddQO; import com.test.test.domain.vo.TestReportVo; diff --git a/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java index c631955..31e1788 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestCaseServiceImpl.java @@ -236,6 +236,8 @@ public class TestCaseServiceImpl implements ITestCaseService testCase.setContextResultMap(contextResultMap); TestCaseLog testCaseLog = new TestCaseLog(); testCaseLog.setCaseId(id); + testCaseLog.setPlanId(testPlanCase.getPlanId()); + testCaseLog.setType(testPlanCase.getType()); testCaseLog.setOperTime(DateUtils.getNowDate()); testCaseLog.setOperType("执行"); testCaseLog.setCaseSid(caseSid); diff --git a/test-test/src/main/java/com/test/test/service/impl/TestReportServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestReportServiceImpl.java index d38a016..274c1a1 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestReportServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestReportServiceImpl.java @@ -1,11 +1,18 @@ package com.test.test.service.impl; +import com.alibaba.fastjson2.JSONObject; +import com.test.common.core.domain.AjaxResult; import com.test.common.utils.DateUtils; import com.test.common.utils.SecurityUtils; +import com.test.common.utils.StringUtils; import com.test.common.utils.bean.BeanUtils; +import com.test.test.domain.TestCaseResult; import com.test.test.domain.TestReport; import com.test.test.domain.qo.TestReportAddQO; +import com.test.test.domain.vo.TestCaseReportVO; import com.test.test.domain.vo.TestReportVo; +import com.test.test.mapper.TestCaseLogMapper; +import com.test.test.mapper.TestCaseResultMapper; import com.test.test.mapper.TestPlanReportMapper; import com.test.test.mapper.TestReportMapper; import com.test.test.service.ITestReportService; @@ -29,6 +36,12 @@ public class TestReportServiceImpl implements ITestReportService { @Resource private TestPlanReportMapper testPlanReportMapper; + @Resource + private TestCaseLogMapper testCaseLogMapper; + + @Resource + private TestCaseResultMapper testCaseResultMapper; + /** * 查询测试报告列表 * @param planId @@ -46,11 +59,27 @@ public class TestReportServiceImpl implements ITestReportService { */ @Override public int addTestReport(TestReportAddQO testReportAddQO) { + String caseSid = testCaseLogMapper.selectTestCaseLogCaseSid(testReportAddQO); + if (StringUtils.isEmpty(caseSid)) { + throw new RuntimeException("未执行用例,无法生成报告"); + } + TestCaseResult testCaseResult = new TestCaseResult(); + testCaseResult.setCaseSid(caseSid); + List testCaseResults = testCaseResultMapper.selectTestCaseResultList(testCaseResult); + int count = testCaseResults.size(); + int passNum = (int)testCaseResults.stream().filter(result -> "成功".equals(result.getStatus())).count(); + TestCaseReportVO testCaseReportVO = new TestCaseReportVO(); + testCaseReportVO.setName(testReportAddQO.getName()); + testCaseReportVO.setResult("success"); + testCaseReportVO.setCaseNum(count); + testCaseReportVO.setPassNum(passNum); + String reportJson = JSONObject.toJSONString(testCaseReportVO); TestReport testReport = new TestReport(); BeanUtils.copyProperties(testReportAddQO,testReport); testReport.setSerialNumber(generateSerialNumber()); - testReport.setResult("0"); + testReport.setResult("1"); testReport.setStatus("0"); + testReport.setReport(reportJson); testReport.setCreateTime(DateUtils.getNowDate()); testReport.setDelFlag("0"); testReport.setUpdateBy(SecurityUtils.getUsername()); diff --git a/test-test/src/main/resources/mapper/test/TestCaseLogMapper.xml b/test-test/src/main/resources/mapper/test/TestCaseLogMapper.xml index a0e2e56..c4788b6 100644 --- a/test-test/src/main/resources/mapper/test/TestCaseLogMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestCaseLogMapper.xml @@ -36,10 +36,21 @@ where id = #{id} + + insert into test_case_log case_id, + plan_id, + type, oper_type, oper_detail, oper_user, @@ -48,6 +59,8 @@ #{caseId}, + #{planId}, + #{type}, #{operType}, #{operDetail}, #{operUser}, diff --git a/test-test/src/main/resources/mapper/test/TestReportMapper.xml b/test-test/src/main/resources/mapper/test/TestReportMapper.xml index af09c4c..1d7e89e 100644 --- a/test-test/src/main/resources/mapper/test/TestReportMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestReportMapper.xml @@ -35,6 +35,7 @@ SELECT tr.name AS name, tr.result AS result, + tr.report AS report, tr.status AS status, tpr.type AS type, tr.create_time AS createTime, diff --git a/test-ui/src/views/test/testplan/caseReport/caseReport.vue b/test-ui/src/views/test/testplan/caseReport/caseReport.vue index 29e53e5..a4a487d 100644 --- a/test-ui/src/views/test/testplan/caseReport/caseReport.vue +++ b/test-ui/src/views/test/testplan/caseReport/caseReport.vue @@ -111,6 +111,7 @@ export default { name: row.name, type: row.result, planId: row.planId, + report: row.report } ) }, diff --git a/test-ui/src/views/test/testplan/caseReport/platformReport.vue b/test-ui/src/views/test/testplan/caseReport/platformReport.vue index 8863efc..f84e247 100644 --- a/test-ui/src/views/test/testplan/caseReport/platformReport.vue +++ b/test-ui/src/views/test/testplan/caseReport/platformReport.vue @@ -31,12 +31,14 @@
-
1
+
{{ reportData.caseNum }}
执行用例数
- 100% -
+ {{ passRate }}% +
+
+
用例通过率
@@ -85,6 +87,7 @@ export default { return { reportType: '', reportTitle: '', + reportData: {}, selectedResult: '', // 选择的测试结果 resultOptions: [ // 测试结果选项 { value: 'all', label: '全部' }, @@ -106,7 +109,7 @@ export default { // 用例类型分布数据 caseTypeDistributionData: { series: [ - { value: 1, name: '接口用例' ,itemStyle: {color: '#6fcdac'} } + { value: 0, name: '接口用例' ,itemStyle: {color: '#6fcdac'} } ] } }; @@ -114,6 +117,14 @@ export default { created() { this.reportTitle = this.$route.query.name; this.reportType = this.$route.query.type; + this.reportData = JSON.parse(this.$route.query.report); + + // 更新饼图数据 + this.resultDistributionData.series[0].value = this.reportData.passNum || 0; + this.resultDistributionData.series[1].value = this.reportData.caseNum - this.reportData.passNum || 0; + + // 更新接口用例饼图数据 + this.caseTypeDistributionData.series[0].value = this.reportData.caseNum || 0; }, watch: { 'dict.type.test_type': { @@ -127,11 +138,29 @@ export default { } }, computed: { - + passRate() { + if (this.reportData.caseNum === 0) return 0; + return (this.reportData.passNum / this.reportData.caseNum) * 100; + } }, mounted() { this.initResultDistributionChart(); this.initCaseTypeDistributionChart(); + + + // 强制重绘图表以应用最新数据 + this.$nextTick(() => { + const chartDom = document.getElementById('result-distribution-chart'); + if (chartDom) { + const myChart = echarts.getInstanceByDom(chartDom); + myChart.setOption({ + series: [{ + type: 'pie', + data: this.resultDistributionData.series + }] + }, true); // true 表示合并选项 + } + }); }, methods: { initResultDistributionChart() { @@ -268,13 +297,29 @@ export default { font-size: 14px; } - .progress-bar { + .progress-bar-container { width: 100px; height: 10px; - background-color: white; + background-color: #e0e0e0; /* 背景颜色表示未完成部分 */ + border-radius: 5px; + overflow: hidden; margin-top: 10px; + } + + + .progress-bar { + height: 100%; + background-color: white; /* 进度条颜色 */ border-radius: 5px; } + + //.progress-bar { + // width: 100px; + // height: 10px; + // background-color: white; + // margin-top: 10px; + // border-radius: 5px; + //} } } }