From 31eba6a8c6261adf5bfef4dafad4dc8efc1f66a2 Mon Sep 17 00:00:00 2001
From: huangxiaoqiang <huangxiaoqiang@hnkhzn.com>
Date: 星期二, 18 二月 2025 18:57:54 +0800
Subject: [PATCH] 1

---
 Code Management/WMS/WIDESEA_WMSServer/WIDESEA_StoragIntegrationServices/MOM/CellState/CellStateService.cs |  128 ++++++++++++++++++++++--------------------
 1 files changed, 66 insertions(+), 62 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 f5b3c70..2746a02 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
@@ -3,11 +3,14 @@
 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 WIDESEA_Model.Models;
+using static Org.BouncyCastle.Math.EC.ECCurve;
 
 namespace WIDESEA_StoragIntegrationServices;
 
@@ -16,10 +19,12 @@
     private readonly LogFactory LogFactory = new LogFactory();
 
     private readonly IBoxingInfoService _boxingInfoService;
+    private readonly ISys_ConfigService _configService;
 
-    public CellStateService(IBoxingInfoService boxingInfoService)
+    public CellStateService(IBoxingInfoService boxingInfoService, ISys_ConfigService configRepository)
     {
         _boxingInfoService = boxingInfoService;
+        _configService = configRepository;
     }
 
     /// <summary>
@@ -33,45 +38,59 @@
         try
         {
             input.SessionId = Guid.NewGuid().ToString();
-            input.Software = "闄堝寲鏈�";
-            input.EquipmentCode = "P1K10040";
-            input.EmployeeNo = "T00001";
+            input.EmployeeNo = "MITest";
             input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
             var inputJson = input.ToDictionary();
-            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/CellState", inputJson);
-            if (x != null)
+            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)
             {
-                ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x);
-                DtBoxingInfo boxingInfo = new DtBoxingInfo()
-                {
-                    IsFull = true,
-                    PalletCode = "",
-                };
-                var details = new List<DtBoxingInfoDetail>();
-                foreach (var item in result.SerialNos)
-                {
-                    DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
-                    {
-                        SerialNumber = item.SerialNo,
-                        OrderNo = item.BindCode,
-                        Status = item.SerialNoStatus,
-                    };
-                    details.Add(detail);
-                }
-                boxingInfo.BoxingInfoDetails = details;
-                var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
-                if (abc.Status)
-                    return content.OK("缁勭洏鎴愬姛");
-                else
-                    return content.Error("缁勭洏澶辫触");
+                throw new InvalidOperationException("WMS IP 鏈厤缃�");
             }
+            var wmsIpAddress = wmsBase + ipAddress;
+
+            var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result;
+            //var x = await HttpsClient.PostAsync("http://c24-cellmi3:12020/api/MachineIntegration/CellState", inputJson);
+            #region
+            //if (x != null)
+            //{
+            //    ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x);
+            //    DtBoxingInfo boxingInfo = new DtBoxingInfo()
+            //    {
+            //        IsFull = true,
+            //        PalletCode = "",
+            //    };
+            //    var details = new List<DtBoxingInfoDetail>();
+            //    foreach (var item in result.SerialNos)
+            //    {
+            //        DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
+            //        {
+            //            SerialNumber = item.SerialNo,
+            //            OrderNo = item.BindCode,
+            //            Status = item.SerialNoStatus,
+            //        };
+            //        details.Add(detail);
+            //    }
+            //    boxingInfo.BoxingInfoDetails = details;
+            //    var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
+            //    if (abc.Status)
+            //        return content.OK("缁勭洏鎴愬姛");
+            //    else
+            //        return content.Error("缁勭洏澶辫触");
+            //}
+            #endregion
+
             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());
             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);
@@ -88,46 +107,31 @@
         try
         {
             input.SessionId = Guid.NewGuid().ToString();
-            input.Software = "闄堝寲鏈�";
-            input.EquipmentCode = "P1K10040";
-            input.EmployeeNo = "T00001";
+            input.EmployeeNo = "MITest";
             input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
             var inputJson = input.ToDictionary();
-            var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/TrayCellsStatus", inputJson);
-            if (x != null)
+            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)
             {
-                ResultTrayCellsStatus result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(x);
-                DtBoxingInfo boxingInfo = new DtBoxingInfo()
-                {
-                    IsFull = true,
-                    PalletCode = "",
-                };
-                var details = new List<DtBoxingInfoDetail>();
-                foreach (var item in result.SerialNos)
-                {
-                    DtBoxingInfoDetail detail = new DtBoxingInfoDetail()
-                    {
-                        SerialNumber = item.SerialNo,
-                        OrderNo = result.BindCode,
-                        Status = item.SerialNoStatus,
-                        BatchNo = item.PositionNo.ToString()
-                    };
-                    details.Add(detail);
-                }
-                boxingInfo.BoxingInfoDetails = details;
-                var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo);
-                if (abc.Status)
-                    content.OK("缁勭洏鎴愬姛", result);
-                else
-                    content.Error("缁勭洏澶辫触");
+                throw new InvalidOperationException("WMS IP 鏈厤缃�");
             }
+            var wmsIpAddress = wmsBase + ipAddress;
+
+            var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result;
+            //var x = await HttpsClient.PostAsync("http://c24-cellmi3:12020/api/MachineIntegration/TrayCellsStatus", inputJson);
+
             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());
             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 content;

--
Gitblit v1.9.3