Procházet zdrojové kódy

增加推送网格员事件

qinchaoyue před 4 měsíci
rodič
revize
daa53f6966

+ 17 - 1
src/Hotline.Application.Tests/Application/SnapshotApplicationTest.cs

@@ -17,6 +17,7 @@ using Hotline.Share.Enums.Snapshot;
 using Hotline.Share.Tools;
 using Hotline.Snapshot;
 using Hotline.Snapshot.Interfaces;
+using Hotline.Snapshot.Notifications;
 using Hotline.Users;
 using Microsoft.AspNetCore.Http;
 using Microsoft.Extensions.DependencyInjection;
@@ -41,8 +42,9 @@ public class SnapshotApplicationTest : TestBase
     private readonly ISessionContext _sessionContext;
     private readonly IGuiderSystemService _guiderSystemService;
     private readonly ISystemSettingCacheManager _systemSettingCacheManager;
+    private readonly SnapshotPushNotificationHandler _snapshotPushNotificationHandler;
 
-    public SnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, ISnapshotApplication snapshotApplication, IIdentityAppService identityAppService, IRepository<RedPackRecord> redPackRecordRepository, IIndustryApplication industryApplication, IIndustryRepository industryRepository, IFileRepository fileRepository, OrderServiceMock orderServiceMock, IOrderRepository orderRepository, IOrderSnapshotRepository orderSnapshotRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ISessionContext sessionContext, IGuiderSystemService guiderSystemService, ISystemSettingCacheManager systemSettingCacheManager) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount)
+    public SnapshotApplicationTest(IAccountRepository accountRepository, IRepository<Role> roleRepository, UserController userController, IServiceScopeFactory scopeFactory, IRepository<User> userRepository, IHttpContextAccessor httpContextAccessor, ISnapshotApplication snapshotApplication, IIdentityAppService identityAppService, IRepository<RedPackRecord> redPackRecordRepository, IIndustryApplication industryApplication, IIndustryRepository industryRepository, IFileRepository fileRepository, OrderServiceMock orderServiceMock, IOrderRepository orderRepository, IOrderSnapshotRepository orderSnapshotRepository, IThirdIdentiyService thirdService, IThirdAccountRepository thirdAccount, ISessionContext sessionContext, IGuiderSystemService guiderSystemService, ISystemSettingCacheManager systemSettingCacheManager, SnapshotPushNotificationHandler snapshotPushNotificationHandler) : base(accountRepository, roleRepository, userController, scopeFactory, userRepository, httpContextAccessor, thirdService, thirdAccount)
     {
         _snapshotApplication = snapshotApplication;
         _identityAppService = identityAppService;
@@ -57,6 +59,7 @@ public class SnapshotApplicationTest : TestBase
         _sessionContext = sessionContext;
         _guiderSystemService = guiderSystemService;
         _systemSettingCacheManager = systemSettingCacheManager;
+        _snapshotPushNotificationHandler = snapshotPushNotificationHandler;
     }
 
     [Fact]
@@ -266,6 +269,19 @@ public class SnapshotApplicationTest : TestBase
         result.Id.ShouldNotBeNull();
     }
 
+    [Fact]
+    public async Task SnapshotPushNotificationHandler_Test()
+    {
+        var orderId = "08dd18e0-1c9e-4aa5-8dc6-f639e8d1b3ea";
+        await _snapshotPushNotificationHandler.Handle(new PostGuiderSystemNotification { OrderId = orderId}, CancellationToken.None);
+        var order = await _orderRepository.GetAsync(orderId);
+        var orderSnapshot = await _orderSnapshotRepository.GetAsync(orderId);
+        orderSnapshot.ShouldNotBeNull();
+        orderSnapshot.GuiderAccLog.ShouldNotBeNullOrEmpty();
+        orderSnapshot.GuiderSystemId.ShouldNotBeNullOrEmpty();
+        orderSnapshot.DeadLine.ShouldNotBeNull();
+    }
+
     [Fact]
     public async Task SaveInvitationCode_Test()
     {

+ 2 - 0
src/Hotline.Application.Tests/Startup.cs

@@ -61,6 +61,7 @@ using Hotline.WeChat;
 using Hotline.Api.Controllers.Snapshot;
 using Hotline.Snapshot.Interfaces;
 using TianQue.Sdk;
+using Hotline.Snapshot.Notifications;
 
 namespace Hotline.Application.Tests;
 public class Startup
@@ -184,6 +185,7 @@ public class Startup
             services.AddScoped<XingTangCallsSyncJob>();
             services.AddXingTangDb(callCenterConfiguration.XingTang);
             services.AddScoped<IGuiderSystemService, TiqnQueService>();
+            services.AddScoped<SnapshotPushNotificationHandler>();
             //ServiceLocator.Instance = services.BuildServiceProvider();
         }
 

+ 13 - 0
src/Hotline.Share/Dtos/Snapshot/ThirdTokenDto.cs

@@ -92,6 +92,19 @@ public class ThirdTokenOutDto
     public string OpenId { get; set; }
 }
 
