diff --git a/test-test/src/main/java/com/test/test/controller/TestCaseResultController.java b/test-test/src/main/java/com/test/test/controller/TestCaseResultController.java new file mode 100644 index 0000000..382a73c --- /dev/null +++ b/test-test/src/main/java/com/test/test/controller/TestCaseResultController.java @@ -0,0 +1,31 @@ +package com.test.test.controller; + +import com.test.common.core.controller.BaseController; +import com.test.common.core.domain.AjaxResult; +import com.test.test.domain.qo.IDQO; +import com.test.test.service.ITestCaseResultService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.*; + +/** + * 用例步骤执行报告Controller + * + * @author liangdl + * @date 2025-03-14 + */ +@RestController +@RequestMapping("/test/testCaseStepResult") +public class TestCaseResultController extends BaseController +{ + @Autowired + private ITestCaseResultService testCaseResultService; + + /** + * 获取用例步骤执行报告详细信息 + */ + @PostMapping(value = "/detail") + public AjaxResult getInfo(@RequestBody IDQO qo) + { + return success(testCaseResultService.selectTestCaseResultById(qo.getId())); + } +} diff --git a/test-test/src/main/java/com/test/test/domain/TestCaseResult.java b/test-test/src/main/java/com/test/test/domain/TestCaseResult.java index c6a4ddd..c62f758 100644 --- a/test-test/src/main/java/com/test/test/domain/TestCaseResult.java +++ b/test-test/src/main/java/com/test/test/domain/TestCaseResult.java @@ -79,4 +79,6 @@ public class TestCaseResult extends BaseEntity { /** 执行结果 */ @Excel(name = "执行结果") private String status; + + private String title; } diff --git a/test-test/src/main/java/com/test/test/domain/TestCaseStep.java b/test-test/src/main/java/com/test/test/domain/TestCaseStep.java index 0b9607a..fc457b0 100644 --- a/test-test/src/main/java/com/test/test/domain/TestCaseStep.java +++ b/test-test/src/main/java/com/test/test/domain/TestCaseStep.java @@ -137,4 +137,7 @@ public class TestCaseStep extends BaseEntity { /** 循环或轮询的子步骤列表 */ private List childrenList; + + /** 执行结果历史列表 */ + private List testCaseResultList; } diff --git a/test-test/src/main/java/com/test/test/mapper/TestCaseResultMapper.java b/test-test/src/main/java/com/test/test/mapper/TestCaseResultMapper.java index bb9b840..9d7da0f 100644 --- a/test-test/src/main/java/com/test/test/mapper/TestCaseResultMapper.java +++ b/test-test/src/main/java/com/test/test/mapper/TestCaseResultMapper.java @@ -28,6 +28,14 @@ public interface TestCaseResultMapper */ public List selectTestCaseResultList(TestCaseResult testCaseResult); + /** + * 查询用例执行报告最小化列表 + * + * @param testCaseResult 用例执行报告 + * @return 用例执行报告集合 + */ + public List selectMinTestCaseResultList(TestCaseResult testCaseResult); + /** * 新增用例执行报告 * diff --git a/test-test/src/main/java/com/test/test/service/ITestCaseResultService.java b/test-test/src/main/java/com/test/test/service/ITestCaseResultService.java index 59e7fff..9cb03fa 100644 --- a/test-test/src/main/java/com/test/test/service/ITestCaseResultService.java +++ b/test-test/src/main/java/com/test/test/service/ITestCaseResultService.java @@ -28,6 +28,14 @@ public interface ITestCaseResultService */ public List selectTestCaseResultList(TestCaseResult testCaseResult); + /** + * 查询用例执行报告最小化列表 + * + * @param testCaseResult 用例执行报告 + * @return 用例执行报告集合 + */ + public List selectMinTestCaseResultList(TestCaseResult testCaseResult); + /** * 新增用例执行报告 * diff --git a/test-test/src/main/java/com/test/test/service/impl/TestCaseResultServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestCaseResultServiceImpl.java index 9ccf867..afb0343 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestCaseResultServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestCaseResultServiceImpl.java @@ -46,6 +46,18 @@ public class TestCaseResultServiceImpl implements ITestCaseResultService return testCaseResultMapper.selectTestCaseResultList(testCaseResult); } + /** + * 查询用例执行报告最小化列表 + * + * @param testCaseResult 用例执行报告 + * @return 用例执行报告 + */ + @Override + public List selectMinTestCaseResultList(TestCaseResult testCaseResult) + { + return testCaseResultMapper.selectMinTestCaseResultList(testCaseResult); + } + /** * 新增用例执行报告 * diff --git a/test-test/src/main/java/com/test/test/service/impl/TestCaseStepServiceImpl.java b/test-test/src/main/java/com/test/test/service/impl/TestCaseStepServiceImpl.java index 97c53a3..30f3aca 100644 --- a/test-test/src/main/java/com/test/test/service/impl/TestCaseStepServiceImpl.java +++ b/test-test/src/main/java/com/test/test/service/impl/TestCaseStepServiceImpl.java @@ -3,14 +3,17 @@ package com.test.test.service.impl; import com.test.common.core.domain.model.JmeterRequest; import com.test.common.utils.DateUtils; import com.test.common.utils.JMeterUtil; +import com.test.test.domain.TestCaseResult; import com.test.test.domain.TestCaseStep; import com.test.test.domain.qo.TestCaseStepAddQO; import com.test.test.mapper.TestCaseStepMapper; +import com.test.test.service.ITestCaseResultService; import com.test.test.service.ITestCaseStepService; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.util.List; import java.util.Map; @@ -27,6 +30,9 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService { @Resource private TestCaseStepMapper testCaseStepMapper; + @Resource + private ITestCaseResultService iTestCaseResultService; + /** * 查询用例步骤 * @@ -49,18 +55,57 @@ public class TestCaseStepServiceImpl implements ITestCaseStepService { testCaseStep.setDelFlag("0"); List caseStepParentList = testCaseStepMapper.selectTestCaseStepList(testCaseStep); for (TestCaseStep testCaseStepParent : caseStepParentList) { + TestCaseResult testCaseResultQuery = new TestCaseResult(); + testCaseResultQuery.setCaseId(testCaseStepParent.getCaseId()); + testCaseResultQuery.setStepId(testCaseStepParent.getId()); + List testCaseResultList = iTestCaseResultService.selectMinTestCaseResultList(testCaseResultQuery); + if (!CollectionUtils.isEmpty(testCaseResultList)) { + int i = 1; + for (TestCaseResult testCaseResult : testCaseResultList) { + String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, testCaseResult.getExecuteTime()); + testCaseResult.setTitle("结果" + i + "(" + dateStr + "),状态:" + testCaseResult.getStatus()); + i ++; + } + } + testCaseStepParent.setTestCaseResultList(testCaseResultList); if (testCaseStepParent.getType() > 2) { // 加载子步骤 TestCaseStep testCaseStepChild = new TestCaseStep(); testCaseStepChild.setDelFlag("0"); testCaseStepChild.setParentId(testCaseStepParent.getId()); List caseStepChildrenList = testCaseStepMapper.selectTestCaseStepList(testCaseStepChild); - testCaseStepParent.setChildrenList(caseStepChildrenList); + this.dealChildrenList(testCaseStepParent, caseStepChildrenList); } } return caseStepParentList; } + /** + * 处理子步骤节点结果记录 + * @param testCaseStepParent + * @param caseStepChildrenList + */ + private void dealChildrenList(TestCaseStep testCaseStepParent, List caseStepChildrenList) { + if (!CollectionUtils.isEmpty(caseStepChildrenList)) { + TestCaseResult testCaseResultQuery = new TestCaseResult(); + for (TestCaseStep testCaseStepChild1 : caseStepChildrenList) { + testCaseResultQuery.setCaseId(testCaseStepChild1.getCaseId()); + testCaseResultQuery.setStepId(testCaseStepChild1.getId()); + List testCaseResultList = iTestCaseResultService.selectMinTestCaseResultList(testCaseResultQuery); + if (!CollectionUtils.isEmpty(testCaseResultList)) { + int i = 1; + for (TestCaseResult testCaseResult : testCaseResultList) { + String dateStr = DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, testCaseResult.getExecuteTime()); + testCaseResult.setTitle("结果" + i + "(" + dateStr + "),状态:" + testCaseResult.getStatus()); + i ++; + } + } + testCaseStepChild1.setTestCaseResultList(testCaseResultList); + } + testCaseStepParent.setChildrenList(caseStepChildrenList); + } + } + /** * 新增用例步骤 * diff --git a/test-test/src/main/resources/mapper/test/TestCaseResultMapper.xml b/test-test/src/main/resources/mapper/test/TestCaseResultMapper.xml index 2c8b30a..bc237b9 100644 --- a/test-test/src/main/resources/mapper/test/TestCaseResultMapper.xml +++ b/test-test/src/main/resources/mapper/test/TestCaseResultMapper.xml @@ -26,6 +26,10 @@ select id, case_id, step_id, request_header, request_body, response_header, response_body, sql_result, polling_count, loop_count, assignment, assertion, use_time, execute_time, status from test_case_result + + select id, case_id, step_id, polling_count, loop_count, use_time, execute_time, status from test_case_result + + + +