From ce8f204db035e6fb7147edb4440591502f5c8567 Mon Sep 17 00:00:00 2001 From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com> Date: 星期四, 10 七月 2025 15:01:32 +0800 Subject: [PATCH] 1 --- Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs | 94 +++++++++++++++++++++++++++++++++++++--------- 1 files changed, 75 insertions(+), 19 deletions(-) diff --git a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs index 1e3aa68..e61bb34 100644 --- a/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs +++ b/Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs @@ -1,14 +1,33 @@ -锘縰sing LogLibrary.Log; +锘縰sing AngleSharp.Io; +using LogLibrary.Log; using Masuit.Tools; +using Newtonsoft.Json; using WIDESEA_Common; +using WIDESEA_Core; +using WIDESEA_Core.Const; +using WIDESEA_Core.Helper; using WIDESEA_DTO; +using WIDESEA_DTO.MOM; +using WIDESEA_IRepository; +using WIDESEA_IServices; +using WIDESEA_IStorageBasicService; using WIDESEA_IStoragIntegrationServices; +using static Org.BouncyCastle.Math.EC.ECCurve; namespace WIDESEA_StoragIntegrationServices; public class CellStateService : ICellStateService { private readonly LogFactory LogFactory = new LogFactory(); + + private readonly IBoxingInfoService _boxingInfoService; + private readonly ISys_ConfigService _configService; + + public CellStateService(IBoxingInfoService boxingInfoService, ISys_ConfigService configRepository) + { + _boxingInfoService = boxingInfoService; + _configService = configRepository; + } /// <summary> /// 鍗曠數鑺睘鎬ц幏鍙� @@ -17,22 +36,34 @@ /// <returns></returns> public async Task<dynamic> GetCellStateAsync(CellStateDto input) { + WebResponseContent content = new WebResponseContent(); try { input.SessionId = Guid.NewGuid().ToString(); - input.Software = "闄堝寲鏈�"; - input.EquipmentCode = "P1K10040"; - input.EmployeeNo = "T00001"; - input.RequestTime = DateTime.UtcNow.ToString(); - var inputJson = input.ToDictionary(); - var x = await HttpsClient.PostAsync("https://localhost:7251/api/CellState/GetCellState", inputJson); + input.EmployeeNo = "MITest"; + input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); + var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); + var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; + var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.CellState)?.ConfigValue; + if (wmsBase == null || ipAddress == null) + { + throw new InvalidOperationException("WMS IP 鏈厤缃�"); + } + var wmsIpAddress = wmsBase + ipAddress; + + var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result; + LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Info(true, $"\r\r--------------------------------------"); - LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Info(true, x); + LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Info(true, result); + return result; } catch (Exception err) { - Console.WriteLine(err.Message.ToString()); + //Console.WriteLine(err.Message.ToString()); LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Error(true, $"\r\r--------------------------------------"); + LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Error(true, $"璇锋眰鍙傛暟: {JsonConvert.SerializeObject(input)}"); + LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Error(true, err.Message); LogFactory.GetLog("鍗曠數鑺睘鎬ц幏鍙�").Error(true, err.StackTrace); } return Task.FromResult<dynamic>(null); @@ -43,26 +74,51 @@ /// </summary> /// <param name="input">鐢佃姱鏁版嵁</param> /// <returns></returns> - public async Task<dynamic> GetTrayCellStatusAsync(TrayCellsStatusDto input) + public async Task<WebResponseContent> GetTrayCellStatusAsync(TrayCellsStatusDto input) { + WebResponseContent content = new WebResponseContent(); try { input.SessionId = Guid.NewGuid().ToString(); - input.Software = "闄堝寲鏈�"; - input.EquipmentCode = "P1K10040"; - input.EmployeeNo = "T00001"; - input.RequestTime = DateTime.UtcNow.ToString(); - var inputJson = input.ToDictionary(); - var x = await HttpsClient.PostAsync("https://localhost:7251/api/CellState/GetCellState", inputJson); + input.EmployeeNo = "MITest"; + input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); + var inputJson = Masuit.Tools.ObjectExtensions.ToDictionary(input); + var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); + var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; + var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.TrayCellsStatus)?.ConfigValue; + if (wmsBase == null || ipAddress == null) + { + throw new InvalidOperationException("WMS IP 鏈厤缃�"); + } + var wmsIpAddress = wmsBase + ipAddress; + + var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result; + + var respone = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result.ToString()); + + if (!respone.Success) + { + MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, respone.MOMMessage, SysConfigConst.TrayCellsStatus); + } + else + { + MoMErrorMsg.DeleteMoMErrorMsg(0, input.TrayBarcode); + } + LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Info(true, $"\r\r--------------------------------------"); - LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Info(true, x); + LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Info(true, result); + content.OK(data: result); } catch (Exception err) { - Console.WriteLine(err.Message.ToString()); + //MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, err.Message, SysConfigConst.TrayCellsStatus); + + //Console.WriteLine(err.Message.ToString()); LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Error(true, $"\r\r--------------------------------------"); + LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Error(true, $"璇锋眰鍙傛暟: {JsonConvert.SerializeObject(input)}"); + LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Error(true, err.Message); LogFactory.GetLog("鏁寸洏鐢佃姱灞炴�ц幏鍙�").Error(true, err.StackTrace); } - return Task.FromResult<dynamic>(null); + return content; } } \ No newline at end of file -- Gitblit v1.9.3