Просмотр исходного кода

Merge branch 'test' of http://110.188.24.182:10023/Fengwo/hotline into test

田爽 5 месяцев назад
Родитель
Сommit
145e851ce0

+ 1 - 2
src/Hotline.Api/Controllers/AiController.cs

@@ -1,5 +1,4 @@
-
-using Consul;
+using Consul;
 using DocumentFormat.OpenXml.Wordprocessing;
 using DotNetCore.CAP;
 using Hotline.Ai.CallOut;

+ 10 - 1
src/Hotline.Application.Tests/Application/SystemSettingCacheManagerTest.cs

@@ -1,20 +1,24 @@
 using Hotline.Caching.Interfaces;
 using Hotline.Caching.Services;
+using Hotline.Settings;
 using Shouldly;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using XF.Domain.Repository;
 
 namespace Hotline.Application.Tests.Application;
 public class SystemSettingCacheManagerTest
 {
     private readonly ISystemSettingCacheManager _systemSettingCacheManager;
+    private readonly IRepository<SystemSetting> _systemSettingRepository;
 
-    public SystemSettingCacheManagerTest(ISystemSettingCacheManager systemSettingCacheManager)
+    public SystemSettingCacheManagerTest(ISystemSettingCacheManager systemSettingCacheManager, IRepository<SystemSetting> systemSettingRepository)
     {
         _systemSettingCacheManager = systemSettingCacheManager;
+        _systemSettingRepository = systemSettingRepository;
     }
 
     [Fact]
@@ -24,5 +28,10 @@ public class SystemSettingCacheManagerTest
         result.ShouldBeTrue();
         var seconds = _systemSettingCacheManager.VisitCallDelaySecond;
         seconds.ShouldBe(60);
+
+        var delaySecond =  _systemSettingCacheManager.DefaultVisitSmsDelaySecond;
+        delaySecond.ShouldBe(172800);
+        var delaySecondEntity = _systemSettingRepository.GetAsync("08dc0681-a6d2-4ce7-877d-db65f846d523");
+        delaySecondEntity.ShouldNotBeNull("DefaultVisitSmsDelaySecond 系统设置为NULL");
     }
 }

+ 1 - 1
src/Hotline.Application/CallCenter/DefaultCallApplication.cs

@@ -483,7 +483,7 @@ public abstract class DefaultCallApplication : ICallApplication
     {
         // 延迟一段时间后去通话记录中查询有通话音频记录文件的那通电话记录关联回工单.
         var second = _systemSettingCacheManager.VisitCallDelaySecond;
-        await _capPublisher.PublishDelayAsync(TimeSpan.FromSeconds(second), EventNames.OrderRelateCall, orderId);
+        await _capPublisher.PublishDelayAsync(TimeSpan.FromSeconds(second), EventNames.OrderRelateCall, orderId, cancellationToken: cancellationToken);
     }
 
     /// <summary>

+ 4 - 6
src/Hotline.Application/Handlers/Order/OrderRelateCallHandler.cs

@@ -16,14 +16,11 @@ namespace Hotline.Application.Handlers.Order
 {
     public class OrderRelateCallHandler : ICapSubscribe, ITransientDependency
     {
-        private readonly IOrderRepository _orderRepository;
-        private readonly IRepository<TrCallRecord> _trCallRecordRepository;
-
+        private readonly ICallApplication _callApplication;
 
-        public OrderRelateCallHandler(IOrderRepository orderRepository, IRepository<TrCallRecord> trCallRecordRepository)
+        public OrderRelateCallHandler(ICallApplication callApplication)
         {
-            _orderRepository = orderRepository;
-            _trCallRecordRepository = trCallRecordRepository;
+            _callApplication = callApplication;
         }
 
         /// <summary>
@@ -35,6 +32,7 @@ namespace Hotline.Application.Handlers.Order
         [CapSubscribe(EventNames.OrderRelateCall)]
         public async Task OrderRelateCallAsync(string orderId, CancellationToken cancellationToken)
         {
+            await _callApplication.OrderRelateCallHandlerAsync(orderId, cancellationToken);
         }
     }
 

+ 3 - 2
src/Hotline.Application/Orders/OrderApplication.cs

@@ -1018,11 +1018,12 @@ public class OrderApplication : IOrderApplication, IScopeDependency
                 .SetColumns(m => m.VisitState == EVisitState.SMSVisiting)
                 .SetColumns(m => m.VisitType == EVisitType.SmsVisit)
                 .SetColumns(m => m.EmployeeId == _sessionContextProvider.SessionContext.RequiredUserId)
-                .ExecuteCommandAsync();
+                .ExecuteCommandAsync(cancellationToken);
 
             // 发送短信后推送一个 48小时的延迟消息队列. 当消息队列收到消息时, 判断用户是否回复了, 如果未回复短信就 默认满意
+            var delaySecond = _systemSettingCacheManager.DefaultVisitSmsDelaySecond;
             await _capPublisher.PublishDelayAsync(
-                TimeSpan.FromDays(2),
+                TimeSpan.FromSeconds(delaySecond),
                 EventNames.UpdateVisitDelaySms,
                 messageDto,
                 cancellationToken: cancellationToken);

+ 6 - 0
src/Hotline/Caching/Interfaces/ISystemSettingCacheManager.cs

@@ -32,5 +32,11 @@ namespace Hotline.Caching.Interfaces
         /// 如果回访通话记录有多条, 需要关联通话时长最长的那条
         /// </summary>
         int VisitCallDelaySecond { get; }
+
+        /// <summary>
+        /// 发送回访短信后等候市民回复短信的时间
+        /// 如果超过这个时间就更新回访为默认满意
+        /// </summary>
+        int DefaultVisitSmsDelaySecond { get; }
     }
 }

+ 39 - 7
src/Hotline/Caching/Services/SystemSettingCacheManager.cs

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

+ 6 - 0
src/Hotline/Settings/SettingConstants.cs

@@ -601,5 +601,11 @@ namespace Hotline.Settings
         /// 如果回访通话记录有多条, 需要关联通话时长最长的那条
         /// </summary>
         public const string VisitCallDelaySecond = "VisitCallDelaySecond";
+
+        /// <summary>
+        /// 发送回访短信后等候市民回复短信的时间
+        /// 如果超过这个时间就更新回访为默认满意
+        /// </summary>
+        public const string DefaultVisitSmsDelaySecond = "DefaultVisitSmsDelaySecond";
     }
 }