增加流水线执行详情查询

This commit is contained in:
xxq250 2025-01-23 16:48:40 +08:00
parent 2b915c52a2
commit 782e2e7e5a
9 changed files with 231 additions and 8 deletions

View File

@ -54,6 +54,26 @@ public class PmsCiPipelinesController extends BaseController
return pmsCiPipelinesService.selectPmsCiPipelinesList(enterpriseIdentifier, pipelineName, pipelineType);
}
/**
* 查询流水线卡片列表
*/
// @RequiresPermissions("pms:pipelines:list")
@GetMapping("/cardList")
@ApiImplicitParams({
@ApiImplicitParam(name = "pageNum", value = "当前记录起始索引", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "pageSize", value = "每页显示记录数", paramType = "query", dataType = "Integer"),
@ApiImplicitParam(name = "orderByColumn", value = "排序列更新时间updateTime创建时间createTime", paramType = "query", dataType = "String"),
@ApiImplicitParam(name = "isAsc", value = "排序的方向desc或者asc,默认asc", paramType = "query", dataType = "String")
})
@ApiOperation("流水线卡片列表")
public GenericsTableDataInfo<PmsCiPipelinesCardVo> cardList(@ApiParam(name = "enterpriseIdentifier", value = "企业标识") @PathVariable String enterpriseIdentifier,
@ApiParam("流水线名称搜索") @RequestParam(required = false) String pipelineName,
@ApiParam("流水线构建类型 1-声明式流水线 2-图形化流水线") @RequestParam(required = false) Integer pipelineType)
{
return pmsCiPipelinesService.selectPmsCiPipelinesCardList(enterpriseIdentifier, pipelineName, pipelineType);
}
/**
* 获取流水线详细信息
*/

View File

@ -0,0 +1,53 @@
package com.microservices.pms.pipeline.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 流水线卡片执行详情对象
*
* @author xxq
* @date 2025-01-23
*/
@Data
@ApiModel("流水线卡片执行详情对象")
public class PmsCiPipelinesCardRunVo {
@ApiModelProperty(value = "名称")
private String name;
@ApiModelProperty(value = "总执行数量")
private Long total;
@ApiModelProperty(value = "成功执行数量")
private Long success;
@ApiModelProperty(value = "失败执行数量")
private Long failure;
@ApiModelProperty(value = "是否定时任务")
private Boolean schedule;
@ApiModelProperty(value = "执行状态")
private Long status;
@ApiModelProperty(value = "开始时间")
private Long started;
@ApiModelProperty(value = "结束时间")
private Long stopped;
@ApiModelProperty(value = "执行时长")
private Long length;
@ApiModelProperty(value = "创建时间")
private Long created;
@ApiModelProperty(value = "更新时间")
private Long updated;
}

View File

@ -0,0 +1,43 @@
package com.microservices.pms.pipeline.domain.vo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* 流水线卡片详情对象 pms_ci_pipelines
*
* @author xxq
* @date 2025-01-23
*/
@Data
@ApiModel("流水线卡片详情对象")
public class PmsCiPipelinesCardVo {
private Long id;
/**
* 仓库owner
*/
@ApiModelProperty(value = "仓库owner")
private String owner;
/**
* 仓库标识
*/
@ApiModelProperty(value = "仓库标识")
private String repoIdentifier;
@ApiModelProperty(value = "仓库名")
private String repoName;
@ApiModelProperty(value = "url")
private String url;
@ApiModelProperty(value = "流水线列表")
private List<PmsCiPipelinesDetailVo> pipelinesList;
}

View File

@ -77,4 +77,6 @@ public class PmsCiPipelinesDetailVo
@ApiModelProperty(value = "流水线模板JSON")
private JSONObject pipelineTemplateJson;
@ApiModelProperty(value = "流水线执行详情")
private PmsCiPipelinesCardRunVo pmsCiPipelinesCardRunVo;
}

View File

