wanshenmean
2026-03-13 0dbc8273bdfbcabcc4b770546245f6b17d787de9
Code/WCS/WIDESEAWCS_Server/WIDESEAWCS_Core/Http/HTTP/HttpClientHelper.cs
@@ -10,6 +10,8 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using WIDESEAWCS_Common;
using WIDESEAWCS_Common.HttpEnum;
using WIDESEAWCS_Core.Caches;
namespace WIDESEA_Core
@@ -23,6 +25,22 @@
        {
            _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
            _cache = cache ?? throw new ArgumentNullException(nameof(cache));
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.CreateTaskInboundAsync)}", $"Task/CreateTaskInbound");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.GetTasksLocation)}", $"Task/GetTasksLocation");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.OutboundFinishTaskAsync)}", $"Task/OutboundFinishTask");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.InboundFinishTaskAsync)}", $"Task/InboundFinishTask");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.GetOutBoundTrayTaskAsync)}", $"Task/GetOutBoundTrayTask");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.CreateTaskInboundTrayAsync)}", $"Task/CreateTaskInboundTray");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.GroupPalletAsync)}", $"Stock/GroupPalletAsync");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.ChangePalletAsync)}", $"Stock/ChangePalletAsync");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.SplitPalletAsync)}", $"Stock/SplitPalletAsync");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.UpdateTaskByStatus)}", $"Task/UpdateTaskByStatus");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.TransferCheck)}", $"LocationInfo/TransferCheck");
            _cache.TryAdd($"{RedisPrefix.Code}:{RedisName.API}:{nameof(ConfigKey.RelocationFinishTask)}", $"Task/RelocationFinishTask");
        }
        /// <summary>
@@ -35,26 +53,31 @@
        /// <returns></returns>
        public HttpResponseResult Post(string url, string content, string contentType = "application/json", HttpRequestConfig? config = null)
        {
            url = _cache.Get(url);
            HttpResponseResult httpResponseResult = ExecuteAsync(async (client) =>
            HttpResponseResult httpResponseResult = Task.Run(async () =>
            {
                var request = new HttpRequestMessage(HttpMethod.Post, url);
                request.Content = new StringContent(content ?? string.Empty, Encoding.UTF8, contentType);
                SetRequestHeaders(request, config?.Headers);
                return await client.SendAsync(request);
            }, config, $"POST {url}").Result;
                return await ExecuteAsync(async (client) =>
                {
                    var request = new HttpRequestMessage(HttpMethod.Post, url);
                    request.Content = new StringContent(content ?? string.Empty, Encoding.UTF8, contentType);
                    SetRequestHeaders(request, config?.Headers);
                    return await client.SendAsync(request);
                }, config, $"POST {url}");
            }).GetAwaiter().GetResult();
            httpResponseResult.ApiUrl = url;
            return httpResponseResult;
        }
        public HttpResponseResult Get(string url, HttpRequestConfig? config = null)
        {
            HttpResponseResult httpResponseResult = ExecuteAsync(async (client) =>
            HttpResponseResult httpResponseResult = Task.Run(async () =>
            {
                var request = new HttpRequestMessage(HttpMethod.Get, url);
                SetRequestHeaders(request, config?.Headers);
                return await client.SendAsync(request);
            }, config, $"GET {url}").Result;
                return await ExecuteAsync(async (client) =>
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, url);
                    SetRequestHeaders(request, config?.Headers);
                    return await client.SendAsync(request);
                }, config, $"GET {url}");
            }).GetAwaiter().GetResult();
            httpResponseResult.ApiUrl = url;
            return httpResponseResult;
@@ -72,6 +95,7 @@
        public HttpResponseResult<TResponse> Post<TResponse>(string url, string content, string contentType = "application/json", HttpRequestConfig? config = null)
        {
            url = BaseAPI.WMSBaseUrl + _cache.Get($"{RedisPrefix.Code}:{RedisName.API}:{url}");
            HttpResponseResult httpResponseResult = Post(url, content, contentType, config);
            HttpResponseResult<TResponse> result = new HttpResponseResult<TResponse>
@@ -113,6 +137,7 @@
        public HttpResponseResult<TResponse> Get<TResponse>(string url, HttpRequestConfig? config = null)
        {
            url = BaseAPI.WMSBaseUrl + _cache.Get(url);
            HttpResponseResult httpResponseResult = Get(url, config);
            HttpResponseResult<TResponse> result = new HttpResponseResult<TResponse>