增加构建通知
This commit is contained in:
parent
1fa033cac2
commit
694e6690ca
@ -113,12 +113,38 @@ public class NotificationTemplateServiceImpl extends BaseServiceImpl<Notificatio
|
||||
StringWriter writer = new StringWriter();
|
||||
template.process(params, writer);
|
||||
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) {
|
||||
log.error("模板渲染失败: {}", e.getMessage(), e);
|
||||
throw new BusinessException(ResponseCode.NOTIFICATION_TEMPLATE_RENDER_ERROR);
|
||||
String friendlyMessage = "模板渲染失败:" + e.getMessage();
|
||||
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
|
||||
@Transactional
|
||||
public void enable(Long id) {
|
||||
|
||||
@ -257,7 +257,7 @@ deploy.record.not.found=部署记录不存在
|
||||
notification.template.not.found=通知模板不存在或已删除
|
||||
notification.template.code.exists=模板编码{0}已存在
|
||||
notification.template.disabled=通知模板已禁用
|
||||
notification.template.render.error=模板渲染失败
|
||||
notification.template.render.error=模板渲染失败:{0}
|
||||
|
||||
# 通知渠道相关 (3120-3139)
|
||||
notification.channel.not.found=通知渠道不存在或已删除
|
||||
|
||||
@ -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.code.exists=Template code {0} already exists
|
||||
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.not.found=Notification channel not found or has been deleted
|
||||
|
||||
@ -190,7 +190,7 @@ deploy.record.not.found=部署记录不存在
|
||||
notification.template.not.found=通知模板不存在或已删除
|
||||
notification.template.code.exists=模板编码{0}已存在
|
||||
notification.template.disabled=通知模板已禁用
|
||||
notification.template.render.error=模板渲染失败
|
||||
notification.template.render.error=模板渲染失败:{0}
|
||||
|
||||
# 通知渠道相关 (3120-3139)
|
||||
notification.channel.not.found=通知渠道不存在或已删除
|
||||
|
||||
Loading…
Reference in New Issue
Block a user