|
|
@@ -1,12 +1,22 @@
|
|
|
package seecoder.devcloud.web.service.impl.pipeline;
|
|
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import seecoder.devcloud.web.dao.pipeline.PipelineHistoryMapper;
|
|
|
+import seecoder.devcloud.web.dao.pipeline.PipelineMapper;
|
|
|
+import seecoder.devcloud.web.dao.user.UserMapper;
|
|
|
+import seecoder.devcloud.web.model.po.pipeline.Pipeline;
|
|
|
+import seecoder.devcloud.web.model.po.pipeline.PipelineHistory;
|
|
|
+import seecoder.devcloud.web.model.po.user.User;
|
|
|
import seecoder.devcloud.web.model.vo.pipeline.PipelineConfigVO;
|
|
|
+import seecoder.devcloud.web.model.vo.pipeline.PipelineCreateVO;
|
|
|
import seecoder.devcloud.web.model.vo.pipeline.PipelineHistoryVO;
|
|
|
import seecoder.devcloud.web.model.vo.pipeline.PipelineInfoVO;
|
|
|
import seecoder.devcloud.web.service.pipeline.PipelineService;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author PuHong Weng
|
|
|
@@ -15,33 +25,78 @@ import java.util.List;
|
|
|
*/
|
|
|
@Service
|
|
|
public class PipelineServiceImpl implements PipelineService {
|
|
|
+
|
|
|
+ private final PipelineHistoryMapper pipelineHistoryMapper;
|
|
|
+
|
|
|
+ private final PipelineMapper pipelineMapper;
|
|
|
+
|
|
|
+ private final UserMapper userMapper;
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ public PipelineServiceImpl(PipelineHistoryMapper pipelineHistoryMapper, PipelineMapper pipelineMapper, UserMapper userMapper) {
|
|
|
+ this.pipelineHistoryMapper = pipelineHistoryMapper;
|
|
|
+ this.pipelineMapper = pipelineMapper;
|
|
|
+ this.userMapper = userMapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
public List<PipelineInfoVO> retrievePipelineInfos(Integer projectId) {
|
|
|
- return null;
|
|
|
+ projectAuthentication(projectId);
|
|
|
+ List<Pipeline> pipelines = pipelineMapper.selectByProjectId(projectId);
|
|
|
+ List<Integer> pipelineIds = pipelines.stream().map(Pipeline::getId).collect(Collectors.toList());
|
|
|
+ List<PipelineHistory> histories = pipelineHistoryMapper.selectRecentlyHistoryBy(pipelineIds);
|
|
|
+ Map<Integer,PipelineHistory> historyMap = histories.stream().collect(Collectors.toMap(PipelineHistory::getPipelineId, x->x));
|
|
|
+ return pipelines.stream().map(x->new PipelineInfoVO(x,historyMap.get(x.getId()))).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PipelineConfigVO retrievePipelineConfig(Integer projectId, Integer pipelineId) {
|
|
|
- return null;
|
|
|
+ projectAuthentication(projectId);
|
|
|
+ return new PipelineConfigVO(pipelineMapper.selectById(pipelineId));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<PipelineHistoryVO> retrievePipelineHistory(Integer projectId, Integer pipelineId) {
|
|
|
- return null;
|
|
|
+ projectAuthentication(projectId);
|
|
|
+ List<PipelineHistory> histories = pipelineHistoryMapper.selectByPipelineId(pipelineId);
|
|
|
+ return histories.stream().map(PipelineHistoryVO::new).collect(Collectors.toList());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void createPipelineConfig(Integer projectId, Integer pipelineId, String templateName) {
|
|
|
+ public void createPipelineConfig(PipelineCreateVO pipelineCreateVO) {
|
|
|
+ projectAuthentication(pipelineCreateVO.getProjectId());
|
|
|
+ Pipeline pipeline = Pipeline.builder()
|
|
|
+ .name(pipelineCreateVO.getName())
|
|
|
+ .projectId(pipelineCreateVO.getProjectId())
|
|
|
+ .configJson("") //todo 提供模板
|
|
|
+ .build();
|
|
|
+ pipelineMapper.insert(pipeline);
|
|
|
+
|
|
|
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void savePipelineConfig(Integer projectId, Integer pipelineId, String configJson) {
|
|
|
- //todo 校验json格式
|
|
|
+ projectAuthentication(projectId);
|
|
|
+ pipelineMapper.updateConfigJson(pipelineId,configJson);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void deletePipelineConfig(Integer projectId, Integer pipelineId) {
|
|
|
+ projectAuthentication(projectId);
|
|
|
+ pipelineMapper.delete(pipelineId);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断用户是否有权限修改这些流水线配置,
|
|
|
+ * 防止用户修改提交的参数从而修改其他组的流水线
|
|
|
+ */
|
|
|
+ private void projectAuthentication(Integer projectId){
|
|
|
+ User user = userMapper.findLoginUser();
|
|
|
+ //todo 鉴权
|
|
|
|
|
|
}
|
|
|
}
|