|
@@ -1,5 +1,8 @@
|
|
using Hotline.Caching.Interfaces;
|
|
using Hotline.Caching.Interfaces;
|
|
using Hotline.Settings;
|
|
using Hotline.Settings;
|
|
|
|
+using Hotline.Share.Tools;
|
|
|
|
+using Microsoft.Extensions.Logging;
|
|
|
|
+using Newtonsoft.Json.Linq;
|
|
using XF.Domain.Cache;
|
|
using XF.Domain.Cache;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Dependency;
|
|
using XF.Domain.Exceptions;
|
|
using XF.Domain.Exceptions;
|
|
@@ -10,13 +13,15 @@ namespace Hotline.Caching.Services
|
|
public class SystemSettingCacheManager : ISystemSettingCacheManager, IScopeDependency
|
|
public class SystemSettingCacheManager : ISystemSettingCacheManager, IScopeDependency
|
|
{
|
|
{
|
|
|
|
|
|
|
|
+ private readonly ILogger<SystemSettingCacheManager> _logger;
|
|
private readonly ITypedCache<SystemSetting> _cacheSystemSetting;
|
|
private readonly ITypedCache<SystemSetting> _cacheSystemSetting;
|
|
private readonly IRepository<SystemSetting> _systemSettingRepository;
|
|
private readonly IRepository<SystemSetting> _systemSettingRepository;
|
|
|
|
|
|
- public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository)
|
|
|
|
|
|
+ public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository, ILogger<SystemSettingCacheManager> logger)
|
|
{
|
|
{
|
|
_cacheSystemSetting = cacheSystemSetting;
|
|
_cacheSystemSetting = cacheSystemSetting;
|
|
_systemSettingRepository = systemSettingRepository;
|
|
_systemSettingRepository = systemSettingRepository;
|
|
|
|
+ _logger = logger;
|
|
}
|
|
}
|
|
|
|
|
|
public SystemSetting? GetSetting(string code)
|
|
public SystemSetting? GetSetting(string code)
|
|
@@ -36,7 +41,7 @@ namespace Hotline.Caching.Services
|
|
_cacheSystemSetting.Remove(code);
|
|
_cacheSystemSetting.Remove(code);
|
|
}
|
|
}
|
|
|
|
|
|
- public string GetOrDefault(string code, string name, string defaultValue, string remark)
|
|
|
|
|
|
+ public string GetOrSetDefault(string code, string name, string defaultValue, string remark, string id = "")
|
|
{
|
|
{
|
|
try
|
|
try
|
|
{
|
|
{
|
|
@@ -48,18 +53,36 @@ namespace Hotline.Caching.Services
|
|
{
|
|
{
|
|
if (e.Message.Contains("无效系统设置"))
|
|
if (e.Message.Contains("无效系统设置"))
|
|
{
|
|
{
|
|
- _systemSettingRepository.AddAsync(new SystemSetting
|
|
|
|
|
|
+ var entity = new SystemSetting
|
|
{
|
|
{
|
|
Code = code,
|
|
Code = code,
|
|
SettingName = name,
|
|
SettingName = name,
|
|
SettingValue = [defaultValue],
|
|
SettingValue = [defaultValue],
|
|
Remark = remark
|
|
Remark = remark
|
|
- }).GetAwaiter().GetResult();
|
|
|
|
|
|
+ };
|
|
|
|
+ if (id.NotNullOrEmpty())
|
|
|
|
+ entity.Id = id;
|
|
|
|
+ _systemSettingRepository.AddAsync(entity).GetAwaiter().GetResult();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return defaultValue;
|
|
return defaultValue;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public T GetOrDefault<T>(string id, string code, string name, T defaultValue, string remark) where T : struct
|
|
|
|
+ {
|
|
|
|
+ var value = GetOrSetDefault(code, name, defaultValue.ToString(), remark, id);
|
|
|
|
+
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ return (T)Convert.ChangeType(value, typeof(T));
|
|
|
|
+ }
|
|
|
|
+ catch (InvalidCastException e)
|
|
|
|
+ {
|
|
|
|
+ _logger.LogError($"无法将 '{value}' 转换为类型 {typeof(T).Name}!已返回默认值 {defaultValue}. {e.Message}");
|
|
|
|
+ }
|
|
|
|
+ return defaultValue;
|
|
|
|
+ }
|
|
|
|
+
|
|
public int EffectiveTimes
|
|
public int EffectiveTimes
|
|
=> int.Parse(GetSetting(SettingConstants.EffectiveTimes)?.SettingValue[0]);
|
|
=> int.Parse(GetSetting(SettingConstants.EffectiveTimes)?.SettingValue[0]);
|
|
|
|
|
|
@@ -88,7 +111,7 @@ namespace Hotline.Caching.Services
|
|
{
|
|
{
|
|
get
|
|
get
|
|
{
|
|
{
|
|
- var value = GetOrDefault(SettingConstants.VisitCallDelaySecond, "回访通话记录同步延时时间(秒)", "60", "保存回访详情时发送延迟消息同步通话记录,如果回访通话记录有多条, 需要关联通话时长最长的那条");
|
|
|
|
|
|
+ var value = GetOrSetDefault(SettingConstants.VisitCallDelaySecond, "回访通话记录同步延时时间(秒)", "60", "保存回访详情时发送延迟消息同步通话记录,如果回访通话记录有多条, 需要关联通话时长最长的那条");
|
|
if (int.TryParse(value, out var seconds))
|
|
if (int.TryParse(value, out var seconds))
|
|
return seconds;
|
|
return seconds;
|
|
|
|
|
|
@@ -100,7 +123,7 @@ namespace Hotline.Caching.Services
|
|
{
|
|
{
|
|
get
|
|
get
|
|
{
|
|
{
|
|
- var value = GetOrDefault(SettingConstants.AutomaticPublishOrder, "自动发布中心直办归档工单", "false", "用于中心直办件归档后默认自动发布, 开启就自动发布.true 或者 false");
|
|
|
|
|
|
+ var value = GetOrSetDefault(SettingConstants.AutomaticPublishOrder, "自动发布中心直办归档工单", "false", "用于中心直办件归档后默认自动发布, 开启就自动发布.true 或者 false");
|
|
if (value == "true")
|
|
if (value == "true")
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
@@ -113,7 +136,7 @@ namespace Hotline.Caching.Services
|
|
{
|
|
{
|
|
get
|
|
get
|
|
{
|
|
{
|
|
- var value = GetOrDefault(SettingConstants.CancelPublishOrderEnabled, "取消发布功能开关", "false", "取消发布功能总开关, 关闭后取消发布功能的所有代码都不会执行.true 或者 false");
|
|
|
|
|
|
+ var value = GetOrSetDefault(SettingConstants.CancelPublishOrderEnabled, "取消发布功能开关", "false", "取消发布功能总开关, 关闭后取消发布功能的所有代码都不会执行.true 或者 false");
|
|
if (value == "true")
|
|
if (value == "true")
|
|
{
|
|
{
|
|
return true;
|
|
return true;
|
|
@@ -121,5 +144,14 @@ namespace Hotline.Caching.Services
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// 发送回访短信后等候市民回复短信的时间(秒)
|
|
|
|
+ /// 如果超过这个时间就更新回访为默认满意
|
|
|
|
+ /// </summary>
|
|
|
|
+ public int DefaultVisitSmsDelaySecond =>
|
|
|
|
+ GetOrDefault<int>("08dc0681-a6d2-4ce7-877d-db65f846d523", SettingConstants.DefaultVisitSmsDelaySecond, "发送回访短信后等候市民回复短信的时间(秒)", 172800,
|
|
|
|
+ "发送回访短信后等候市民回复短信的时间(秒), 如果超过这个时间就更新回访为默认满意. 默认 172800.");
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|