增加构建通知
This commit is contained in:
parent
566425869d
commit
3a7492ac91
@ -6,6 +6,7 @@ import jakarta.validation.constraints.NotBlank;
|
|||||||
import jakarta.validation.constraints.NotNull;
|
import jakarta.validation.constraints.NotNull;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -65,8 +66,11 @@ public class DeployExecuteRequest {
|
|||||||
@Valid
|
@Valid
|
||||||
private NotificationConfig notification;
|
private NotificationConfig notification;
|
||||||
|
|
||||||
|
@Schema(description = "执行时间", required = true)
|
||||||
|
private Date deployDate = new Date();
|
||||||
|
|
||||||
@Schema(description = "部署备注")
|
@Schema(description = "部署备注")
|
||||||
private String remark;
|
private String deployRemark;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jenkins配置
|
* Jenkins配置
|
||||||
@ -106,7 +110,7 @@ public class DeployExecuteRequest {
|
|||||||
@Data
|
@Data
|
||||||
@Schema(description = "通知配置")
|
@Schema(description = "通知配置")
|
||||||
public static class NotificationConfig {
|
public static class NotificationConfig {
|
||||||
|
|
||||||
@Schema(description = "通知渠道ID")
|
@Schema(description = "通知渠道ID")
|
||||||
private Long notificationChannelId;
|
private Long notificationChannelId;
|
||||||
|
|
||||||
|
|||||||
@ -107,7 +107,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private RuntimeService runtimeService;
|
private RuntimeService runtimeService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private IWorkflowNodeLogService workflowNodeLogService;
|
private IWorkflowNodeLogService workflowNodeLogService;
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
// 补充查询作为成员但不是负责人的团队
|
// 补充查询作为成员但不是负责人的团队
|
||||||
Set<Long> missingTeamIds = teamIds.stream()
|
Set<Long> missingTeamIds = teamIds.stream()
|
||||||
.filter(id -> !teamMap.containsKey(id))
|
.filter(id -> !teamMap.containsKey(id))
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
if (!missingTeamIds.isEmpty()) {
|
if (!missingTeamIds.isEmpty()) {
|
||||||
teamRepository.findAllById(missingTeamIds).forEach(team -> teamMap.put(team.getId(), team));
|
teamRepository.findAllById(missingTeamIds).forEach(team -> teamMap.put(team.getId(), team));
|
||||||
}
|
}
|
||||||
@ -191,7 +191,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
// 7. 批量查询所有团队的应用配置
|
// 7. 批量查询所有团队的应用配置
|
||||||
List<TeamApplication> allTeamApps = teamApplicationRepository.findByTeamIdIn(teamIds);
|
List<TeamApplication> allTeamApps = teamApplicationRepository.findByTeamIdIn(teamIds);
|
||||||
|
|
||||||
// 8. 提取所有需要的ID集合
|
// 8. 提取所有需要的ID集合
|
||||||
Set<Long> allEnvIds = new HashSet<>();
|
Set<Long> allEnvIds = new HashSet<>();
|
||||||
Set<Long> appIds = new HashSet<>();
|
Set<Long> appIds = new HashSet<>();
|
||||||
@ -218,16 +218,16 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
// 10. 批量查询团队环境配置(获取团队配置的环境)
|
// 10. 批量查询团队环境配置(获取团队配置的环境)
|
||||||
List<TeamEnvironmentConfig> teamEnvConfigs = teamEnvironmentConfigRepository.findByTeamIdIn(teamIds);
|
List<TeamEnvironmentConfig> teamEnvConfigs = teamEnvironmentConfigRepository.findByTeamIdIn(teamIds);
|
||||||
Map<String, TeamEnvironmentConfig> teamEnvConfigMap = teamEnvConfigs.stream()
|
Map<String, TeamEnvironmentConfig> teamEnvConfigMap = teamEnvConfigs.stream()
|
||||||
.collect(toMap(c -> c.getTeamId() + "_" + c.getEnvironmentId(), c -> c));
|
.collect(toMap(c -> c.getTeamId() + "_" + c.getEnvironmentId(), c -> c));
|
||||||
|
|
||||||
// 从团队环境配置中提取环境ID
|
// 从团队环境配置中提取环境ID
|
||||||
Set<Long> teamConfiguredEnvIds = teamEnvConfigs.stream()
|
Set<Long> teamConfiguredEnvIds = teamEnvConfigs.stream()
|
||||||
.map(TeamEnvironmentConfig::getEnvironmentId)
|
.map(TeamEnvironmentConfig::getEnvironmentId)
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
// 合并应用配置中的环境ID和团队配置的环境ID
|
// 合并应用配置中的环境ID和团队配置的环境ID
|
||||||
allEnvIds.addAll(teamConfiguredEnvIds);
|
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));
|
||||||
@ -291,9 +291,9 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
// 17. 批量查询审批人信息
|
// 17. 批量查询审批人信息
|
||||||
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())
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
Map<Long, User> approverMap = !approverUserIds.isEmpty()
|
Map<Long, User> approverMap = !approverUserIds.isEmpty()
|
||||||
? userRepository.findAllById(approverUserIds).stream().collect(toMap(User::getId, u -> u))
|
? userRepository.findAllById(approverUserIds).stream().collect(toMap(User::getId, u -> u))
|
||||||
: Collections.emptyMap();
|
: Collections.emptyMap();
|
||||||
@ -392,17 +392,17 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
// 构建环境列表
|
// 构建环境列表
|
||||||
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
|
List<TeamApplication> teamApps = teamAppsMap.get(teamId);
|
||||||
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
|
List<UserDeployableTeamEnvironmentDTO> environments = new ArrayList<>();
|
||||||
|
|
||||||
// 按环境分组应用(如果有应用的话)
|
// 按环境分组应用(如果有应用的话)
|
||||||
Map<Long, List<TeamApplication>> appsByEnv = (teamApps != null && !teamApps.isEmpty())
|
Map<Long, List<TeamApplication>> appsByEnv = (teamApps != null && !teamApps.isEmpty())
|
||||||
? teamApps.stream().collect(groupingBy(TeamApplication::getEnvironmentId))
|
? teamApps.stream().collect(groupingBy(TeamApplication::getEnvironmentId))
|
||||||
: Collections.emptyMap();
|
: Collections.emptyMap();
|
||||||
|
|
||||||
// 遍历所有团队配置的环境,有应用就显示应用,没应用就显示空列表
|
// 遍历所有团队配置的环境,有应用就显示应用,没应用就显示空列表
|
||||||
for (Environment env : envMap.values()) {
|
for (Environment env : envMap.values()) {
|
||||||
// 获取该环境的应用列表(没有则为空列表)
|
// 获取该环境的应用列表(没有则为空列表)
|
||||||
List<TeamApplication> envApps = appsByEnv.getOrDefault(env.getId(), Collections.emptyList());
|
List<TeamApplication> envApps = appsByEnv.getOrDefault(env.getId(), Collections.emptyList());
|
||||||
|
|
||||||
UserDeployableTeamEnvironmentDTO envDTO = buildUserDeployableTeamEnvironmentDTO(
|
UserDeployableTeamEnvironmentDTO envDTO = buildUserDeployableTeamEnvironmentDTO(
|
||||||
currentUserId, team.getOwnerId(),
|
currentUserId, team.getOwnerId(),
|
||||||
teamId, env, envApps,
|
teamId, env, envApps,
|
||||||
@ -455,10 +455,10 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
TeamEnvironmentConfig config = teamEnvConfigMap.get(configKey);
|
TeamEnvironmentConfig config = teamEnvConfigMap.get(configKey);
|
||||||
if (config != null) {
|
if (config != null) {
|
||||||
boolean requiresApproval = config.getApprovalRequired() != null ? config.getApprovalRequired() : false;
|
boolean requiresApproval = config.getApprovalRequired() != null ? config.getApprovalRequired() : false;
|
||||||
|
|
||||||
dto.setRequiresApproval(requiresApproval);
|
dto.setRequiresApproval(requiresApproval);
|
||||||
dto.setRequireCodeReview(config.getRequireCodeReview() != null ? config.getRequireCodeReview() : false);
|
dto.setRequireCodeReview(config.getRequireCodeReview() != null ? config.getRequireCodeReview() : false);
|
||||||
|
|
||||||
// 兜底逻辑:只有需要审批时才返回审批人列表
|
// 兜底逻辑:只有需要审批时才返回审批人列表
|
||||||
if (requiresApproval && config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
|
if (requiresApproval && config.getApproverUserIds() != null && !config.getApproverUserIds().isEmpty()) {
|
||||||
List<UserDeployableTeamEnvironmentApproverDTO> approvers = config.getApproverUserIds().stream()
|
List<UserDeployableTeamEnvironmentApproverDTO> approvers = config.getApproverUserIds().stream()
|
||||||
@ -479,10 +479,10 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
} else {
|
} else {
|
||||||
dto.setApprovers(Collections.emptyList());
|
dto.setApprovers(Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 构建通知配置 - 使用MapStruct转换器
|
// 构建通知配置 - 使用MapStruct转换器
|
||||||
TeamEnvironmentNotificationConfig notificationConfig = notificationConfigMap.get(configKey);
|
TeamEnvironmentNotificationConfig notificationConfig = notificationConfigMap.get(configKey);
|
||||||
UserTeamEnvironmentNotificationConfigDTO notificationConfigDTO =
|
UserTeamEnvironmentNotificationConfigDTO notificationConfigDTO =
|
||||||
notificationConfigConverter.toUserDTO(notificationConfig, channelMap, templateMap);
|
notificationConfigConverter.toUserDTO(notificationConfig, channelMap, templateMap);
|
||||||
dto.setNotificationConfig(notificationConfigDTO);
|
dto.setNotificationConfig(notificationConfigDTO);
|
||||||
} else {
|
} else {
|
||||||
@ -615,33 +615,33 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
*/
|
*/
|
||||||
private Map<Long, DeployStatisticsDTO> queryDeployStatistics(List<Long> teamApplicationIds) {
|
private Map<Long, DeployStatisticsDTO> queryDeployStatistics(List<Long> teamApplicationIds) {
|
||||||
Map<Long, DeployStatisticsDTO> statisticsMap = new HashMap<>();
|
Map<Long, DeployStatisticsDTO> statisticsMap = new HashMap<>();
|
||||||
List<Object[]> statisticsList = deployRecordRepository.findDeployStatisticsByTeamApplicationIds(teamApplicationIds);
|
List<Object[]> statisticsList = deployRecordRepository.findDeployStatisticsByTeamApplicationIds(teamApplicationIds);
|
||||||
|
|
||||||
for (Object[] row : statisticsList) {
|
for (Object[] row : statisticsList) {
|
||||||
Long teamApplicationId = (Long) row[0];
|
Long teamApplicationId = (Long) row[0];
|
||||||
Long totalCount = ((Number) row[1]).longValue();
|
Long totalCount = ((Number) row[1]).longValue();
|
||||||
Long successCount = ((Number) row[2]).longValue();
|
Long successCount = ((Number) row[2]).longValue();
|
||||||
Long failedCount = ((Number) row[3]).longValue();
|
Long failedCount = ((Number) row[3]).longValue();
|
||||||
Long runningCount = ((Number) row[4]).longValue();
|
Long runningCount = ((Number) row[4]).longValue();
|
||||||
|
|
||||||
LocalDateTime lastDeployTime = null;
|
LocalDateTime lastDeployTime = null;
|
||||||
if (row[5] != null) {
|
if (row[5] != null) {
|
||||||
if (row[5] instanceof Timestamp) {
|
if (row[5] instanceof Timestamp) {
|
||||||
lastDeployTime = ((Timestamp) row[5]).toLocalDateTime();
|
lastDeployTime = ((Timestamp) row[5]).toLocalDateTime();
|
||||||
} else if (row[5] instanceof LocalDateTime) {
|
} else if (row[5] instanceof LocalDateTime) {
|
||||||
lastDeployTime = (LocalDateTime) row[5];
|
lastDeployTime = (LocalDateTime) row[5];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DeployStatisticsDTO stats = new DeployStatisticsDTO();
|
|
||||||
stats.setTotalCount(totalCount);
|
|
||||||
stats.setSuccessCount(successCount);
|
|
||||||
stats.setFailedCount(failedCount);
|
|
||||||
stats.setRunningCount(runningCount);
|
|
||||||
stats.setLastDeployTime(lastDeployTime);
|
|
||||||
statisticsMap.put(teamApplicationId, stats);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DeployStatisticsDTO stats = new DeployStatisticsDTO();
|
||||||
|
stats.setTotalCount(totalCount);
|
||||||
|
stats.setSuccessCount(successCount);
|
||||||
|
stats.setFailedCount(failedCount);
|
||||||
|
stats.setRunningCount(runningCount);
|
||||||
|
stats.setLastDeployTime(lastDeployTime);
|
||||||
|
statisticsMap.put(teamApplicationId, stats);
|
||||||
|
}
|
||||||
|
|
||||||
return statisticsMap;
|
return statisticsMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -649,12 +649,12 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
* 批量查询最新部署记录
|
* 批量查询最新部署记录
|
||||||
*/
|
*/
|
||||||
private Map<Long, DeployRecord> queryLatestRecords(List<Long> teamApplicationIds) {
|
private Map<Long, DeployRecord> queryLatestRecords(List<Long> teamApplicationIds) {
|
||||||
List<DeployRecord> latestRecords = deployRecordRepository.findLatestDeployRecordsByTeamApplicationIds(teamApplicationIds);
|
List<DeployRecord> latestRecords = deployRecordRepository.findLatestDeployRecordsByTeamApplicationIds(teamApplicationIds);
|
||||||
Map<Long, DeployRecord> latestRecordMap = latestRecords.stream()
|
Map<Long, DeployRecord> latestRecordMap = latestRecords.stream()
|
||||||
.collect(toMap(DeployRecord::getTeamApplicationId, r -> r));
|
.collect(toMap(DeployRecord::getTeamApplicationId, r -> r));
|
||||||
|
|
||||||
// 更新统计信息中的最新状态和部署人
|
// 更新统计信息中的最新状态和部署人
|
||||||
latestRecordMap.forEach((teamAppId, record) -> {
|
latestRecordMap.forEach((teamAppId, record) -> {
|
||||||
// 这里可以添加额外的处理逻辑
|
// 这里可以添加额外的处理逻辑
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -756,7 +756,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
*/
|
*/
|
||||||
private void createDeployRecord(DeployExecuteRequest request, WorkflowInstanceDTO workflowInstance, String businessKey) {
|
private void createDeployRecord(DeployExecuteRequest request, WorkflowInstanceDTO workflowInstance, String businessKey) {
|
||||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||||
deployRecordService.createDeployRecord(workflowInstance.getId(), businessKey, request.getTeamApplicationId(), request.getTeamId(), request.getApplicationId(), request.getEnvironmentId(), currentUsername, request.getRemark());
|
deployRecordService.createDeployRecord(workflowInstance.getId(), businessKey, request.getTeamApplicationId(), request.getTeamId(), request.getApplicationId(), request.getEnvironmentId(), currentUsername, request.getDeployRemark());
|
||||||
|
|
||||||
log.info("部署记录已创建: businessKey={}, workflowInstanceId={}", businessKey, workflowInstance.getId());
|
log.info("部署记录已创建: businessKey={}, workflowInstanceId={}", businessKey, workflowInstance.getId());
|
||||||
}
|
}
|
||||||
@ -778,7 +778,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
public List<DeployApprovalTaskDTO> getMyApprovalTasks(Long teamId, Long environmentId, List<String> workflowDefinitionKeys) {
|
public List<DeployApprovalTaskDTO> getMyApprovalTasks(Long teamId, Long environmentId, List<String> workflowDefinitionKeys) {
|
||||||
// 1. 获取当前登录用户
|
// 1. 获取当前登录用户
|
||||||
String currentUsername = SecurityUtils.getCurrentUsername();
|
String currentUsername = SecurityUtils.getCurrentUsername();
|
||||||
log.info("查询用户 {} 的部署审批任务, teamId={}, environmentId={}, workflowDefinitionKeys={}",
|
log.info("查询用户 {} 的部署审批任务, teamId={}, environmentId={}, workflowDefinitionKeys={}",
|
||||||
currentUsername, teamId, environmentId, workflowDefinitionKeys);
|
currentUsername, teamId, environmentId, workflowDefinitionKeys);
|
||||||
|
|
||||||
// 2. 查询用户的部署工作流待办任务(支持多个工作流)
|
// 2. 查询用户的部署工作流待办任务(支持多个工作流)
|
||||||
@ -786,20 +786,20 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
.taskCandidateOrAssigned(currentUsername)
|
.taskCandidateOrAssigned(currentUsername)
|
||||||
.orderByTaskCreateTime()
|
.orderByTaskCreateTime()
|
||||||
.desc();
|
.desc();
|
||||||
|
|
||||||
// 如果指定了工作流定义Key列表,则精确筛选这些工作流的所有待审批任务
|
// 如果指定了工作流定义Key列表,则精确筛选这些工作流的所有待审批任务
|
||||||
if (workflowDefinitionKeys != null && !workflowDefinitionKeys.isEmpty()) {
|
if (workflowDefinitionKeys != null && !workflowDefinitionKeys.isEmpty()) {
|
||||||
// 过滤掉空字符串
|
// 过滤掉空字符串
|
||||||
List<String> validKeys = workflowDefinitionKeys.stream()
|
List<String> validKeys = workflowDefinitionKeys.stream()
|
||||||
.filter(key -> key != null && !key.trim().isEmpty())
|
.filter(key -> key != null && !key.trim().isEmpty())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
if (!validKeys.isEmpty()) {
|
if (!validKeys.isEmpty()) {
|
||||||
taskQuery.processDefinitionKeyIn(validKeys);
|
taskQuery.processDefinitionKeyIn(validKeys);
|
||||||
log.debug("按工作流定义Key列表筛选: {}", validKeys);
|
log.debug("按工作流定义Key列表筛选: {}", validKeys);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Task> tasks = taskQuery.list();
|
List<Task> tasks = taskQuery.list();
|
||||||
|
|
||||||
if (tasks.isEmpty()) {
|
if (tasks.isEmpty()) {
|
||||||
@ -830,7 +830,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
log.debug("按团队ID筛选后剩余 {} 个任务", result.size());
|
log.debug("按团队ID筛选后剩余 {} 个任务", result.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (environmentId != null) {
|
if (environmentId != null) {
|
||||||
result = result.stream()
|
result = result.stream()
|
||||||
.filter(task -> environmentId.equals(task.getEnvironmentId()))
|
.filter(task -> environmentId.equals(task.getEnvironmentId()))
|
||||||
@ -873,8 +873,8 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
// 4. 查询部署记录
|
// 4. 查询部署记录
|
||||||
DeployRecord deployRecord = deployRecordRepository.findByBusinessKeyAndDeletedFalse(businessKey)
|
DeployRecord deployRecord = deployRecordRepository.findByBusinessKeyAndDeletedFalse(businessKey)
|
||||||
.orElseThrow(() -> new BusinessException(ResponseCode.DEPLOY_RECORD_NOT_FOUND,
|
.orElseThrow(() -> new BusinessException(ResponseCode.DEPLOY_RECORD_NOT_FOUND,
|
||||||
new Object[]{businessKey}));
|
new Object[] {businessKey}));
|
||||||
|
|
||||||
// 5. 构建 DTO
|
// 5. 构建 DTO
|
||||||
DeployApprovalTaskDTO dto = new DeployApprovalTaskDTO();
|
DeployApprovalTaskDTO dto = new DeployApprovalTaskDTO();
|
||||||
@ -905,8 +905,8 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
if (approvalInputs != null) {
|
if (approvalInputs != null) {
|
||||||
dto.setApprovalTitle(approvalInputs.getApprovalTitle());
|
dto.setApprovalTitle(approvalInputs.getApprovalTitle());
|
||||||
dto.setApprovalContent(approvalInputs.getApprovalContent());
|
dto.setApprovalContent(approvalInputs.getApprovalContent());
|
||||||
dto.setApprovalMode(approvalInputs.getApprovalMode() != null
|
dto.setApprovalMode(approvalInputs.getApprovalMode() != null
|
||||||
? approvalInputs.getApprovalMode().name()
|
? approvalInputs.getApprovalMode().name()
|
||||||
: null);
|
: null);
|
||||||
dto.setAllowDelegate(approvalInputs.getAllowDelegate());
|
dto.setAllowDelegate(approvalInputs.getAllowDelegate());
|
||||||
dto.setAllowAddSign(approvalInputs.getAllowAddSign());
|
dto.setAllowAddSign(approvalInputs.getAllowAddSign());
|
||||||
@ -918,7 +918,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
dto.setDeployRecordId(deployRecord.getId());
|
dto.setDeployRecordId(deployRecord.getId());
|
||||||
dto.setBusinessKey(businessKey);
|
dto.setBusinessKey(businessKey);
|
||||||
dto.setDeployStartTime(deployRecord.getStartTime());
|
dto.setDeployStartTime(deployRecord.getStartTime());
|
||||||
|
|
||||||
// 使用 BeanUtils 批量复制同名字段
|
// 使用 BeanUtils 批量复制同名字段
|
||||||
BeanUtils.copyProperties(deployRequest, dto);
|
BeanUtils.copyProperties(deployRequest, dto);
|
||||||
|
|
||||||
@ -1053,7 +1053,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
* <p>从 NodeContext 的 inputs 字段中解析审批配置
|
* <p>从 NodeContext 的 inputs 字段中解析审批配置
|
||||||
*
|
*
|
||||||
* @param variables 流程变量 Map
|
* @param variables 流程变量 Map
|
||||||
* @param nodeId 审批节点ID
|
* @param nodeId 审批节点ID
|
||||||
* @return ApprovalInputMapping 对象,解析失败返回 null
|
* @return ApprovalInputMapping 对象,解析失败返回 null
|
||||||
*/
|
*/
|
||||||
private ApprovalInputMapping extractApprovalInputMapping(Map<String, Object> variables, String nodeId) {
|
private ApprovalInputMapping extractApprovalInputMapping(Map<String, Object> variables, String nodeId) {
|
||||||
@ -1069,9 +1069,9 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
if (nodeData instanceof Map) {
|
if (nodeData instanceof Map) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Map<String, Object> nodeDataMap = (Map<String, Object>) nodeData;
|
Map<String, Object> nodeDataMap = (Map<String, Object>) nodeData;
|
||||||
NodeContext<ApprovalInputMapping, ApprovalOutputs> nodeContext =
|
NodeContext<ApprovalInputMapping, ApprovalOutputs> nodeContext =
|
||||||
NodeContext.fromMap(nodeDataMap, ApprovalInputMapping.class, ApprovalOutputs.class, objectMapper);
|
NodeContext.fromMap(nodeDataMap, ApprovalInputMapping.class, ApprovalOutputs.class, objectMapper);
|
||||||
|
|
||||||
// 3. 返回 inputMapping
|
// 3. 返回 inputMapping
|
||||||
return nodeContext.getInputMapping();
|
return nodeContext.getInputMapping();
|
||||||
}
|
}
|
||||||
@ -1110,16 +1110,16 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DeployNodeLogDTO getNodeLogs(String processInstanceId, String nodeId) {
|
public DeployNodeLogDTO getNodeLogs(String processInstanceId, String nodeId) {
|
||||||
DeployNodeLogDTO result = new DeployNodeLogDTO();
|
DeployNodeLogDTO result = new DeployNodeLogDTO();
|
||||||
result.setProcessInstanceId(processInstanceId);
|
result.setProcessInstanceId(processInstanceId);
|
||||||
result.setNodeId(nodeId);
|
result.setNodeId(nodeId);
|
||||||
|
|
||||||
// 查询日志
|
// 查询日志
|
||||||
List<WorkflowNodeLogDTO> logs = workflowNodeLogService.getNodeLogs(processInstanceId, nodeId);
|
List<WorkflowNodeLogDTO> logs = workflowNodeLogService.getNodeLogs(processInstanceId, nodeId);
|
||||||
|
|
||||||
if (logs.isEmpty()) {
|
if (logs.isEmpty()) {
|
||||||
// 判断是过期还是还没有日志
|
// 判断是过期还是还没有日志
|
||||||
result.setExpired(true);
|
result.setExpired(true);
|
||||||
@ -1128,7 +1128,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
} else {
|
} else {
|
||||||
result.setExpired(false);
|
result.setExpired(false);
|
||||||
result.setMessage("查询成功");
|
result.setMessage("查询成功");
|
||||||
|
|
||||||
// 转换为 DTO
|
// 转换为 DTO
|
||||||
List<DeployNodeLogDTO.LogEntry> logEntries = logs.stream()
|
List<DeployNodeLogDTO.LogEntry> logEntries = logs.stream()
|
||||||
.map(log -> {
|
.map(log -> {
|
||||||
@ -1141,7 +1141,7 @@ public class DeployServiceImpl implements IDeployService {
|
|||||||
return entry;
|
return entry;
|
||||||
})
|
})
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
result.setLogs(logEntries);
|
result.setLogs(logEntries);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -91,8 +91,7 @@ public class JenkinsBuildDelegate extends BaseNodeDelegate<JenkinsBuildInputMapp
|
|||||||
JenkinsBuildResponse buildDetails = jenkinsServiceIntegration.getBuildDetails(externalSystem, jobName, buildInfo.getBuildNumber());
|
JenkinsBuildResponse buildDetails = jenkinsServiceIntegration.getBuildDetails(externalSystem, jobName, buildInfo.getBuildNumber());
|
||||||
|
|
||||||
// 打印调试信息
|
// 打印调试信息
|
||||||
log.info("Build details - changeSets: {}, artifacts: {}",
|
log.info("Build details - changeSets: {}, artifacts: {}", buildDetails.getChangeSets(), buildDetails.getArtifacts());
|
||||||
buildDetails.getChangeSets(), buildDetails.getArtifacts());
|
|
||||||
|
|
||||||
// 6. 设置输出结果(执行到这里说明构建成功)
|
// 6. 设置输出结果(执行到这里说明构建成功)
|
||||||
// ✅ 直接修改预初始化的 output 对象
|
// ✅ 直接修改预初始化的 output 对象
|
||||||
|
|||||||
@ -37,7 +37,7 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationInput
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private INotificationChannelRepository notificationChannelRepository;
|
private INotificationChannelRepository notificationChannelRepository;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private INotificationTemplateRepository notificationTemplateRepository;
|
private INotificationTemplateRepository notificationTemplateRepository;
|
||||||
|
|
||||||
@ -48,45 +48,39 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationInput
|
|||||||
logWarn(String.format("Notification delegate parameter verification failed - channelId: %s, templateId: %s", input.getChannelId(), input.getNotificationTemplateId()));
|
logWarn(String.format("Notification delegate parameter verification failed - channelId: %s, templateId: %s", input.getChannelId(), input.getNotificationTemplateId()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
// 2. 查询渠道和模板信息
|
||||||
// 2. 查询渠道和模板信息
|
NotificationChannel channel = notificationChannelRepository.findById(input.getChannelId()).orElseThrow(() -> new RuntimeException("通知渠道不存在: " + input.getChannelId()));
|
||||||
NotificationChannel channel = notificationChannelRepository.findById(input.getChannelId()).orElseThrow(() -> new RuntimeException("通知渠道不存在: " + input.getChannelId()));
|
NotificationTemplate template = notificationTemplateRepository.findById(input.getNotificationTemplateId()).orElseThrow(() -> new RuntimeException("通知模板不存在: " + input.getNotificationTemplateId()));
|
||||||
NotificationTemplate template = notificationTemplateRepository.findById(input.getNotificationTemplateId()).orElseThrow(() -> new RuntimeException("通知模板不存在: " + input.getNotificationTemplateId()));
|
|
||||||
|
|
||||||
// 3. 构建SendNotificationRequest
|
// 3. 构建SendNotificationRequest
|
||||||
SendNotificationRequest request = new SendNotificationRequest();
|
SendNotificationRequest request = new SendNotificationRequest();
|
||||||
request.setNotificationTemplateId(input.getNotificationTemplateId());
|
request.setNotificationTemplateId(input.getNotificationTemplateId());
|
||||||
request.setTemplateParams(execution.getVariables());
|
request.setTemplateParams(execution.getVariables());
|
||||||
|
|
||||||
// 4. 根据渠道类型创建sendRequest,并从模板配置中获取参数
|
// 4. 根据渠道类型创建sendRequest,并从模板配置中获取参数
|
||||||
switch (channel.getChannelType()) {
|
switch (channel.getChannelType()) {
|
||||||
case WEWORK -> {
|
case WEWORK -> {
|
||||||
WeworkSendNotificationRequest weworkRequest = new WeworkSendNotificationRequest();
|
WeworkSendNotificationRequest weworkRequest = new WeworkSendNotificationRequest();
|
||||||
weworkRequest.setChannelId(input.getChannelId());
|
weworkRequest.setChannelId(input.getChannelId());
|
||||||
// 从模板配置中获取消息类型
|
// 从模板配置中获取消息类型
|
||||||
weworkRequest.setMessageType(getWeworkMessageType(template));
|
weworkRequest.setMessageType(getWeworkMessageType(template));
|
||||||
request.setSendRequest(weworkRequest);
|
request.setSendRequest(weworkRequest);
|
||||||
}
|
|
||||||
case EMAIL -> {
|
|
||||||
EmailSendNotificationRequest emailRequest = new EmailSendNotificationRequest();
|
|
||||||
emailRequest.setChannelId(input.getChannelId());
|
|
||||||
// 收件人从工作流变量获取
|
|
||||||
emailRequest.setToReceivers(getEmailReceivers(execution, configs));
|
|
||||||
// 其他配置(HTML格式等)由NotificationService根据模板配置自动设置
|
|
||||||
request.setSendRequest(emailRequest);
|
|
||||||
}
|
|
||||||
default -> throw new RuntimeException("不支持的渠道类型: " + channel.getChannelType());
|
|
||||||
}
|
}
|
||||||
|
case EMAIL -> {
|
||||||
// 5. 发送通知(NotificationService会处理模板渲染和详细配置)
|
EmailSendNotificationRequest emailRequest = new EmailSendNotificationRequest();
|
||||||
notificationService.send(request);
|
emailRequest.setChannelId(input.getChannelId());
|
||||||
|
// 收件人从工作流变量获取
|
||||||
log.info("工作流通知发送成功 - 渠道ID: {}, 模板ID: {}",
|
emailRequest.setToReceivers(getEmailReceivers(execution, configs));
|
||||||
input.getChannelId(), input.getNotificationTemplateId());
|
// 其他配置(HTML格式等)由NotificationService根据模板配置自动设置
|
||||||
} catch (Exception e) {
|
request.setSendRequest(emailRequest);
|
||||||
logError("工作流通知发送失败: " + e.getMessage());
|
}
|
||||||
throw new RuntimeException("通知发送失败", e);
|
default -> throw new RuntimeException("不支持的渠道类型: " + channel.getChannelType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 5. 发送通知(NotificationService会处理模板渲染和详细配置)
|
||||||
|
notificationService.send(request);
|
||||||
|
|
||||||
|
log.info("工作流通知发送成功 - 渠道ID: {}, 模板ID: {}", input.getChannelId(), input.getNotificationTemplateId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,7 +97,7 @@ public class NotificationNodeDelegate extends BaseNodeDelegate<NotificationInput
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.warn("解析企业微信模板配置失败,使用默认消息类型: {}", e.getMessage());
|
log.warn("解析企业微信模板配置失败,使用默认消息类型: {}", e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 默认使用TEXT类型
|
// 默认使用TEXT类型
|
||||||
return WeworkMessageTypeEnum.TEXT;
|
return WeworkMessageTypeEnum.TEXT;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user