zhaoxingrui 5 éve
szülő
commit
3dcfc4fb33

+ 4 - 4
web/src/main/java/cn/seecoder/web/dao/APITest/APITestMapper.java

@@ -34,14 +34,14 @@ public interface APITestMapper {
     @Options(useGeneratedKeys = true, keyProperty = "param1.id")
     boolean execute(TestResult testResult, String... ignoredCols);
 
-    @Select("select * from test_result where test_id = #{id} and pipeline_record_id = -1")
-    List<TestResult> selectTestResultByTestId(Integer id);
+    @Select("select * from test_result where test_id = #{testId} and pipeline_record_id = #{pipelineRecordId}")
+    List<TestResult> selectTestResultByTestId(@Param("testId") Integer testId,@Param("pipelineRecordId") Integer pipelineRecordId);
 
     @Delete("delete from test_result where test_id = #{id}")
     boolean deleteTestResult(Integer id);
 
-    @Select("select * from test_result where test_id = #{id} and pipeline_record_id = -1 order by id DESC LIMIT 0,1")
-    TestResult selectLatestTestResultById(Integer id);
+    @Select("select * from test_result where test_id = #{testId} and pipeline_record_id = #{pipelineRecordId} order by id DESC LIMIT 0,1")
+    TestResult selectLatestTestResultById(@Param("testId") Integer testId,@Param("pipelineRecordId") Integer pipelineRecordId);
 
     @Select("select * from test_result where pipeline_record_id = #{recordId}")
     List<APITestResultVO> selectByPipelineRecordId(Integer recordId);

+ 25 - 2
web/src/main/java/cn/seecoder/web/service/impl/APITest/APITestServiceImpl.java

@@ -102,7 +102,19 @@ public class APITestServiceImpl implements APITestService {
 
     @Override
     public List<APITestResultVO> getAPITestResultByTestId(Integer testId) {
-        List<TestResult> testResultVOS = apiTestMapper.selectTestResultByTestId(testId);
+
+        TestInfo testInfo = apiTestMapper.selectByTestId(testId);
+
+        //获取最新的部署构建信息id
+        List<Integer> pipelineIds = pipelineMapper.selectByProjectId(testInfo.getProjectId()).stream().map(PipelinePO::getId).collect(Collectors.toList());
+        PipelineRecordPO latestRecord;
+        if (pipelineIds.size() == 0){
+            latestRecord = null;
+        } else {
+            latestRecord = pipelineRecordMapper.selectPipelinesLatestRecord(pipelineIds);
+        }
+        Integer recordId = latestRecord==null? -1:latestRecord.getId();
+        List<TestResult> testResultVOS = apiTestMapper.selectTestResultByTestId(testId, recordId);
         List<APITestResultVO> apiTestResultVOList = new ArrayList<>();
         for (TestResult testResult: testResultVOS) {
             apiTestResultVOList.add(new APITestResultVO(transform1(testResult)));
@@ -112,7 +124,18 @@ public class APITestServiceImpl implements APITestService {
 
     @Override
     public APITestResultVO getLatestTestResultByTestId(Integer testId) {
-        TestResult testResult = apiTestMapper.selectLatestTestResultById(testId);
+        TestInfo testInfo = apiTestMapper.selectByTestId(testId);
+
+        List<Integer> pipelineIds = pipelineMapper.selectByProjectId(testInfo.getProjectId()).stream().map(PipelinePO::getId).collect(Collectors.toList());
+        PipelineRecordPO latestRecord;
+        if (pipelineIds.size() == 0){
+            latestRecord = null;
+        } else {
+            latestRecord = pipelineRecordMapper.selectPipelinesLatestRecord(pipelineIds);
+        }
+
+        TestResult testResult = apiTestMapper.selectLatestTestResultById(testId, latestRecord==null?-1:latestRecord.getId());
+
         if (testResult == null) {
             return null;
         }

+ 1 - 1
web/src/main/java/cn/seecoder/web/service/impl/auto_test/AutoTestServiceImpl.java

@@ -41,7 +41,7 @@ public class AutoTestServiceImpl implements AutoTestService {
         }
         return apiTestMapper.selectByPipelineRecordId(latestRecord.getId()).stream()
                 .map(x->{
-                    APITestResultVO vo = new APITestResultVO();
+                    APITestResultVO vo = new APITestResultVO(null);
                     BeanUtils.copyProperties(x, vo);
                     return vo;
                 })