打印了JENKINS节点日志

This commit is contained in:
dengqichen 2025-11-10 09:49:41 +08:00
parent e8f6102067
commit d0f2e78ee7
5 changed files with 98 additions and 7 deletions

View File

@ -29,6 +29,9 @@ public class TeamApplicationDTO extends BaseDTO {
@Schema(description = "部署系统IDJenkins系统") @Schema(description = "部署系统IDJenkins系统")
private Long deploySystemId; private Long deploySystemId;
@Schema(description = "部署系统名称")
private String deploySystemName;
@Schema(description = "部署任务IDJenkins Job") @Schema(description = "部署任务IDJenkins Job")
private String deployJob; private String deployJob;

View File

@ -45,4 +45,12 @@ public interface IRepositoryGroupRepository extends IBaseRepository<RepositoryGr
* 根据Git系统组ID外部系统ID查询仓库组 * 根据Git系统组ID外部系统ID查询仓库组
*/ */
Optional<RepositoryGroup> findByRepoGroupIdAndExternalSystemIdAndDeletedFalse(Long repoGroupId, Long externalSystemId); Optional<RepositoryGroup> findByRepoGroupIdAndExternalSystemIdAndDeletedFalse(Long repoGroupId, Long externalSystemId);
/**
* 根据Git系统组ID列表批量查询仓库组用于填充扩展字段
*
* @param repoGroupIds Git系统组ID列表
* @return 仓库组列表
*/
List<RepositoryGroup> findByRepoGroupIdIn(List<Long> repoGroupIds);
} }

View File

