diff --git a/ZR.Service/mes/wms-u8/ERP_WMS_interactiveService.cs b/ZR.Service/mes/wms-u8/ERP_WMS_interactiveService.cs index da19123e..cdb873b9 100644 --- a/ZR.Service/mes/wms-u8/ERP_WMS_interactiveService.cs +++ b/ZR.Service/mes/wms-u8/ERP_WMS_interactiveService.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Globalization; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; using U8Server.Util; @@ -23,7 +24,7 @@ namespace ZR.Service.mes.wms_u8 /// /// /// - public ERP_WMS_interactiveModelResult Inbounded(string urlBase,List eRP_WMS_InteractiveModels) + public ERP_WMS_interactiveModelResult Inbounded(string urlBase, List eRP_WMS_InteractiveModels) { string url = urlBase + "/wms/mes/inbounded"; @@ -34,7 +35,7 @@ namespace ZR.Service.mes.wms_u8 headers.Add("sign", GetSign.GetBy16Md5()); string postData = JsonConvert.SerializeObject(eRP_WMS_InteractiveModels); - Object result = HttpHelper.HttpPost(url, postData, contentType, 30, headers); + Object result = HttpHelper.HttpPost(url, postData, contentType, 5, headers); if (result != null && result is ERP_WMS_interactiveModelResult) { return (ERP_WMS_interactiveModelResult)result; @@ -50,7 +51,7 @@ namespace ZR.Service.mes.wms_u8 /// /// /// - public ERP_WMS_interactiveModelResult Outbounded(string urlBase, List eRP_WMS_InteractiveModels) + public ERP_WMS_interactiveModelResult Outbounded(string urlBase, List eRP_WMS_InteractiveModels) { string url = urlBase + "/wms/mes/outbounded"; @@ -61,7 +62,7 @@ namespace ZR.Service.mes.wms_u8 headers.Add("sign", GetSign.GetBy16Md5()); string postData = JsonConvert.SerializeObject(eRP_WMS_InteractiveModels); - Object result = HttpHelper.HttpPost(url, postData, contentType, 30, headers); + Object result = HttpHelper.HttpPost(url, postData, contentType, 5, headers); if (result != null && result is ERP_WMS_interactiveModelResult) { return (ERP_WMS_interactiveModelResult)result; @@ -69,5 +70,77 @@ namespace ZR.Service.mes.wms_u8 return null; } + + /// + /// 入库接口 - 异步版本 + /// + public async Task InboundedAsync(string urlBase, List eRP_WMS_InteractiveModels) + { + string url = urlBase + "/wms/mes/inbounded"; + + string contentType = "application/json"; + Dictionary headers = new Dictionary + { + { "appid", "gN9yId!!lfwaRoi3" }, + { "timestamp", DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) }, + { "sign", GetSign.GetBy16Md5() } + }; + + string postData = JsonConvert.SerializeObject(eRP_WMS_InteractiveModels); + + try + { + // 调用HttpHelper的异步方法 + string resultJson = await HttpHelper.HttpPostAsync(url, postData, contentType, 5, headers); + + // 反序列化结果 + if (!string.IsNullOrEmpty(resultJson) && resultJson != "异常:*") + { + return JsonConvert.DeserializeObject(resultJson); + } + } + catch (Exception ex) + { + Console.WriteLine($"InboundedAsync 异常: {ex.Message}"); + } + + return null; + } + + /// + /// 出库接口 - 异步版本 + /// + public async Task OutboundedAsync(string urlBase, List eRP_WMS_InteractiveModels) + { + string url = urlBase + "/wms/mes/outbounded"; + + string contentType = "application/json"; + Dictionary headers = new Dictionary + { + { "appid", "gN9yId!!lfwaRoi3" }, + { "timestamp", DateTime.Now.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture) }, + { "sign", GetSign.GetBy16Md5() } + }; + + string postData = JsonConvert.SerializeObject(eRP_WMS_InteractiveModels); + + try + { + // 调用HttpHelper的异步方法 + string resultJson = await HttpHelper.HttpPostAsync(url, postData, contentType, 5, headers); + + // 反序列化结果 + if (!string.IsNullOrEmpty(resultJson) && resultJson != "异常:*") + { + return JsonConvert.DeserializeObject(resultJson); + } + } + catch (Exception ex) + { + Console.WriteLine($"OutboundedAsync 异常: {ex.Message}"); + } + + return null; + } } } diff --git a/ZR.Service/mes/wms/WMentryWarehousing_productService.cs b/ZR.Service/mes/wms/WMentryWarehousing_productService.cs index c5fa47fb..72561adc 100644 --- a/ZR.Service/mes/wms/WMentryWarehousing_productService.cs +++ b/ZR.Service/mes/wms/WMentryWarehousing_productService.cs @@ -2,6 +2,7 @@ using System.Linq; using System.Security.Cryptography; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Infrastructure.Attribute; using SqlSugar; using ZR.Model.MES.wms; @@ -213,12 +214,12 @@ namespace ZR.Service.mes.wms } string urlBase = "http://gam.com.cn:8054/"; ERP_WMS_interactiveService _eRP_WMS_InteractiveService = new(); - ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Inbounded( - urlBase, - u8PackageList - ); - //TODO 对U8返回结果进行解析 - logger.Warn(u8ErpResult); + // 异步发送U8 + _ = Task.Run(async () => { + var u8ErpResult = await _eRP_WMS_InteractiveService.InboundedAsync(urlBase, u8PackageList); + //TODO 对U8返回结果进行解析 + logger.Warn(u8ErpResult); + }); Context.Ado.CommitTran(); return result; } diff --git a/ZR.Service/mes/wms/WmGoodsOutProductionService.cs b/ZR.Service/mes/wms/WmGoodsOutProductionService.cs index 25539dec..c9f60da6 100644 --- a/ZR.Service/mes/wms/WmGoodsOutProductionService.cs +++ b/ZR.Service/mes/wms/WmGoodsOutProductionService.cs @@ -1,5 +1,6 @@ using System; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Aliyun.OSS; using Infrastructure.Attribute; using Microsoft.AspNetCore.Http.HttpResults; @@ -188,13 +189,13 @@ namespace ZR.Service.mes.wms } string urlBase = "http://gam.com.cn:8054/"; ERP_WMS_interactiveService _eRP_WMS_InteractiveService = new(); - ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Outbounded( - urlBase, - u8PackageList - ); - //TODO 对U8返回结果进行解析 - logger.Warn(u8ErpResult); - + // 后台执行不阻塞主线程 + _ = Task.Run(async () => { + var u8ErpResult = await _eRP_WMS_InteractiveService.OutboundedAsync(urlBase, u8PackageList); + // 处理结果... + //TODO 对U8返回结果进行解析 + logger.Warn(u8ErpResult); + }); return Context.Insertable(model).ExecuteReturnEntity(); } @@ -419,12 +420,19 @@ namespace ZR.Service.mes.wms } string urlBase = "http://gam.com.cn:8054/"; ERP_WMS_interactiveService _eRP_WMS_InteractiveService = new(); - ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Outbounded( - urlBase, - u8PackageList - ); + // 后台执行不阻塞主线程 + _ = Task.Run(async () => { + var u8ErpResult = await _eRP_WMS_InteractiveService.OutboundedAsync(urlBase, u8PackageList); + // 处理结果... + //TODO 对U8返回结果进行解析 + logger.Warn(u8ErpResult); + }); + /* ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Outbounded( + urlBase, + u8PackageList + );*/ //TODO 对U8返回结果进行解析 - logger.Warn(u8ErpResult); + /* logger.Warn(u8ErpResult);*/ return "ok"; } } diff --git a/ZR.Service/mes/wms/WmOutOrderService.cs b/ZR.Service/mes/wms/WmOutOrderService.cs index 97a648a0..ed5793ba 100644 --- a/ZR.Service/mes/wms/WmOutOrderService.cs +++ b/ZR.Service/mes/wms/WmOutOrderService.cs @@ -2,6 +2,7 @@ using System; using System.Data; using System.Linq; using System.Text.RegularExpressions; +using System.Threading.Tasks; using Infrastructure.Attribute; using Mapster; using SqlSugar; @@ -622,12 +623,19 @@ namespace ZR.Service.mes.wms } string urlBase = "http://gam.com.cn:8054/"; ERP_WMS_interactiveService _eRP_WMS_InteractiveService = new(); - ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Outbounded( - urlBase, - u8PackageList - ); - //TODO 对U8返回结果进行解析 - logger.Warn(u8ErpResult); + // 后台执行不阻塞主线程 + _ = Task.Run(async () => { + var u8ErpResult = await _eRP_WMS_InteractiveService.OutboundedAsync(urlBase, u8PackageList); + // 处理结果... + //TODO 对U8返回结果进行解析 + logger.Warn(u8ErpResult); + }); + /* + *ERP_WMS_interactiveModelResult u8ErpResult = _eRP_WMS_InteractiveService.Outbounded( + urlBase, + u8PackageList + ); + logger.Warn(u8ErpResult);*/ Context.Ado.CommitTran(); return (sum_delete, sum_insert); }