using System.Collections.Generic;
using System.Threading.Tasks;
namespace NPP.SmartSchedue.Api.Contracts.Services.Notification;
///
/// 通知模板服务接口
/// 决策点7:模板通知,支持通知内容模板,可替换变量
///
public interface INotificationTemplateService
{
#region 模板渲染
///
/// 渲染通知模板
/// 支持变量替换,如:{变量名}
///
/// 模板内容
/// 变量字典
/// 渲染后的内容
Task RenderTemplateAsync(string template, Dictionary variables);
///
/// 同步渲染通知模板
///
/// 模板内容
/// 变量字典
/// 渲染后的内容
string RenderTemplate(string template, Dictionary variables);
#endregion
#region 模板验证
///
/// 验证模板语法是否正确
///
/// 模板内容
/// 验证结果
Task ValidateTemplateAsync(string template);
///
/// 同步验证模板语法
///
/// 模板内容
/// 验证结果
TemplateValidationResult ValidateTemplate(string template);
#endregion
#region 变量解析
///
/// 提取模板中的变量列表
///
/// 模板内容
/// 变量名列表
Task> ExtractVariablesAsync(string template);
///
/// 同步提取模板中的变量列表
///
/// 模板内容
/// 变量名列表
List ExtractVariables(string template);
#endregion
#region 内置变量
///
/// 获取系统内置变量
///
/// 内置变量字典
Task> GetSystemVariablesAsync();
///
/// 获取业务相关变量
///
/// 业务类型
/// 业务ID
/// 业务数据
/// 业务变量字典
Task> GetBusinessVariablesAsync(
string businessType,
long? businessId = null,
string businessData = "");
#endregion
#region 模板预定义
///
/// 获取预定义模板列表
///
/// 模板分类
/// 预定义模板列表
Task> GetPredefinedTemplatesAsync(string category = "");
///
/// 获取指定预定义模板
///
/// 模板ID
/// 预定义模板
Task GetPredefinedTemplateAsync(string templateId);
#endregion
}
///
/// 模板验证结果
///
public class TemplateValidationResult
{
///
/// 是否验证通过
///
public bool IsValid { get; set; } = true;
///
/// 错误信息列表
///
public List Errors { get; set; } = new List();
///
/// 警告信息列表
///
public List Warnings { get; set; } = new List();
///
/// 发现的变量列表
///
public List Variables { get; set; } = new List();
///
/// 添加错误信息
///
/// 错误信息
public void AddError(string error)
{
IsValid = false;
Errors.Add(error);
}
///
/// 添加警告信息
///
/// 警告信息
public void AddWarning(string warning)
{
Warnings.Add(warning);
}
}
///
/// 预定义模板
///
public class PredefinedTemplate
{
///
/// 模板ID
///
public string TemplateId { get; set; } = "";
///
/// 模板名称
///
public string TemplateName { get; set; } = "";
///
/// 模板分类
///
public string Category { get; set; } = "";
///
/// 模板描述
///
public string Description { get; set; } = "";
///
/// 邮件主题模板
///
public string EmailSubjectTemplate { get; set; } = "";
///
/// 邮件内容模板
///
public string EmailContentTemplate { get; set; } = "";
///
/// 系统消息标题模板
///
public string SystemMessageTitleTemplate { get; set; } = "";
///
/// 系统消息内容模板
///
public string SystemMessageContentTemplate { get; set; } = "";
///
/// 支持的变量列表
///
public List SupportedVariables { get; set; } = new List();
}
///
/// 模板变量定义
///
public class TemplateVariable
{
///
/// 变量名
///
public string Name { get; set; } = "";
///
/// 变量描述
///
public string Description { get; set; } = "";
///
/// 变量类型
///
public string Type { get; set; } = "string";
///
/// 是否必需
///
public bool IsRequired { get; set; } = false;
///
/// 默认值
///
public string DefaultValue { get; set; } = "";
///
/// 示例值
///
public string ExampleValue { get; set; } = "";
}