@ -324,20 +324,21 @@ public class RepositoryProjectServiceImpl extends BaseServiceImpl<RepositoryProj
return; return;
} }
// 1. 收集所有仓库组ID // 1. 收集所有仓库组 repo_group_idGit系统的组ID不是数据库主键
Set<Long> repoGroupIds = projects.stream() Set<Long> repoGroupIds = projects.stream()
.map(RepositoryProjectDTO::getRepoGroupId) .map(RepositoryProjectDTO::getRepoGroupId)
.filter(id -> id != null) .filter(id -> id != null)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
// 2. 批量查询仓库组信息 // 2. 批量查询仓库组信息根据 repo_group_id 字段查询不是主键 id
Map<Long, RepositoryGroup> repoGroupMap = Collections.emptyMap(); Map<Long, RepositoryGroup> repoGroupMap = Collections.emptyMap();
if (!repoGroupIds.isEmpty()) { if (!repoGroupIds.isEmpty()) {
repoGroupMap = repositoryGroupRepository.findAllById(repoGroupIds).stream() List<Long> repoGroupIdList = new ArrayList<>(repoGroupIds);
.collect(Collectors.toMap(RepositoryGroup::getId, Function.identity())); repoGroupMap = repositoryGroupRepository.findByRepoGroupIdIn(repoGroupIdList).stream()
.collect(Collectors.toMap(RepositoryGroup::getRepoGroupId, Function.identity()));
} }
// 3. 填充仓库组名称 // 3. 填充仓库组名称使用 repo_group_id 作为 key
Map<Long, RepositoryGroup> finalRepoGroupMap = repoGroupMap; Map<Long, RepositoryGroup> finalRepoGroupMap = repoGroupMap;
projects.forEach(project -> { projects.forEach(project -> {
if (project.getRepoGroupId() != null) { if (project.getRepoGroupId() != null) {

View File

@ -8,7 +8,9 @@ import com.qqchen.deploy.backend.deploy.entity.Environment;
import com.qqchen.deploy.backend.deploy.entity.Team; import com.qqchen.deploy.backend.deploy.entity.Team;
import com.qqchen.deploy.backend.deploy.entity.TeamApplication; import com.qqchen.deploy.backend.deploy.entity.TeamApplication;
import com.qqchen.deploy.backend.deploy.query.TeamApplicationQuery; import com.qqchen.deploy.backend.deploy.query.TeamApplicationQuery;
import com.qqchen.deploy.backend.deploy.entity.ExternalSystem;
import com.qqchen.deploy.backend.deploy.repository.IApplicationRepository; import com.qqchen.deploy.backend.deploy.repository.IApplicationRepository;
import com.qqchen.deploy.backend.deploy.repository.IExternalSystemRepository;
import com.qqchen.deploy.backend.deploy.repository.IDeployRecordRepository; import com.qqchen.deploy.backend.deploy.repository.IDeployRecordRepository;
import com.qqchen.deploy.backend.deploy.repository.IEnvironmentRepository; import com.qqchen.deploy.backend.deploy.repository.IEnvironmentRepository;
import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository; import com.qqchen.deploy.backend.deploy.repository.ITeamApplicationRepository;
@ -51,6 +53,9 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
@Resource @Resource
private IWorkflowDefinitionRepository workflowDefinitionRepository; private IWorkflowDefinitionRepository workflowDefinitionRepository;
@Resource
private IExternalSystemRepository externalSystemRepository;
@Resource @Resource
private TeamApplicationConverter teamApplicationConverter; private TeamApplicationConverter teamApplicationConverter;
@ -80,7 +85,7 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
} }
/** /**
* 批量填充扩展字段teamNameapplicationNameapplicationCodeenvironmentName * 批量填充扩展字段teamNameapplicationNameapplicationCodeenvironmentNameworkflowDefinitionNamedeploySystemName
* *
* <p>使用批量查询避免N+1问题 * <p>使用批量查询避免N+1问题
*/ */
@ -110,6 +115,11 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
.filter(Objects::nonNull) .filter(Objects::nonNull)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
Set<Long> deploySystemIds = teamApps.stream()
.map(TeamApplicationDTO::getDeploySystemId)
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// 2. 批量查询团队信息 // 2. 批量查询团队信息
Map<Long, Team> teamMap = new HashMap<>(); Map<Long, Team> teamMap = new HashMap<>();
if (!teamIds.isEmpty()) { if (!teamIds.isEmpty()) {
@ -142,7 +152,15 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
); );
} }
// 6. 填充扩展字段 // 6. 批量查询外部系统信息
Map<Long, ExternalSystem> externalSystemMap = new HashMap<>();
if (!deploySystemIds.isEmpty()) {
externalSystemRepository.findAllById(deploySystemIds).forEach(system ->
externalSystemMap.put(system.getId(), system)
);
}
// 7. 填充扩展字段
teamApps.forEach(teamApp -> { teamApps.forEach(teamApp -> {
// 填充团队名称 // 填充团队名称
if (teamApp.getTeamId() != null) { if (teamApp.getTeamId() != null) {
@ -176,6 +194,14 @@ public class TeamApplicationServiceImpl extends BaseServiceImpl<TeamApplication,
teamApp.setWorkflowDefinitionName(workflow.getName()); teamApp.setWorkflowDefinitionName(workflow.getName());
} }
} }
// 填充部署系统名称
if (teamApp.getDeploySystemId() != null) {
ExternalSystem system = externalSystemMap.get(teamApp.getDeploySystemId());
if (system != null) {
teamApp.setDeploySystemName(system.getName());
}
}
}); });
} }

View File

@ -0,0 +1,53 @@
package com.qqchen.deploy.backend.workflow.dto;
import com.qqchen.deploy.backend.workflow.enums.LogLevel;
import com.qqchen.deploy.backend.workflow.enums.LogSource;
import lombok.Data;
/**
* 工作流节点日志 DTO
* <p>
* 日志存储在 Redis Stream 不再使用 MySQL此类仅用于数据传输
*
* @author qqchen
* @since 2025-11-03
*/
@Data
public class WorkflowNodeLogDTO {
/**
* 流程实例IDFlowable processInstanceId
*/
private String processInstanceId;
/**
* 节点IDFlowable nodeId, 例如: sid_xxx
*/
private String nodeId;
/**
* 日志序号保证同一节点内日志有序从1开始递增
*/
private Long sequenceId;
/**
* 时间戳Unix毫秒
*/
private Long timestamp;
/**
* 日志级别INFO, WARN, ERROR, DEBUG
*/
private LogLevel level;
/**
* 日志来源JENKINS, FLOWABLE, SHELL, NOTIFICATION
*/
private LogSource source;
/**
* 日志内容
*/
private String message;
}