Merge remote-tracking branch 'origin/master'

This commit is contained in:
liangdaliang
2025-07-01 16:37:12 +08:00
15 changed files with 397 additions and 37 deletions

View File

@@ -5,6 +5,7 @@ import com.test.common.core.controller.BaseController;
import com.test.common.core.domain.AjaxResult;
import com.test.common.core.page.TableDataInfo;
import com.test.common.enums.BusinessType;
import com.test.test.domain.TestReport;
import com.test.test.domain.qo.IDQO;
import com.test.test.domain.qo.TestReportAddQO;
import com.test.test.domain.vo.TestReportVo;
@@ -53,4 +54,36 @@ public class TestReportController extends BaseController {
public AjaxResult addTestReport(@RequestBody TestReportAddQO testReportAddQO) {
return toAjax(testReportService.addTestReport(testReportAddQO));
}
/**
* 查询测试计划关联测试报告详情
*/
@PostMapping("/caseExecuteDetail")
public AjaxResult caseExecuteDetail(@RequestBody IDQO id) {
return success(testReportService.selectCaseTestReportById(id.getId()));
}
/**
* 删除测试报告
* @param id
* @return
*/
@Log(title = "测试报告", businessType = BusinessType.DELETE)
@PostMapping("/delExecuteCaseReport")
public AjaxResult delExecuteCaseReport(@RequestBody IDQO id) {
TestReport testReport = testReportService.selectCaseTestReportById(id.getId());
testReport.setDelFlag("1");
return toAjax(testReportService.updateExecuteCaseReport(testReport));
}
/**
* 修改测试计划关联测试报告
* @param testReport
*/
@Log(title = "测试报告", businessType = BusinessType.UPDATE)
@PostMapping("/updateExecuteCaseReport")
public AjaxResult updateExecuteCaseReport(@RequestBody TestReport testReport) {
return toAjax(testReportService.updateExecuteCaseReport(testReport));
}
}

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

