소스 검색

feat: 可视化流水线信息的获取

370774330@qq.com 5 년 전
부모
커밋
3d80bb7783

+ 37 - 0
web/src/main/java/seecoder/devcloud/web/controller/pipeline/StageController.java

@@ -0,0 +1,37 @@
+package seecoder.devcloud.web.controller.pipeline;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.GetMapping;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import seecoder.devcloud.web.model.vo.Response;
+import seecoder.devcloud.web.model.vo.pipeline.StageVO;
+import seecoder.devcloud.web.service.pipeline.StageService;
+
+import java.util.List;
+
+/**
+ * @author PuHong Weng
+ * @date 2021/4/15
+ * @description:
+ */
+@RestController
+@RequestMapping("/stages")
+@Api(tags = "流水线配置可视化块信息 API")
+public class StageController {
+
+    private final StageService stageService;
+
+    @Autowired
+    public StageController(StageService stageService) {
+        this.stageService = stageService;
+    }
+
+    @GetMapping
+    @ApiOperation(value = "获取流水线项目stage的可视化展示信息", httpMethod = "GET")
+    public Response<List<StageVO>> getAll(){
+        return Response.buildSuccess(stageService.getAll());
+    }
+}

+ 1 - 1
web/src/main/java/seecoder/devcloud/web/dao/pipeline/StageMapper.java

@@ -25,6 +25,6 @@ public interface StageMapper {
     @Select("select * from stage")
     @Select("select * from stage")
     List<StagePO> selectAllStages();
     List<StagePO> selectAllStages();
 
 
-    @Select("select from stage_configs where stage_id = #{stageId}")
+    @Select("select * from stage_config where stage_id = #{stageId}")
     List<StageConfigPO> selectConfigs(Integer stageId);
     List<StageConfigPO> selectConfigs(Integer stageId);
 }
 }

+ 0 - 15
web/src/main/java/seecoder/devcloud/web/model/po/pipeline/StagePO.java

@@ -3,9 +3,6 @@ package seecoder.devcloud.web.model.po.pipeline;
 import lombok.Builder;
 import lombok.Builder;
 import lombok.Data;
 import lombok.Data;
 
 
-import java.util.HashMap;
-import java.util.Map;
-
 /**
 /**
  * @author PuHong Weng
  * @author PuHong Weng
  * @date 2021/4/14
  * @date 2021/4/14
@@ -28,23 +25,11 @@ public class StagePO {
      */
      */
     private String description;
     private String description;
 
 
-    /**
-     * 仅作展示用的字段
-     */
-    private Map<String,String> fakeConfigs;
-
     /**
     /**
      * 识别名称,用于转换成对应的流水线真实步骤Handler,见core包的 HandlerConfigTable
      * 识别名称,用于转换成对应的流水线真实步骤Handler,见core包的 HandlerConfigTable
      */
      */
     private String name;
     private String name;
 
 
-    /**
-     * 可以配置的字段属性
-     */
-    @Builder.Default
-    private Map<String,String> configs = new HashMap<>();
-
-
 
 
 
 
 }
 }

+ 3 - 1
web/src/main/java/seecoder/devcloud/web/model/vo/pipeline/StageVO.java

@@ -35,8 +35,10 @@ public class StageVO {
     @ApiModelProperty("可以配置的字段属性")
     @ApiModelProperty("可以配置的字段属性")
     private Map<String,String> configs;
     private Map<String,String> configs;
 
 
-    public StageVO(StagePO stagePO){
+    public StageVO(StagePO stagePO, Map<String,String> fakeConfigs, Map<String,String> configs){
         BeanUtils.copyProperties(stagePO,this);
         BeanUtils.copyProperties(stagePO,this);
+        this.fakeConfigs = fakeConfigs;
+        this.configs = configs;
     }
     }
 
 
 }
 }

+ 7 - 8
web/src/main/java/seecoder/devcloud/web/service/impl/pipeline/StageServiceImpl.java

@@ -9,6 +9,7 @@ import seecoder.devcloud.web.model.vo.pipeline.StageVO;
 import seecoder.devcloud.web.service.pipeline.StageService;
 import seecoder.devcloud.web.service.pipeline.StageService;
 
 
 import java.util.List;
 import java.util.List;
+import java.util.Map;
 import java.util.stream.Collectors;
 import java.util.stream.Collectors;
 
 
 /**
 /**
@@ -29,14 +30,12 @@ public class StageServiceImpl implements StageService {
     @Override
     @Override
     public List<StageVO> getAll() {
     public List<StageVO> getAll() {
         List<StagePO> stages = stageMapper.selectAllStages();
         List<StagePO> stages = stageMapper.selectAllStages();
-        for (StagePO stage : stages){
+        return stages.stream().map(stage -> {
             List<StageConfigPO> pos = stageMapper.selectConfigs(stage.getId());
             List<StageConfigPO> pos = stageMapper.selectConfigs(stage.getId());
-            if (pos.size() == 0){
-                continue;
-            }
-            stage.setFakeConfigs(pos.stream().filter(StageConfigPO::getFake).collect(Collectors.toMap(StageConfigPO::getName, StageConfigPO::getValue)));
-            stage.setConfigs(pos.stream().filter(x->!x.getFake()).collect(Collectors.toMap(StageConfigPO::getName, StageConfigPO::getValue)));
-        }
-        return stages.stream().map(x->new StageVO(x)).collect(Collectors.toList());
+            Map<String,String> fakeConfigs = pos.stream().filter(StageConfigPO::getFake).collect(Collectors.toMap(StageConfigPO::getName, StageConfigPO::getValue));
+            Map<String,String> configs = pos.stream().filter(x->!x.getFake()).collect(Collectors.toMap(StageConfigPO::getName, StageConfigPO::getValue));
+            return new StageVO(stage,fakeConfigs,configs);
+        }).collect(Collectors.toList());
+
     }
     }
 }
 }

+ 0 - 4
web/src/test/java/seecoder/devcloud/web/dao/pipeline/StageMapperTest.java

@@ -8,8 +8,6 @@ import org.springframework.boot.test.context.SpringBootTest;
 import org.springframework.test.context.junit4.SpringRunner;
 import org.springframework.test.context.junit4.SpringRunner;
 import seecoder.devcloud.web.model.po.pipeline.StagePO;
 import seecoder.devcloud.web.model.po.pipeline.StagePO;
 
 
-import java.util.HashMap;
-
 /**
 /**
  * @author PuHong Weng
  * @author PuHong Weng
  * @date 2021/4/14
  * @date 2021/4/14
@@ -32,8 +30,6 @@ class StageMapperTest {
         StagePO stagePO = StagePO.builder()
         StagePO stagePO = StagePO.builder()
                 .name("Maven测试并构建")
                 .name("Maven测试并构建")
                 .description("构建打包过程")
                 .description("构建打包过程")
-                .fakeConfigs(new HashMap<>())
-                .configs(new HashMap<>())
                 .title("Maven测试并构建")
                 .title("Maven测试并构建")
                 .build();
                 .build();
         stageMapper.insert(stagePO,"id","fakeConfigs","configs");
         stageMapper.insert(stagePO,"id","fakeConfigs","configs");