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

refactor: 重構stage 配置信息格式

370774330@qq.com 5 лет назад
Родитель
Сommit
e621cc3da9

+ 1 - 1
web/src/main/java/cn/seecoder/web/model/po/pipeline/StageConfigPO.java

@@ -16,5 +16,5 @@ public class StageConfigPO {
      * true 则为学生不可以配置的属性,仅作展示用
      * false 则为学生可以配置的属性
      */
-    private Boolean fake;
+    private Boolean editable;
 }

+ 24 - 8
web/src/main/java/cn/seecoder/web/model/vo/pipeline/StageVO.java

@@ -1,12 +1,14 @@
 package cn.seecoder.web.model.vo.pipeline;
 
+import cn.seecoder.web.model.po.pipeline.StageConfigPO;
 import cn.seecoder.web.model.po.pipeline.StagePO;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import org.springframework.beans.BeanUtils;
 
-import java.util.Map;
+import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * @author PuHong Weng
@@ -26,19 +28,33 @@ public class StageVO {
     @ApiModelProperty("描述信息")
     private String description;
 
-    @ApiModelProperty("仅作展示用的字段")
-    private Map<String,String> fakeConfigs;
 
     @ApiModelProperty("识别名称,用于转换成对应的流水线真实步骤Handler,见core包的 HandlerConfigTable")
     private String name;
 
-    @ApiModelProperty("可以配置的字段属性")
-    private Map<String,String> configs;
+    @ApiModelProperty("配置的字段属性")
+    private List<StageConfigVO> configs;
 
-    public StageVO(StagePO stagePO, Map<String,String> fakeConfigs, Map<String,String> configs){
+    public StageVO(StagePO stagePO, List<StageConfigPO> configs){
         BeanUtils.copyProperties(stagePO,this);
-        this.fakeConfigs = fakeConfigs;
-        this.configs = configs;
+        this.configs = configs.stream().map(
+                x->{
+                    StageConfigVO vo = new StageConfigVO();
+                    BeanUtils.copyProperties(x,vo);
+                    return vo;
+                }
+        ).collect(Collectors.toList());
     }
 
+    @Data
+    public static class StageConfigVO{
+        private Integer id;
+        private String name;
+        private String value;
+        /**
+         * true 则为学生不可以配置的属性,仅作展示用
+         * false 则为学生可以配置的属性
+         */
+        private Boolean editable;
+    }
 }

+ 3 - 6
web/src/main/java/cn/seecoder/web/service/impl/pipeline/StageServiceImpl.java

@@ -1,15 +1,14 @@
 package cn.seecoder.web.service.impl.pipeline;
 
 import cn.seecoder.web.dao.pipeline.StageMapper;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
 import cn.seecoder.web.model.po.pipeline.StageConfigPO;
 import cn.seecoder.web.model.po.pipeline.StagePO;
 import cn.seecoder.web.model.vo.pipeline.StageVO;
 import cn.seecoder.web.service.pipeline.StageService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
 
 import java.util.List;
-import java.util.Map;
 import java.util.stream.Collectors;
 
 /**
@@ -32,9 +31,7 @@ public class StageServiceImpl implements StageService {
         List<StagePO> stages = stageMapper.selectAllStages();
         return stages.stream().map(stage -> {
             List<StageConfigPO> pos = stageMapper.selectConfigs(stage.getId());
-            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);
+            return new StageVO(stage,pos);
         }).collect(Collectors.toList());
 
     }

+ 4 - 4
web/src/main/resources/sql/init.sql

@@ -68,11 +68,11 @@ create table if not exists devcloud.stage
 
 create table if not exists devcloud.stage_config
 (
-    id    int auto_increment
+    id       int auto_increment
         primary key,
-    `key` varchar(63) null,
-    value text        null,
-    fake  tinyint(1)  null
+    name     varchar(63) null,
+    value    text        null,
+    editable tinyint(1)  null
 );
 
 create table if not exists devcloud.test_case