打印了JENKINS节点日志

This commit is contained in:
dengqichen 2025-11-11 10:56:00 +08:00
parent 63e0df6085
commit 8712f199a1
3 changed files with 114 additions and 28 deletions

View File

@ -27,4 +27,4 @@ public interface IEnvironmentRepository extends IBaseRepository<Environment, Lon
nativeQuery = true)
Integer countByProjectGroupId(@Param("projectGroupId") Long projectGroupId);
}
}

View File

@ -173,11 +173,7 @@ public class DeployServiceImpl implements IDeployService {
// 7. 批量查询所有团队的应用配置
List<TeamApplication> allTeamApps = teamApplicationRepository.findByTeamIdIn(teamIds);
if (allTeamApps.isEmpty()) {
log.debug("团队 {} 未配置任何应用", teamIds);
return Collections.emptyList();
}
// 8. 提取所有需要的ID集合
Set<Long> allEnvIds = new HashSet<>();
Set<Long> appIds = new HashSet<>();
@ -201,7 +197,20 @@ public class DeployServiceImpl implements IDeployService {
Map<Long, List<TeamApplication>> teamAppsMap = allTeamApps.stream()
.collect(groupingBy(TeamApplication::getTeamId));
// 10. 批量查询环境信息
// 10. 批量查询团队环境配置获取团队配置的环境
List<TeamEnvironmentConfig> teamEnvConfigs = teamEnvironmentConfigRepository.findByTeamIdIn(teamIds);
Map<String, TeamEnvironmentConfig> teamEnvConfigMap = teamEnvConfigs.stream()
.collect(toMap(c -> c.getTeamId() + "_" + c.getEnvironmentId(), c -> c));
// 从团队环境配置中提取环境ID
Set<Long> teamConfiguredEnvIds = teamEnvConfigs.stream()
.map(TeamEnvironmentConfig::getEnvironmentId)
.collect(Collectors.toSet());
// 合并应用配置中的环境ID和团队配置的环境ID
allEnvIds.addAll(teamConfiguredEnvIds);
// 批量查询环境信息
Map<Long, Environment> envMap = environmentRepository.findAllById(allEnvIds).stream()
.collect(toMap(Environment::getId, e -> e));
@ -220,12 +229,7 @@ public class DeployServiceImpl implements IDeployService {
? workflowDefinitionRepository.findAllById(workflowIds).stream().collect(toMap(WorkflowDefinition::getId, w -> w))
: Collections.emptyMap();
// 14. 批量查询团队环境配置
List<TeamEnvironmentConfig> teamEnvConfigs = teamEnvironmentConfigRepository.findByTeamIdIn(teamIds);
Map<String, TeamEnvironmentConfig> teamEnvConfigMap = teamEnvConfigs.stream()
.collect(toMap(c -> c.getTeamId() + "_" + c.getEnvironmentId(), c -> c));
// 15. 批量查询审批人信息
// 14. 批量查询审批人信息
Set<Long> approverUserIds = teamEnvConfigs.stream()
.filter(c -> c.getApproverUserIds() != null)
.flatMap(c -> c.getApproverUserIds().stream())
@ -234,12 +238,12 @@ public class DeployServiceImpl implements IDeployService {
? userRepository.findAllById(approverUserIds).stream().collect(toMap(User::getId, u -> u))
: Collections.emptyMap();
// 16. 批量查询动态数据部署统计最近记录
// 15. 批量查询动态数据部署统计最近记录
Map<Long, DeployStatisticsDTO> statisticsMap = queryDeployStatistics(teamApplicationIds);
Map<Long, DeployRecord> latestRecordMap = queryLatestRecords(teamApplicationIds);
Map<Long, List<DeployRecordSummaryDTO>> recentRecordsMap = queryRecentRecords(teamApplicationIds);
// 17. 为每个团队组装完整数据
// 16. 为每个团队组装完整数据
List<UserTeamDeployableDTO> result = new ArrayList<>();
for (Long teamId : teamIds) {
UserTeamDeployableDTO teamDTO = buildUserTeamDeployableDTO(
@ -323,12 +327,13 @@ public class DeployServiceImpl implements IDeployService {
// 构建环境列表
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
if (teamApps != null && !teamApps.isEmpty()) {
// 按环境分组
// 有应用配置按环境分组
Map<Long, List<TeamApplication>> appsByEnv = teamApps.stream()
.collect(groupingBy(TeamApplication::getEnvironmentId));
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
for (Map.Entry<Long, List<TeamApplication>> entry : appsByEnv.entrySet()) {
Long envId = entry.getKey();
Environment env = envMap.get(envId);
@ -345,14 +350,24 @@ public class DeployServiceImpl implements IDeployService {
);
environments.add(envDTO);
}
// 按sort排序
environments.sort(Comparator.comparingInt(e -> e.getSort() != null ? e.getSort() : Integer.MAX_VALUE));
dto.setEnvironments(environments);
} else {
dto.setEnvironments(Collections.emptyList());
// 没有应用配置显示所有可用环境但应用列表为空
for (Environment env : envMap.values()) {
UserDeployableTeamEnvironmentDTO envDTO = buildUserDeployableTeamEnvironmentDTO(
currentUserId, team.getOwnerId(),
teamId, env, Collections.emptyList(), // 空的应用列表
appMap, systemMap, workflowMap,
teamEnvConfigMap, approverMap,
statisticsMap, latestRecordMap, recentRecordsMap
);
environments.add(envDTO);
}
}
// 按sort排序
environments.sort(Comparator.comparingInt(e -> e.getSort() != null ? e.getSort() : Integer.MAX_VALUE));
dto.setEnvironments(environments);
return dto;
}
@ -386,13 +401,15 @@ public class DeployServiceImpl implements IDeployService {
String configKey = teamId + "_" + env.getId();
TeamEnvironmentConfig config = teamEnvConfigMap.get(configKey);
if (config != null) {
dto.setRequiresApproval(config.getApprovalRequired() != null ? config.getApprovalRequired() : false);
boolean requiresApproval = config.getApprovalRequired() != null ? config.getApprovalRequired() : false;
boolean notificationEnabled = config.getNotificationEnabled() != null ? config.getNotificationEnabled() : true;
dto.setRequiresApproval(requiresApproval);
dto.setRequireCodeReview(config.getRequireCodeReview() != null ? config.getRequireCodeReview() : false);
dto.setNotificationEnabled(config.getNotificationEnabled() != null ? config.getNotificationEnabled() : true);
dto.setNotificationChannelId(config.getNotificationChannelId());
// 设置审批人列表
if (config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
dto.setNotificationEnabled(notificationEnabled);
// 兜底逻辑只有需要审批时才返回审批人列表
if (requiresApproval && config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
List<UserDeployableTeamEnvironmentApproverDTO> approvers = config.getApproverUserIds().stream()
.map(userId -> {
User user = approverMap.get(userId);
@ -411,6 +428,13 @@ public class DeployServiceImpl implements IDeployService {
} else {
dto.setApprovers(Collections.emptyList());
}
// 兜底逻辑只有启用通知时才返回通知渠道ID
if (notificationEnabled) {
dto.setNotificationChannelId(config.getNotificationChannelId());
} else {
dto.setNotificationChannelId(null);
}
} else {
dto.setRequiresApproval(false);
dto.setRequireCodeReview(false);

View File

@ -86,6 +86,68 @@ public class TeamEnvironmentConfigServiceImpl
return list;
}
/**
* 重写创建方法添加数据一致性兜底逻辑
*/
@Override
@Transactional(rollbackFor = Exception.class)
public TeamEnvironmentConfigDTO create(TeamEnvironmentConfigDTO dto) {
// 执行兜底逻辑确保数据一致性
applyDataConsistencyRules(dto);
return super.create(dto);
}
/**
* 重写更新方法添加数据一致性兜底逻辑
*/
@Override
@Transactional(rollbackFor = Exception.class)
public TeamEnvironmentConfigDTO update(Long id, TeamEnvironmentConfigDTO dto) {
// 执行兜底逻辑确保数据一致性
applyDataConsistencyRules(dto);
return super.update(id, dto);
}
/**
* 数据一致性兜底逻辑
* <p>规则
* <ul>
* <li>1. 如果不需要审批approvalRequired = false清空审批人列表</li>
* <li>2. 如果不需要通知notificationEnabled = false清空通知渠道</li>
* <li>3. 如果不需要代码审查requireCodeReview = false清空代码审查相关配置</li>
* </ul>
*/
private void applyDataConsistencyRules(TeamEnvironmentConfigDTO dto) {
if (dto == null) {
return;
}
// 规则1不需要审批时清空审批人
if (dto.getApprovalRequired() != null && !dto.getApprovalRequired()) {
if (dto.getApproverUserIds() != null && !dto.getApproverUserIds().isEmpty()) {
log.info("兜底逻辑触发:团队 {} 环境 {} 不需要审批,清空审批人列表 {}",
dto.getTeamId(), dto.getEnvironmentId(), dto.getApproverUserIds());
dto.setApproverUserIds(null);
}
}
// 规则2不需要通知时清空通知渠道
if (dto.getNotificationEnabled() != null && !dto.getNotificationEnabled()) {
if (dto.getNotificationChannelId() != null) {
log.info("兜底逻辑触发:团队 {} 环境 {} 不需要通知,清空通知渠道 {}",
dto.getTeamId(), dto.getEnvironmentId(), dto.getNotificationChannelId());
dto.setNotificationChannelId(null);
}
}
// 规则3不需要代码审查时清空相关配置如果将来有相关字段
if (dto.getRequireCodeReview() != null && !dto.getRequireCodeReview()) {
// 目前没有代码审查相关的其他配置字段
// 如果将来有 codeReviewerUserIds在这里清空
log.debug("团队 {} 环境 {} 不需要代码审查", dto.getTeamId(), dto.getEnvironmentId());
}
}
/**
* 批量填充扩展字段environmentNamenotificationChannelNameapplicationCount
*