From ec755cb92e38f5ddac9e00ef8d9cb244174832ff Mon Sep 17 00:00:00 2001 From: 18942506660 <18942506660@A18942506660> Date: Tue, 7 Nov 2023 17:07:32 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E6=8E=A5=E8=80=81ops?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/Controllers/TestController.cs | 14 +++- src/WMS.Web.Api/appsettings.json | 5 ++ src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml | 7 ++ src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml | 10 +++ src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml | 10 +++ src/WMS.Web.Core/Dto/OpsBoxRequest.cs | 19 +++++ src/WMS.Web.Core/Dto/OpsBoxResponse.cs | 13 +++ src/WMS.Web.Domain/Entitys/Box.cs | 8 +- .../IService/Public/IHttpClientService.cs | 1 + .../IService/Public/IOpsService.cs | 13 +++ src/WMS.Web.Domain/Options/OpsOptions.cs | 16 ++++ .../Services/Public/HttpClientService.cs | 6 +- .../Services/Public/OpsService.cs | 81 +++++++++++++++++++ .../DependencyInjection/AppBuilder.cs | 3 + 14 files changed, 199 insertions(+), 7 deletions(-) create mode 100644 src/WMS.Web.Core/Dto/OpsBoxRequest.cs create mode 100644 src/WMS.Web.Core/Dto/OpsBoxResponse.cs create mode 100644 src/WMS.Web.Domain/IService/Public/IOpsService.cs create mode 100644 src/WMS.Web.Domain/Options/OpsOptions.cs create mode 100644 src/WMS.Web.Domain/Services/Public/OpsService.cs diff --git a/src/WMS.Web.Api/Controllers/TestController.cs b/src/WMS.Web.Api/Controllers/TestController.cs index a85b78cd..a46d6ea7 100644 --- a/src/WMS.Web.Api/Controllers/TestController.cs +++ b/src/WMS.Web.Api/Controllers/TestController.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.Threading.Tasks; +using WMS.Web.Core.Dto; using WMS.Web.Core.Internal.Results; using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService; @@ -23,19 +24,28 @@ namespace WMS.Web.Api.Controllers private readonly IErpService _erpService; private IInStockTaskService _inStockTaskService; private IBasicsRepositories _transactionRepositories; + private readonly IOpsService _opsService; - public TestController(IErpService erpService, IInStockTaskService inStockTaskService, IBasicsRepositories transactionRepositories) + public TestController(IErpService erpService, IInStockTaskService inStockTaskService, + IBasicsRepositories transactionRepositories, IOpsService opsService) { this._erpService = erpService; this._inStockTaskService = inStockTaskService; this._transactionRepositories = transactionRepositories; + _opsService = opsService; } [HttpGet] [Route("hj")] public async Task TestHJ() { - var res = await this._erpService.BillQueryForSubStock(); + OpsBoxRequest request = new OpsBoxRequest() + { + StrartTime = DateTime.Now.AddYears(-1), + EndTime=DateTime.Now + }; + await _opsService.GetBox(request); + //var res = await this._erpService.BillQueryForSubStock(); //var result= await this._erpService.BillQueryForPurchaseInStock(); //var result = await this._erpService.BillQueryForOrg(); var result = await this._erpService.BillQueryForMaterial(); diff --git a/src/WMS.Web.Api/appsettings.json b/src/WMS.Web.Api/appsettings.json index 1420980f..0afcdc17 100644 --- a/src/WMS.Web.Api/appsettings.json +++ b/src/WMS.Web.Api/appsettings.json @@ -43,6 +43,11 @@ "ErpId": "ce20210909", "PurchaseInstockFieldKeys": "FBillNo,FUOM,FSupplierId.FName,FPurchaseOrgId.FName,FMaterialName,FMaterialId.FNumber" }, + "OpsOptions": { + "Url": "http://39.108.150.2:8050/", + "UserName": "admin", + "PassWord": "888888" + }, "Qiniu": { "AccessKey": "dOsTum4a5qvhPTBbZRPX0pIOU7PZWRX7htKjztms", "SecretKey": "KFxsGbnErkALFfeGdMa8QWTdodJbamMX0iznLe-q", diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index 42c97a90..443d7192 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -283,6 +283,13 @@ 仓库id + + + 根据仓库获取金蝶子仓库 + + 仓库id + + 获取仓位:模糊名称 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index 9ff5164b..dd09a194 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -2280,6 +2280,16 @@ 操作 Id集合 + + + 老ops箱信息请求 + + + + + 老ops箱信息 + + 根据单号搜索出库单任务信息 diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 4c5cc7b1..f9cbe9cd 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -1907,6 +1907,11 @@ 采购入库:字段 + + + 老ops对接 + + Quartz定时任务-配置项 @@ -2558,6 +2563,11 @@ + + + ops服务 + + 保存单个key value diff --git a/src/WMS.Web.Core/Dto/OpsBoxRequest.cs b/src/WMS.Web.Core/Dto/OpsBoxRequest.cs new file mode 100644 index 00000000..4497d64b --- /dev/null +++ b/src/WMS.Web.Core/Dto/OpsBoxRequest.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto +{ + /// + /// 老ops箱信息请求 + /// + public class OpsBoxRequest + { + public DateTime StrartTime { get; set; } + public DateTime EndTime { get; set; } + public string BoxBillNo { get; set; } + + public int Page { get; set; } = 1; + public int Limit { get; set; } = 10000000; + } +} diff --git a/src/WMS.Web.Core/Dto/OpsBoxResponse.cs b/src/WMS.Web.Core/Dto/OpsBoxResponse.cs new file mode 100644 index 00000000..3ad53221 --- /dev/null +++ b/src/WMS.Web.Core/Dto/OpsBoxResponse.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Core.Dto +{ + /// + /// 老ops箱信息 + /// + public class OpsBoxResponse + { + } +} diff --git a/src/WMS.Web.Domain/Entitys/Box.cs b/src/WMS.Web.Domain/Entitys/Box.cs index b26d2c0e..2083e5ff 100644 --- a/src/WMS.Web.Domain/Entitys/Box.cs +++ b/src/WMS.Web.Domain/Entitys/Box.cs @@ -34,12 +34,16 @@ namespace WMS.Web.Domain.Entitys /// /// 供应商Id /// - public int SupplierId { get; set; } + public int? SupplierId { get; set; } + /// + /// 组织Id + /// + public int? OrgId { get; set; } /// /// 创建时间(对应老OPS的创建时间) /// public DateTime CreateTime { get; set; } = DateTime.Now; - + /// /// 明细 /// diff --git a/src/WMS.Web.Domain/IService/Public/IHttpClientService.cs b/src/WMS.Web.Domain/IService/Public/IHttpClientService.cs index 6b35e31a..42a5e48c 100644 --- a/src/WMS.Web.Domain/IService/Public/IHttpClientService.cs +++ b/src/WMS.Web.Domain/IService/Public/IHttpClientService.cs @@ -8,6 +8,7 @@ namespace WMS.Web.Domain.IService.Public { public interface IHttpClientService { + HttpClient BuildHttpClient(Dictionary dicDefaultHeaders, int? timeoutSecond = 180); Task GetAsync(string url, int timeoutSecond = 180); Task GetAsync(string url, Dictionary dicHeaders, int timeoutSecond = 180); Task PostAsync(string url, string requestBody, int timeoutSecond = 180); diff --git a/src/WMS.Web.Domain/IService/Public/IOpsService.cs b/src/WMS.Web.Domain/IService/Public/IOpsService.cs new file mode 100644 index 00000000..7d6c5c38 --- /dev/null +++ b/src/WMS.Web.Domain/IService/Public/IOpsService.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto; + +namespace WMS.Web.Domain.IService.Public +{ + public interface IOpsService + { + Task GetBox(OpsBoxRequest request); + } +} diff --git a/src/WMS.Web.Domain/Options/OpsOptions.cs b/src/WMS.Web.Domain/Options/OpsOptions.cs new file mode 100644 index 00000000..3fe9cfc1 --- /dev/null +++ b/src/WMS.Web.Domain/Options/OpsOptions.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace WMS.Web.Domain.Options +{ + /// + /// 老ops对接 + /// + public class OpsOptions + { + public string Url { get; set; } + public string UserName { get; set; } + public string PassWord { get; set; } + } +} diff --git a/src/WMS.Web.Domain/Services/Public/HttpClientService.cs b/src/WMS.Web.Domain/Services/Public/HttpClientService.cs index db4f48e0..016bd2dd 100644 --- a/src/WMS.Web.Domain/Services/Public/HttpClientService.cs +++ b/src/WMS.Web.Domain/Services/Public/HttpClientService.cs @@ -105,8 +105,8 @@ namespace WMS.Web.Domain.Services.Public /// public async Task PostAsync(string url, string requestBody, Dictionary dicHeaders, int timeoutSecond = 180) { - var client = BuildHttpClient(null, timeoutSecond); - var requestContent = GenerateStringContent(requestBody, dicHeaders); + var client = BuildHttpClient(dicHeaders, timeoutSecond); + var requestContent = GenerateStringContent(requestBody, contentHeaders); var response = await client.PostAsync(url, requestContent); var responseContent = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) @@ -213,7 +213,7 @@ namespace WMS.Web.Domain.Services.Public /// /// /// - private HttpClient BuildHttpClient(Dictionary dicDefaultHeaders, int? timeoutSecond) + public HttpClient BuildHttpClient(Dictionary dicDefaultHeaders, int? timeoutSecond=180) { var httpClient = _clientFactory.CreateClient("ops_client"); httpClient.DefaultRequestHeaders.Clear(); //为了使客户端不受最后一个请求的影响,它需要清除DefaultRequestHeaders diff --git a/src/WMS.Web.Domain/Services/Public/OpsService.cs b/src/WMS.Web.Domain/Services/Public/OpsService.cs new file mode 100644 index 00000000..22f77fd8 --- /dev/null +++ b/src/WMS.Web.Domain/Services/Public/OpsService.cs @@ -0,0 +1,81 @@ +using Microsoft.Extensions.Caching.Memory; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using WMS.Web.Core.Dto; +using WMS.Web.Domain.IService.Public; +using WMS.Web.Domain.Options; + +namespace WMS.Web.Domain.Services.Public +{ + /// + /// ops服务 + /// + public class OpsService : IOpsService + { + private readonly IHttpClientService _httpClientService; + private readonly ILogger _logger; + private readonly IMemoryCache _memoryCache; + private int hours = 10;//过期时间 默认10小时 + private readonly OpsOptions _option; + + public OpsService(IHttpClientService httpClientService, ILogger logger, + IMemoryCache memoryCache, IOptions option) + { + this._memoryCache = memoryCache; + this._httpClientService = httpClientService; + this._logger = logger; + _option = option?.Value; + } + + public async Task GetBox(OpsBoxRequest request) + { + var token = await GetToken(); + Dictionary dicHeaders = new Dictionary(); + dicHeaders.Add("Authorization", "Bearer " + token); + //_httpClientService.BuildHttpClient(contentHeaders); + var res= await _httpClientService.PostAsync(_option.Url + "BarCode/carton-box_api/carton-box", JsonConvert.SerializeObject(request), dicHeaders); + } + + private async Task GetToken() + { + OpsLogin login = new OpsLogin() + { + hAccount = _option.UserName, + hPassword = _option.PassWord + }; + var res = await _httpClientService.PostAsync(_option.Url + "api/login", JsonConvert.SerializeObject(login)); + var token = res.data?.token ?? ""; + if (string.IsNullOrEmpty(token)) + _logger.LogInformation("老Ops登录失败:" + res?.errors); + return token; + } + + } + public class OpsLogin + { + public OpsLogin() { } + public string hAccount { get; set; } = "admin"; + public string hPassword { get; set; } = "888888"; + } + public class OpsInfo + { + public int code { get; set; } + public string message { get; set; } + public string date { get; set; } + public string token { get; set; } + } + public class OpsReponse + { + public int statusCode { get; set; } + public bool succeeded { get; set; } + public string errors { get; set; } + public string extras { get; set; } + + public OpsInfo data { get; set; } + } +} diff --git a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs index 3e16e9c1..e603ca56 100644 --- a/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs +++ b/src/WMS.Web.Repositories/DependencyInjection/AppBuilder.cs @@ -174,6 +174,8 @@ namespace WMS.Web.Repositories.DependencyInjection Services.Configure(Configuration.GetSection("HttpOptions")); Services.AddOptions(); Services.Configure(Configuration.GetSection("ErpOptions")); + Services.AddOptions(); + Services.Configure(Configuration.GetSection("OpsOptions")); } /// @@ -234,6 +236,7 @@ namespace WMS.Web.Repositories.DependencyInjection Services.AddTransient(); Services.AddTransient(); Services.AddTransient(); + Services.AddTransient(); Services.AddTransient();