diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/TeamEnvironmentNotificationConfigDTO.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/TeamEnvironmentNotificationConfigDTO.java index ddebe20e..87537ab1 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/TeamEnvironmentNotificationConfigDTO.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/TeamEnvironmentNotificationConfigDTO.java @@ -65,4 +65,19 @@ public class TeamEnvironmentNotificationConfigDTO extends BaseDTO { * 通知渠道名称(扩展字段,非数据库字段) */ private String notificationChannelName; + + /** + * 部署通知模板名称(扩展字段,非数据库字段) + */ + private String deployNotificationTemplateName; + + /** + * 构建通知模板名称(扩展字段,非数据库字段) + */ + private String buildNotificationTemplateName; + + /** + * 构建失败通知模板名称(扩展字段,非数据库字段) + */ + private String buildFailureNotificationTemplateName; } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/UserTeamEnvironmentNotificationConfigDTO.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/UserTeamEnvironmentNotificationConfigDTO.java index 92a1d227..767e01d1 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/UserTeamEnvironmentNotificationConfigDTO.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/dto/UserTeamEnvironmentNotificationConfigDTO.java @@ -62,4 +62,22 @@ public class UserTeamEnvironmentNotificationConfigDTO { */ @Schema(description = "通知渠道名称(扩展字段,非数据库字段)") private String notificationChannelName; + + /** + * 部署通知模板名称(扩展字段,非数据库字段) + */ + @Schema(description = "部署通知模板名称(扩展字段,非数据库字段)") + private String deployNotificationTemplateName; + + /** + * 构建通知模板名称(扩展字段,非数据库字段) + */ + @Schema(description = "构建通知模板名称(扩展字段,非数据库字段)") + private String buildNotificationTemplateName; + + /** + * 构建失败通知模板名称(扩展字段,非数据库字段) + */ + @Schema(description = "构建失败通知模板名称(扩展字段,非数据库字段)") + private String buildFailureNotificationTemplateName; } diff --git a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamEnvironmentConfigServiceImpl.java b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamEnvironmentConfigServiceImpl.java index 20d68bbd..0edc403a 100644 --- a/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamEnvironmentConfigServiceImpl.java +++ b/backend/src/main/java/com/qqchen/deploy/backend/deploy/service/impl/TeamEnvironmentConfigServiceImpl.java @@ -16,7 +16,9 @@ import com.qqchen.deploy.backend.framework.enums.ResponseCode; import com.qqchen.deploy.backend.framework.exception.BusinessException; import com.qqchen.deploy.backend.framework.service.impl.BaseServiceImpl; import com.qqchen.deploy.backend.notification.entity.NotificationChannel; +import com.qqchen.deploy.backend.notification.entity.NotificationTemplate; import com.qqchen.deploy.backend.notification.repository.INotificationChannelRepository; +import com.qqchen.deploy.backend.notification.repository.INotificationTemplateRepository; import jakarta.annotation.Resource; import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; @@ -48,6 +50,9 @@ public class TeamEnvironmentConfigServiceImpl @Resource private INotificationChannelRepository notificationChannelRepository; + @Resource + private INotificationTemplateRepository notificationTemplateRepository; + @Resource private ITeamApplicationRepository teamApplicationRepository; @@ -272,7 +277,28 @@ public class TeamEnvironmentConfigServiceImpl ); } - // 5. 填充扩展字段 + // 5. 批量查询通知模板信息 + Set templateIds = new HashSet<>(); + notificationConfigMap.values().forEach(nc -> { + if (nc.getDeployNotificationTemplateId() != null) { + templateIds.add(nc.getDeployNotificationTemplateId()); + } + if (nc.getBuildNotificationTemplateId() != null) { + templateIds.add(nc.getBuildNotificationTemplateId()); + } + if (nc.getBuildFailureNotificationTemplateId() != null) { + templateIds.add(nc.getBuildFailureNotificationTemplateId()); + } + }); + + Map templateMap = new HashMap<>(); + if (!templateIds.isEmpty()) { + notificationTemplateRepository.findAllById(templateIds).forEach(template -> + templateMap.put(template.getId(), template) + ); + } + + // 6. 填充扩展字段 configs.forEach(config -> { // 填充环境名称 if (config.getEnvironmentId() != null) { @@ -299,6 +325,30 @@ public class TeamEnvironmentConfigServiceImpl } } + // 填充部署通知模板名称 + if (notificationConfig.getDeployNotificationTemplateId() != null) { + NotificationTemplate template = templateMap.get(notificationConfig.getDeployNotificationTemplateId()); + if (template != null) { + notificationConfigDTO.setDeployNotificationTemplateName(template.getName()); + } + } + + // 填充构建通知模板名称 + if (notificationConfig.getBuildNotificationTemplateId() != null) { + NotificationTemplate template = templateMap.get(notificationConfig.getBuildNotificationTemplateId()); + if (template != null) { + notificationConfigDTO.setBuildNotificationTemplateName(template.getName()); + } + } + + // 填充构建失败通知模板名称 + if (notificationConfig.getBuildFailureNotificationTemplateId() != null) { + NotificationTemplate template = templateMap.get(notificationConfig.getBuildFailureNotificationTemplateId()); + if (template != null) { + notificationConfigDTO.setBuildFailureNotificationTemplateName(template.getName()); + } + } + config.setNotificationConfig(notificationConfigDTO); } }