Ver código fonte

Merge branch 'master' of http://git.fwt.com/Hotline/hotline

xf 2 anos atrás
pai
commit
d32eaac47f

+ 7 - 2
src/Hotline.Api/Controllers/SettingController.cs

@@ -1,4 +1,5 @@
-using Hotline.CallCenter.Manage;
+using Hotline.Caches;
+using Hotline.CallCenter.Manage;
 using Hotline.Permissions;
 using Hotline.Settings;
 using Hotline.Share.Requests;
@@ -15,12 +16,14 @@ namespace Hotline.Api.Controllers
         private readonly IVoiceFileDomainService _voiceFileDomainService;
         private readonly ISystemSettingRepository _systemSettingsRepository;
         private readonly ISystemSettingGroupRepository _systemSettingGroupRepository;
+        private readonly ISystemSettingCacheManager _systemSettingCacheManager;
 
-        public SettingController(IVoiceFileDomainService voiceFileDomainService, ISystemSettingRepository systemSettingsRepository, ISystemSettingGroupRepository systemSettingGroupRepository)
+        public SettingController(IVoiceFileDomainService voiceFileDomainService, ISystemSettingRepository systemSettingsRepository, ISystemSettingGroupRepository systemSettingGroupRepository,ISystemSettingCacheManager systemSettingCacheManager)
         {
             _voiceFileDomainService = voiceFileDomainService;
             _systemSettingsRepository = systemSettingsRepository;
             _systemSettingGroupRepository = systemSettingGroupRepository;
+            _systemSettingCacheManager = systemSettingCacheManager;
         }
 
         /// <summary>
@@ -81,6 +84,8 @@ namespace Hotline.Api.Controllers
                 {
                     model.SettingValue = request.list[i].value;
                     await _systemSettingsRepository.UpdateAsync(model, HttpContext.RequestAborted);
+                    //清除缓存
+                    _systemSettingCacheManager.DelSystemSetting(model.Code);
                 }
             }
         }

+ 1 - 1
src/Hotline.Api/StartupExtensions.cs

@@ -46,7 +46,7 @@ internal static class StartupExtensions
 #endif
 
         services.Configure<DeviceConfigs>(d => configuration.GetSection(nameof(DeviceConfigs)).Bind(d));
-        services.Configure<WorkTimeSettings>(d => configuration.GetSection(nameof(WorkTimeSettings)).Bind(d));
+        //services.Configure<WorkTimeSettings>(d => configuration.GetSection(nameof(WorkTimeSettings)).Bind(d));
         services.Configure<IdentityConfiguration>(d => configuration.GetSection(nameof(IdentityConfiguration)).Bind(d));
 
         // Add services to the container.

+ 9 - 9
src/Hotline.Api/appsettings.json

@@ -72,15 +72,15 @@
   "Cors": {
     "Origins": [ "http://localhost:8888", "http://admin.hotline.fw.com", "http://hotline.fw.com" ]
   },
-  "WorkTimeSettings": {
-    "MorningBegin": "08:00",
-    "MorningEnd": "12:00",
-    "AfterBegin": "15:00",
-    "AfterEnd": "21:00",
-    "WorkDay": [ 1, 2, 3, 4, 5, 0, 6 ],
-    "WorkCategory": "08da9b9f-a35d-4ade-8ea7-55e8abbcdefd",
-    "RestCategory": "08daa5f5-ac7a-4ced-8295-1c78baa15f9e"
-  },
+  //"WorkTimeSettings": {
+  //  "MorningBegin": "08:00",
+  //  "MorningEnd": "12:00",
+  //  "AfterBegin": "15:00",
+  //  "AfterEnd": "21:00",
+  //  "WorkDay": [ 1, 2, 3, 4, 5, 0, 6 ],
+  //  "WorkCategory": "08da9b9f-a35d-4ade-8ea7-55e8abbcdefd",
+  //  "RestCategory": "08daa5f5-ac7a-4ced-8295-1c78baa15f9e"
+  //},
   "Exceptionless": {
     "InUse": false,
     "ServerUrl": "http://log.fw.com",

+ 35 - 3
src/Hotline.Application/Handlers/CallCenter/FlowControl/IncomingNotificationHandler.cs

@@ -27,13 +27,18 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
         private readonly ITypedCache<WorkTimeSettings> _worktimeCache;
         private readonly IOptionsSnapshot<WorkTimeSettings> _worktimeOptions;
         private readonly ILogger<IncomingNotificationHandler> _logger;
+        private readonly ISystemSettingGroupRepository _systemSettingGroupRepository;
+        private readonly ISystemSettingRepository _systemSettingRepository;
+        
 
         public IncomingNotificationHandler(
             ICallRepository callRepository, ICallDetailRepository callDetailRepository,
             ISystemSettingCacheManager systemSettingCacheManager, IIvrCacheManager ivrCacheManager,
             INewRockClient newRockClient, IOptionsSnapshot<DeviceConfigs> options,
             ITypedCache<WorkTimeSettings> worktimeCache, IOptionsSnapshot<WorkTimeSettings> worktimeOptions,
-            ILogger<IncomingNotificationHandler> logger)
+            ILogger<IncomingNotificationHandler> logger,
+            ISystemSettingGroupRepository systemSettingGroupRepository,
+            ISystemSettingRepository systemSettingRepository)
         {
             _callRepository = callRepository;
             _callDetailRepository = callDetailRepository;
@@ -44,6 +49,8 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
             _worktimeCache = worktimeCache;
             _worktimeOptions = worktimeOptions;
             _logger = logger;
+            _systemSettingGroupRepository = systemSettingGroupRepository;
+            _systemSettingRepository = systemSettingRepository;
         }
 
         public async Task Handle(IncomingNotification notification, CancellationToken cancellationToken)