@@ -9,6 +9,9 @@ public class TestReportVo extends BaseEntity {
private static final long serialVersionUID = -4331077290310280474L;
/** 测试报告id */
private Long id;
/**
* 测试报告名称
*/
@@ -17,6 +20,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

@@ -20,4 +20,18 @@ public interface TestReportMapper {
* @return
*/
int addTestReport(TestReport testReport);
/**
* 查询用例执行测试报告详情
* @param id
* @return
*/
TestReport selectCaseTestReportById(Long id);
/**
* 修改用例执行测试报告
* @param testReport
* @return
*/
int updateExecuteCaseReport(TestReport testReport);
}

View File

@@ -23,4 +23,18 @@ public interface ITestReportService {
* @return
*/
public int addTestReport(TestReportAddQO testReportAddQO);
/**
* 更新执行用例测试报告
* @param testReport
* @return
*/
public int updateExecuteCaseReport(TestReport testReport);
/**
* 查询测试报告详情
* @param id
* @return
*/
public TestReport selectCaseTestReportById(Long id);
}

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,17 @@
package com.test.test.service.impl;
import com.alibaba.fastjson2.JSONObject;
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 +35,12 @@ public class TestReportServiceImpl implements ITestReportService {
@Resource
private TestPlanReportMapper testPlanReportMapper;
@Resource
private TestCaseLogMapper testCaseLogMapper;
@Resource
private TestCaseResultMapper testCaseResultMapper;
/**
* 查询测试报告列表
* @param planId
@@ -46,11 +58,33 @@ 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();
if (count == passNum) {
testReportAddQO.setResult("1");
}
TestCaseReportVO testCaseReportVO = new TestCaseReportVO();
testCaseReportVO.setName(testReportAddQO.getName());
testCaseReportVO.setResult("0");
testCaseReportVO.setCaseNum(count);
testCaseReportVO.setPassNum(passNum);
String reportJson = JSONObject.toJSONString(testCaseReportVO);
TestReport testReport = new TestReport();
if (count == passNum) {
testReport.setResult("1");
}
BeanUtils.copyProperties(testReportAddQO,testReport);
testReport.setSerialNumber(generateSerialNumber());
testReport.setResult("0");
testReport.setStatus("0");
testReport.setReport(reportJson);
testReport.setCreateTime(DateUtils.getNowDate());
testReport.setDelFlag("0");
testReport.setUpdateBy(SecurityUtils.getUsername());
@@ -61,6 +95,27 @@ public class TestReportServiceImpl implements ITestReportService {
return testPlanReportMapper.insertTestPlanReport(testReportAddQO);
}
/**
* 更新执行用例报告
* @param testReport
* @return
*/
@Override
public int updateExecuteCaseReport(TestReport testReport) {
testReport.setUpdateTime(DateUtils.getNowDate());
return testReportMapper.updateExecuteCaseReport(testReport);
}
/**
* 根据id查询报告
* @param id
* @return
*/
@Override
public TestReport selectCaseTestReportById(Long id) {
return testReportMapper.selectCaseTestReportById(id);
}
/**
* 生成随机序列号
* @return

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

@@ -149,19 +149,23 @@
(SELECT COUNT(1) FROM test_plan_case tpc
WHERE tpc.plan_id = tp.id
AND tpc.del_flag = '0'
AND tpc.type = '1') AS functionTestPassNum,
AND tpc.type = '1'
AND tpc.execute_result = '1') AS functionTestPassNum,
(SELECT COUNT(1) FROM test_plan_case tpc
WHERE tpc.plan_id = tp.id
AND tpc.del_flag = '0'
AND tpc.type = '2') AS regressionTestPassNum,
AND tpc.type = '2'
AND tpc.execute_result = '1') AS regressionTestPassNum,
(SELECT COUNT(1) FROM test_plan_case tpc
WHERE tpc.plan_id = tp.id
AND tpc.del_flag = '0'
AND tpc.type = '3') AS preProductionTestPassNum,
AND tpc.type = '3'
AND tpc.execute_result = '1') AS preProductionTestPassNum,
(SELECT COUNT(1) FROM test_plan_case tpc
WHERE tpc.plan_id = tp.id
AND tpc.del_flag = '0'
AND tpc.type = '4') AS productionTestPassNum,
AND tpc.type = '4'
AND tpc.execute_result = '1') AS productionTestPassNum,
tp.version,
(
SELECT COUNT(1) FROM test_plan_defect tpd

View File

@@ -31,18 +31,72 @@
</trim>
</insert>
<resultMap type="TestReport" id="TestReportResult">
<result property="id" column="id"/>
<result property="serialNumber" column="serial_number"/>
<result property="name" column="name"/>
<result property="result" column="result"/>
<result property="status" column="status"/>
<result property="report" column="report"/>
<result property="updateBy" column="update_by"/>
<result property="createTime" column="create_time"/>
<result property="updateTime" column="update_time"/>
<result property="version" column="version"/>
<result property="delFlag" column="del_flag"/>
</resultMap>
<sql id="selectTestReportVo">
SELECT id,
serial_number,
name,
result,
status,
report,
update_by,
create_time,
update_time,
version,
del_flag
FROM test_report
</sql>
<select id="selectTestReportList" parameterType="Long" resultType="TestReportVo">
SELECT
tr.name AS name,
tr.result AS result,
tr.status AS status,
tpr.type AS type,
tr.create_time AS createTime,
tr.update_by AS updateBy
SELECT tr.id AS id,
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,
tr.update_by AS updateBy,
tr.update_time AS updateTime
FROM test_plan_report tpr
LEFT JOIN test_report tr ON tr.id = tpr.report_id
LEFT JOIN test_report tr ON tr.id = tpr.report_id
WHERE tpr.plan_id = #{planId}
AND tpr.del_flag = '0'
AND tr.del_flag = '0'
ORDER BY tr.create_time DESC
</select>
<select id="selectCaseTestReportById" parameterType="Long" resultMap="TestReportResult">
<include refid="selectTestReportVo"/>
where id = #{id}
</select>
<update id="updateExecuteCaseReport" parameterType="testReport">
update test_report
<trim prefix="SET" suffixOverrides=",">
<if test="serialNumber != null">serial_number = #{serialNumber},</if>
<if test="name != null">name = #{name},</if>
<if test="result != null">result = #{result},</if>
<if test="status != null">status = #{status},</if>
<if test="report != null">report = #{report},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
<if test="createTime != null">create_time = #{createTime},</if>
<if test="updateTime != null">update_time = #{updateTime},</if>
<if test="version != null">version = #{version},</if>
<if test="delFlag != null">del_flag = #{delFlag},</if>
</trim>
where id = #{id}
</update>
</mapper>