Procházet zdrojové kódy

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

qinchaoyue před 5 dny
rodič
revize
9e78cddaeb

+ 1 - 1
src/Hotline.Api/Controllers/OrderController.cs

@@ -7223,7 +7223,7 @@ public class OrderController : BaseController
                 BusinessType = dto.BusinessType
             };
 
-            if (dto.FlowDirection is not EFlowDirection.OrgToOrg)
+            if (dto.FlowDirection is not EFlowDirection.OrgToOrg and not EFlowDirection.Other)
             {
                 //重新计算期满时间
                 ExpiredTimeWithConfig expiredTime;

+ 7 - 1
src/Hotline/Caching/Interfaces/ISystemSettingCacheManager.cs

@@ -1,4 +1,5 @@
 using Hotline.Settings;
+using Hotline.Snapshot;
 
 namespace Hotline.Caching.Interfaces
 {
@@ -62,7 +63,7 @@ namespace Hotline.Caching.Interfaces
         /// 微信小程序Secret
         /// </summary>
         string WxOpenAppSecret { get; }
-        
+
         /// <summary>
         /// 微信小程序OpenId
         /// </summary>
@@ -104,6 +105,11 @@ namespace Hotline.Caching.Interfaces
         /// </summary>
         string TianQuanPostAcceptInfoApi { get; }
 
+        /// <summary>
+        /// 天阙接口请求方式
+        /// </summary>
+        ETianqueRequestMode TianQueRequestMode { get; }
+
         bool Snapshot { get; }
 
         /// <summary>

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

@@ -9,6 +9,7 @@ using Microsoft.Extensions.Logging;
 using Microsoft.Extensions.Options;
 using Newtonsoft.Json.Linq;
 using System.Reflection.Metadata.Ecma335;
+using Hotline.Snapshot;
 using XF.Domain.Cache;
 using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
@@ -216,6 +217,10 @@ namespace Hotline.Caching.Services
         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");
 
+        public ETianqueRequestMode TianQueRequestMode =>
+            GetOrDefault("08dc941d-3344-420f-8c3a-fdb7a90d0948", SettingConstants.TianQueRequestMode, "天阙接口请求方式",
+                ETianqueRequestMode.ProEnvProUrl, "天阙接口请求方式");
+
         /// <summary>
         /// 随手拍功能开关
         /// </summary>

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

@@ -695,6 +695,11 @@ namespace Hotline.Settings
         /// </summary>
         public const string TianQuanPostAcceptInfoApi = "TianQuanPostAcceptInfoApi";
 
+        /// <summary>
+        /// 天阙接口请求方式
+        /// </summary>
+        public const string TianQueRequestMode = "TianQueRequestMode";
+
         /// <summary>
         /// 网格员回复等待时间(单位:小时)
         /// 超过该时间自动退回工单

+ 29 - 0
src/Hotline/Snapshot/ETianqueRequestMode.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Snapshot
+{
+    /// <summary>
+    /// 天阙接口请求方式
+    /// </summary>
+    public enum ETianqueRequestMode
+    {
+        /// <summary>
+        /// 测试环境测试地址
+        /// </summary>
+        TestEnvTestUrl = 0,
+
+        /// <summary>
+        /// 生产环境测试地址
+        /// </summary>
+        ProEnvTestUrl = 1,
+
+        /// <summary>
+        /// 生产环境正式地址
+        /// </summary>
+        ProEnvProUrl = 2,
+    }
+}

+ 8 - 7
src/TianQue.Sdk/TQHttpClient.cs

@@ -16,6 +16,7 @@ public class TQHttpClient
 {
     private readonly string AppSecret;
     private readonly string AppKey;
+    private readonly IHttpClientFactory _httpClientFactory;
 
     /// <summary>
     /// ssh服务器ip
@@ -41,22 +42,21 @@ public class TQHttpClient
 
     private readonly ILogger<TQHttpClient> _logger;
 
-    public TQHttpClient(string appSecret, string appKey, ILogger<TQHttpClient> logger)
+    public TQHttpClient(string appSecret, string appKey, IHttpClientFactory httpClientFactory, ILogger<TQHttpClient> logger)
     {
         AppSecret = appSecret;
         AppKey = appKey;
+        _httpClientFactory = httpClientFactory;
         _logger = logger;
     }
 
-    public TQHttpClient(string appSecret, string appKey, string sshHost, int sshPort, string sshUserName, string sshPassword, ILogger<TQHttpClient> logger)
+    public TQHttpClient(string appSecret, string appKey, string sshHost, int sshPort, string sshUserName, string sshPassword, IHttpClientFactory httpClientFactory, ILogger<TQHttpClient> logger)
+        : this(appSecret, appKey, httpClientFactory, logger)
     {
-        AppSecret = appSecret;
-        AppKey = appKey;
         SSHHost = sshHost;
         SSHPort = sshPort;
         SSHUserName = sshUserName;
         SSHPassword = sshPassword;
-        _logger = logger;
         _sshClient = new SshClient(SSHHost, SSHPort, SSHUserName, SSHPassword);
     }
 
@@ -66,7 +66,8 @@ public class TQHttpClient
         {
             var headers = new Dictionary<string, object> { { "_timeStamp", DateTime.Now.ToUnixTimeMilliseconds() }, { "_nonce", SignUtils.GenerateNonce() } };
             var sortedDic = new SortedDictionary<string, object>(data.ToDictionary());
-            var body = sortedDic.ToJson(new JsonSerializerSettings {
+            var body = sortedDic.ToJson(new JsonSerializerSettings
+            {
                 NullValueHandling = NullValueHandling.Ignore,
                 ContractResolver = new CamelCasePropertyNamesContractResolver(),
                 DateFormatString = "yyyy-MM-dd HH:mm:ss.fff"
@@ -90,7 +91,7 @@ public class TQHttpClient
             {
                 content.Headers.Add(header.Key, header.Value.ToString());
             }
-            var resp = await (new HttpClient()).PostAsync(uri.ToString(), content);
+            var resp = await (_httpClientFactory.CreateClient()).PostAsync(uri.ToString(), content);
             resp.EnsureSuccessStatusCode();
             var result = await resp.Content.ReadAsStringAsync();
             _logger.LogInformation($"天阙交互; url: {uri.ToString()}, headers: {headers.ToJson()} request: {body}, response: {result}");

+ 42 - 19
src/TianQue.Sdk/TiqnQueService.cs

@@ -22,11 +22,13 @@ public class TiqnQueService : IGuiderSystemService, IScopeDependency
 {
     private readonly ILogger<TQHttpClient> _logger;
     private readonly ISystemSettingCacheManager _sysSetting;
+    private readonly IHttpClientFactory _httpClientFactory;
 
-    public TiqnQueService(ILogger<TQHttpClient> logger, ISystemSettingCacheManager sysSetting)
+    public TiqnQueService(ILogger<TQHttpClient> logger, ISystemSettingCacheManager sysSetting, IHttpClientFactory httpClientFactory)
     {
         _logger = logger;
         _sysSetting = sysSetting;
+        _httpClientFactory = httpClientFactory;
     }
 
     /// <summary>
@@ -39,16 +41,16 @@ public class TiqnQueService : IGuiderSystemService, IScopeDependency
     public async Task<ApiResponse<GuiderSystemOutDto>> PostOrder(Order order, OrderSnapshot orderSnapshot, ThirdTokenDto tokenDto)
     {
         var baseUrl = _sysSetting.TianQuanPostAcceptInfoApi;
-        TQHttpClient httpClient;
-        var isDbueg = baseUrl.Contains("test");
-        if (isDbueg)
-        {
-            httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, "171.94.154.2", 22, "root", "ZGbyy@2024!", _logger);
-        }
-        else
-        {
-            httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, _logger);
-        }
+
+        //var isDbueg = baseUrl.Contains("test");
+        //if (isDbueg)
+        //{
+        //    httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, "171.94.154.2", 22, "root", "ZGbyy@2024!", _logger);
+        //}
+        //else
+        //{
+        //    httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, _logger);
+        //}
         var acceptInfo = order.Adapt<AcceptInfo>();
         acceptInfo.ReplyCode = order.No!; // 唯一标识
         acceptInfo.TypeName = order.AcceptType!; // 诉求类型名称
@@ -61,22 +63,43 @@ public class TiqnQueService : IGuiderSystemService, IScopeDependency
         acceptInfo.RootCategoryInfo = ""; // order.HotspotName!; // 热点分类(大类)
         acceptInfo.CategoryInfo = "";// order.HotspotSpliceName!; // 热点分类(小类)
         acceptInfo.DeadLine = orderSnapshot.DeadLine!.Value; // 截止时间
-        if(isDbueg)
-        {
-            acceptInfo.Prod = false; // 正式/测试
-        }
-        else
+
+        var tianqueRequestMode = _sysSetting.TianQueRequestMode;
+        TQHttpClient httpClient;
+        switch (tianqueRequestMode)
         {
-            acceptInfo.Prod = true; // 正式/测试
+            case ETianqueRequestMode.TestEnvTestUrl:
+                httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, "171.94.154.2", 22, "root", "ZGbyy@2024!", _httpClientFactory, _logger);
+                acceptInfo.Prod = false;
+                break;
+            case ETianqueRequestMode.ProEnvTestUrl:
+                httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, _httpClientFactory, _logger);
+                acceptInfo.Prod = false;
+                break;
+            case ETianqueRequestMode.ProEnvProUrl:
+                httpClient = new TQHttpClient(tokenDto.Secret, tokenDto.AppId, _httpClientFactory, _logger);
+                acceptInfo.Prod = true;
+                break;
+            default:
+                throw new ArgumentOutOfRangeException();
         }
 
+        //if (isDbueg)
+        //{
+        //    acceptInfo.Prod = false; // 正式/测试
+        //}
+        //else
+        //{
+        //    acceptInfo.Prod = true; // 正式/测试
+        //}
+
         // 反映人信息
         acceptInfo.PersonList = new List<PersonInfo>
         {
             new() {
                 ReflectPhone = order.Contact!, // 电话
                 ReflectUserName = order.FromName!, // 姓名
-            } 
+            }
         };
         if (order.FileJson != null)
         {
@@ -91,7 +114,7 @@ public class TiqnQueService : IGuiderSystemService, IScopeDependency
             }
         }
         acceptInfo.ValidateObject();
-        var result = await httpClient.PostAsync<ApiReponse<AcceptInfoSuccessDto>>(new Uri(_sysSetting.TianQuanPostAcceptInfoApi), acceptInfo);
+        var result = await httpClient.PostAsync<ApiReponse<AcceptInfoSuccessDto>>(new Uri(baseUrl), acceptInfo);
         return new ApiResponse<GuiderSystemOutDto>
         {
             Code = result.Success ? 0 : 1,