From 8c3a3fd584e38e72bfb321ab70bfcfc2ab0a4e2e Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期四, 16 四月 2026 23:18:01 +0800
Subject: [PATCH] refactor(StockService): 移除注释掉的MES绑定解绑相关代码
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs | 189 +++++++++++++++++++++++++++++++++++++++--------
1 files changed, 157 insertions(+), 32 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
index 8f98594..d2f1044 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockSerivce.cs
@@ -1,4 +1,6 @@
-锘縰sing SqlSugar;
+锘縰sing Newtonsoft.Json;
+using SqlSugar;
+using WIDESEA_Common.Constants;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_DTO.MES;
@@ -35,6 +37,16 @@
public IStockInfo_HtyService StockInfo_HtyService { get; }
/// <summary>
+ /// 浠撳簱鏈嶅姟
+ /// </summary>
+ public IWarehouseService _warehouseService { get; }
+
+ /// <summary>
+ /// SqlSugar瀹㈡埛绔紙鐢ㄤ簬涓存椂琛ㄦ搷浣滐級
+ /// </summary>
+ public ISqlSugarClient SqlSugarClient { get; }
+
+ /// <summary>
/// Mes鎺ュ彛鏈嶅姟
/// </summary>
public IMesService _mesService { get; }
@@ -51,13 +63,17 @@
IStockInfoService stockInfoService,
IStockInfoDetail_HtyService stockInfoDetail_HtyService,
IStockInfo_HtyService stockInfo_HtyService,
- IMesService mesService)
+ IMesService mesService,
+ IWarehouseService warehouseService,
+ ISqlSugarClient sqlSugarClient)
{
StockInfoDetailService = stockInfoDetailService;
StockInfoService = stockInfoService;
StockInfoDetail_HtyService = stockInfoDetail_HtyService;
StockInfo_HtyService = stockInfo_HtyService;
_mesService = mesService;
+ _warehouseService = warehouseService;
+ SqlSugarClient = sqlSugarClient;
}
/// <summary>
@@ -116,32 +132,18 @@
var now = DateTime.Now;
var details = stock.Details.Select(item => new Dt_StockInfoDetail
{
- MaterielCode = "鐢佃姱",
- MaterielName = "鐢佃姱",
+ MaterielCode = StockConstants.MATERIAL_CODE,
+ MaterielName = StockConstants.MATERIAL_NAME,
StockQuantity = item.Quantity,
- Unit = "PCS",
- Creater = "system",
- OrderNo = "111",
+ Unit = StockConstants.UNIT,
+ Creater = StockConstants.SYSTEM_USER,
+ OrderNo = StockConstants.DEFAULT_ORDER_NO,
ProductionDate = now.ToString(),
EffectiveDate = now.AddYears(1).ToString(),
SerialNumber = item.CellBarcode,
InboundOrderRowNo = item.Channel,
Status = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
}).ToList();
-
- var bindRequest = new BindContainerRequest
- {
- ContainerCode = stock?.TargetPalletNo,
- EquipmentCode = "STK-GROUP-001",
- ResourceCode = "STK-GROUP-001",
- LocalTime = now,
- OperationType = 0, // 0浠h〃缁勭洏
- ContainerSfcList = details.Select(d => new ContainerSfcItem
- {
- Sfc = d.SerialNumber,
- Location = d.InboundOrderRowNo.ToString(),
- }).ToList()
- };
return await ExecuteWithinTransactionAsync(async () =>
{
@@ -154,23 +156,23 @@
return result ? content.OK("缁勭洏鎴愬姛") : content.Error("缁勭洏澶辫触");
}
+ int WarehouseId = stock.Roadway switch
+ {
+ "娉ㄦ恫缁勭洏鏈烘鎵�" => (await _warehouseService.Db.Queryable<Dt_Warehouse>().FirstAsync(w => w.WarehouseCode == "GWSC1")).WarehouseId,
+ "鎹㈢洏鏈烘鎵�" => (await _warehouseService.Db.Queryable<Dt_Warehouse>().FirstAsync(w => w.WarehouseCode == "HCSC1")).WarehouseId
+ };
+
var entity = new Dt_StockInfo
{
PalletCode = stock.TargetPalletNo,
- //WarehouseId = stock.WarehouseId > 0 ? stock.WarehouseId : 1,
- WarehouseId = 1,
+ WarehouseId = WarehouseId,
StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
- Creater = "system",
+ Creater = StockConstants.SYSTEM_USER,
Details = details
};
result = StockInfoService.Repository.AddData(entity, x => x.Details);
if (!result) return content.Error("缁勭洏澶辫触");
- var mesResult = _mesService.BindContainer(bindRequest);
- if (mesResult == null || mesResult.Data == null || !mesResult.Data.IsSuccess)
- {
- return content.Error($"缁勭洏鎴愬姛锛屼絾MES缁戝畾澶辫触: {mesResult?.Data?.Msg ?? mesResult?.ErrorMessage ?? "鏈煡閿欒"}");
- }
return content.OK("缁勭洏鎴愬姛");
});
}
@@ -209,7 +211,7 @@
PalletCode = stock.TargetPalletNo,
WarehouseId = sourceStock.WarehouseId,
StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.GetHashCode(),
- Creater = "system",
+ Creater = StockConstants.SYSTEM_USER,
};
var newId = StockInfoService.Repository.AddData(newStock);
@@ -235,6 +237,7 @@
detailEntities.ForEach(d => d.StockId = targetStock.Id);
var result = await StockInfoDetailService.Repository.UpdateDataAsync(detailEntities);
if (!result) return content.Error("鎹㈢洏澶辫触");
+
return content.OK("鎹㈢洏鎴愬姛");
});
}
@@ -254,6 +257,30 @@
{
if (stock == null || string.IsNullOrWhiteSpace(stock.SourcePalletNo))
return content.Error("婧愭墭鐩樺彿涓嶈兘涓虹┖");
+
+ // 骞傜瓑鍐欏叆锛氭鏌ヤ复鏃惰〃鏄惁宸叉湁璇ユ墭鐩樿褰曪紝鏃犲垯鍐欏叆
+ var existingTemp = SqlSugarClient.Queryable<Dt_SplitTemp>()
+ .Where(t => t.PalletCode == stock.SourcePalletNo)
+ .First();
+ if (existingTemp == null)
+ {
+ // 鏌ヨ璇ユ墭鐩樺綋鍓嶆墍鏈夌數鑺紝瀛樺叆涓存椂琛�
+ var sourceStockForTemp = StockInfoService.Repository.QueryFirst(s => s.PalletCode == stock.SourcePalletNo);
+ if (sourceStockForTemp != null)
+ {
+ var allDetails = StockInfoDetailService.Repository.QueryData(d => d.StockId == sourceStockForTemp.Id);
+ if (allDetails != null && allDetails.Any())
+ {
+ var sfcListJson = JsonConvert.SerializeObject(allDetails.Select(d => d.SerialNumber).ToList());
+ await SqlSugarClient.Insertable(new Dt_SplitTemp
+ {
+ PalletCode = stock.SourcePalletNo,
+ SfcList = sfcListJson,
+ CreateTime = DateTime.Now
+ }).ExecuteCommandAsync();
+ }
+ }
+ }
return await ExecuteWithinTransactionAsync(async () =>
{
@@ -279,8 +306,6 @@
if (await StockInfo_HtyService.Repository.AddDataAsync(CreateStockHistory(new[] { sourceStock }, "鎷嗙洏")) <= 0)
return content.Error("鎷嗙洏鍘嗗彶璁板綍淇濆瓨澶辫触");
- var result = await StockInfoDetailService.Repository.DeleteDataAsync(detailEntities);
- if (!result) return content.Error("鎷嗙洏澶辫触");
return content.OK("鎷嗙洏鎴愬姛");
});
}
@@ -362,5 +387,105 @@
OutboundDate = s.OutboundDate
}).ToList();
}
+
+ /// <summary>
+ /// 鎵归噺鎷嗙洏纭 - 涓�娆℃�ц皟鐢∕ES瑙g粦鏁翠釜鎵樼洏
+ /// </summary>
+ /// <param name="palletCode">婧愭墭鐩樺彿</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public async Task<WebResponseContent> SplitPalletConfirmAsync(string palletCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (string.IsNullOrWhiteSpace(palletCode))
+ return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+ // 1. 浠庝复鏃惰〃璇诲彇鐢佃姱鍒楄〃
+ var tempRecord = SqlSugarClient.Queryable<Dt_SplitTemp>()
+ .Where(t => t.PalletCode == palletCode)
+ .First();
+ if (tempRecord == null)
+ return content.Error("鏈壘鍒版媶鐩樹复鏃惰褰曪紝璇峰厛鎵ц鎷嗙洏鎿嶄綔");
+
+ var sfcList = JsonConvert.DeserializeObject<List<string>>(tempRecord.SfcList);
+ if (sfcList == null || !sfcList.Any())
+ return content.Error("涓存椂琛ㄤ腑鐢佃姱鍒楄〃涓虹┖");
+
+ // 2. 璋冪敤MES瑙g粦
+ var unbindRequest = new UnBindContainerRequest
+ {
+ EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
+ ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ 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 ?? "鏈煡閿欒"}");
+ }
+
+ // 3. 鍒犻櫎涓存椂琛ㄨ褰�
+ await SqlSugarClient.Deleteable<Dt_SplitTemp>().Where(t => t.PalletCode == palletCode).ExecuteCommandAsync();
+
+ return content.OK("鎵归噺鎷嗙洏纭鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ return content.Error($"鎵归噺鎷嗙洏纭澶辫触: {ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵归噺缁勭洏纭 - 涓�娆℃�ц皟鐢∕ES缁戝畾鏁翠釜鎵樼洏
+ /// </summary>
+ /// <param name="palletCode">鐩爣鎵樼洏鍙�</param>
+ /// <returns>鎿嶄綔缁撴灉</returns>
+ public async Task<WebResponseContent> GroupPalletConfirmAsync(string palletCode)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (string.IsNullOrWhiteSpace(palletCode))
+ return content.Error("鎵樼洏鍙蜂笉鑳戒负绌�");
+
+ // 1. 鏌ヨ璇ユ墭鐩樹笅鐨勬墍鏈夌數鑺槑缁�
+ var stockInfo = StockInfoService.Repository.QueryFirst(s => s.PalletCode == palletCode);
+ if (stockInfo == null)
+ return content.Error("鎵樼洏涓嶅瓨鍦�");
+
+ var details = StockInfoDetailService.Repository.QueryData(d => d.StockId == stockInfo.Id);
+ if (details == null || !details.Any())
+ return content.Error("鎵樼洏涓嬫棤鐢佃姱鏁版嵁");
+
+ // 2. 璋冪敤MES缁戝畾
+ var bindRequest = new BindContainerRequest
+ {
+ ContainerCode = palletCode,
+ EquipmentCode = StockConstants.MES_EQUIPMENT_CODE,
+ ResourceCode = StockConstants.MES_RESOURCE_CODE,
+ LocalTime = DateTime.Now,
+ OperationType = StockConstants.MES_BIND_OPERATION_TYPE,
+ ContainerSfcList = details.Select(d => new ContainerSfcItem
+ {
+ Sfc = d.SerialNumber,
+ 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 ?? "鏈煡閿欒"}");
+ }
+
+ return content.OK("鎵归噺缁勭洏纭鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ return content.Error($"鎵归噺缁勭洏纭澶辫触: {ex.Message}");
+ }
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.3