diff --git a/test-test/src/main/java/com/test/test/controller/TestReportController.java b/test-test/src/main/java/com/test/test/controller/TestReportController.java index d787408..e05599e 100644 --- a/test-test/src/main/java/com/test/test/controller/TestReportController.java +++ b/test-test/src/main/java/com/test/test/controller/TestReportController.java @@ -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)); + } + } 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..2c255c1 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 @@ -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; 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/mapper/TestReportMapper.java b/test-test/src/main/java/com/test/test/mapper/TestReportMapper.java index a1bbaed..8aa297f 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestReportMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestReportMapper.java @@ -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); } 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..a142344 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 @@ -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); } 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 b561a59..0caf83f 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..4902ed5 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,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 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 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/TestPlanMapper.xml b/test-test/src/main/resources/mapper/test/TestPlanMapper.xml index ba252cf..c4425b9 100644 --- a/test-test/src/main/resources/mapper/test/TestPlanMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestPlanMapper.xml @@ -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 diff --git a/test-test/src/main/resources/mapper/test/TestReportMapper.xml b/test-test/src/main/resources/mapper/test/TestReportMapper.xml index af09c4c..2a841e5 100644 --- a/test-test/src/main/resources/mapper/test/TestReportMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestReportMapper.xml @@ -31,18 +31,72 @@ + + + + + + + + + + + + + + + + SELECT id, + serial_number, + name, + result, + status, + report, + update_by, + create_time, + update_time, + version, + del_flag + FROM test_report + + + + + + + update test_report + + serial_number = #{serialNumber}, + name = #{name}, + result = #{result}, + status = #{status}, + report = #{report}, + update_by = #{updateBy}, + create_time = #{createTime}, + update_time = #{updateTime}, + version = #{version}, + del_flag = #{delFlag}, + + where id = #{id} + \ No newline at end of file diff --git a/test-ui/src/api/test/testPlan.js b/test-ui/src/api/test/testPlan.js index a1272b6..c885184 100644 --- a/test-ui/src/api/test/testPlan.js +++ b/test-ui/src/api/test/testPlan.js @@ -9,6 +9,8 @@ const api = { testPlanProjectList: '/test/testPlanProject/list', addTestReport: 'test/testReport/addTestReport', getTestReportList: 'test/testReport/reportList', + delExecuteCaseReport: 'test/testReport/delExecuteCaseReport', + updateExecuteCaseReport: 'test/testReport/updateExecuteCaseReport', getPlanOverview:'test/testPlan/planOverview', getPlanCaseTrendData: 'test/testPlan/planCaseTrendData', } @@ -77,6 +79,22 @@ export function getTestReportList(data) { }) } +export function delExecuteCaseReport(id) { + return request({ + url: api.delExecuteCaseReport, + method: 'post', + data: {id} + }) +} + +export function updateExecuteCaseReport(data) { + return request({ + url: api.updateExecuteCaseReport, + method: 'post', + data: data + }) +} + export function getPlanOverview(id) { return request({ url: api.getPlanOverview, diff --git a/test-ui/src/views/test/testplan/caseReport/caseReport.vue b/test-ui/src/views/test/testplan/caseReport/caseReport.vue index 29e53e5..2f50e77 100644 --- a/test-ui/src/views/test/testplan/caseReport/caseReport.vue +++ b/test-ui/src/views/test/testplan/caseReport/caseReport.vue @@ -35,6 +35,11 @@ + + + @@ -230,7 +301,12 @@ export default { .report-container { height: 300px; margin-bottom: 20px; - background: linear-gradient(90deg, #6fcdac, #9ed2bb); + &.status-not-passed { + background: linear-gradient(180deg, #e7998b, #e8b1b0); + } + &.status-passed { + background: linear-gradient(180deg, #6fcdac, #9ed2bb); + } .report-header { color: white; @@ -268,13 +344,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; + //} } } }