+public class GuiderSystemOutDto
+{
+    /// <summary>
+    /// 网格员系统Id
+    /// </summary>
+    public string GuiderSystemId { get; set; }
+
+    /// <summary>
+    /// 附加数据
+    /// </summary>
+    public string JsonData { get; set; }
+}
+
 public class ThirdTokenDto : ThirdTokenInDto
 {
     /// <summary>

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

@@ -89,5 +89,10 @@ namespace Hotline.Caching.Interfaces
         /// 天阙服务AppKey|AppSecret
         /// </summary>
         string TianQueAppKeySecret { get; }
+
+        /// <summary>
+        /// 天阙推送受理信息接口Url
+        /// </summary>
+        string TianQuanPostAcceptInfoApi { get; }
     }
 }

+ 6 - 0
src/Hotline/Caching/Services/SystemSettingCacheManager.cs

@@ -187,5 +187,11 @@ namespace Hotline.Caching.Services
         /// </summary>
         public string TianQueAppKeySecret =>
             GetOrDefault("08dcf4d7-3746-4f16-86b6-ef820421e5cb", SettingConstants.TianQueAppKeySecret, "天阙服务AppKey|AppSecret", "TAjYAYuA|c01eb299b9d784bf55681af4da86bab6ba428101", "天阙服务 AppKey|AppSecret, Key 和 Secret 使用 | 分隔");
+
+        /// <summary>
+        /// 天阙推送受理信息接口Url
+        /// </summary>
+        public string TianQuanPostAcceptInfoApi =>
+            GetOrDefault("08dcd143-5f4b-477f-80e2-c2326d1d82e8", SettingConstants.TianQuanPostAcceptInfoApi, "天阙推送受理信息API接口地址", "http://10.0.188.11:6090/api/v1/test/accept/saveAcceptInfoApi", "测试: http://10.0.188.11:6090/api/v1/test/accept/saveAcceptInfoApi  正式: http://10.0.188.11:6090/api/v1/prod/accept/saveAcceptInfoApi");
     }
 }

+ 7 - 2
src/Hotline/Settings/SettingConstants.cs

@@ -656,12 +656,17 @@ namespace Hotline.Settings
         /// <summary>
         /// 小程序Banner集合
         /// </summary>
-        public static string AppBanner = "小程序Banner";
+        public const string AppBanner = "小程序Banner";
 
         /// <summary>
         /// 天阙服务AppKey|AppSecret
         /// </summary>
-        public static string TianQueAppKeySecret = "TianQueAppKeySecret";
+        public const string TianQueAppKeySecret = "TianQueAppKeySecret";
+
+        /// <summary>
+        /// 天阙推送受理信息接口Url
+        /// </summary>
+        public const string TianQuanPostAcceptInfoApi = "TianQuanPostAcceptInfoApi";
 
         /// <summary>
         /// 部门满意度明细不显示工单

+ 3 - 2
src/Hotline/Snapshot/Interfaces/IGuiderSystemService.cs

@@ -1,4 +1,5 @@
-using Hotline.Orders;
+using Fw.Utility.UnifyResponse;
+using Hotline.Orders;
 using Hotline.Share.Dtos.Snapshot;
 using System;
 using System.Collections.Generic;
@@ -13,6 +14,6 @@ namespace Hotline.Snapshot.Interfaces;
 /// </summary>
 public interface IGuiderSystemService
 {
-   Task<string> PostOrder(Order order, OrderSnapshot orderSnapshot, ThirdTokenDto tokenDto);
+   Task<ApiResponse<GuiderSystemOutDto>> PostOrder(Order order, OrderSnapshot orderSnapshot, ThirdTokenDto tokenDto);
 }
 

+ 74 - 0
src/Hotline/Snapshot/Notifications/PostGuiderSystemNotification.cs

