增加部署日志

This commit is contained in:
dengqichen 2025-11-12 22:36:55 +08:00
parent 1791eb13cb
commit c2e1d69ee4
8 changed files with 69 additions and 6 deletions

View File

@ -235,7 +235,13 @@ public enum ResponseCode {
NOTIFICATION_TEMPLATE_NOT_FOUND(3100, "notification.template.not.found"), NOTIFICATION_TEMPLATE_NOT_FOUND(3100, "notification.template.not.found"),
NOTIFICATION_TEMPLATE_CODE_EXISTS(3101, "notification.template.code.exists"), NOTIFICATION_TEMPLATE_CODE_EXISTS(3101, "notification.template.code.exists"),
NOTIFICATION_TEMPLATE_DISABLED(3102, "notification.template.disabled"), NOTIFICATION_TEMPLATE_DISABLED(3102, "notification.template.disabled"),
NOTIFICATION_TEMPLATE_RENDER_ERROR(3103, "notification.template.render.error"); NOTIFICATION_TEMPLATE_RENDER_ERROR(3103, "notification.template.render.error"),
// 通知渠道相关错误码 (3120-3139)
NOTIFICATION_CHANNEL_NOT_FOUND(3120, "notification.channel.not.found"),
NOTIFICATION_CHANNEL_DISABLED(3121, "notification.channel.disabled"),
NOTIFICATION_CHANNEL_CONFIG_ERROR(3122, "notification.channel.config.error"),
NOTIFICATION_SEND_FAILED(3123, "notification.send.failed");
private final int code; private final int code;
private final String messageKey; // 国际化消息key private final String messageKey; // 国际化消息key

View File

@ -1,16 +1,29 @@
package com.qqchen.deploy.backend.notification.entity.config; package com.qqchen.deploy.backend.notification.entity.config;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.qqchen.deploy.backend.notification.enums.NotificationChannelTypeEnum; import com.qqchen.deploy.backend.notification.enums.NotificationChannelTypeEnum;
import lombok.Data; import lombok.Data;
/** /**
* 模板配置基类 * 模板配置基类
* 用于实体层与DTO层的BaseTemplateConfigDTO对应 * 用于实体层与DTO层的BaseTemplateConfigDTO对应
*
* 使用 PROPERTY 方式通过 channelType 字段进行多态反序列化
* *
* @author qqchen * @author qqchen
* @since 2025-11-12 * @since 2025-11-12
*/ */
@Data @Data
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "channelType"
)
@JsonSubTypes({
@JsonSubTypes.Type(value = WeworkTemplateConfig.class, name = "WEWORK"),
@JsonSubTypes.Type(value = EmailTemplateConfig.class, name = "EMAIL")
})
public abstract class BaseTemplateConfig { public abstract class BaseTemplateConfig {
/** /**

View File

@ -16,6 +16,11 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class EmailTemplateConfig extends BaseTemplateConfig { public class EmailTemplateConfig extends BaseTemplateConfig {
/**
* 渠道类型用于Jackson反序列化
*/
private final NotificationChannelTypeEnum channelType = NotificationChannelTypeEnum.EMAIL;
/** /**
* 内容类型 * 内容类型
*/ */

View File

@ -15,6 +15,11 @@ import lombok.EqualsAndHashCode;
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class WeworkTemplateConfig extends BaseTemplateConfig { public class WeworkTemplateConfig extends BaseTemplateConfig {
/**
* 渠道类型用于Jackson反序列化
*/
private final NotificationChannelTypeEnum channelType = NotificationChannelTypeEnum.WEWORK;
/** /**
* 消息类型 * 消息类型
*/ */

View File

@ -126,11 +126,11 @@ public class NotificationChannelServiceImpl
// 2. 查询渠道配置 // 2. 查询渠道配置
NotificationChannel channel = notificationChannelRepository.findById(request.getChannelId()) NotificationChannel channel = notificationChannelRepository.findById(request.getChannelId())
.orElseThrow(() -> new BusinessException(ResponseCode.DATA_NOT_FOUND)); .orElseThrow(() -> new BusinessException(ResponseCode.NOTIFICATION_CHANNEL_NOT_FOUND));
// 3. 校验渠道状态 // 3. 校验渠道状态
if (!channel.getEnabled()) { if (!channel.getEnabled()) {
throw new BusinessException(ResponseCode.DATA_NOT_FOUND); throw new BusinessException(ResponseCode.NOTIFICATION_CHANNEL_DISABLED);
} }
// 4. 获取对应的适配器 // 4. 获取对应的适配器
@ -153,9 +153,13 @@ public class NotificationChannelServiceImpl
adapter.send(config, request); adapter.send(config, request);
log.info("通知发送成功 - 渠道ID: {}", channel.getId()); log.info("通知发送成功 - 渠道ID: {}", channel.getId());
} catch (IllegalArgumentException e) {
// 配置错误 Webhook Key 未配置
log.error("通知渠道配置错误 - 渠道ID: {}, 错误: {}", channel.getId(), e.getMessage());
throw new BusinessException(ResponseCode.NOTIFICATION_CHANNEL_CONFIG_ERROR, new Object[]{e.getMessage()});
} catch (Exception e) { } catch (Exception e) {
log.error("通知发送失败 - 渠道ID: {}, 错误: {}", channel.getId(), e.getMessage(), e); log.error("通知发送失败 - 渠道ID: {}, 错误: {}", channel.getId(), e.getMessage(), e);
throw new BusinessException(ResponseCode.ERROR, new Object[]{e.getMessage()}); throw new BusinessException(ResponseCode.NOTIFICATION_SEND_FAILED, new Object[]{e.getMessage()});
} }
} }

