| | |
| | | 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 |
| | |
| | | { |
| | | _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> |
| | |
| | | /// <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; |
| | |
| | | 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> |
| | |
| | | |
| | | 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> |