@@ -0,0 +1,74 @@
+using Hotline.Caching.Interfaces;
+using Hotline.Orders;
+using Hotline.Settings;
+using Hotline.Share.Dtos.Snapshot;
+using Hotline.Share.Tools;
+using Hotline.Snapshot.Interfaces;
+using MediatR;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Snapshot.Notifications;
+
+/// <summary>
+/// 推送网格员系统通知
+/// </summary>
+public class PostGuiderSystemNotification : INotification
+{
+    /// <summary>
+    /// Id
+    /// </summary>
+    public string OrderId { get; set; }
+}
+
+/// <summary>
+/// 推送网格员系统
+/// </summary>
+public class SnapshotPushNotificationHandler : INotificationHandler<PostGuiderSystemNotification>
+{
+    private readonly string LogName = "推送网格员系统";
+    private readonly IGuiderSystemService _guiderSystemService;
+    private readonly IOrderRepository _orderRepository;
+    private readonly ISystemLogRepository _systemLog;
+    private readonly ISystemSettingCacheManager _sysSetting;
+    private readonly IOrderSnapshotRepository _orderSnapshotRepository;
+
+    public SnapshotPushNotificationHandler(IGuiderSystemService guiderSystemService, IOrderRepository orderRepository, ISystemLogRepository systemLog, ISystemSettingCacheManager systemSettingCacheManager, IOrderSnapshotRepository orderSnapshotRepository)
+    {
+        _guiderSystemService = guiderSystemService;
+        _orderRepository = orderRepository;
+        _systemLog = systemLog;
+        _sysSetting = systemSettingCacheManager;
+        _orderSnapshotRepository = orderSnapshotRepository;
+    }
+
+    public async Task Handle(PostGuiderSystemNotification notification, CancellationToken cancellationToken)
+    {
+        var order = await _orderRepository.GetAsync(notification.OrderId);
+        var orderSnapshot = await _orderSnapshotRepository.GetAsync(notification.OrderId);
+        if (order is null || orderSnapshot is null)
+        {
+            var msg = order is null ? "order" : "orderSnapshot";
+            _systemLog.Add(LogName, $"OrderId: {notification.OrderId}", $"根据Id查询{msg}为null");
+        }
+        var keySecret = _sysSetting.TianQueAppKeySecret.Split(',');
+        var token = new ThirdTokenDto
+        {
+            AppId = keySecret[0],
+            Secret = keySecret[1]
+        };
+        var result = await _guiderSystemService.PostOrder(order, orderSnapshot, token);
+        if (result.Code != 0)
+        {
+            _systemLog.Add(LogName, $"OrderNo: {order.No}", $"推送失败: {result.ToJson()}");
+        }
+        orderSnapshot.GuiderSystemId = result.Result.GuiderSystemId;
+        orderSnapshot.DeadLine = DateTime.Now.AddHours(_sysSetting.OvertimeBack);
+        orderSnapshot.GuiderAccLog = result.Result.ToJson();
+        await _orderSnapshotRepository.UpdateAsync(orderSnapshot);
+        _systemLog.Add(LogName, $"OrderNo: {order.No}", status: 1);
+    }
+}

+ 12 - 0
src/Hotline/Snapshot/OrderSnapshot.cs

@@ -76,6 +76,18 @@ public class OrderSnapshot : CreationSoftDeleteEntity
 
     #region 网格员回复
 
+    /// <summary>
+    /// 网格员系统Id
+    /// </summary>
+    [SugarColumn(ColumnDescription = "网格员系统Id")]
+    public string? GuiderSystemId { get;  set; }
+
+    /// <summary>
+    /// 网格员系统交互日志
+    /// </summary>
+    [SugarColumn(ColumnDescription = "网格员系统交互日志")]
+    public string? GuiderAccLog { get; set; }
+
     /// <summary>
     /// 网格员回复截止日期
     /// </summary>

+ 18 - 7
src/TianQue.Sdk/TiqnQueService.cs

@@ -1,4 +1,6 @@
-using Hotline.Orders;
+using Fw.Utility.UnifyResponse;
+using Hotline.Caching.Interfaces;
+using Hotline.Orders;
 using Hotline.Share.Dtos.Snapshot;
 using Hotline.Share.Tools;
 using Hotline.Snapshot;
@@ -18,14 +20,15 @@ namespace TianQue.Sdk;
 public class TiqnQueService : IGuiderSystemService, IScopeDependency
 {
     private readonly ILogger<TQHttpClient> _logger;
-    private readonly string _url = "http://10.0.188.11:6090/api/v1/test/accept/saveAcceptInfoApi";
+    private readonly ISystemSettingCacheManager _sysSetting;
 
-    public TiqnQueService(ILogger<TQHttpClient> logger)
+    public TiqnQueService(ILogger<TQHttpClient> logger, ISystemSettingCacheManager sysSetting)
     {
         _logger = logger;
+        _sysSetting = sysSetting;
     }
 
-    public async Task<string> PostOrder(Order order, OrderSnapshot orderSnapshot, ThirdTokenDto tokenDto)
+    public async Task<ApiResponse<GuiderSystemOutDto>> PostOrder(Order order, OrderSnapshot orderSnapshot, ThirdTokenDto tokenDto)
     {
         TQHttpClient httpClient;
 #if DEBUG
@@ -55,13 +58,21 @@ public class TiqnQueService : IGuiderSystemService, IScopeDependency
         acceptInfo.PersonList = new List<PersonInfo>
         {
             new() {
-                // ReflectCardId = // 反映人身份证号
                 ReflectPhone = order.Contact!, // 电话
                 ReflectUserName = order.FromName!, // 姓名
             } 
         };
         acceptInfo.ValidateObject();
-        var result = await httpClient.PostAsync<ApiReponse<AcceptInfoSuccessDto>>(new Uri(_url), acceptInfo);
-        return result.ToJson();
+        var result = await httpClient.PostAsync<ApiReponse<AcceptInfoSuccessDto>>(new Uri(_sysSetting.TianQuanPostAcceptInfoApi), acceptInfo);
+        return new ApiResponse<GuiderSystemOutDto>
+        {
+            Code = result.Success ? 0 : 1,
+            Message = result.Msg,
+            Result = new GuiderSystemOutDto
+            {
+                GuiderSystemId = result.Data.AppealNumber,
+                JsonData = result.Data.ToJson()
+            }
+        };
     }
 }