View File

@ -257,4 +257,10 @@ deploy.record.not.found=部署记录不存在
notification.template.not.found=通知模板不存在或已删除 notification.template.not.found=通知模板不存在或已删除
notification.template.code.exists=模板编码{0}已存在 notification.template.code.exists=模板编码{0}已存在
notification.template.disabled=通知模板已禁用 notification.template.disabled=通知模板已禁用
notification.template.render.error=模板渲染失败 notification.template.render.error=模板渲染失败
# 通知渠道相关 (3120-3139)
notification.channel.not.found=通知渠道不存在或已删除
notification.channel.disabled=通知渠道已禁用
notification.channel.config.error=通知渠道配置错误:{0}
notification.send.failed=通知发送失败:{0}

View File

@ -185,3 +185,15 @@ deploy.permission.denied=No permission to deploy application in this environment
deploy.environment.locked=Environment is locked, deployment prohibited deploy.environment.locked=Environment is locked, deployment prohibited
deploy.approval.required=Approval required for deployment in this environment deploy.approval.required=Approval required for deployment in this environment
deploy.record.not.found=Deployment record not found deploy.record.not.found=Deployment record not found
# Notification Template Related (3100-3119)
notification.template.not.found=Notification template not found or has been deleted
notification.template.code.exists=Template code {0} already exists
notification.template.disabled=Notification template is disabled
notification.template.render.error=Template rendering failed
# Notification Channel Related (3120-3139)
notification.channel.not.found=Notification channel not found or has been deleted
notification.channel.disabled=Notification channel is disabled
notification.channel.config.error=Notification channel configuration error: {0}
notification.send.failed=Notification send failed: {0}

View File

@ -184,4 +184,16 @@ deploy.already.running=该应用正在部署中,请等待当前部署完成
deploy.permission.denied=无权限在此环境部署应用 deploy.permission.denied=无权限在此环境部署应用
deploy.environment.locked=环境已锁定,禁止部署 deploy.environment.locked=环境已锁定,禁止部署
deploy.approval.required=该环境需要审批才能部署 deploy.approval.required=该环境需要审批才能部署
deploy.record.not.found=部署记录不存在 deploy.record.not.found=部署记录不存在
# 通知模板相关 (3100-3119)
notification.template.not.found=通知模板不存在或已删除
notification.template.code.exists=模板编码{0}已存在
notification.template.disabled=通知模板已禁用
notification.template.render.error=模板渲染失败
# 通知渠道相关 (3120-3139)
notification.channel.not.found=通知渠道不存在或已删除
notification.channel.disabled=通知渠道已禁用
notification.channel.config.error=通知渠道配置错误:{0}
notification.send.failed=通知发送失败:{0}