增加构建通知

This commit is contained in:
dengqichen 2025-11-13 17:13:39 +08:00
parent 1fa033cac2
commit 694e6690ca
4 changed files with 31 additions and 5 deletions

View File

@ -113,12 +113,38 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
StringWriter writer = new StringWriter(); StringWriter writer = new StringWriter();
template.process(params, writer); template.process(params, writer);
return writer.toString(); return writer.toString();
} catch (freemarker.core.InvalidReferenceException e) {
// 提取缺失的变量名
String errorMessage = e.getMessage();
String missingVariable = extractMissingVariable(errorMessage);
String friendlyMessage = String.format("缺少必需的参数 '%s',请检查传入的参数是否完整", missingVariable);
log.error("模板渲染失败: {}", friendlyMessage, e);
throw new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_RENDER_ERROR, new Object[]{friendlyMessage});
} catch (Exception e) { } catch (Exception e) {
log.error("模板渲染失败: {}", e.getMessage(), e); String friendlyMessage = "模板渲染失败:" + e.getMessage();
throw new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_RENDER_ERROR); log.error("模板渲染失败: {}", friendlyMessage, e);
throw new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_RENDER_ERROR, new Object[]{friendlyMessage});
} }
} }
/**
* 从FreeMarker错误信息中提取缺失的变量名
*/
private String extractMissingVariable(String errorMessage) {
// 错误信息格式: "The following has evaluated to null or missing: ==> variableName [in template ...]"
if (errorMessage != null && errorMessage.contains("==> ")) {
int start = errorMessage.indexOf("==> ") + 4;
int end = errorMessage.indexOf(" ", start);
if (end == -1) {
end = errorMessage.indexOf("[", start);
}
if (end > start) {
return errorMessage.substring(start, end).trim();
}
}
return "未知参数";
}
@Override @Override
@Transactional @Transactional
public void enable(Long id) { public void enable(Long id) {

View File

@ -257,7 +257,7 @@ 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=模板渲染失败{0}
# 通知渠道相关 (3120-3139) # 通知渠道相关 (3120-3139)
notification.channel.not.found=通知渠道不存在或已删除 notification.channel.not.found=通知渠道不存在或已删除

View File

@ -190,7 +190,7 @@ deploy.record.not.found=Deployment record not found
notification.template.not.found=Notification template not found or has been deleted notification.template.not.found=Notification template not found or has been deleted
notification.template.code.exists=Template code {0} already exists notification.template.code.exists=Template code {0} already exists
notification.template.disabled=Notification template is disabled notification.template.disabled=Notification template is disabled
notification.template.render.error=Template rendering failed notification.template.render.error=Template rendering failed: {0}
# Notification Channel Related (3120-3139) # Notification Channel Related (3120-3139)
notification.channel.not.found=Notification channel not found or has been deleted notification.channel.not.found=Notification channel not found or has been deleted

View File

@ -190,7 +190,7 @@ 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=模板渲染失败{0}
# 通知渠道相关 (3120-3139) # 通知渠道相关 (3120-3139)
notification.channel.not.found=通知渠道不存在或已删除 notification.channel.not.found=通知渠道不存在或已删除