1
0
Просмотр исходного кода

feat: 新增手动完成、关闭功能测试以及对应记录的功能,新增构建信息与功能测试的关联功能,查看功能测试最新部署下的操作功能。统一命名规范, 删除废弃的tree log相关类

370774330@qq.com 5 лет назад
Родитель
Сommit
97d25fc2fa
18 измененных файлов с 383 добавлено и 225 удалено
  1. 4 4
      api/src/main/java/cn/seecoder/api/k8s/model/Deployment.java
  2. 16 7
      web/src/main/java/cn/seecoder/web/controller/pipeline/PipelineController.java
  3. 38 22
      web/src/main/java/cn/seecoder/web/controller/project/FuncTestController.java
  4. 0 49
      web/src/main/java/cn/seecoder/web/dao/pipeline/PipelineHistoryMapper.java
  5. 68 0
      web/src/main/java/cn/seecoder/web/dao/pipeline/PipelineRecordMapper.java
  6. 7 4
      web/src/main/java/cn/seecoder/web/dao/project/FuncTestCaseMapper.java
  7. 4 4
      web/src/main/java/cn/seecoder/web/dao/project/FuncTestStepMapper.java
  8. 30 0
      web/src/main/java/cn/seecoder/web/model/enums/FuncTestOperatorEnum.java
  9. 1 1
      web/src/main/java/cn/seecoder/web/model/po/project/FuncTestCasePO.java
  10. 1 1
      web/src/main/java/cn/seecoder/web/model/po/project/FuncTestStepPO.java
  11. 8 5
      web/src/main/java/cn/seecoder/web/model/vo/pipeline/PipelineRecordVO.java
  12. 26 21
      web/src/main/java/cn/seecoder/web/service/impl/pipeline/PipelineServiceImpl.java
  13. 144 0
      web/src/main/java/cn/seecoder/web/service/impl/project/FuncFuncTestServiceImpl.java
  14. 0 87
      web/src/main/java/cn/seecoder/web/service/impl/project/TestCaseServiceImpl.java
  15. 1 1
      web/src/main/java/cn/seecoder/web/service/impl/tree/TreeNodeServiceImpl.java
  16. 4 2
      web/src/main/java/cn/seecoder/web/service/pipeline/PipelineService.java
  17. 10 6
      web/src/main/java/cn/seecoder/web/service/project/FuncTestService.java
  18. 21 11
      web/src/test/java/cn/seecoder/web/dao/pipeline/PipelineHistoryMapperTest.java

+ 4 - 4
api/src/main/java/cn/seecoder/api/k8s/model/Deployment.java

@@ -57,7 +57,7 @@ public class Deployment extends K8sAbstractObject<V1Deployment> {
      * 保留历史replica set的个数
      */
     @Builder.Default
-    private int revisionHistoryLimit = DEFAULT_REVISION_HISTORY_LIMIT;
+    private int revisionRecordLimit = DEFAULT_REVISION_HISTORY_LIMIT;
 
     @ReadOnlyProperty
     private V1DeploymentStatus status;
@@ -70,7 +70,7 @@ public class Deployment extends K8sAbstractObject<V1Deployment> {
                 .stream().map(V1LocalObjectReference::getName).collect(Collectors.toList());
         this.replicas = v1Deployment.getSpec().getReplicas();
         this.timeout = v1Deployment.getSpec().getProgressDeadlineSeconds();
-        this.revisionHistoryLimit = v1Deployment.getSpec().getRevisionHistoryLimit();
+        this.revisionRecordLimit = v1Deployment.getSpec().getRevisionRecordLimit();
         this.volumes =  v1Deployment.getSpec().getTemplate().getSpec().getVolumes();
         this.nodeSelectors = v1Deployment.getSpec().getTemplate().getSpec().getNodeSelector();
         this.status = v1Deployment.getStatus();
@@ -116,7 +116,7 @@ public class Deployment extends K8sAbstractObject<V1Deployment> {
                 .withProgressDeadlineSeconds(timeout)
                 .withStrategy(new V1DeploymentStrategy().type(DEFAULT_UPDATE_STRATEGY))
 //                .withStrategy(new V1DeploymentStrategy().rollingUpdate(rollingUpdateDeployment))
-                .withRevisionHistoryLimit(revisionHistoryLimit)
+                .withRevisionRecordLimit(revisionRecordLimit)
                 .withSelector(this.toDeploymentV1LabelSelector())
                 .withTemplate(this.toPodSpecTemplate())
                 .build();
@@ -129,7 +129,7 @@ public class Deployment extends K8sAbstractObject<V1Deployment> {
         v1Deployment.getMetadata().setAnnotations(this.getAnnotations());
         v1Deployment.getSpec().setReplicas(this.replicas);
         v1Deployment.getSpec().setProgressDeadlineSeconds(timeout);
-        v1Deployment.getSpec().setRevisionHistoryLimit(revisionHistoryLimit);
+        v1Deployment.getSpec().setRevisionRecordLimit(revisionRecordLimit);
         v1Deployment.getSpec().getTemplate().getSpec().setContainers(containers == null ? null : this.containers.stream().map(Container::toK8sObject).collect(Collectors.toList()));
         v1Deployment.getSpec().getTemplate().getSpec().setVolumes(volumes == null ? null : this.volumes);
         v1Deployment.getSpec().getTemplate().getSpec().setImagePullSecrets(

+ 16 - 7
web/src/main/java/cn/seecoder/web/controller/pipeline/PipelineController.java

@@ -51,24 +51,33 @@ public class PipelineController {
         return Response.buildSuccess(pipelineService.retrievePipelineConfig(projectId, pipelineId));
     }
 
-    @GetMapping("/history/list")
+    @GetMapping("/record/list")
     @ApiOperation(value = "获取指定一条流水线的历史构建信息列表", httpMethod = "GET")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query"),
             @ApiImplicitParam(name = "pipelineId", dataType ="int",paramType = "query")
     })
-    public Response<List<PipelineHistoryVO>> retrievePipelineHistory(@RequestParam("projectId")Integer projectId,
+    public Response<List<PipelineRecordVO>> retrievePipelineRecord(@RequestParam("projectId")Integer projectId,
                                                                      @RequestParam("pipelineId")Integer pipelineId) throws AccessDeniedException {
-        return Response.buildSuccess(pipelineService.retrievePipelineHistory(projectId,pipelineId));
+        return Response.buildSuccess(pipelineService.retrievePipelineRecord(projectId,pipelineId));
     }
 
-    @GetMapping("/history/details")
+    @GetMapping("/record")
+    @ApiOperation(value = "获取一条流水线的历史构建信息", httpMethod = "GET")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "recordId", dataType ="int",paramType = "query"),
+    })
+    public Response<PipelineRecordVO> retrievePipelineRecord(@RequestParam("recordId")Integer recordId) throws AccessDeniedException {
+        return Response.buildSuccess(pipelineService.retrieveRecordById(recordId));
+    }
+
+    @GetMapping("/record/details")
     @ApiOperation(value = "获取指定一条构建信息的日志详情", httpMethod = "GET")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "historyId", dataType ="int",paramType = "query"),