@@ -109,7 +116,32 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
 
         private Ivr GetCorrectIvr()
         {
-            var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d => _worktimeOptions.Value, ExpireMode.Absolute, TimeSpan.FromDays(1));
+            //TODO 从数据库或缓存中获取配置信息
+
+            //var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d => _worktimeOptions.Value, ExpireMode.Absolute, TimeSpan.FromDays(1));
+            var worktimeSettings = _worktimeCache.GetOrAdd("worktimesettings", d =>
+            {
+                WorkTimeSettings model = new WorkTimeSettings();
+                var settingslist = _systemSettingGroupRepository.GetAsync(x => x.GroupCode == "WorkTimeSetting").GetAwaiter().GetResult().SystemSettings;
+                if (settingslist !=null)
+                {
+                    //上午开始时间
+                    model.MorningBegin =  settingslist.First(x => x.Code == SettingConstants.MorningBegin).SettingValue;
+                    //上午结束时间
+                    model.MorningEnd = settingslist.First(x => x.Code == SettingConstants.MorningEnd).SettingValue;
+                    //下午开始时间
+                    model.AfterBegin = settingslist.First(x => x.Code == SettingConstants.AfterBegin).SettingValue;
+                    //下午结束时间
+                    model.AfterEnd = settingslist.First(x=>x.Code == SettingConstants.AfterEnd).SettingValue;
+                    //工作日
+                    model.WorkDay = settingslist.First(x => x.Code == SettingConstants.WorkTimeSetting).SettingValue;
+                    //工作时间IVR
+                    model.WorkCategory = _systemSettingRepository.GetAsync(x => x.Code == SettingConstants.WorkCategory).GetAwaiter().GetResult().SettingValue;
+                    //休息时间IVR
+                    model.RestCategory = _systemSettingRepository.GetAsync(x => x.Code == SettingConstants.RestCategory).GetAwaiter().GetResult().SettingValue;
+                }
+                return model;
+            }, ExpireMode.Absolute);
             var categoryId = GetCorrectCategory(worktimeSettings);
             var ivrList = _ivrCacheManager.GetIvrs();
             var ivr = ivrList.First(x => x.IvrCategoryId == categoryId && x.IsRoot);
