using MyCode.Project.Infrastructure.Constant; using MyCode.Project.Infrastructure.Extensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyCode.Project.Domain.Businesses.WorkProcess { /// /// 通知模板基类 /// public abstract class NotificationTemplateBase { /// /// 业务说明 /// public string First { get; set; } /// /// 备注 /// public string Remark { get; set; } /// /// 参数字典 /// protected Dictionary ParamDict = new Dictionary(); /// /// 备注模板 /// protected string Template { get; set; } /// /// 添加参数 /// /// 键 /// 值 protected void Add(string key, object value) { if (string.IsNullOrEmpty(key)) { return; } if (value==null || value.SafeString().IsEmpty()) { return; } ParamDict.Add(key, value); } /// /// 初始化参数值 /// protected virtual void InitParamValue() { } /// /// 格式化备注模板 /// /// public void FormatRemarkTemplate() { if (Template.IsEmpty()) { return; } InitParamValue(); var tpl = Template; foreach (var param in ParamDict) { var value = param.Value.SafeString(); tpl = tpl.Replace(param.Key, value); } tpl = tpl.Replace(LxmConst.WechatTemplate.LINE_KEY, LxmConst.WechatTemplate.LINE); Remark = tpl; } /// /// 设置 备注模板 /// /// 短信模板 public void SetTemplate(string template) { Template = template; } } }