+            @ApiImplicitParam(name = "recordId", dataType ="int",paramType = "query"),
     })
-    public Response<String> retrievePipelineHistoryDetails(@RequestParam("historyId")Integer historyId) {
-        return Response.buildSuccess(pipelineService.retrievePipelineHistoryDetails(historyId));
+    public Response<String> retrievePipelineRecordDetails(@RequestParam("recordId")Integer recordId) {
+        return Response.buildSuccess(pipelineService.retrievePipelineRecordDetails(recordId));
     }
 
 

+ 38 - 22
web/src/main/java/cn/seecoder/web/controller/project/TestCaseController.java → web/src/main/java/cn/seecoder/web/controller/project/FuncTestController.java

@@ -7,9 +7,9 @@ import io.swagger.annotations.ApiOperation;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import cn.seecoder.web.model.vo.Response;
-import cn.seecoder.web.model.vo.project.TestCaseVO;
-import cn.seecoder.web.model.vo.project.TestStepVO;
-import cn.seecoder.web.service.project.TestCaseService;
+import cn.seecoder.web.model.vo.project.FuncTestCaseVO;
+import cn.seecoder.web.model.vo.project.FuncTestStepVO;
+import cn.seecoder.web.service.project.FuncTestService;
 
 import java.util.List;
 
@@ -21,27 +21,27 @@ import java.util.List;
 @Api(tags = "测试用例相关 API")
 @RestController
 @RequestMapping("/test_cases")
-public class TestCaseController {
+public class FuncTestController {
 
-    private final TestCaseService testCaseService;
+    private final FuncTestService funcTestService;
 
     @Autowired
-    public TestCaseController(TestCaseService testCaseService) {
-        this.testCaseService = testCaseService;
+    public FuncTestController(FuncTestService funcTestService) {
+        this.funcTestService = funcTestService;
     }
 
     @ApiOperation(value = "获取项目的测试用例列表", httpMethod = "GET")
     @ApiImplicitParam(name = "projectId",dataType ="int", paramType = "query")
     @GetMapping
-    public Response<List<TestCaseVO>> getTestCases(@RequestParam("projectId") Integer projectId){
-        return Response.buildSuccess(testCaseService.getTestCases(projectId));
+    public Response<List<FuncTestCaseVO>> getTestCases(@RequestParam("projectId") Integer projectId){
+        return Response.buildSuccess(funcTestService.getTestCases(projectId));
     }
 
     @GetMapping("/steps")
     @ApiOperation(value = "获取测试用例的步骤列表", httpMethod = "GET")
     @ApiImplicitParam(name = "testCaseId",dataType ="int", paramType = "query")
-    public Response<List<TestStepVO>> getTestSteps(@RequestParam("testCaseId")Integer testCaseId){
-        return Response.buildSuccess(testCaseService.getTestSteps(testCaseId));
+    public Response<List<FuncTestStepVO>> getTestSteps(@RequestParam("testCaseId")Integer testCaseId){
+        return Response.buildSuccess(funcTestService.getTestSteps(testCaseId));
     }
 
 
@@ -53,7 +53,7 @@ public class TestCaseController {
             @ApiImplicitParam(name = "title",dataType ="string", paramType = "query")
     })
     public Response createTestCase(@RequestParam("projectId") Integer projectId,@RequestParam("title") String title){
-        testCaseService.createTestCase(projectId, title);
+        funcTestService.createTestCase(projectId, title);
         return Response.buildSuccess();
     }
 
@@ -64,18 +64,27 @@ public class TestCaseController {
     })
     @PutMapping
     public Response updateTestCaseTitle(@RequestParam("testCaseId") Integer testCaseId,@RequestParam("title") String title){
-        testCaseService.updateTestCaseTitle(testCaseId, title);
+        funcTestService.updateTestCaseTitle(testCaseId, title);
         return Response.buildSuccess();
     }
 
-    @ApiOperation(value = "更新测试用例测试状态", httpMethod = "PUT")
+    @ApiOperation(value = "完成测试用例测试", httpMethod = "PUT")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "testCaseId",dataType ="int", paramType = "query"),
-            @ApiImplicitParam(name = "pass",dataType ="boolean", paramType = "query")
     })
-    @PutMapping("/pass")
-    public Response updateTestCaseState(@RequestParam("testCaseId") Integer testCaseId,@RequestParam("pass") Boolean pass){
-        testCaseService.updateTestCaseState(testCaseId, pass);
+    @PutMapping("/finish")
+    public Response finish(@RequestParam("testCaseId") Integer testCaseId){
+        funcTestService.finish(testCaseId);
+        return Response.buildSuccess();
+    }
+
+    @ApiOperation(value = "重新开放测试用例测试", httpMethod = "PUT")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "testCaseId",dataType ="int", paramType = "query"),
+    })
+    @PutMapping("/reopen")
+    public Response reopen(@RequestParam("testCaseId") Integer testCaseId){
+        funcTestService.reopen(testCaseId);
         return Response.buildSuccess();
     }
 
