From e9feb28be7d4417b24bd53a77332846e2cbab734 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期二, 18 十一月 2025 11:32:30 +0800
Subject: [PATCH] 提交
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs | 181 +++++++++++++++++++++++++++++++++++++++------
1 files changed, 156 insertions(+), 25 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs"
index 54ae514..18b32f1 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/SplitPackageService.cs"
@@ -84,7 +84,7 @@
SupplyCode = stockDetail.SupplyCode,
WarehouseCode = stockDetail.WarehouseCode,
BarcodeQty = stockDetail.BarcodeQty,
- BarcodeUnit = stockDetail.Barcode,
+ BarcodeUnit = stockDetail.BarcodeUnit,
BusinessType = stockDetail.BusinessType,
Unit = stockDetail.Unit,
StockId = lockInfo.StockId,
@@ -170,48 +170,180 @@
}
}
- // 鎾ら攢鎷嗗寘
+
+ //public async Task<WebResponseContent> RevertSplitPackage(string originalBarcode)
+ //{
+ // try
+ // {
+ // _unitOfWorkManage.BeginTran();
+
+ // // 1. 鏌ユ壘鏈�杩戠殑鏈挙閿�鎷嗗寘璁板綍
+ // var splitRecord = await Db.Queryable<Dt_SplitPackageRecord>()
+ // .Where(x => x.OriginalBarcode == originalBarcode && !x.IsReverted)
+ // .OrderByDescending(x => x.SplitTime)
+ // .FirstAsync();
+
+ // if (splitRecord == null)
+ // return WebResponseContent.Instance.Error("鏈壘鍒板彲鎾ら攢鐨勬媶鍖呰褰�");
+
+ // // 2. 妫�鏌ユ柊鏉$爜鏄惁宸叉嫞閫�
+ // var newLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ // .Where(x => x.CurrentBarcode == splitRecord.NewBarcode)
+ // .FirstAsync();
+
+ // if (newLockInfo?.Status ==6) // 鍋囪鐘舵��2琛ㄧず宸叉嫞閫�
+ // return WebResponseContent.Instance.Error("鏂版潯鐮佸凡鎷i�夛紝鏃犳硶鎾ら攢鎷嗗寘");
+
+ // // 3. 鑾峰彇鍘熸潯鐮佺殑閿佸畾淇℃伅
+ // var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ // .Where(x => x.CurrentBarcode == originalBarcode)
+ // .FirstAsync();
+
+ // if (originalLockInfo == null)
+ // return WebResponseContent.Instance.Error("鏈壘鍒板師鏉$爜閿佸畾淇℃伅");
+
+
+ // originalLockInfo.AssignQuantity += splitRecord.RemainQuantity;
+ // // originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ // originalLockInfo.IsSplitted = 0; // 鏍囪涓烘湭鎷嗗寘
+ // await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+
+ // // 5. 杩樺師鍘熸潯鐮佸簱瀛樿褰�
+ // var originalStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ // .Where(x => x.Barcode == originalBarcode && x.StockId == splitRecord.StockId)
+ // .FirstAsync();
+
+ // if (originalStockDetail != null)
+ // {
+ // // 灏嗘媶鍑虹殑鏁伴噺鍔犲洖鍒板師鏉$爜搴撳瓨
+ // originalStockDetail.StockQuantity += splitRecord.RemainQuantity;
+ // originalStockDetail.OutboundQuantity += splitRecord.RemainQuantity;
+ // await _stockInfoDetailService.Db.Updateable(originalStockDetail).ExecuteCommandAsync();
+ // }
+
+ // // 6. 鍒犻櫎鏂版潯鐮佺殑閿佸畾淇℃伅
+ // if (newLockInfo != null)
+ // {
+ // await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
+ // .Where(x => x.CurrentBarcode == splitRecord.NewBarcode)
+ // .ExecuteCommandAsync();
+ // }
+
+ // // 7. 鍒犻櫎鏂版潯鐮佺殑搴撳瓨璁板綍
+ // var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ // .Where(x => x.Barcode == splitRecord.NewBarcode)
+ // .FirstAsync();
+
+ // if (newStockDetail != null)
+ // {
+ // await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+ // .Where(x => x.Barcode == splitRecord.NewBarcode)
+ // .ExecuteCommandAsync();
+ // }
+
+ // // 8. 鏇存柊鎷嗗寘璁板綍涓哄凡鎾ら攢
+ // splitRecord.IsReverted = true;
+
+ // await Db.Updateable(splitRecord).ExecuteCommandAsync();
+
+ // _unitOfWorkManage.CommitTran();
+
+ // return WebResponseContent.Instance.OK($"鎾ら攢鎷嗗寘鎴愬姛锛岃繕鍘熸暟閲忥細{splitRecord.SplitQty}");
+
+ // }
+ // catch (Exception ex)
+ // {
+ // _unitOfWorkManage.RollbackTran();
+ // return WebResponseContent.Instance.Error($"鎾ら攢鎷嗗寘澶辫触锛歿ex.Message}");
+ // }
+ //}
+
public async Task<WebResponseContent> RevertSplitPackage(string originalBarcode)
{
try
{
_unitOfWorkManage.BeginTran();
- // 鏌ユ壘鏈�杩戠殑鏈挙閿�鎷嗗寘璁板綍
- var splitPackage = await Db.Queryable<Dt_SplitPackageRecord>()
+
+ // 1. 鏌ユ壘鎵�鏈夋湭鎾ら攢鐨勬媶鍖呰褰�
+ var splitRecords = await Db.Queryable<Dt_SplitPackageRecord>()
.Where(x => x.OriginalBarcode == originalBarcode && !x.IsReverted)
- .OrderByDescending(x => x.CreateDate)
- .FirstAsync();
+ .OrderBy(x => x.SplitTime) // 鎸夋椂闂存搴忥紝浠庢渶鏃╁紑濮嬫挙閿�
+ .ToListAsync();
- if (splitPackage == null)
- return WebResponseContent.Instance.Error("鏈壘鍒版媶鍖呰褰�");
+ if (splitRecords == null || !splitRecords.Any())
+ return WebResponseContent.Instance.Error("鏈壘鍒板彲鎾ら攢鐨勬媶鍖呰褰�");
- // 妫�鏌ユ柊鏉$爜鏄惁宸叉嫞閫�
- var newOutStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.CurrentBarcode == splitPackage.NewBarcode)
- .FirstAsync();
+ // 2. 妫�鏌ユ墍鏈夋柊鏉$爜鏄惁宸叉嫞閫�
+ var newBarcodes = splitRecords.Select(x => x.NewBarcode).ToList();
+ var newLockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => newBarcodes.Contains(x.CurrentBarcode))
+ .ToListAsync();
- if (newOutStockInfo.Status == 2)
- return WebResponseContent.Instance.Error("鏂版潯鐮佸凡鎷i�夛紝鏃犳硶鎾ら攢鎷嗗寘");
+ var pickedBarcodes = newLockInfos.Where(x => x.Status == 2).Select(x => x.CurrentBarcode).ToList();
+ if (pickedBarcodes.Any())
+ return WebResponseContent.Instance.Error($"浠ヤ笅鏉$爜宸叉嫞閫夛紝鏃犳硶鎾ら攢锛歿string.Join(",", pickedBarcodes)}");
- // 杩樺師鍘熷嚭搴撹鎯呮暟閲�
- var originalOutStockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ // 3. 鑾峰彇鍘熸潯鐮佷俊鎭�
+ var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
.Where(x => x.CurrentBarcode == originalBarcode)
.FirstAsync();
- originalOutStockInfo.AssignQuantity += splitPackage.SplitQty;
- await _outStockLockInfoService.Db.Updateable(originalOutStockInfo).ExecuteCommandAsync();
+ if (originalLockInfo == null)
+ return WebResponseContent.Instance.Error("鏈壘鍒板師鏉$爜閿佸畾淇℃伅");
- // 鍒犻櫎鏂板嚭搴撹鎯呰褰�
+ var originalStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.Barcode == originalBarcode && x.StockId == originalLockInfo.StockId)
+ .FirstAsync();
+
+ // 4. 鑾峰彇鎵�鏈夋柊鏉$爜鐨勫簱瀛樿褰�
+ var newStockDetails = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => newBarcodes.Contains(x.Barcode))
+ .ToListAsync();
+
+ // 5. 璁$畻鎬昏繕鍘熸暟閲�
+ decimal totalRevertQty = newStockDetails.Sum(x => x.StockQuantity);
+
+ // 6. 杩樺師鍘熸潯鐮佸簱瀛樿褰�
+ if (originalStockDetail != null)
+ {
+ // 鍘熸潯鐮佸綋鍓嶆暟閲忓姞涓婃墍鏈夋柊鏉$爜鐨勬暟閲�
+ originalStockDetail.StockQuantity += totalRevertQty;
+ originalStockDetail.OutboundQuantity += totalRevertQty;
+ await _stockInfoDetailService.Db.Updateable(originalStockDetail).ExecuteCommandAsync();
+ }
+
+ // 7. 杩樺師鍘熸潯鐮侀攣瀹氫俊鎭�
+ decimal totalAssignQty = newLockInfos.Sum(x => x.AssignQuantity);
+ originalLockInfo.AssignQuantity += totalAssignQty;
+ if (originalLockInfo.OrderQuantity < originalLockInfo.AssignQuantity)
+ {
+ originalLockInfo.AssignQuantity=originalLockInfo.OrderQuantity;
+ }
+ originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ originalLockInfo.IsSplitted = 0;
+ await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+
+ // 8. 鍒犻櫎鎵�鏈夋柊鏉$爜鐨勯攣瀹氫俊鎭�
await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
- .Where(x => x.CurrentBarcode == splitPackage.NewBarcode)
+ .Where(x => newBarcodes.Contains(x.CurrentBarcode))
.ExecuteCommandAsync();
- // 鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢
- splitPackage.IsReverted = true;
- await Db.Updateable(splitPackage).ExecuteCommandAsync();
+ // 9. 鍒犻櫎鎵�鏈夋柊鏉$爜鐨勫簱瀛樿褰�
+ await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+ .Where(x => newBarcodes.Contains(x.Barcode))
+ .ExecuteCommandAsync();
+
+ // 10. 鏍囪鎵�鏈夋媶鍖呰褰曚负宸叉挙閿�
+ foreach (var record in splitRecords)
+ {
+ record.IsReverted = true;
+
+ }
+ await Db.Updateable(splitRecords).ExecuteCommandAsync();
_unitOfWorkManage.CommitTran();
- return WebResponseContent.Instance.OK("鎾ら攢鎷嗗寘鎴愬姛");
+
+ return WebResponseContent.Instance.OK($"鎾ら攢鎷嗗寘鎴愬姛锛屽叡杩樺師{splitRecords.Count}娆℃媶鍖咃紝鎬绘暟閲忥細{totalRevertQty}");
}
catch (Exception ex)
@@ -220,7 +352,6 @@
return WebResponseContent.Instance.Error($"鎾ら攢鎷嗗寘澶辫触锛歿ex.Message}");
}
}
-
// 鑾峰彇鎷嗗寘淇℃伅
public async Task<WebResponseContent> GetSplitPackageInfo(string orderNo, string palletCode, string barcode)
{
--
Gitblit v1.9.3