From fba665e8a67fcec20a6bbb2722efbee0e33dc6ad Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 00:34:57 +0800
Subject: [PATCH] fix(StockInfoController): MES凭证改为动态获取

---
 Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)

diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
index 4488b40..02447f2 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/Controllers/Stock/StockInfoController.cs
@@ -9,6 +9,7 @@
 using WIDESEA_IBasicService;
 using WIDESEA_ISystemService;
 using WIDESEA_Model.Models;
+using WIDESEA_Common.Constants;
 using WIDESEA_Common.StockEnum;
 using System.Diagnostics;
 
@@ -23,6 +24,7 @@
     {
         private readonly IMesLogService _mesLogService;
         private readonly IMesService _mesService;
+        private readonly IMESDeviceConfigService _mesDeviceConfigService;
         private readonly ISys_DictionaryService _sysDictionaryService;
         private readonly IStockInfoService _stockInfoService;
 
@@ -30,11 +32,13 @@
             IStockInfoService service,
             IMesLogService mesLogService,
             IMesService mesService,
+            IMESDeviceConfigService mesDeviceConfigService,
             ISys_DictionaryService sysDictionaryService,
             IStockInfoService stockInfoService) : base(service)
         {
             _mesLogService = mesLogService;
             _mesService = mesService;
+            _mesDeviceConfigService = mesDeviceConfigService;
             _sysDictionaryService = sysDictionaryService;
             _stockInfoService = stockInfoService;
         }
@@ -83,15 +87,21 @@
                     return response.Error($"褰撳墠搴撳瓨鐘舵�佷笉鍏佽杩涚珯鎿嶄綔锛屽綋鍓嶇姸鎬侊細{stockInfo.StockStatus}");
                 }
 
-                // 4. 鏋勯�燤ES璇锋眰
+                // 4. 鍔ㄦ�佽幏鍙朚ES鍑瘉
+                string deviceName = stockInfo.Remark == "GW_1" ? "楂樻俯闈欑疆1"
+                    : stockInfo.Remark == "GW_2" ? "楂樻俯闈欑疆2"
+                    : "甯告俯闈欑疆1";
+                var mesConfig = _mesDeviceConfigService.GetByDeviceName(deviceName);
+
                 var mesRequest = new InboundInContainerRequest
                 {
-                    EquipmentCode = "STK-GROUP-001",
-                    ResourceCode = "STK-GROUP-001",
+                    EquipmentCode = mesConfig?.EquipmentCode ?? StockConstants.MES_EQUIPMENT_CODE,
+                    ResourceCode = mesConfig?.ResourceCode ?? StockConstants.MES_RESOURCE_CODE,
                     LocalTime = DateTime.Now,
                     ContainerCode = dto.PalletCode
                 };
 
+                string token = mesConfig?.Token;
                 string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
                 string palletCode = stockInfo.PalletCode;
 
@@ -101,7 +111,9 @@
                     var localStopwatch = Stopwatch.StartNew();
                     try
                     {
-                        var result = _mesService.InboundInContainer(mesRequest);
+                        var result = string.IsNullOrWhiteSpace(token)
+                            ? _mesService.InboundInContainer(mesRequest)
+                            : _mesService.InboundInContainer(mesRequest, token);
                         localStopwatch.Stop();
 
                         bool isSuccess = result?.IsSuccess ?? false;
@@ -186,11 +198,16 @@
                     return response.Error($"褰撳墠搴撳瓨鐘舵�佷笉鍏佽鍑虹珯鎿嶄綔锛屽綋鍓嶇姸鎬侊細{stockInfo.StockStatus}");
                 }
 
-                // 4. 鏋勯�燤ES璇锋眰
+                // 4. 鍔ㄦ�佽幏鍙朚ES鍑瘉
+                string deviceName = stockInfo.Remark == "GW_1" ? "楂樻俯闈欑疆1"
+                    : stockInfo.Remark == "GW_2" ? "楂樻俯闈欑疆2"
+                    : "甯告俯闈欑疆1";
+                var mesConfig = _mesDeviceConfigService.GetByDeviceName(deviceName);
+
                 var mesRequest = new OutboundInContainerRequest
                 {
-                    EquipmentCode = "STK-GROUP-001",
-                    ResourceCode = "STK-GROUP-001",
+                    EquipmentCode = mesConfig?.EquipmentCode ?? StockConstants.MES_EQUIPMENT_CODE,
+                    ResourceCode = mesConfig?.ResourceCode ?? StockConstants.MES_RESOURCE_CODE,
                     LocalTime = DateTime.Now,
                     ContainerCode = dto.PalletCode,
                     ParamList = dto.ParamList?.Select(p => new ParamItem
@@ -201,6 +218,7 @@
                     }).ToList()
                 };
 
+                string token = mesConfig?.Token;
                 string requestJson = System.Text.Json.JsonSerializer.Serialize(mesRequest);
                 string palletCode = stockInfo.PalletCode;
 
@@ -210,7 +228,9 @@
                     var localStopwatch = Stopwatch.StartNew();
                     try
                     {
-                        var result = _mesService.OutboundInContainer(mesRequest);
+                        var result = string.IsNullOrWhiteSpace(token)
+                            ? _mesService.OutboundInContainer(mesRequest)
+                            : _mesService.OutboundInContainer(mesRequest, token);
                         localStopwatch.Stop();
 
                         bool isSuccess = result?.IsSuccess ?? false;

--
Gitblit v1.9.3