From 1866b69e8f67e382a0a75268d63e6418c8ae02e7 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期二, 13 一月 2026 09:55:01 +0800
Subject: [PATCH] 1
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs | 203 ++++++++++++++++++++++++++++++++++----------------
1 files changed, 136 insertions(+), 67 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/OutboundPickingService.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/OutboundPickingService.cs"
index 586cd82..534a7df 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/OutboundPickingService.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/OutboundPickingService.cs"
@@ -34,6 +34,8 @@
using WIDESEA_BasicService.MESOperation;
using WIDESEA_Core.Util;
using WIDESEA_DTO.Allocate;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
+using WIDESEA_IRecordService;
namespace WIDESEA_OutboundService
{
@@ -70,6 +72,8 @@
private readonly IFeedbackMesService _feedbackMesService;
private readonly HttpClientHelper _httpClientHelper;
private readonly IRepository<Dt_MesReturnRecord> _mesReturnRecord;
+ private readonly IStockQuantityChangeRecordService _stockQuantityChangeRecordService;
+ private readonly IInboundOrderService _inboundOrderService;
private Dictionary<string, string> stations = new Dictionary<string, string>
{
@@ -88,7 +92,7 @@
public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
- IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog, IInboundService inboundService, IFeedbackMesService feedbackMesService, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord) : base(BaseDal)
+ IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository, IInboundOrderDetailService inboundOrderDetailService, IRepository<Dt_WarehouseArea> warehouseAreaRepository, IReCheckOrderService reCheckOrderService, ITask_HtyService task_HtyService, IRepository<Dt_InterfaceLog> interfaceLog, IInboundService inboundService, IFeedbackMesService feedbackMesService, HttpClientHelper httpClientHelper, IRepository<Dt_MesReturnRecord> mesReturnRecord,IStockQuantityChangeRecordService stockQuantityChangeRecordService,IInboundOrderService inboundOrderService) : base(BaseDal)
{
_unitOfWorkManage = unitOfWorkManage;
_stockInfoService = stockInfoService;
@@ -115,6 +119,8 @@
_feedbackMesService = feedbackMesService;
_httpClientHelper = httpClientHelper;
_mesReturnRecord = mesReturnRecord;
+ _stockQuantityChangeRecordService = stockQuantityChangeRecordService;
+ _inboundOrderService = inboundOrderService;
}
@@ -2365,7 +2371,7 @@
foreach (var detail in inboundOrder.Details)
{
if (detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt() &&
- !string.IsNullOrEmpty(detail.Barcode))
+ !string.IsNullOrEmpty(detail.Barcode)&& detail.OutBoxbarcodes == noStockOut.barCode)
{
detailLists.Add(detail);
}
@@ -2386,11 +2392,18 @@
{
item.NoStockOutQty = 0;
- var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == item.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt() && (detail.OrderQuantity-detail.LockQuantity-detail.MoveQty-detail.NoStockOutQty)>0);
+ var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == item.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt()&& detail.OrderQuantity - detail.LockQuantity - detail.MoveQty - detail.NoStockOutQty > 0);
- if (matchedCode == null)
+ if (matchedCode != null)
{
- return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓item.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+ if(matchedCode.OrderQuantity - matchedCode.LockQuantity - matchedCode.MoveQty - matchedCode.NoStockOutQty < 0)
+ {
+ return WebResponseContent.Instance.Error($"鐗╂枡{item.MaterielCode}鍙嚭鏁伴噺婧㈠嚭{(matchedCode.LockQuantity + matchedCode.MoveQty + matchedCode.NoStockOutQty) - matchedCode.OrderQuantity}");
+ }
+ }
+ else
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓item.MaterielCode} 瀵瑰簲鐨勭墿鏂�");
}
if (!matchedCode.BatchNo.IsNullOrEmpty() && matchedCode.BatchNo != "")
{
@@ -2426,6 +2439,10 @@
}
}
}
+ else
+ {
+ item.WarehouseCode = matchedCode.WarehouseCode;
+ }
//鍓╀綑鍏ュ簱鏁伴噺鍗宠櫄鎷熷嚭鍏ュ簱鍓╀綑鍙嚭鏁伴噺
decimal outQuantity = item.OrderQuantity - item.ReceiptQuantity;
@@ -2446,7 +2463,7 @@
Barcodes barcodes = new Barcodes
{
Barcode = item.Barcode,
- Qty = item.BarcodeQty,
+ Qty = item.OrderQuantity,
SupplyCode = item?.SupplyCode ?? "",
BatchNo = item?.BatchNo ?? "",
Unit = item?.Unit ?? ""
@@ -2467,7 +2484,6 @@
{
return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗘暟閲忔孩鍑簕matchedCode.OrderQuantity - matchedCode.LockQuantity-matchedCode.NoStockOutQty-matchedCode.MoveQty}");
}
- item.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
outDetails.Add(matchedCode);
}
@@ -2519,7 +2535,7 @@
Barcodes barcodes = new Barcodes
{
Barcode = matchedDetail.Barcode,
- Qty = matchedDetail.BarcodeQty,
+ Qty = matchedDetail.OrderQuantity,
SupplyCode = matchedDetail?.SupplyCode ?? "",
BatchNo = matchedDetail?.BatchNo ?? "",
Unit = matchedDetail?.Unit ?? ""
@@ -2585,13 +2601,14 @@
Dictionary<int, Dt_InboundOrder> updateInboundOrders = new Dictionary<int, Dt_InboundOrder>();
+ List<Dt_StockQuantityChangeRecord> changeRecords = new List<Dt_StockQuantityChangeRecord>();
_unitOfWorkManage.BeginTran();
List<Dt_InboundOrderDetail> allInboundDetails = _inboundOrderDetailService.Db
- .Queryable<Dt_InboundOrderDetail>()
- .Where(detail => noStockOutSubmit.BarCodeSubmit.Contains(detail.Barcode)
- && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt())
- .ToList();
+ .Queryable<Dt_InboundOrderDetail>()
+ .Where(detail => noStockOutSubmit.BarCodeSubmit.Contains(detail.Barcode)
+ && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt())
+ .ToList();
var detailGroupByOrderId = allInboundDetails.GroupBy(d => d.OrderId).ToList();
foreach (var group in detailGroupByOrderId)
@@ -2600,8 +2617,24 @@
List<Dt_InboundOrderDetail> groupDetails = group.ToList();
List<string> groupBarCodes = groupDetails.Select(d => d.Barcode).ToList();
-
orderIdBarCodeDict[orderId] = groupBarCodes;
+
+ Dt_InboundOrder currentInboundOrder = null;
+ if (!updateInboundOrders.TryGetValue(orderId, out currentInboundOrder))
+ {
+ currentInboundOrder = _inboundOrderRepository.Db
+ .Queryable<Dt_InboundOrder>()
+ .Where(x => x.Id == orderId)
+ .Includes(x => x.Details)
+ .First();
+
+ if (currentInboundOrder == null)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟ID涓� {orderId} 鐨勫崟鎹�");
+ }
+ updateInboundOrders[orderId] = currentInboundOrder;
+ }
foreach (var detail in groupDetails)
{
@@ -2613,53 +2646,49 @@
detail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
}
updateInboundDetails.Add(detail);
- }
- if (!updateInboundOrders.ContainsKey(orderId))
- {
- Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db
- .Queryable<Dt_InboundOrder>()
- .Where(x => x.Id == orderId)
- .Includes(x => x.Details)
- .First();
-
- if (inboundOrder == null)
+ //娣诲姞搴撳瓨鍙樺姩璁板綍
+ Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord
{
- _unitOfWorkManage.RollbackTran();
- return WebResponseContent.Instance.Error($"鏈壘鍒板叆搴撳崟ID涓� {orderId} 鐨勫崟鎹�");
- }
-
- // 鍒ゆ柇鏁村崟鏄惁鍏ㄩ儴瀹屾垚
- int totalDetailCount = inboundOrder.Details.Count();
- int beforeDetailCount = inboundOrder.Details.Where(x => x.OrderId == orderId && x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
- .Count();
- int finishedDetailCount = updateInboundDetails
- .Where(x => x.OrderId == orderId && x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
- .Count();
-
- inboundOrder.OrderStatus = totalDetailCount == finishedDetailCount+beforeDetailCount
- ? InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()
- : InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
-
- updateInboundOrders[orderId] = inboundOrder;
+ StockDetailId = detail.Id,
+ PalleCode = DateTime.Now.ToString(),
+ MaterielCode = detail.MaterielCode,
+ MaterielName = detail.MaterielName ?? "",
+ BatchNo = detail.BatchNo ?? "",
+ OriginalSerilNumber = detail.Barcode,
+ NewSerilNumber = "",
+ OrderNo = currentInboundOrder.InboundOrderNo,
+ TaskNum = 0,
+ ChangeType = (int)StockChangeTypeEnum.Inbound,
+ ChangeQuantity = detail.NoStockOutQty,
+ BeforeQuantity = detail.OverInQuantity - detail.NoStockOutQty,
+ AfterQuantity = detail.OverInQuantity,
+ SupplyCode = detail.SupplyCode ?? "",
+ WarehouseCode = detail.WarehouseCode ?? "",
+ Remark = $"铏氭嫙鍏ュ簱"
+ };
+ changeRecords.Add(changeRecord);
}
+
+ var inboundOrder = updateInboundOrders[orderId];
+ int totalDetailCount = inboundOrder.Details.Count;
+
+ int finishedDetailCount = inboundOrder.Details.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt())
+ + groupDetails.Count(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt());
+
+ inboundOrder.OrderStatus = totalDetailCount == finishedDetailCount
+ ? InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()
+ : InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
}
- // 6. 鎵归噺鏇存柊鏄庣粏鍜屼富鍗曪紙鎵归噺鎿嶄綔鎻愬崌鎬ц兘锛�
if (updateInboundDetails.Any())
{
- foreach (var detail in updateInboundDetails)
- {
- _inboundOrderDetailService.UpdateData(detail);
- }
-
+ _inboundOrderDetailService.Db.Updateable(updateInboundDetails).ExecuteCommand();
}
if (updateInboundOrders.Any())
{
- foreach (var order in updateInboundOrders.Values)
- {
- _inboundOrderRepository.UpdateData(order);
- }
+ // 鎵归噺鏇存柊鍏ュ簱涓诲崟
+ _inboundOrderService.Db.Updateable(updateInboundOrders.Values.ToList()).ExecuteCommand();
}
// 7. 寰幆鍒嗙粍缁撴灉锛岃皟鐢∕ES鍥炰紶鏂规硶锛堟寜鍏ュ簱鍗曞垎缁勫洖浼狅級
@@ -2669,20 +2698,20 @@
List<string> barCodeList = kvp.Value;
//鍏ュ簱鍥炰紶MES
NoStockOutBatchInOrderFeedbackToMes(orderId, barCodeList);
-
}
//鍙鍑哄簱鏉$爜鐨勫嚭搴撳崟鏄庣粏杩涜璁$畻鍥炰紶
List<Dt_OutboundOrderDetail> outboundOrderDetail = outboundOrder.Details
- .Where(x => !string.IsNullOrWhiteSpace(x.documentsNO)
- && noStockOutSubmit.BarCodeSubmit.Any(barcode =>
- x.documentsNO.IndexOf(barcode, StringComparison.OrdinalIgnoreCase) >= 0))
- .ToList();
+ .Where(x => !string.IsNullOrWhiteSpace(x.documentsNO)
+ && noStockOutSubmit.BarCodeSubmit.Any(barcode =>
+ x.documentsNO.IndexOf(barcode, StringComparison.OrdinalIgnoreCase) >= 0))
+ .ToList();
foreach (var item in outboundOrderDetail)
{
- item.LockQuantity = item.NoStockOutQty;
- item.OverOutQuantity = item.NoStockOutQty;
+ item.LockQuantity += item.NoStockOutQty;
+ item.OverOutQuantity += item.NoStockOutQty;
+ item.CurrentDeliveryQty = item.NoStockOutQty;
//娣诲姞鍥炰紶MES鍙傛暟
List<Barcodes> barcodesList = new List<Barcodes>();
List<Barcodes> documentsNOList = new List<Barcodes>();
@@ -2703,18 +2732,47 @@
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
item.ReturnJsonData = JsonConvert.SerializeObject(barcodesList, settings);
-
+ //娣诲姞搴撳瓨鍙樺姩璁板綍
+ Dt_StockQuantityChangeRecord changeRecord = new Dt_StockQuantityChangeRecord
+ {
+ StockDetailId = item.Id,
+ PalleCode = DateTime.Now.ToString(),
+ MaterielCode = item.MaterielCode,
+ MaterielName = item.MaterielName ?? "",
+ BatchNo = item.BatchNo ?? "",
+ OriginalSerilNumber = item.ReturnJsonData,
+ NewSerilNumber = "",
+ OrderNo = outboundOrder.OrderNo,
+ TaskNum = 0,
+ ChangeType = (int)StockChangeTypeEnum.Inbound,
+ ChangeQuantity = -item.NoStockOutQty,
+ BeforeQuantity = item.OrderQuantity,
+ AfterQuantity = item.OrderQuantity - item.OverOutQuantity,
+ SupplyCode = item.SupplyCode ?? "",
+ WarehouseCode = item.WarehouseCode ?? "",
+ Remark = $"铏氭嫙鍑哄簱"
+ };
+ changeRecords.Add(changeRecord);
outboundOrderDetails.Add(item);
}
_outboundOrderDetailService.UpdateData(outboundOrderDetails);
-
+ //鎵归噺娣诲姞搴撳瓨鍙樺姩璁板綍
+ if (changeRecords.Any())
+ {
+ _stockQuantityChangeRecordService.Db.Insertable(changeRecords).ExecuteCommand();
+ }
// 妫�鏌ュ嚭搴撳崟鏄惁瀹屾垚
if (CheckOutboundOrderCompleted(outboundOrder.OrderNo))
{
outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
- _outboundOrderService.UpdateData(outboundOrder);
+
}
+ else
+ {
+ outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+ }
+ _outboundOrderService.UpdateData(outboundOrder);
_unitOfWorkManage.CommitTran();
//鍑哄簱鍥炰紶MES
_feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
@@ -2774,7 +2832,7 @@
BusinessType = "3",
FactoryArea = inboundOrder.FactoryArea,
OperationType = 1,
- Operator = inboundOrder.Operator,
+ Operator = App.User.UserName,
OrderNo = inboundOrder.UpperOrderNo,
fromWarehouse = allocate?.FromWarehouse ?? "",
toWarehouse = allocate?.ToWarehouse ?? "",
@@ -2790,11 +2848,17 @@
if (response != null && response.IsSuccess)
{
- _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 });
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id && barCodeList.Contains(it.Barcode)).ExecuteCommand();
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
}
else
{
- _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 });
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 })
+ .Where(it => it.OrderId == inboundOrder.Id && barCodeList.Contains(it.Barcode)).ExecuteCommand();
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus =2})
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
return content.Error("鍥炰紶MES澶辫触");
}
}
@@ -2807,7 +2871,7 @@
business_type = inboundOrder.BusinessType,
factoryArea = inboundOrder.FactoryArea,
operationType = 1,
- Operator = inboundOrder.Operator,
+ Operator = App.User.UserName,
orderNo = inboundOrder.UpperOrderNo,
status = inboundOrder.OrderStatus,
details = NoStockOutFeedbackInboundDetailsModelDto(detail)
@@ -2821,11 +2885,16 @@
if (response != null && response.IsSuccess)
{
- _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 });
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id && barCodeList.Contains(it.Barcode)).ExecuteCommand();
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
}
else
{
- _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 });
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 2 }).Where(it => it.OrderId == inboundOrder.Id && barCodeList.Contains(it.Barcode)).ExecuteCommand();
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 2 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
return content.Error("鍥炰紶MES澶辫触");
}
}
@@ -2859,7 +2928,7 @@
}).ToList();
return groupedData;
}
- public List<FeedbackInboundDetailsModel> NoStockOutFeedbackInboundDetailsModelDto(List<Dt_InboundOrderDetail> inboundOrderDetails)
+ public List<FeedbackInboundDetailsModel> NoStockOutFeedbackInboundDetailsModelDto(List<Dt_InboundOrderDetail> inboundOrderDetails )
{
var groupedData = inboundOrderDetails.GroupBy(item => new { item.MaterielCode, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
.Select(group => new FeedbackInboundDetailsModel
--
Gitblit v1.9.3