@@ -118,7 +150,7 @@ namespace Hotline.Application.Handlers.CallCenter.FlowControl
 
         private string GetCorrectCategory(WorkTimeSettings settings)
         {
-            if (!settings.WorkDay.Contains((int)DateTime.Now.DayOfWeek))
+            if (!settings.WorkDay.Contains(((int)DateTime.Now.DayOfWeek).ToString()))
                 return settings.RestCategory;
             var time = TimeOnly.FromDateTime(DateTime.Now);
             if ((time >= TimeOnly.Parse(settings.MorningBegin) && time <= TimeOnly.Parse(settings.MorningEnd))

+ 15 - 0
src/Hotline.Repository.SqlSugar/System/SystemAuthorityRepository.cs

@@ -18,6 +18,10 @@ namespace Hotline.Repository.SqlSugar.System
         /// <returns></returns>
         public async Task<IReadOnlyList<SystemMenu>> GetMyMenu(string[] roles)
         {
+            if (roles.Contains("sysadmin"))
+            {
+                return await Db.Queryable<SystemMenu>().OrderBy(x => x.DisplayOrder).ToTreeAsync(x => x.children, it => it.ParentId, "");
+            }
             var list = await Db.Queryable<SystemAuthority>()
                 .Where(x => roles.Contains(x.RoleCode)).ToListAsync();
             var menuarr = new List<string>();
@@ -36,6 +40,10 @@ namespace Hotline.Repository.SqlSugar.System
         /// <returns></returns>
         public async Task<IReadOnlyList<string>> GetMyButton(string[] roles)
         {
+            if (roles.Contains("sysadmin"))
+            {
+                return await Db.Queryable<SystemButton>().Select(x => x.PermissionCode).ToListAsync();
+            }
             var list = await Db.Queryable<SystemAuthority>()
                 .Where(x => roles.Contains(x.RoleCode)).ToListAsync();
             var buttonarr = new List<string>();
@@ -53,6 +61,13 @@ namespace Hotline.Repository.SqlSugar.System
         /// <returns></returns>
         public IReadOnlyList<string> GetPermission(List<string> roles)
         {
+            if (roles.Contains("sysadmin"))
+            {
+                var menucodelist = Db.Queryable<SystemMenu>().Select(x => x.PermissionCode).ToList();
+                var buttoncodelist = Db.Queryable<SystemButton>().Select(x => x.PermissionCode).ToList();
+                menucodelist.AddRange(buttoncodelist);
+                return menucodelist;
+            }
             var list = Db.Queryable<SystemAuthority>()
                 .Where(x => roles.Contains(x.RoleCode)).ToList();
             var permissionarr = new List<string>();

+ 2 - 0
src/Hotline/Caches/ISystemSettingCacheManager.cs

@@ -6,5 +6,7 @@ namespace Hotline.Caches
     public interface ISystemSettingCacheManager
     {
         SystemSetting GetSetting(string code);
+
+        bool DelSystemSetting(string code);
     }
 }

+ 5 - 0
src/Hotline/Caches/SystemSettingCacheManager.cs

@@ -28,5 +28,10 @@ namespace Hotline.Caches
             });
             return setting;
         }
+
+        public bool DelSystemSetting(string code)
+        {
+            return _cacheSystemSetting.Remove(code);
+        }
     }
 }

+ 1 - 1
src/Hotline/Settings/WorkTimeSettings.cs

@@ -10,7 +10,7 @@
         
         public string AfterEnd { get; set; }
 
-        public List<int> WorkDay { get; set; }
+        public string WorkDay { get; set; }
 
         public string WorkCategory { get; set; }
 

+ 42 - 1
src/XF.Domain/Constants/SettingConstants.cs

@@ -8,8 +8,49 @@ namespace XF.Domain.Constants
 {
     public class SettingConstants
     {
+        /// <summary>
+        /// 是否启用IVR
+        /// </summary>
         public const string IVRConfig = "IVRConfig";
 
-        public const string WorkTimeVoice = "WorkTimeVoice";
+        /// <summary>
+        /// 时段定义
+        /// </summary>
+        public const string TimeOrder = "TimeOrder";
+
+        /// <summary>
+        /// 工作日定义
+        /// </summary>
+        public const string WorkTimeSetting = "WorkTimeSetting";
+
+        /// <summary>
+        /// 工作时段语音导航
+        /// </summary>
+        public const string WorkCategory = "WorkCategory";
+
+        /// <summary>
+        /// 休息时段语音导航
+        /// </summary>
+        public const string RestCategory = "RestCategory";
+
+        /// <summary>
+        /// 上午开始时间
+        /// </summary>
+        public const string MorningBegin = "MorningBegin";
+
+        /// <summary>
+        /// 上午结束时间
+        /// </summary>
+        public const string MorningEnd = "MorningEnd";
+
+        /// <summary>
+        /// 下午开始时间
+        /// </summary>
+        public const string AfterBegin = "AfterBegin";
+
+        /// <summary>
+        /// 下午结束时间
+        /// </summary>
+        public const string AfterEnd = "AfterEnd";
     }
 }