From 96adc295cb04fd135d63d3a907f2732274f90965 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 21 四月 2026 01:11:21 +0800
Subject: [PATCH] feat: 添加MES异步上传辅助服务并重构相关代码
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs | 146 ++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 126 insertions(+), 20 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index d2f1044..1e37368 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -3,6 +3,7 @@
using WIDESEA_Common.Constants;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
+using WIDESEA_Core.Helper;
using WIDESEA_DTO.MES;
using WIDESEA_DTO.Stock;
using WIDESEA_IBasicService;
@@ -51,6 +52,9 @@
/// </summary>
public IMesService _mesService { get; }
+ private readonly IMesLogService _mesLogService;
+ private readonly IMesUploadHelper _mesUploadHelper;
+
/// <summary>
/// 鏋勯�犲嚱鏁�
/// </summary>
@@ -58,6 +62,7 @@
/// <param name="stockInfoService">搴撳瓨淇℃伅鏈嶅姟</param>
/// <param name="stockInfoDetail_HtyService">搴撳瓨鏄庣粏鍘嗗彶鏈嶅姟</param>
/// <param name="stockInfo_HtyService">搴撳瓨鍘嗗彶鏈嶅姟</param>
+ /// <param name="mesUploadHelper">MES寮傛涓婁紶杈呭姪鏈嶅姟</param>
public StockService(
IStockInfoDetailService stockInfoDetailService,
IStockInfoService stockInfoService,
@@ -65,7 +70,9 @@
IStockInfo_HtyService stockInfo_HtyService,
IMesService mesService,
IWarehouseService warehouseService,
- ISqlSugarClient sqlSugarClient)
+ ISqlSugarClient sqlSugarClient,
+ IMesLogService mesLogService,
+ IMesUploadHelper mesUploadHelper)
{
StockInfoDetailService = stockInfoDetailService;
StockInfoService = stockInfoService;
@@ -74,6 +81,8 @@
_mesService = mesService;
_warehouseService = warehouseService;
SqlSugarClient = sqlSugarClient;
+ _mesLogService = mesLogService;
+ _mesUploadHelper = mesUploadHelper;
}
/// <summary>
@@ -392,8 +401,9 @@
/// 鎵归噺鎷嗙洏纭 - 涓�娆℃�ц皟鐢∕ES瑙g粦鏁翠釜鎵樼洏
/// </summary>
/// <param name="palletCode">婧愭墭鐩樺彿</param>
+ /// <param name="deviceName">璁惧鍚嶇О锛堢敤浜庡姩鎬丮ES鍑瘉鏌ヨ锛�</param>
/// <returns>鎿嶄綔缁撴灉</returns>
- public async Task<WebResponseContent> SplitPalletConfirmAsync(string palletCode)
+ public async Task<WebResponseContent> SplitPalletConfirmAsync(string palletCode, string deviceName)
{
WebResponseContent content = new WebResponseContent();
try
@@ -412,22 +422,52 @@
if (sfcList == null || !sfcList.Any())
return content.Error("涓存椂琛ㄤ腑鐢佃姱鍒楄〃涓虹┖");
- // 2. 璋冪敤MES瑙g粦
+ // 2. 鑾峰彇MES璁惧閰嶇疆锛堝姩鎬佸嚟璇侊級
+ string equipmentCode = StockConstants.MES_EQUIPMENT_CODE;
+ string resourceCode = StockConstants.MES_RESOURCE_CODE;
+ string token = null;
+
+ if (!string.IsNullOrWhiteSpace(deviceName))
+ {
+ var mesConfig = ResolveMesConfig(deviceName, palletCode);
+ if (mesConfig != null)
+ {
+ equipmentCode = mesConfig.EquipmentCode;
+ resourceCode = mesConfig.ResourceCode;
+ token = mesConfig.Token;
+ }
+ }
+
+ // 3. Fire-and-forget寮傛璋冪敤MES瑙g粦
var unbindRequest = new UnBindContainerRequest
{
- EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
- ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
LocalTime = DateTime.Now,
ContainCode = palletCode,
SfcList = sfcList
};
- var unbindResult = _mesService.UnBindContainer(unbindRequest);
- if (unbindResult == null || unbindResult.Data == null || !unbindResult.Data.IsSuccess)
- {
- return content.Error($"MES瑙g粦澶辫触: {unbindResult?.Data?.Msg ?? unbindResult?.ErrorMessage ?? "鏈煡閿欒"}");
- }
+ string requestJson = unbindRequest.ToJson();
+ var localToken = token;
- // 3. 鍒犻櫎涓存椂琛ㄨ褰�
+ _mesUploadHelper.FireAndForget(
+ palletCode,
+ MesUploadStatusEnum.鎷嗙洏涓婁紶鎴愬姛,
+ "UnBindContainer",
+ requestJson,
+ () =>
+ {
+ var result = string.IsNullOrWhiteSpace(localToken)
+ ? _mesService.UnBindContainer(unbindRequest)
+ : _mesService.UnBindContainer(unbindRequest, localToken);
+ return (
+ result?.Data?.IsSuccess ?? false,
+ System.Text.Json.JsonSerializer.Serialize(result),
+ result?.Data?.Msg ?? result?.ErrorMessage ?? "鏈煡閿欒"
+ );
+ });
+
+ // 4. 鍒犻櫎涓存椂琛ㄨ褰�
await SqlSugarClient.Deleteable<Dt_SplitTemp>().Where(t => t.PalletCode == palletCode).ExecuteCommandAsync();
return content.OK("鎵归噺鎷嗙洏纭鎴愬姛");
@@ -442,8 +482,9 @@
/// 鎵归噺缁勭洏纭 - 涓�娆℃�ц皟鐢∕ES缁戝畾鏁翠釜鎵樼洏
/// </summary>
/// <param name="palletCode">鐩爣鎵樼洏鍙�</param>
+ /// <param name="deviceName">璁惧鍚嶇О锛堢敤浜庡姩鎬丮ES鍑瘉鏌ヨ锛�</param>
/// <returns>鎿嶄綔缁撴灉</returns>
- public async Task<WebResponseContent> GroupPalletConfirmAsync(string palletCode)
+ public async Task<WebResponseContent> GroupPalletConfirmAsync(string palletCode, string deviceName)
{
WebResponseContent content = new WebResponseContent();
try
@@ -460,12 +501,28 @@
if (details == null || !details.Any())
return content.Error("鎵樼洏涓嬫棤鐢佃姱鏁版嵁");
- // 2. 璋冪敤MES缁戝畾
+ // 2. 鑾峰彇MES璁惧閰嶇疆锛堝姩鎬佸嚟璇侊級
+ string equipmentCode = StockConstants.MES_EQUIPMENT_CODE;
+ string resourceCode = StockConstants.MES_RESOURCE_CODE;
+ string token = null;
+
+ if (!string.IsNullOrWhiteSpace(deviceName))
+ {
+ var mesConfig = ResolveMesConfig(deviceName, palletCode);
+ if (mesConfig != null)
+ {
+ equipmentCode = mesConfig.EquipmentCode;
+ resourceCode = mesConfig.ResourceCode;
+ token = mesConfig.Token;
+ }
+ }
+
+ // 3. 璋冪敤MES缁戝畾
var bindRequest = new BindContainerRequest
{
ContainerCode = palletCode,
- EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
- ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ EquipmentCode = equipmentCode,
+ ResourceCode = resourceCode,
LocalTime = DateTime.Now,
OperationType = StockConstants.MES_BIND_OPERATION_TYPE,
ContainerSfcList = details.Select(d => new ContainerSfcItem
@@ -474,11 +531,26 @@
Location = d.InboundOrderRowNo.ToString()
}).ToList()
};
- var bindResult = _mesService.BindContainer(bindRequest);
- if (bindResult == null || bindResult.Data == null || !bindResult.Data.IsSuccess)
- {
- return content.Error($"MES缁戝畾澶辫触: {bindResult?.Data?.Msg ?? bindResult?.ErrorMessage ?? "鏈煡閿欒"}");
- }
+ string requestJson = bindRequest.ToJson();
+ var localToken = token;
+
+ // 3. Fire-and-forget寮傛璋冪敤MES缁戝畾
+ _mesUploadHelper.FireAndForget(
+ palletCode,
+ MesUploadStatusEnum.缁勭洏涓婁紶鎴愬姛,
+ "BindContainer",
+ requestJson,
+ () =>
+ {
+ var result = string.IsNullOrWhiteSpace(localToken)
+ ? _mesService.BindContainer(bindRequest)
+ : _mesService.BindContainer(bindRequest, localToken);
+ return (
+ result?.Data?.IsSuccess ?? false,
+ System.Text.Json.JsonSerializer.Serialize(result),
+ result?.Data?.Msg ?? result?.ErrorMessage ?? "鏈煡閿欒"
+ );
+ });
return content.OK("鎵归噺缁勭洏纭鎴愬姛");
}
@@ -487,5 +559,39 @@
return content.Error($"鎵归噺缁勭洏纭澶辫触: {ex.Message}");
}
}
+
+ /// <summary>
+ /// 鏍规嵁璁惧鍚嶇О鍜屾墭鐩樺彿瑙f瀽MES璁惧閰嶇疆
+ /// </summary>
+ /// <param name="deviceName">璁惧鍚嶇О</param>
+ /// <param name="palletCode">鎵樼洏鍙凤紙鐢ㄤ簬鏌ヨ浠撳簱缂栫爜锛�</param>
+ /// <returns>MES璁惧閰嶇疆锛屼笉瀛樺湪鏃惰繑鍥瀗ull</returns>
+ private Dt_MESDeviceConfig ResolveMesConfig(string deviceName, string palletCode)
+ {
+ // 鎹㈢洏鏈烘鎵嬮渶瑕佸尯鍒嗕粨搴�
+ if (deviceName.Contains("鎹㈢洏"))
+ {
+ // 鏌ヨ鎵樼洏瀵瑰簲鐨勪粨搴撶紪鐮�
+ var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode);
+ if (stockInfo != null && stockInfo.WarehouseId > 0)
+ {
+ var warehouse = _warehouseService.Repository.QureyDataById(stockInfo.WarehouseId);
+ if (warehouse != null && !string.IsNullOrWhiteSpace(warehouse.WarehouseCode))
+ {
+ // 鍏堟寜璁惧鍚�+浠撳簱缂栫爜鏌ヨ
+ var config = SqlSugarClient.Queryable<Dt_MESDeviceConfig>()
+ .Where(c => c.DeviceName == deviceName && c.WarehouseCode == warehouse.WarehouseCode)
+ .First();
+ if (config != null)
+ return config;
+ }
+ }
+ }
+
+ // 鎸夎澶囧悕绉版煡璇紙閫傜敤浜庣粍鐩樻満姊版墜鎴栨崲鐩樻満姊版墜鏈壘鍒颁粨搴撳尮閰嶇殑鎯呭喌锛�
+ return SqlSugarClient.Queryable<Dt_MESDeviceConfig>()
+ .Where(c => c.DeviceName == deviceName)
+ .First();
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.3