@ -30,6 +30,7 @@ public interface PmsCiPipelinesMapper
* @return 流水线集合
*/
public List<PmsCiPipelines> selectPmsCiPipelinesList(PmsCiPipelines pmsCiPipelines);
public List<PmsCiPipelines> selectPmsCiPipelinesCardList(PmsCiPipelines pmsCiPipelines);
/**
* 新增流水线

View File

@ -32,6 +32,7 @@ public interface IPmsCiPipelinesService
* @return 流水线集合
*/
public GenericsTableDataInfo<PmsCiPipelinesDetailVo> selectPmsCiPipelinesList(String enterpriseIdentifier, String pipelineName, Integer pipelineType);
public GenericsTableDataInfo<PmsCiPipelinesCardVo> selectPmsCiPipelinesCardList(String enterpriseIdentifier, String pipelineName, Integer pipelineType);
/**
* 新增流水线

View File

@ -1,15 +1,12 @@
package com.microservices.pms.pipeline.service.impl;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.DateUtils;
import com.microservices.common.core.utils.StringUtils;
import com.microservices.common.core.utils.YamlValidatorUtils;
import com.microservices.common.core.utils.html.EscapeUtil;
import com.microservices.common.core.web.page.GenericsTableDataInfo;
import com.microservices.common.httpClient.domain.EntryDto;
import com.microservices.common.httpClient.domain.FileEntryDto;
@ -19,21 +16,26 @@ import com.microservices.pms.common.service.IPmsCommonService;
import com.microservices.pms.enterprise.domain.PmsEnterprise;
import com.microservices.pms.enterprise.service.IPmsEnterpriseService;
import com.microservices.pms.pipeline.domain.PmsCiPipelineGraphics;
import com.microservices.pms.pipeline.domain.PmsCiPipelines;
import com.microservices.pms.pipeline.domain.vo.*;
import com.microservices.pms.pipeline.mapper.PmsCiPipelinesMapper;
import com.microservices.pms.pipeline.service.IPmsCiPipelineGraphicsService;
import com.microservices.pms.utils.PmsConstants;
import com.microservices.pms.pipeline.service.IPmsCiPipelinesService;
import com.microservices.pms.utils.PmsGitLinkRequestUrl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.microservices.pms.pipeline.mapper.PmsCiPipelinesMapper;
import com.microservices.pms.pipeline.domain.PmsCiPipelines;
import com.microservices.pms.pipeline.service.IPmsCiPipelinesService;
import org.springframework.transaction.annotation.Transactional;
import javax.servlet.http.HttpServletResponse;
import java.net.URISyntaxException;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import static com.microservices.common.core.utils.JSONUtils.convertObjectToJSONObject;
import static com.microservices.common.core.utils.PageUtils.startPage;
@ -104,6 +106,28 @@ public class PmsCiPipelinesServiceImpl implements IPmsCiPipelinesService {
return toPage(pipelinesList, this::buildPmsCiPipelinesDetailVo);
}
/**
* 查询流水线卡片列表
*
* @param enterpriseIdentifier 企业标识
* @param pipelineName 流水线名
* @param pipelineType
* @return 流水线
*/
@Override
public GenericsTableDataInfo<PmsCiPipelinesCardVo> selectPmsCiPipelinesCardList(String enterpriseIdentifier, String pipelineName, Integer pipelineType) {
PmsEnterprise pmsEnterprise = pmsEnterpriseService.selectPmsEnterpriseByIdentifier(enterpriseIdentifier);
PmsCiPipelines pmsCiPipelines = new PmsCiPipelines();
pmsCiPipelines.setPipelineName(pipelineName);
pmsCiPipelines.setPmsEnterpriseId(pmsEnterprise.getId());
pmsCiPipelines.setPipelineType(pipelineType);
startPage();
List<PmsCiPipelines> pipelinesList = pmsCiPipelinesMapper.selectPmsCiPipelinesCardList(pmsCiPipelines);
String workflows = Optional.ofNullable(pipelinesList).orElse(Collections.emptyList()).stream().map(PmsCiPipelines::getFileName).collect(Collectors.joining(","));
List<PmsCiPipelinesCardRunVo> result = gitLinkRequestHelper.doGetToObjectList(PmsGitLinkRequestUrl.GET_ACTION_RUN_DATA(pmsCiPipelines.getOwner(), workflows), PmsCiPipelinesCardRunVo.class);
return toPage(pipelinesList, x -> this.buildPmsCiPipelinesCardDetailVo(x, result));
}
private PmsCiPipelinesDetailVo buildPmsCiPipelinesDetailVo(PmsCiPipelines pmsCiPipelines) {
PmsCiPipelinesDetailVo pmsCiPipelinesDetailVo = new PmsCiPipelinesDetailVo();
BeanUtils.copyProperties(pmsCiPipelines, pmsCiPipelinesDetailVo);
@ -111,6 +135,20 @@ public class PmsCiPipelinesServiceImpl implements IPmsCiPipelinesService {
return pmsCiPipelinesDetailVo;
}
private PmsCiPipelinesCardVo buildPmsCiPipelinesCardDetailVo(PmsCiPipelines pmsCiPipelines, List<PmsCiPipelinesCardRunVo> result) {
PmsCiPipelinesCardVo pmsCiPipelinesCardVo = new PmsCiPipelinesCardVo();
BeanUtils.copyProperties(pmsCiPipelines, pmsCiPipelinesCardVo);
pmsCiPipelinesCardVo.setUrl(EscapeUtil.removeExtraSlashOfUrl(gitLinkRequestHelper.gitLinkUrl + "/" + pmsCiPipelines.getOwner() + "/" + pmsCiPipelines.getRepoIdentifier()));
PmsCiPipelines queryCiPipelines = new PmsCiPipelines();
queryCiPipelines.setRepoIdentifier(pmsCiPipelines.getRepoIdentifier());
queryCiPipelines.setOwner(pmsCiPipelines.getOwner());
queryCiPipelines.setPmsEnterpriseId(pmsCiPipelines.getPmsEnterpriseId());
List<PmsCiPipelines> pipelinesList = pmsCiPipelinesMapper.selectPmsCiPipelinesCardList(queryCiPipelines);
pmsCiPipelinesCardVo.setPipelinesList(Optional.ofNullable(pipelinesList).orElse(Collections.emptyList()).stream().map(this::buildPmsCiPipelinesDetailVo).collect(Collectors.toList()));
pmsCiPipelinesCardVo.getPipelinesList().forEach(x -> x.setPmsCiPipelinesCardRunVo(result.stream().filter(a -> a.getName().equals(x.getFileName())).findFirst().orElse(null)));
return pmsCiPipelinesCardVo;
}
/**
* 新增流水线
*

View File

@ -395,4 +395,45 @@ public class PmsGitLinkRequestUrl extends GitLinkRequestUrl {
public static GitLinkRequestUrl GET_PIPELINE_RUN_RESULTS(String owner, String repoIdentifier, String run){
return getGitLinkRequestUrl(String.format("/api/v1/%s/%s/pipelines/run_results.json?run_id=%s", owner, repoIdentifier, run));
}
public static GitLinkRequestUrl GET_ACTION_NODES(String keyword, Integer pageNum, Integer pageSize) {
String path = String.format("/api/action/nodes.json?search=%s", keyword);
if (pageNum != null && pageSize != null) {
path = path + String.format("&page=%s&limit=%s", pageNum, pageSize);
}
return getGitLinkRequestUrl(path);
}
public static GitLinkRequestUrl CREATE_ACTION_NODE(Long actionNodeId) {
return getGitLinkRequestUrl(String.format("api/action/nodes/%s", actionNodeId));
}
public static GitLinkRequestUrl GET_ACTION_NODE_TYPES(String keyword, Integer pageNum, Integer pageSize){
String path = String.format("/api/action/nodes.json?search=%s", keyword);
if (pageNum != null && pageSize != null) {
path = path + String.format("&page=%s&limit=%s", pageNum, pageSize);
}
return getGitLinkRequestUrl(path);
}
public static GitLinkRequestUrl CREATE_ACTION_NODE_TYPE(Long actionNodeTypeId) {
return getGitLinkRequestUrl(String.format("api/action/node_types/%s", actionNodeTypeId));
}
public static GitLinkRequestUrl GET_ACTION_TEMPLATES(String keyword, Integer pageNum, Integer pageSize){
String path = String.format("/api/action/templates.json?search=%s", keyword);
if (pageNum != null && pageSize != null) {
path = path + String.format("&page=%s&limit=%s", pageNum, pageSize);
}
return getGitLinkRequestUrl(path);
}
public static GitLinkRequestUrl CREATE_ACTION_TEMPLATE(Long actionTemplateId) {
return getGitLinkRequestUrl(String.format("api/action/action_templates/%s", actionTemplateId));
}
public static GitLinkRequestUrl GET_ACTION_RUN_DATA(String owner, String workflows) {
return getGitLinkRequestUrl(String.format("api/pm/action_runs?owner_id=%s&workflows=%s", owner, workflows));
}
}

View File

@ -55,6 +55,30 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
${params.dataScope}
</where>
</select>
<select id="selectPmsCiPipelinesCardList" parameterType="PmsCiPipelines" resultMap="PmsCiPipelinesResult">
select owner,repo_identifier,repo_name,pms_enterprise_id
<where>
<if test="pipelineName != null and pipelineName != ''"> and pipeline_name like concat('%', #{pipelineName}, '%')</if>
<if test="pipelineStatus != null and pipelineStatus != ''"> and pipeline_status = #{pipelineStatus}</if>
<if test="fileName != null and fileName != ''"> and file_name like concat('%', #{fileName}, '%')</if>
<if test="login != null and login != ''"> and login = #{login}</if>
<if test="sync != null "> and sync = #{sync}</if>
<if test="repoName != null and repoName != ''"> and repo_name = #{repoName}</if>
<if test="repoIdentifier != null and repoIdentifier != ''"> and repo_identifier = #{repoIdentifier}</if>
<if test="branch != null and branch != ''"> and branch = #{branch}</if>
<if test="pipelineType != null"> and pipeline_type = #{pipelineType}</if>
<if test="event != null and event != ''"> and event = #{event}</if>
<if test="sha != null and sha != ''"> and sha = #{sha}</if>
<if test="owner != null and owner != ''"> and owner = #{owner}</if>
<if test="deptId != null "> and dept_id = #{deptId}</if>
<if test="pmsEnterpriseId != null "> and pms_enterprise_id = #{pmsEnterpriseId}</if>
<if test="pmsProjectId != null "> and pms_project_id = #{pmsProjectId}</if>
<!-- 数据范围过滤 -->
${params.dataScope}
</where>
GROUP BY owner,repo_identifier,repo_name
</select>
<select id="selectPmsCiPipelinesById" parameterType="Long" resultMap="PmsCiPipelinesResult">
<include refid="selectPmsCiPipelinesVo"/>