fix:测试计划新建报告及报告详情显示

This commit is contained in:
pfl
2025-06-25 13:50:21 +08:00
parent ef4d51876f
commit ef741fcb64
11 changed files with 138 additions and 8 deletions

View File

@@ -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;

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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<TestCaseLog> selectTestCaseLogList(TestCaseLog testCaseLog);
/**
* 查询用例日志列表
*
* @param testCaseLog 用例日志
* @return 用例日志集合
*/
public String selectTestCaseLogCaseSid(TestReportAddQO testCaseLog);
/**
* 新增用例日志
*

View File

@@ -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;

View File

@@ -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);

View File

@@ -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<TestCaseResult> 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());

View File

@@ -36,10 +36,21 @@
where id = #{id}
</select>
<select id="selectTestCaseLogCaseSid" resultType="java.lang.String">
SELECT case_sid
FROM test_case_log
WHERE plan_id = #{planId}
AND type = #{type}
ORDER BY id
DESC limit 1
</select>
<insert id="insertTestCaseLog" parameterType="TestCaseLog" useGeneratedKeys="true" keyProperty="id">
insert into test_case_log
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="caseId != null">case_id,</if>
<if test="planId != null">plan_id,</if>
<if test="type != null">type,</if>
<if test="operType != null">oper_type,</if>
<if test="operDetail != null">oper_detail,</if>
<if test="operUser != null">oper_user,</if>
@@ -48,6 +59,8 @@
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="caseId != null">#{caseId},</if>
<if test="planId != null">#{planId},</if>
<if test="type != null">#{type},</if>
<if test="operType != null">#{operType},</if>
<if test="operDetail != null">#{operDetail},</if>
<if test="operUser != null">#{operUser},</if>

View File

@@ -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,