打印了JENKINS节点日志
This commit is contained in:
parent
63e0df6085
commit
8712f199a1
@ -173,10 +173,6 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
// 7. 批量查询所有团队的应用配置
|
// 7. 批量查询所有团队的应用配置
|
||||||
List<TeamApplication> allTeamApps = teamApplicationRepository.findByTeamIdIn(teamIds);
|
List<TeamApplication> allTeamApps = teamApplicationRepository.findByTeamIdIn(teamIds);
|
||||||
if (allTeamApps.isEmpty()) {
|
|
||||||
log.debug("团队 {} 未配置任何应用", teamIds);
|
|
||||||
return Collections.emptyList();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 8. 提取所有需要的ID集合
|
// 8. 提取所有需要的ID集合
|
||||||
Set<Long> allEnvIds = new HashSet<>();
|
Set<Long> allEnvIds = new HashSet<>();
|
||||||
@ -201,7 +197,20 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
Map<Long, List<TeamApplication>> teamAppsMap = allTeamApps.stream()
|
Map<Long, List<TeamApplication>> teamAppsMap = allTeamApps.stream()
|
||||||
.collect(groupingBy(TeamApplication::getTeamId));
|
.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()
|
Map<Long, Environment> envMap = environmentRepository.findAllById(allEnvIds).stream()
|
||||||
.collect(toMap(Environment::getId, e -> e));
|
.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))
|
? workflowDefinitionRepository.findAllById(workflowIds).stream().collect(toMap(WorkflowDefinition::getId, w -> w))
|
||||||
: Collections.emptyMap();
|
: Collections.emptyMap();
|
||||||
|
|
||||||
// 14. 批量查询团队环境配置
|
// 14. 批量查询审批人信息
|
||||||
List<TeamEnvironmentConfig> teamEnvConfigs = teamEnvironmentConfigRepository.findByTeamIdIn(teamIds);
|
|
||||||
Map<String, TeamEnvironmentConfig> teamEnvConfigMap = teamEnvConfigs.stream()
|
|
||||||
.collect(toMap(c -> c.getTeamId() + "_" + c.getEnvironmentId(), c -> c));
|
|
||||||
|
|
||||||
// 15. 批量查询审批人信息
|
|
||||||
Set<Long> approverUserIds = teamEnvConfigs.stream()
|
Set<Long> approverUserIds = teamEnvConfigs.stream()
|
||||||
.filter(c -> c.getApproverUserIds() != null)
|
.filter(c -> c.getApproverUserIds() != null)
|
||||||
.flatMap(c -> c.getApproverUserIds().stream())
|
.flatMap(c -> c.getApproverUserIds().stream())
|
||||||
@ -234,12 +238,12 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
? userRepository.findAllById(approverUserIds).stream().collect(toMap(User::getId, u -> u))
|
? userRepository.findAllById(approverUserIds).stream().collect(toMap(User::getId, u -> u))
|
||||||
: Collections.emptyMap();
|
: Collections.emptyMap();
|
||||||
|
|
||||||
// 16. 批量查询动态数据(部署统计、最近记录)
|
// 15. 批量查询动态数据(部署统计、最近记录)
|
||||||
Map<Long, DeployStatisticsDTO> statisticsMap = queryDeployStatistics(teamApplicationIds);
|
Map<Long, DeployStatisticsDTO> statisticsMap = queryDeployStatistics(teamApplicationIds);
|
||||||
Map<Long, DeployRecord> latestRecordMap = queryLatestRecords(teamApplicationIds);
|
Map<Long, DeployRecord> latestRecordMap = queryLatestRecords(teamApplicationIds);
|
||||||
Map<Long, List<DeployRecordSummaryDTO>> recentRecordsMap = queryRecentRecords(teamApplicationIds);
|
Map<Long, List<DeployRecordSummaryDTO>> recentRecordsMap = queryRecentRecords(teamApplicationIds);
|
||||||
|
|
||||||
// 17. 为每个团队组装完整数据
|
// 16. 为每个团队组装完整数据
|
||||||
List<UserTeamDeployableDTO> result = new ArrayList<>();
|
List<UserTeamDeployableDTO> result = new ArrayList<>();
|
||||||
for (Long teamId : teamIds) {
|
for (Long teamId : teamIds) {
|
||||||
UserTeamDeployableDTO teamDTO = buildUserTeamDeployableDTO(
|
UserTeamDeployableDTO teamDTO = buildUserTeamDeployableDTO(
|
||||||
@ -323,12 +327,13 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
// 构建环境列表
|
// 构建环境列表
|
||||||
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
|
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
|
||||||
|
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
|
||||||
|
|
||||||
if (teamApps != null && !teamApps.isEmpty()) {
|
if (teamApps != null && !teamApps.isEmpty()) {
|
||||||
// 按环境分组
|
// 有应用配置:按环境分组
|
||||||
Map<Long, List<TeamApplication>> appsByEnv = teamApps.stream()
|
Map<Long, List<TeamApplication>> appsByEnv = teamApps.stream()
|
||||||
.collect(groupingBy(TeamApplication::getEnvironmentId));
|
.collect(groupingBy(TeamApplication::getEnvironmentId));
|
||||||
|
|
||||||
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
|
|
||||||
for (Map.Entry<Long, List<TeamApplication>> entry : appsByEnv.entrySet()) {
|
for (Map.Entry<Long, List<TeamApplication>> entry : appsByEnv.entrySet()) {
|
||||||
Long envId = entry.getKey();
|
Long envId = entry.getKey();
|
||||||
Environment env = envMap.get(envId);
|
Environment env = envMap.get(envId);
|
||||||
@ -345,13 +350,23 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
);
|
);
|
||||||
environments.add(envDTO);
|
environments.add(envDTO);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// 没有应用配置:显示所有可用环境,但应用列表为空
|
||||||
|
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排序
|
// 按sort排序
|
||||||
environments.sort(Comparator.comparingInt(e -> e.getSort() != null ? e.getSort() : Integer.MAX_VALUE));
|
environments.sort(Comparator.comparingInt(e -> e.getSort() != null ? e.getSort() : Integer.MAX_VALUE));
|
||||||
dto.setEnvironments(environments);
|
dto.setEnvironments(environments);
|
||||||
} else {
|
|
||||||
dto.setEnvironments(Collections.emptyList());
|
|
||||||
}
|
|
||||||
|
|
||||||
return dto;
|
return dto;
|
||||||
}
|
}
|
||||||
@ -386,13 +401,15 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
String configKey = teamId + "_" + env.getId();
|
String configKey = teamId + "_" + env.getId();
|
||||||
TeamEnvironmentConfig config = teamEnvConfigMap.get(configKey);
|
TeamEnvironmentConfig config = teamEnvConfigMap.get(configKey);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
dto.setRequiresApproval(config.getApprovalRequired() != null ? config.getApprovalRequired() : false);
|
boolean requiresApproval = config.getApprovalRequired() != null ? config.getApprovalRequired() : false;
|
||||||
dto.setRequireCodeReview(config.getRequireCodeReview() != null ? config.getRequireCodeReview() : false);
|
boolean notificationEnabled = config.getNotificationEnabled() != null ? config.getNotificationEnabled() : true;
|
||||||
dto.setNotificationEnabled(config.getNotificationEnabled() != null ? config.getNotificationEnabled() : true);
|
|
||||||
dto.setNotificationChannelId(config.getNotificationChannelId());
|
|
||||||
|
|
||||||
// 设置审批人列表
|
dto.setRequiresApproval(requiresApproval);
|
||||||
if (config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
|
dto.setRequireCodeReview(config.getRequireCodeReview() != null ? config.getRequireCodeReview() : false);
|
||||||
|
dto.setNotificationEnabled(notificationEnabled);
|
||||||
|
|
||||||
|
// 兜底逻辑:只有需要审批时才返回审批人列表
|
||||||
|
if (requiresApproval && config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
|
||||||
List<UserDeployableTeamEnvironmentApproverDTO> approvers = config.getApproverUserIds().stream()
|
List<UserDeployableTeamEnvironmentApproverDTO> approvers = config.getApproverUserIds().stream()
|
||||||
.map(userId -> {
|
.map(userId -> {
|
||||||
User user = approverMap.get(userId);
|
User user = approverMap.get(userId);
|
||||||
@ -411,6 +428,13 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
} else {
|
} else {
|
||||||
dto.setApprovers(Collections.emptyList());
|
dto.setApprovers(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 兜底逻辑:只有启用通知时才返回通知渠道ID
|
||||||
|
if (notificationEnabled) {
|
||||||
|
dto.setNotificationChannelId(config.getNotificationChannelId());
|
||||||
|
} else {
|
||||||
|
dto.setNotificationChannelId(null);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
dto.setRequiresApproval(false);
|
dto.setRequiresApproval(false);
|
||||||
dto.setRequireCodeReview(false);
|
dto.setRequireCodeReview(false);
|
||||||
|
|||||||
@ -86,6 +86,68 @@ public class TeamEnvironmentConfigServiceImpl
|
|||||||
return list;
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量填充扩展字段:environmentName、notificationChannelName、applicationCount
|
* 批量填充扩展字段:environmentName、notificationChannelName、applicationCount
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user