@@ -83,7 +92,7 @@ public class TestCaseController {
     @ApiImplicitParam(name = "testCaseId",dataType ="int", paramType = "query")
     @DeleteMapping
     public Response deleteTestCase(@RequestParam("testCaseId") Integer testCaseId){
-        testCaseService.deleteTestCase(testCaseId);
+        funcTestService.deleteTestCase(testCaseId);
         return Response.buildSuccess();
     }
 
@@ -91,7 +100,7 @@ public class TestCaseController {
     @ApiImplicitParam(name = "testCaseId",dataType ="int", paramType = "query")
     @PostMapping("/steps")
     public Response createEmptyTestStep(@RequestParam("testCaseId") Integer testCaseId){
-        testCaseService.createEmptyTestStep(testCaseId);
+        funcTestService.createEmptyTestStep(testCaseId);
         return Response.buildSuccess();
     }
 
@@ -103,7 +112,7 @@ public class TestCaseController {
     })
     @PutMapping("/steps")
     public Response updateTestStepDescription(@RequestParam("testStepId") Integer testStepId, @RequestParam("description") String description){
-        testCaseService.updateTestStepDescription(testStepId, description);
+        funcTestService.updateTestStepDescription(testStepId, description);
         return Response.buildSuccess();
     }
 
@@ -111,7 +120,14 @@ public class TestCaseController {
     @ApiImplicitParam(name = "testStepId",dataType ="int", paramType = "query")
     @DeleteMapping("/steps")
     public Response deleteTestStep(@RequestParam("testStepId") Integer testStepId){
-        testCaseService.deleteTestStep(testStepId);
+        funcTestService.deleteTestStep(testStepId);
         return Response.buildSuccess();
     }
+
+    @ApiOperation(value = "获取当前部署的所有相关测试用例历史记录信息", httpMethod = "GET")
+    @ApiImplicitParam(name = "projectId",dataType ="int", paramType = "query")
+    @GetMapping("/record/latest")
+    public Response getLatestRecord(@RequestParam("projectId") Integer projectId){
+        return Response.buildSuccess(funcTestService.getLatestRecord(projectId));
+    }
 }

+ 0 - 49
web/src/main/java/cn/seecoder/web/dao/pipeline/PipelineHistoryMapper.java

@@ -1,49 +0,0 @@
-package cn.seecoder.web.dao.pipeline;
-
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
-import org.apache.ibatis.annotations.*;
-import org.springframework.stereotype.Repository;
-import cn.seecoder.web.dao.provider.GeneralInsertUpdateSqlProvider;
-
-import java.util.List;
-
-/**
- * @author PuHong Weng
- * @date 2021/3/12
- * @description:
- */
-@Repository
-public interface PipelineHistoryMapper {
-
-    @InsertProvider(type = GeneralInsertUpdateSqlProvider.class, method = "insert")
-    @Options(useGeneratedKeys = true, keyProperty = "param1.id", keyColumn = "id")
-    void insert(PipelineHistoryPO pipelineHistoryPO, String... ignoredCols);
-
-    @UpdateProvider(type = GeneralInsertUpdateSqlProvider.class, method = "updateById")
-    int update(PipelineHistoryPO pipelineHistoryPO);
-
-
-    @Select("select id, pipeline_id, start_time, user_id, result from pipeline_history where pipeline_id = #{pipelineId}")
-    List<PipelineHistoryPO> selectByPipelineId(Integer pipelineId);
-
-    @Select("select details from pipeline_history where id = #{id}")
-    String selectDetailsById(Integer id);
-
-    /**
-     * 获取一个项目里所有流水线配置的最新构建历史
-     */
-    @Select("<script>" +
-            "SELECT * " +
-            " FROM   pipeline_history, " +
-            "(  SELECT pipeline_id, MAX(start_time) start_time" +
-            "   FROM pipeline_history " +
-            "   WHERE pipeline_id in " +
-            "   <foreach collection='pipelineIds' open='(' item='pipelineId' separator=',' close=')'> #{pipelineId}</foreach>" +
-            "   GROUP BY pipeline_id " +
-            ") histories " +
-            " WHERE histories.pipeline_id = pipeline_history.pipeline_id " +
-            "  AND histories.start_time = pipeline_history.start_time " +
-            "</script>")
-    List<PipelineHistoryPO> selectPipelinesLatestHistories(@Param("pipelineIds") List<Integer> pipelineIds);
-
-}

+ 68 - 0
web/src/main/java/cn/seecoder/web/dao/pipeline/PipelineRecordMapper.java

@@ -0,0 +1,68 @@
+package cn.seecoder.web.dao.pipeline;
+
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
+import org.apache.ibatis.annotations.*;
+import org.springframework.stereotype.Repository;
+import cn.seecoder.web.dao.provider.GeneralInsertUpdateSqlProvider;
+
+import java.util.List;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/3/12
+ * @description:
+ */
+@Repository
+public interface PipelineRecordMapper {
+
+    @InsertProvider(type = GeneralInsertUpdateSqlProvider.class, method = "insert")
+    @Options(useGeneratedKeys = true, keyProperty = "param1.id", keyColumn = "id")
+    void insert(PipelineRecordPO pipelineRecordPO, String... ignoredCols);
+
+    @UpdateProvider(type = GeneralInsertUpdateSqlProvider.class, method = "updateById")
+    int update(PipelineRecordPO pipelineRecordPO);
+
+    @Select("select id, pipeline_id, start_time, user_id, result from pipeline_record where id = #{id}")
+    PipelineRecordPO selectById(Integer id);
+
+
+    @Select("select id, pipeline_id, start_time, user_id, result from pipeline_record where pipeline_id = #{pipelineId}")
+    List<PipelineRecordPO> selectByPipelineId(Integer pipelineId);
+
+    @Select("select details from pipeline_record where id = #{id}")
+    String selectDetailsById(Integer id);
+
+    /**
+     * 获取一个项目里所有流水线配置的所有构建历史,多个流水线只会返回一条其中最新的构建信息
+     * 注意:一个项目可以有多个流水线,它是从多个流水线的构建历史信息中,选出最新的那一条(无论构建成功还是失败)
+     */
+    @Select("<script>" +
+            "SELECT *" +
+            " FROM pipeline_record " +
+            " WHERE start_time = (" +
+            "       SELECT MAX(start_time) " +
+            "       FROM pipeline_record" +
+            "       WHERE pipeline_id in " +
+            "       <foreach collection='pipelineIds' open='(' item='pipelineId' separator=',' close=')'> #{pipelineId}</foreach> " +
+            "   ) " +
+            "</script>")
+    PipelineRecordPO selectPipelinesLatestRecord(@Param("pipelineIds") List<Integer> pipelineIds);
+
+    /**
+     * 获取一个项目里所有流水线配置的各自的最新构建历史,每个流水线都会返回一条自己的最新构建信息
+     */
+    @Select("<script>" +
+            "SELECT * " +
+            " FROM   pipeline_record, " +
+            "(  SELECT pipeline_id, MAX(start_time) start_time" +
+            "   FROM pipeline_record " +
+            "   WHERE pipeline_id in " +
+            "   <foreach collection='pipelineIds' open='(' item='pipelineId' separator=',' close=')'> #{pipelineId}</foreach>" +
+            "   GROUP BY pipeline_id " +
+            ") records " +
+            " WHERE records.pipeline_id = pipeline_record.pipeline_id " +
+            "  AND records.start_time = pipeline_record.start_time " +
+            "</script>")
+    List<PipelineRecordPO> selectPipelinesLatestRecords(@Param("pipelineIds") List<Integer> pipelineIds);
+
+}

+ 7 - 4
web/src/main/java/cn/seecoder/web/dao/project/FuncTestCaseMapper.java

@@ -3,7 +3,7 @@ package cn.seecoder.web.dao.project;
 import org.apache.ibatis.annotations.*;
 import org.springframework.stereotype.Repository;
 import cn.seecoder.web.dao.provider.GeneralInsertUpdateSqlProvider;
-import cn.seecoder.web.model.po.project.TestCasePO;
+import cn.seecoder.web.model.po.project.FuncTestCasePO;
 
 import java.util.List;
 
@@ -17,14 +17,17 @@ public interface FuncTestCaseMapper {
 
     @InsertProvider(type = GeneralInsertUpdateSqlProvider.class, method = "insert")
     @Options(useGeneratedKeys = true, keyProperty = "param1.id", keyColumn = "id")
-    int insert(TestCasePO testCasePO, String... ignoredCols);
+    int insert(FuncTestCasePO funcTestCasePO, String... ignoredCols);
 
     @UpdateProvider(type= GeneralInsertUpdateSqlProvider.class, method="updateById")
-    int update(TestCasePO testCasePO);
+    int update(FuncTestCasePO funcTestCasePO);
 
     @Delete("delete from func_test_case where id = #{id}")
     int delete(Integer id);
 
     @Select("select * from func_test_case where project_id = #{projectId}")
-    List<TestCasePO> selectByProjectId(Integer projectId);
+    List<FuncTestCasePO> selectByProjectId(Integer projectId);
+
+    @Select("select * from func_test_case where id = #{id}")
+    FuncTestCasePO selectById(Integer id);
 }

+ 4 - 4
web/src/main/java/cn/seecoder/web/dao/project/FuncTestStepMapper.java

@@ -3,7 +3,7 @@ package cn.seecoder.web.dao.project;
 import org.apache.ibatis.annotations.*;
 import org.springframework.stereotype.Repository;
 import cn.seecoder.web.dao.provider.GeneralInsertUpdateSqlProvider;
-import cn.seecoder.web.model.po.project.TestStepPO;
+import cn.seecoder.web.model.po.project.FuncTestStepPO;
 
 import java.util.List;
 
@@ -17,14 +17,14 @@ public interface FuncTestStepMapper {
 
     @InsertProvider(type = GeneralInsertUpdateSqlProvider.class, method = "insert")
     @Options(useGeneratedKeys = true, keyProperty = "param1.id", keyColumn = "id")
-    int insert(TestStepPO testStepPO, String... ignoredCols);
+    int insert(FuncTestStepPO funcTestStepPO, String... ignoredCols);
 
     @UpdateProvider(type= GeneralInsertUpdateSqlProvider.class, method="updateById")
-    int update(TestStepPO testStepPO);
+    int update(FuncTestStepPO funcTestStepPO);
 
     @Delete("delete from func_test_step where id = #{id}")
     int delete(Integer id);
 
     @Select("select * from func_test_step where test_case_id = #{testCaseId}")
-    List<TestStepPO> selectByProjectId(Integer testCaseId);
+    List<FuncTestStepPO> selectByProjectId(Integer testCaseId);
 }

+ 30 - 0
web/src/main/java/cn/seecoder/web/model/enums/FuncTestOperatorEnum.java

@@ -0,0 +1,30 @@
+package cn.seecoder.web.model.enums;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/22
+ * @description:
+ */
+
+public enum FuncTestOperatorEnum {
+
+    @JsonProperty("完成测试")
+    FINISH("完成测试"),
+
+    @JsonProperty("重新开放测试")
+    REOPEN("重新开放测试");
+
+    private final String value;
+
+    FuncTestOperatorEnum(String value) {
+        this.value = value;
+    }
+
+    @Override
+    public String toString(){
+        return value;
+    }
+
+}

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/po/project/TestCasePO.java → web/src/main/java/cn/seecoder/web/model/po/project/FuncTestCasePO.java

@@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class TestCasePO {
+public class FuncTestCasePO {
 
     Integer id;
 

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/po/project/TestStepPO.java → web/src/main/java/cn/seecoder/web/model/po/project/FuncTestStepPO.java

@@ -14,7 +14,7 @@ import lombok.NoArgsConstructor;
 @Builder
 @NoArgsConstructor
 @AllArgsConstructor
-public class TestStepPO {
+public class FuncTestStepPO {
 
     Integer id;
 

+ 8 - 5
web/src/main/java/cn/seecoder/web/model/vo/pipeline/PipelineHistoryVO.java → web/src/main/java/cn/seecoder/web/model/vo/pipeline/PipelineRecordVO.java

@@ -1,6 +1,6 @@
 package cn.seecoder.web.model.vo.pipeline;
 
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
@@ -17,14 +17,17 @@ import java.sql.Timestamp;
 @Data
 @NoArgsConstructor
 @ApiModel("流水线历史构建记录")
-public class PipelineHistoryVO {
+public class PipelineRecordVO {
 
     @ApiModelProperty("流水线构建历史id")
     Integer id;
 
-    @ApiModelProperty("流水线id")
+    @ApiModelProperty("所属流水线id")
     Integer pipelineId;
 
+    @ApiModelProperty("所属的流水线名称")
+    String pipelineName;
+
     @ApiModelProperty("构建开始的时间")
     Timestamp startTime;
 
@@ -41,8 +44,8 @@ public class PipelineHistoryVO {
     String details;
 
 
-    public PipelineHistoryVO(PipelineHistoryPO history, String username){
-        BeanUtils.copyProperties(history,this);
+    public PipelineRecordVO(PipelineRecordPO record, String username){
+        BeanUtils.copyProperties(record,this);
         this.username = username;
     }
 }

+ 26 - 21
web/src/main/java/cn/seecoder/web/service/impl/pipeline/PipelineServiceImpl.java

@@ -3,11 +3,11 @@ package cn.seecoder.web.service.impl.pipeline;
 import cn.seecoder.common.exceptions.ServiceException;
 import cn.seecoder.web.core.pipeline.PipelineException;
 import cn.seecoder.web.core.pipeline.template.PipelineTemplateTable;
-import cn.seecoder.web.dao.pipeline.PipelineHistoryMapper;
 import cn.seecoder.web.dao.pipeline.PipelineMapper;
+import cn.seecoder.web.dao.pipeline.PipelineRecordMapper;
 import cn.seecoder.web.dao.user.UserMapper;
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
 import cn.seecoder.web.model.po.pipeline.PipelinePO;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
 import cn.seecoder.web.model.po.user.UserPO;
 import cn.seecoder.web.model.vo.pipeline.*;
 import cn.seecoder.web.service.pipeline.PipelineService;
@@ -27,7 +27,7 @@ import java.util.stream.Collectors;
 @Service
 public class PipelineServiceImpl implements PipelineService {
 
-    private final PipelineHistoryMapper pipelineHistoryMapper;
+    private final PipelineRecordMapper pipelineRecordMapper;
 
     private final PipelineMapper pipelineMapper;
 
@@ -35,8 +35,8 @@ public class PipelineServiceImpl implements PipelineService {
 
 
     @Autowired
-    public PipelineServiceImpl(PipelineHistoryMapper pipelineHistoryMapper, PipelineMapper pipelineMapper, UserMapper userMapper) {
-        this.pipelineHistoryMapper = pipelineHistoryMapper;
+    public PipelineServiceImpl(PipelineRecordMapper pipelineRecordMapper, PipelineMapper pipelineMapper, UserMapper userMapper) {
+        this.pipelineRecordMapper = pipelineRecordMapper;
         this.pipelineMapper = pipelineMapper;
         this.userMapper = userMapper;
     }
@@ -53,18 +53,18 @@ public class PipelineServiceImpl implements PipelineService {
 
         List<Integer> pipelineIds = pipelinePOS.stream().map(PipelinePO::getId).collect(Collectors.toList());
         // 获取流水线历史
-        List<PipelineHistoryPO> histories = pipelineHistoryMapper.selectPipelinesRecentlyHistory(pipelineIds);
-        Map<Integer, PipelineHistoryPO> historyMap = histories.stream().collect(Collectors.toMap(PipelineHistoryPO::getPipelineId, x->x));
+        List<PipelineRecordPO> records = pipelineRecordMapper.selectPipelinesLatestRecords(pipelineIds);
+        Map<Integer, PipelineRecordPO> recordMap = records.stream().collect(Collectors.toMap(PipelineRecordPO::getPipelineId, x->x));
         // 获取流水线历史中具体执行人信息
-        List<Integer> userIds = histories.stream().map(PipelineHistoryPO::getUserId).collect(Collectors.toList());
+        List<Integer> userIds = records.stream().map(PipelineRecordPO::getUserId).collect(Collectors.toList());
         Map<Integer, String> usernameMap =  userMapper.selectByIds(userIds).stream().collect(Collectors.toMap(UserPO::getId, UserPO::getUsername));
         return pipelinePOS.stream().map(x->{
-            PipelineHistoryPO pipelineHistoryPO = historyMap.getOrDefault(x.getId(),null);
-            if (pipelineHistoryPO == null){
+            PipelineRecordPO pipelineRecordPO = recordMap.getOrDefault(x.getId(),null);
+            if (pipelineRecordPO == null){
                 return new PipelineInfoVO(x,null,null);
             }
-            String username = usernameMap.get(pipelineHistoryPO.getUserId());
-            return new PipelineInfoVO(x,pipelineHistoryPO,username);
+            String username = usernameMap.get(pipelineRecordPO.getUserId());
+            return new PipelineInfoVO(x,pipelineRecordPO,username);
         }).collect(Collectors.toList());
     }
 
@@ -75,17 +75,17 @@ public class PipelineServiceImpl implements PipelineService {
     }
 
     @Override
-    public List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) {
+    public List<PipelineRecordVO> retrievePipelineRecord(Integer projectId, Integer pipelineId) {
         //projectAuthentication(projectId);
-        List<PipelineHistoryPO> histories = pipelineHistoryMapper.selectByPipelineId(pipelineId);
-        List<Integer> userIds = histories.stream().map(PipelineHistoryPO::getUserId).collect(Collectors.toList());
+        List<PipelineRecordPO> records = pipelineRecordMapper.selectByPipelineId(pipelineId);
+        List<Integer> userIds = records.stream().map(PipelineRecordPO::getUserId).collect(Collectors.toList());
         Map<Integer, String> usernameMap =  userMapper.selectByIds(userIds).stream().collect(Collectors.toMap(UserPO::getId, UserPO::getUsername));
-        return histories.stream().map(x->new PipelineHistoryVO(x,usernameMap.get(x.getUserId()))).collect(Collectors.toList());
+        return records.stream().map(x->new PipelineRecordVO(x,usernameMap.get(x.getUserId()))).collect(Collectors.toList());
     }
 
     @Override
-    public String retrievePipelineHistoryDetails(Integer historyId) {
-        return pipelineHistoryMapper.selectDetailsById(historyId);
+    public String retrievePipelineRecordDetails(Integer recordId) {
+        return pipelineRecordMapper.selectDetailsById(recordId);
     }
 
     @Override
@@ -128,7 +128,12 @@ public class PipelineServiceImpl implements PipelineService {
     }
 
 
-
-
-
+    @Override
+    public PipelineRecordVO retrieveRecordById(Integer id) {
+        PipelineRecordPO recordPO = pipelineRecordMapper.selectById(id);
+        String username = userMapper.select(recordPO.getUserId()).getUsername();
+        PipelineRecordVO recordVO = new PipelineRecordVO(recordPO,username);
+        recordVO.setPipelineName(pipelineMapper.selectById(recordPO.getPipelineId()).getName());
+        return recordVO;
+    }
 }

+ 144 - 0
web/src/main/java/cn/seecoder/web/service/impl/project/FuncFuncTestServiceImpl.java

@@ -0,0 +1,144 @@
+package cn.seecoder.web.service.impl.project;
+
+import cn.seecoder.web.dao.pipeline.PipelineRecordMapper;
+import cn.seecoder.web.dao.pipeline.PipelineMapper;
+import cn.seecoder.web.dao.project.FuncTestCaseMapper;
+import cn.seecoder.web.dao.project.FuncTestRecordMapper;
+import cn.seecoder.web.dao.project.FuncTestStepMapper;
+import cn.seecoder.web.model.enums.FuncTestOperatorEnum;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
+import cn.seecoder.web.model.po.project.FuncTestCasePO;
+import cn.seecoder.web.model.po.project.FuncTestRecordPO;
+import cn.seecoder.web.model.po.project.FuncTestStepPO;
+import cn.seecoder.web.model.vo.project.FuncTestCaseVO;
+import cn.seecoder.web.model.vo.project.FuncTestRecordVO;
+import cn.seecoder.web.model.vo.project.FuncTestStepVO;
+import cn.seecoder.web.service.project.FuncTestService;
+import org.springframework.beans.BeanUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.sql.Timestamp;
+import java.util.List;
+import java.util.stream.Collectors;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/10
+ * @description:
+ */
+@Service
+public class FuncFuncTestServiceImpl implements FuncTestService {
+
+    private final FuncTestCaseMapper funcTestCaseMapper;
+
+    private final FuncTestStepMapper funcTestStepMapper;
+
+    private final FuncTestRecordMapper funcTestRecordMapper;
+
+    private final PipelineMapper pipelineMapper;
+
+    private final PipelineRecordMapper pipelineRecordMapper;
+
+    @Autowired
+    public FuncFuncTestServiceImpl(FuncTestCaseMapper funcTestCaseMapper, FuncTestStepMapper funcTestStepMapper, FuncTestRecordMapper funcTestRecordMapper, PipelineMapper pipelineMapper, PipelineRecordMapper pipelineRecordMapper) {
+        this.funcTestCaseMapper = funcTestCaseMapper;
+        this.funcTestStepMapper = funcTestStepMapper;
+        this.funcTestRecordMapper = funcTestRecordMapper;
+        this.pipelineMapper = pipelineMapper;
+        this.pipelineRecordMapper = pipelineRecordMapper;
+    }
+
+    @Override
+    public List<FuncTestCaseVO> getTestCases(Integer projectId) {
+        return funcTestCaseMapper.selectByProjectId(projectId).stream()
+                .map(FuncTestCaseVO::new).collect(Collectors.toList());
+    }
+
+    @Override
+    public List<FuncTestStepVO> getTestSteps(Integer testCaseId) {
+        return null;
+    }
+
+    @Override
+    @Transactional
+    public void createTestCase(Integer projectId, String title) {
+        funcTestCaseMapper.insert(FuncTestCasePO.builder().projectId(projectId).title(title).build());
+    }
+
+    @Override
+    @Transactional
+    public void updateTestCaseTitle(Integer testCaseId, String title) {
+        funcTestCaseMapper.update(FuncTestCasePO.builder().id(testCaseId).title(title).build());
+    }
+
+    @Override
+    @Transactional
+    public void finish(Integer testCaseId) {
+        FuncTestCasePO po = funcTestCaseMapper.selectById(testCaseId);
+        po.setPass(true);
+        funcTestCaseMapper.update(po);
+
+        List<Integer> pipelineIds = pipelineMapper.selectByProjectId(po.getProjectId()).stream().map(x->x.getId()).collect(Collectors.toList());
+        PipelineRecordPO latestRecord = pipelineRecordMapper.selectPipelinesLatestRecord(pipelineIds);
+        funcTestRecordMapper.insert(FuncTestRecordPO.builder()
+                .timestamp(new Timestamp(System.currentTimeMillis()))
+                .operationType(FuncTestOperatorEnum.FINISH)
+                .pipelineRecordId(latestRecord.getId())
+                .build(),"id");
+    }
+
+    @Override
+    @Transactional
+    public void reopen(Integer testCaseId) {
+        FuncTestCasePO po = funcTestCaseMapper.selectById(testCaseId);
+        po.setPass(false);
+        funcTestCaseMapper.update(po);
+
+        List<Integer> pipelineIds = pipelineMapper.selectByProjectId(po.getProjectId()).stream().map(x->x.getId()).collect(Collectors.toList());
+        PipelineRecordPO latestRecord = pipelineRecordMapper.selectPipelinesLatestRecord(pipelineIds);
+        funcTestRecordMapper.insert(FuncTestRecordPO.builder()
+                .timestamp(new Timestamp(System.currentTimeMillis()))
+                .operationType(FuncTestOperatorEnum.REOPEN)
+                .pipelineRecordId(latestRecord.getId())
+                .build(),"id");
+    }
+
+    @Override
+    @Transactional
+    public void deleteTestCase(Integer testCaseId) {
+        funcTestCaseMapper.delete(testCaseId);
+    }
+
+    @Override
+    @Transactional
+    public void createEmptyTestStep(Integer testCaseId) {
+        funcTestStepMapper.insert(FuncTestStepPO.builder().description("").testCaseId(testCaseId).build());
+    }
+
+    @Override
+    @Transactional
+    public void updateTestStepDescription(Integer testStepId, String description) {
+        funcTestStepMapper.insert(FuncTestStepPO.builder().description(description).id(testStepId).build());
+    }
+
+    @Override
+    @Transactional
+    public void deleteTestStep(Integer testStepId) {
+        funcTestStepMapper.delete(testStepId);
+    }
+
+    @Override
+    public List<FuncTestRecordVO> getLatestRecord(Integer projectId) {
+        List<Integer> pipelineIds = pipelineMapper.selectByProjectId(projectId).stream().map(x->x.getId()).collect(Collectors.toList());
+        PipelineRecordPO latestRecord = pipelineRecordMapper.selectPipelinesLatestRecord(pipelineIds);
+        return funcTestRecordMapper.selectByPipelineHistoryId(latestRecord.getId()).stream()
+                .map(x->{
+                    FuncTestRecordVO vo = new FuncTestRecordVO();
+                    BeanUtils.copyProperties(x,vo);
+                    return vo;
+                })
+                .collect(Collectors.toList());
+    }
+}

+ 0 - 87
web/src/main/java/cn/seecoder/web/service/impl/project/TestCaseServiceImpl.java

@@ -1,87 +0,0 @@
-package cn.seecoder.web.service.impl.project;
-
-import cn.seecoder.web.dao.project.FuncTestCaseMapper;
-import cn.seecoder.web.service.project.TestCaseService;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import cn.seecoder.web.dao.project.FuncTestStepMapper;
-import cn.seecoder.web.model.po.project.TestCasePO;
-import cn.seecoder.web.model.po.project.TestStepPO;
-import cn.seecoder.web.model.vo.project.TestCaseVO;
-import cn.seecoder.web.model.vo.project.TestStepVO;
-
-import java.util.List;
-import java.util.stream.Collectors;
-
-/**
- * @author PuHong Weng
- * @date 2021/4/10
- * @description:
- */
-@Service
-public class TestCaseServiceImpl implements TestCaseService {
-
-    private final FuncTestCaseMapper funcTestCaseMapper;
-
-    private final FuncTestStepMapper funcTestStepMapper;
-
-    @Autowired
-    public TestCaseServiceImpl(FuncTestCaseMapper funcTestCaseMapper, FuncTestStepMapper funcTestStepMapper) {
-        this.funcTestCaseMapper = funcTestCaseMapper;
-        this.funcTestStepMapper = funcTestStepMapper;
-    }
-
-    @Override
-    public List<TestCaseVO> getTestCases(Integer projectId) {
-        return funcTestCaseMapper.selectByProjectId(projectId).stream()
-                .map(TestCaseVO::new).collect(Collectors.toList());
-    }
-
-    @Override
-    public List<TestStepVO> getTestSteps(Integer testCaseId) {
-        return null;
-    }
-
-    @Override
-    @Transactional
-    public void createTestCase(Integer projectId, String title) {
-        funcTestCaseMapper.insert(TestCasePO.builder().projectId(projectId).title(title).build());
-    }
-
-    @Override
-    @Transactional
-    public void updateTestCaseTitle(Integer testCaseId, String title) {
-        funcTestCaseMapper.update(TestCasePO.builder().id(testCaseId).title(title).build());
-    }
-
-    @Override
-    @Transactional
-    public void updateTestCaseState(Integer testCaseId, Boolean pass) {
-        funcTestCaseMapper.update(TestCasePO.builder().id(testCaseId).pass(pass).build());
-    }
-
-    @Override
-    @Transactional
-    public void deleteTestCase(Integer testCaseId) {
-        funcTestCaseMapper.delete(testCaseId);
-    }
-
-    @Override
-    @Transactional
-    public void createEmptyTestStep(Integer testCaseId) {
-        funcTestStepMapper.insert(TestStepPO.builder().description("").testCaseId(testCaseId).build());
-    }
-
-    @Override
-    @Transactional
-    public void updateTestStepDescription(Integer testStepId, String description) {
-        funcTestStepMapper.insert(TestStepPO.builder().description(description).id(testStepId).build());
-    }
-
-    @Override
-    @Transactional
-    public void deleteTestStep(Integer testStepId) {
-        funcTestStepMapper.delete(testStepId);
-    }
-}

+ 1 - 1
web/src/main/java/cn/seecoder/web/service/impl/tree/TreeNodeServiceImpl.java

@@ -176,7 +176,7 @@ public class TreeNodeServiceImpl implements TreeNodeService {
         int projectId = nodesPO.get(0).getProjectId();
         List<Integer> userIds = nodesPO.stream().filter(x->x.getProcessorId()!=null).map(TreeNodePO::getProcessorId).collect(Collectors.toList());
         Map<Integer,String> usernameMap = userIds.size() == 0? new HashMap<>() : userMapper.selectByIds(userIds).stream().collect(Collectors.toMap(UserPO::getId, UserPO::getUsername));
-        List<CommitPO> commits = commitMapper.selectByProjectIdAndType(projectId, CommitRelatedType.TREE_ID);
+        List<CommitPO> commits = commitMapper.selectByProjectIdAndType(projectId, CommitRelatedEnum.TREE_ID);
         Map<Integer, List<CommitPO>> commitsMap = commits.stream().collect(Collectors.groupingBy(CommitPO::getRelatedId));
         return nodesPO.stream().map(po -> new TreeNodeVO(po,usernameMap.getOrDefault(po.getProcessorId(),"no one"),commitsMap.getOrDefault(po.getId(),new ArrayList<>()))).collect(Collectors.toList());
     }

+ 4 - 2
web/src/main/java/cn/seecoder/web/service/pipeline/PipelineService.java

@@ -34,12 +34,12 @@ public interface PipelineService {
     /**
      * 获取指定一条流水线的历史构建信息
      */
-    List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) throws AccessDeniedException;
+    List<PipelineRecordVO> retrievePipelineRecord(Integer projectId, Integer pipelineId) throws AccessDeniedException;
 
     /**
      * 获取流水线日志的详情
      */
-    String retrievePipelineHistoryDetails(Integer historyId);
+    String retrievePipelineRecordDetails(Integer recordId);
 
     /**
      * 依据模板创建一个流水线配置
@@ -59,4 +59,6 @@ public interface PipelineService {
 
 
     List<String> getTemplateNames();
+
+    PipelineRecordVO retrieveRecordById(Integer id);
 }

+ 10 - 6
web/src/main/java/cn/seecoder/web/service/project/TestCaseService.java → web/src/main/java/cn/seecoder/web/service/project/FuncTestService.java

@@ -1,7 +1,8 @@
 package cn.seecoder.web.service.project;
 
-import cn.seecoder.web.model.vo.project.TestCaseVO;
-import cn.seecoder.web.model.vo.project.TestStepVO;
+import cn.seecoder.web.model.vo.project.FuncTestCaseVO;
+import cn.seecoder.web.model.vo.project.FuncTestRecordVO;
+import cn.seecoder.web.model.vo.project.FuncTestStepVO;
 
 import java.util.List;
 
@@ -10,17 +11,19 @@ import java.util.List;
  * @date 2021/4/10
  * @description:
  */
-public interface TestCaseService {
+public interface FuncTestService {
 
-    List<TestCaseVO> getTestCases(Integer projectId);
+    List<FuncTestCaseVO> getTestCases(Integer projectId);
 
-    List<TestStepVO> getTestSteps(Integer testCaseId);
+    List<FuncTestStepVO> getTestSteps(Integer testCaseId);
 
     void createTestCase(Integer projectId, String title);
 
     void updateTestCaseTitle(Integer testCaseId, String title);
 
-    void updateTestCaseState(Integer testCaseId, Boolean pass);
+    void finish(Integer testCaseId);
+
+    void reopen(Integer testCaseId);
 
     void deleteTestCase(Integer testCaseId);
 
@@ -30,4 +33,5 @@ public interface TestCaseService {
 
     void deleteTestStep(Integer testStepId);
 
+    List<FuncTestRecordVO> getLatestRecord(Integer projectId);
 }

+ 21 - 11
web/src/test/java/cn/seecoder/web/dao/pipeline/PipelineHistoryMapperTest.java

@@ -1,12 +1,14 @@
 package cn.seecoder.web.dao.pipeline;
 
+import cn.seecoder.web.DevcloudWebApplication;
+import cn.seecoder.web.model.po.pipeline.PipelineRecordPO;
 import org.junit.jupiter.api.Test;
 import org.junit.runner.RunWith;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.ActiveProfiles;
 import org.springframework.test.context.junit4.SpringRunner;
-import cn.seecoder.web.model.po.pipeline.PipelineHistoryPO;
 
 import java.util.Arrays;
 
@@ -16,36 +18,44 @@ import java.util.Arrays;
  * @description:
  */
 @RunWith(SpringRunner.class)
-@SpringBootTest
+@SpringBootTest(classes = DevcloudWebApplication.class)
 @MapperScan(basePackages = {"cn.seecoder.web.dao"})
-class PipelineHistoryMapperTest {
+@ActiveProfiles("test")
+class PipelineRecordMapperTest {
 
-    private final PipelineHistoryMapper historyMapper;
+    private final PipelineRecordMapper recordMapper;
 
     @Autowired
-    PipelineHistoryMapperTest(PipelineHistoryMapper historyMapper) {
-        this.historyMapper = historyMapper;
+    PipelineRecordMapperTest(PipelineRecordMapper recordMapper) {
+        this.recordMapper = recordMapper;
     }
 
     @Test
     void insert(){
-        PipelineHistoryPO po = PipelineHistoryPO
+        PipelineRecordPO po = PipelineRecordPO
                 .builder()
                 .pipelineId(1)
                 .details("leftright")
                 .result("down")
                 .userId(1345)
                 .build();
-        historyMapper.insert(po,"id","startTime");
+        recordMapper.insert(po,"id","startTime");
     }
 
     @Test
     void selectByPipelineId() {
-        System.out.println(historyMapper.selectByPipelineId(4));
+        System.out.println(recordMapper.selectByPipelineId(4));
+    }
+
+
+    @Test
+    void selectPipelinesLatestRecord() {
+
+        System.out.println(recordMapper.selectPipelinesLatestRecord(Arrays.asList(1,2,3)));
     }
 
     @Test
-    void selectPipelinesRecentlyHistory() {
-        System.out.println(historyMapper.selectPipelinesRecentlyHistory(Arrays.asList(1)));
+    void selectPipelinesLatestRecords() {
+        System.out.println(recordMapper.selectPipelinesLatestRecords(Arrays.asList(1,2,3)));
     }
 }