From 213c9c2a2c24eecbb9d6716f190cc265101a642e Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期一, 01 十二月 2025 11:51:02 +0800
Subject: [PATCH] 提交
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs | 1453 +++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 1,287 insertions(+), 166 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 8e030a2..448d71e 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"
@@ -20,13 +20,18 @@
using WIDESEA_Core.BaseServices;
using WIDESEA_Core.Enums;
using WIDESEA_Core.Helper;
+using WIDESEA_Core.Utilities;
+using WIDESEA_DTO.Allocate;
using WIDESEA_DTO.Basic;
using WIDESEA_DTO.Inbound;
using WIDESEA_DTO.Outbound;
+using WIDESEA_IAllocateService;
using WIDESEA_IBasicService;
+using WIDESEA_IInboundService;
using WIDESEA_IOutboundService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
namespace WIDESEA_OutboundService
{
@@ -50,6 +55,10 @@
private readonly IESSApiService _eSSApiService;
private readonly IInvokeMESService _invokeMESService;
private readonly IDailySequenceService _dailySequenceService;
+ private readonly IAllocateService _allocateService;
+ private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+ private readonly IInboundOrderDetailService _inboundOrderDetailService;
+ private readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
private readonly ILogger<OutboundPickingService> _logger;
@@ -70,7 +79,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) : 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) : base(BaseDal)
{
_unitOfWorkManage = unitOfWorkManage;
_stockInfoService = stockInfoService;
@@ -86,6 +95,10 @@
_logger = logger;
_invokeMESService = invokeMESService;
_dailySequenceService = dailySequenceService;
+ _allocateService = allocateService;
+ _inboundOrderRepository = inboundOrderRepository;
+ _inboundOrderDetailService = inboundOrderDetailService;
+ _warehouseAreaRepository = warehouseAreaRepository;
}
@@ -187,10 +200,10 @@
return WebResponseContent.Instance.Error(overPickingValidation.ErrorMessage);
}
- // 鎵ц鍒嗘嫞閫昏緫
+ // 鎵ц鍒嗘嫞閫昏緫锛堝彧澶勭悊搴撳瓨鍜岄攣瀹氾紝涓嶅鐞嗚鍗曪級
var pickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, orderNo, palletCode, barcode, actualQty);
- // 鏇存柊鐩稿叧鏁版嵁
+ // 缁熶竴鏇存柊璁㈠崟鏁版嵁锛堟墍鏈夊垎鏀兘鍦ㄨ繖閲屾洿鏂帮級
await UpdateOrderRelatedData(orderDetail.Id, pickingResult.ActualPickedQty, orderNo);
// 璁板綍鎿嶄綔鍘嗗彶
@@ -207,6 +220,7 @@
return WebResponseContent.Instance.Error($"鎷i�夌‘璁ゅけ璐ワ細{ex.Message}");
}
}
+
/// <summary>
/// 鍙栨秷鎷i��
/// </summary>
@@ -224,19 +238,19 @@
}
_unitOfWorkManage.BeginTran();
- // 1. 鍓嶇疆楠岃瘉
+ // 鍓嶇疆楠岃瘉
var validationResult = await ValidateCancelRequest(orderNo, palletCode, barcode);
if (!validationResult.IsValid)
return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
var (pickingRecord, lockInfo, orderDetail) = validationResult.Data;
- // 2. 鎵ц鍙栨秷閫昏緫
+ //鎵ц鍙栨秷閫昏緫
await ExecuteCancelLogic(lockInfo, pickingRecord, orderDetail, orderNo);
_unitOfWorkManage.CommitTran();
- return WebResponseContent.Instance.OK($"鍙栨秷鍒嗘嫞鎴愬姛锛屾仮澶嶆暟閲忥細{pickingRecord.PickQuantity}");
+ return WebResponseContent.Instance.OK($"鍙栨秷鍒嗘嫞鎴愬姛");
}
catch (Exception ex)
{
@@ -290,16 +304,19 @@
//鎵ц鍥炲簱鎿嶄綔
await ExecuteReturnOperations(orderNo, palletCode, stockInfo, task, statusAnalysis);
+ await ReleaseAllLocksForReallocation(orderNo, palletCode, statusAnalysis);
+
_unitOfWorkManage.CommitTran();
-
+
// 鍒涘缓鍥炲簱浠诲姟
- await CreateReturnTaskAndHandleESS(orderNo, palletCode, task, TaskTypeEnum.InPick);
+ await CreateReturnTaskAndHandleESS(orderNo, palletCode, task, TaskTypeEnum.InPick, task.PalletType);
// 鏇存柊璁㈠崟鐘舵�侊紙涓嶈Е鍙慚ES鍥炰紶锛�
await UpdateOrderStatusForReturn(orderNo);
- return WebResponseContent.Instance.OK($"鍥炲簱鎿嶄綔鎴愬姛锛屽叡鍥炲簱鏁伴噺锛歿statusAnalysis.TotalReturnQty}");
+ return WebResponseContent.Instance.OK($"鍥炲簱鎿嶄綔鎴愬姛");
+ //return WebResponseContent.Instance.OK($"鍥炲簱鎿嶄綔鎴愬姛锛屽叡鍥炲簱鏁伴噺锛歿statusAnalysis.TotalReturnQty}");
}
catch (Exception ex)
{
@@ -549,9 +566,11 @@
return ValidationResult<bool>.Success(true);
}
+
+
private async Task<PickingResult> ExecutePickingLogic(
- Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail, Dt_StockInfoDetail stockDetail,
- string orderNo, string palletCode, string barcode, decimal actualQty)
+ Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail, Dt_StockInfoDetail stockDetail,
+ string orderNo, string palletCode, string barcode, decimal actualQty)
{
decimal stockQuantity = stockDetail.StockQuantity;
var result = new PickingResult
@@ -565,21 +584,26 @@
if (actualQty < stockQuantity)
{
await HandleSplitPacking(lockInfo, stockDetail, actualQty, stockQuantity, result);
+ // 鎷嗗寘鍦烘櫙杩斿洖瀹為檯鎷i�夋暟閲�
+ result.ActualPickedQty = actualQty;
}
else if (actualQty == stockQuantity)
{
await HandleFullPicking(lockInfo, stockDetail, actualQty, result);
+ // 鏁村寘鎷i�夎繑鍥炲疄闄呮嫞閫夋暟閲�
+ result.ActualPickedQty = actualQty;
}
else
{
await HandlePartialPicking(lockInfo, stockDetail, actualQty, stockQuantity, result);
+ // 閮ㄥ垎鎷i�夎繑鍥炶皟鏁村悗鐨勬暟閲�
+ result.ActualPickedQty = result.ActualPickedQty; // 宸茬粡鍦ㄦ柟娉曞唴璋冩暣
}
return result;
}
-
private async Task HandleSplitPacking(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
- decimal actualQty, decimal stockQuantity, PickingResult result)
+ decimal actualQty, decimal stockQuantity, PickingResult result)
{
decimal remainingStockQty = stockQuantity - actualQty;
@@ -588,10 +612,10 @@
stockDetail.OutboundQuantity = remainingStockQty;
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
- //鐢熸垚鏂版潯鐮�
+ // 鐢熸垚鏂版潯鐮�
string newBarcode = await GenerateNewBarcode();
- //鍒涘缓鏂伴攣瀹氫俊鎭�
+ // 鍒涘缓鏂伴攣瀹氫俊鎭�
var newLockInfo = await CreateSplitLockInfo(lockInfo, actualQty, newBarcode);
// 璁板綍鎷嗗寘鍘嗗彶
@@ -608,11 +632,10 @@
result.FinalBarcode = newBarcode;
result.SplitResults.AddRange(CreateSplitResults(lockInfo, actualQty, remainingStockQty, newBarcode, stockDetail.Barcode));
- await UpdateOrderRelatedData(lockInfo.OrderDetailId, actualQty, lockInfo.OrderNo);
- _logger.LogInformation($"鎷嗗寘鍒嗘嫞鏇存柊璁㈠崟鏄庣粏 - OrderDetailId: {lockInfo.OrderDetailId}, 鍒嗘嫞鏁伴噺: {actualQty}");
+
+ _logger.LogInformation($"鎷嗗寘鍒嗘嫞瀹屾垚 - OrderDetailId: {lockInfo.OrderDetailId}, 鍒嗘嫞鏁伴噺: {actualQty}");
}
-
private async Task HandleFullPicking(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
decimal actualQty, PickingResult result)
{
@@ -664,9 +687,7 @@
if (newOverOutQuantity > currentOrderDetail.NeedOutQuantity)
{
-
_logger.LogError($"闃茶秴鎷f鏌ュけ璐� - OrderDetailId: {orderDetailId}, 宸插嚭搴�: {newOverOutQuantity}, 闇�姹�: {currentOrderDetail.NeedOutQuantity}, 鏈鍒嗘嫞: {pickedQty}");
-
decimal adjustedQty = currentOrderDetail.NeedOutQuantity - currentOrderDetail.OverOutQuantity;
@@ -675,6 +696,7 @@
_logger.LogWarning($"鑷姩璋冩暣鍒嗘嫞鏁伴噺闃叉瓒呮嫞锛氫粠{pickedQty}璋冩暣涓簕adjustedQty}");
newOverOutQuantity = currentOrderDetail.NeedOutQuantity;
newPickedQty = currentOrderDetail.PickedQty + adjustedQty;
+ pickedQty = adjustedQty; // 鏇存柊瀹為檯鎷i�夋暟閲�
}
else
{
@@ -682,15 +704,21 @@
}
}
- // 鏇存柊璁㈠崟鏄庣粏
+ // 鏇存柊璁㈠崟鏄庣粏鏁伴噺鍜岀姸鎬�
await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
.SetColumns(it => new Dt_OutboundOrderDetail
{
PickedQty = newPickedQty,
OverOutQuantity = newOverOutQuantity,
+ OrderDetailStatus = newOverOutQuantity >= currentOrderDetail.NeedOutQuantity ?
+ OrderDetailStatusEnum.Over.ObjToInt() :
+ OrderDetailStatusEnum.Outbound.ObjToInt()
})
.Where(it => it.Id == orderDetailId)
.ExecuteCommandAsync();
+
+ // 鏇存柊閿佸畾鏁伴噺
+ await UpdateOrderDetailLockQuantity(orderDetailId);
// 妫�鏌ュ苟鏇存柊璁㈠崟鐘舵��
await CheckAndUpdateOrderStatus(orderNo);
@@ -721,7 +749,15 @@
PickQuantity = result.ActualPickedQty,
PickTime = DateTime.Now,
Operator = App.User.UserName,
- OutStockLockId = result.FinalLockInfo.Id
+ OutStockLockId = result.FinalLockInfo.Id,
+ BarcodeUnit = result.FinalLockInfo.BarcodeUnit,
+ BarcodeQty = result.FinalLockInfo.BarcodeQty,
+ BatchNo = result.FinalLockInfo.BatchNo,
+ lineNo = result.FinalLockInfo.lineNo,
+ SupplyCode = result.FinalLockInfo.SupplyCode,
+ WarehouseCode = result.FinalLockInfo.WarehouseCode,
+
+
};
await Db.Insertable(pickingHistory).ExecuteCommandAsync();
@@ -730,7 +766,73 @@
#endregion
#region 鍙栨秷鍒嗘嫞绉佹湁鏂规硶
+ private async Task<ValidationResult<bool>> ValidateDataConsistencyBeforeCancel(CancelPickingContext context)
+ {
+ try
+ {
+ // 楠岃瘉璁㈠崟鏄庣粏鏁版嵁
+ var currentOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == context.OrderDetail.Id);
+ if (currentOrderDetail.OverOutQuantity < context.PickingRecord.PickQuantity)
+ return ValidationResult<bool>.Error($"璁㈠崟鏄庣粏宸插嚭搴撴暟閲�({currentOrderDetail.OverOutQuantity})灏忎簬鍙栨秷鏁伴噺({context.PickingRecord.PickQuantity})");
+
+ if (currentOrderDetail.PickedQty < context.PickingRecord.PickQuantity)
+ return ValidationResult<bool>.Error($"璁㈠崟鏄庣粏宸叉嫞閫夋暟閲�({currentOrderDetail.PickedQty})灏忎簬鍙栨秷鏁伴噺({context.PickingRecord.PickQuantity})");
+
+ // 楠岃瘉閿佸畾淇℃伅鏁版嵁
+ var currentLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == context.LockInfo.Id);
+
+ if (currentLockInfo.PickedQty < context.PickingRecord.PickQuantity)
+ return ValidationResult<bool>.Error($"閿佸畾淇℃伅宸叉嫞閫夋暟閲�({currentLockInfo.PickedQty})灏忎簬鍙栨秷鏁伴噺({context.PickingRecord.PickQuantity})");
+
+ ////// 楠岃瘉搴撳瓨鏁版嵁
+ ////var currentStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ //// .FirstAsync(x => x.Barcode == context.PickingRecord.Barcode && x.StockId == context.PickingRecord.StockId);
+
+ ////if (currentStockDetail == null)
+ //// return ValidationResult<bool>.Error($"鏈壘鍒板搴旂殑搴撳瓨鏄庣粏璁板綍");
+
+ ////if (currentStockDetail.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt() ||
+ //// currentStockDetail.Status == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+ //// return ValidationResult<bool>.Error($"鏉$爜{context.PickingRecord.Barcode}宸茬粡鍥炲簱锛屾棤娉曞彇娑堝垎鎷�");
+
+ // 楠岃瘉鐘舵�佹祦杞殑鍚堟硶鎬�
+ if (!await CanCancelPicking(currentLockInfo, null))
+ return ValidationResult<bool>.Error($"褰撳墠鐘舵�佷笉鍏佽鍙栨秷鍒嗘嫞");
+
+ return ValidationResult<bool>.Success(true);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鍙栨秷鍒嗘嫞鏁版嵁涓�鑷存�ч獙璇佸け璐�: {ex.Message}");
+ return ValidationResult<bool>.Error($"鏁版嵁楠岃瘉澶辫触: {ex.Message}");
+ }
+ }
+
+ private async Task<bool> CanCancelPicking(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail)
+ {
+ // 閿佸畾淇℃伅鐘舵�佹鏌�
+ if (lockInfo.Status != (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ return false;
+
+ ////// 搴撳瓨鐘舵�佹鏌�
+ ////if (stockDetail.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+ //// return false;
+
+ // 濡傛灉鏄媶鍖呰褰曪紝杩橀渶瑕佹鏌ョ埗閿佸畾淇℃伅鐘舵��
+ if (lockInfo.IsSplitted == 1 && lockInfo.ParentLockId.HasValue)
+ {
+ var parentLock = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == lockInfo.ParentLockId.Value);
+
+ if (parentLock == null || parentLock.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
+ return false;
+ }
+
+ return true;
+ }
private async Task<ValidationResult<(Dt_PickingRecord, Dt_OutStockLockInfo, Dt_OutboundOrderDetail)>> ValidateCancelRequest(string orderNo, string palletCode, string barcode)
{
// 鍩虹鍙傛暟楠岃瘉
@@ -838,30 +940,25 @@
stockDetail.Status == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt();
}
private async Task ExecuteCancelLogic(Dt_OutStockLockInfo lockInfo, Dt_PickingRecord pickingRecord,
- Dt_OutboundOrderDetail orderDetail, string orderNo)
+ Dt_OutboundOrderDetail orderDetail, string orderNo)
{
decimal cancelQty = pickingRecord.PickQuantity;
- var currentStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .Where(it => it.Barcode == pickingRecord.Barcode && it.StockId == pickingRecord.StockId)
- .FirstAsync();
-
- if (currentStockDetail != null &&
- (currentStockDetail.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt() ||
- currentStockDetail.Status == StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt()))
+ // 鏁版嵁涓�鑷存�ч獙璇�
+ var context = new CancelPickingContext
{
- throw new Exception($"鏉$爜{pickingRecord.Barcode}宸茬粡鍥炲簱锛屾棤娉曞彇娑堝垎鎷�");
- }
- // 妫�鏌ュ彇娑堝悗鏁伴噺涓嶄細涓鸿礋鏁�
- decimal newOverOutQuantity = orderDetail.OverOutQuantity - cancelQty;
- decimal newPickedQty = orderDetail.PickedQty - cancelQty;
+ LockInfo = lockInfo,
+ PickingRecord = pickingRecord,
+ OrderDetail = orderDetail,
+ OrderNo = orderNo,
+ CancelQuantity = cancelQty
+ };
- if (newOverOutQuantity < 0 || newPickedQty < 0)
- {
- throw new Exception($"鍙栨秷鍒嗘嫞灏嗗鑷存暟鎹紓甯革細宸插嚭搴搟newOverOutQuantity}锛屽凡鎷i�墈newPickedQty}");
- }
+ var validationResult = await ValidateDataConsistencyBeforeCancel(context);
+ if (!validationResult.IsValid)
+ throw new Exception(validationResult.ErrorMessage);
- // 澶勭悊涓嶅悓绫诲瀷鐨勫彇娑�
+ // 澶勭悊涓嶅悓绫诲瀷鐨勫彇娑�
if (lockInfo.IsSplitted == 1 && lockInfo.ParentLockId.HasValue)
{
await HandleSplitBarcodeCancel(lockInfo, pickingRecord, cancelQty);
@@ -871,16 +968,23 @@
await HandleNormalBarcodeCancel(lockInfo, pickingRecord, cancelQty);
}
- // 鏇存柊璁㈠崟鏄庣粏
+ // 鏇存柊璁㈠崟鏄庣粏
await UpdateOrderDetailOnCancel(pickingRecord.OrderDetailId, cancelQty);
// 鍒犻櫎鎷i�夎褰�
- await Db.Deleteable<Dt_PickingRecord>()
+ var deleteResult = await Db.Deleteable<Dt_PickingRecord>()
.Where(x => x.Id == pickingRecord.Id)
.ExecuteCommandAsync();
- // 閲嶆柊妫�鏌ヨ鍗曠姸鎬�
+ if (deleteResult <= 0)
+ throw new Exception("鍒犻櫎鎷i�夎褰曞け璐�");
+
+ _logger.LogInformation($"鍒犻櫎鎷i�夎褰� - 璁板綍ID: {pickingRecord.Id}, 鏉$爜: {pickingRecord.Barcode}");
+
+ // 閲嶆柊妫�鏌ヨ鍗曠姸鎬�
await UpdateOrderStatusForReturn(orderNo);
+
+
}
private async Task HandleSplitBarcodeCancel(Dt_OutStockLockInfo lockInfo, Dt_PickingRecord pickingRecord, decimal cancelQty)
@@ -893,61 +997,85 @@
if (parentLockInfo == null)
throw new Exception("鏈壘鍒扮埗閿佸畾淇℃伅锛屾棤娉曞彇娑堟媶鍖呭垎鎷�");
+ // 妫�鏌ョ埗鏉$爜鍜屾媶鍖呮潯鐮佺殑鐘舵��
if (await IsLockInfoReturned(parentLockInfo))
- {
throw new Exception($"鐖舵潯鐮亄parentLockInfo.CurrentBarcode}宸茬粡鍥炲簱锛屾棤娉曞彇娑堟媶鍖呭垎鎷�");
- }
+
if (await IsLockInfoReturned(lockInfo))
- {
throw new Exception($"鎷嗗寘鏉$爜{lockInfo.CurrentBarcode}宸茬粡鍥炲簱锛屾棤娉曞彇娑堟媶鍖呭垎鎷�");
- }
+
// 鎭㈠鐖堕攣瀹氫俊鎭殑鍒嗛厤鏁伴噺
parentLockInfo.AssignQuantity += cancelQty;
+ parentLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�; // 鎭㈠涓哄嚭搴撲腑鐘舵��
await _outStockLockInfoService.Db.Updateable(parentLockInfo).ExecuteCommandAsync();
- // 鎭㈠搴撳瓨
- var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ // 鎭㈠鐖舵潯鐮佸簱瀛�
+ var parentStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.Where(x => x.Barcode == parentLockInfo.CurrentBarcode && x.StockId == parentLockInfo.StockId)
.FirstAsync();
- if (stockDetail != null)
+ if (parentStockDetail != null)
{
- stockDetail.StockQuantity += cancelQty;
- stockDetail.OutboundQuantity = stockDetail.StockQuantity;
- stockDetail.Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
- await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ parentStockDetail.StockQuantity += cancelQty;
+ parentStockDetail.OutboundQuantity = parentStockDetail.StockQuantity;
+ parentStockDetail.Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+ await _stockInfoDetailService.Db.Updateable(parentStockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鎭㈠鐖舵潯鐮佸簱瀛� - 鏉$爜: {parentStockDetail.Barcode}, 鎭㈠鏁伴噺: {cancelQty}, 鏂板簱瀛�: {parentStockDetail.StockQuantity}");
+ }
+
+ // 澶勭悊鎷嗗寘浜х敓鐨勬柊鏉$爜搴撳瓨
+ var splitStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId)
+ .FirstAsync();
+
+ if (splitStockDetail != null)
+ {
+ // 鍒犻櫎鎷嗗寘浜х敓鐨勬柊鏉$爜搴撳瓨璁板綍
+ await _stockInfoDetailService.Db.Deleteable(splitStockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒犻櫎鎷嗗寘鏂版潯鐮佸簱瀛� - 鏉$爜: {splitStockDetail.Barcode}");
}
// 鏇存柊鎷嗗寘璁板綍鐘舵��
- await _splitPackageService.Db.Updateable<Dt_SplitPackageRecord>()
+ var updateCount = await _splitPackageService.Db.Updateable<Dt_SplitPackageRecord>()
.SetColumns(x => new Dt_SplitPackageRecord
{
Status = (int)SplitPackageStatusEnum.宸叉挙閿�,
IsReverted = true,
+ Operator = App.User.UserName,
+ RevertTime = DateTime.Now
})
.Where(x => x.NewBarcode == lockInfo.CurrentBarcode && !x.IsReverted)
.ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏇存柊鎷嗗寘璁板綍鐘舵�� - 鏇存柊璁板綍鏁�: {updateCount}");
// 鍒犻櫎鎷嗗寘浜х敓鐨勯攣瀹氫俊鎭�
await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
.Where(x => x.Id == lockInfo.Id)
.ExecuteCommandAsync();
- await UpdateOrderDetailOnCancel(pickingRecord.OrderDetailId, cancelQty);
+ _logger.LogInformation($"鍒犻櫎鎷嗗寘閿佸畾淇℃伅 - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}");
}
-
private async Task HandleNormalBarcodeCancel(Dt_OutStockLockInfo lockInfo, Dt_PickingRecord pickingRecord, decimal cancelQty)
{
if (await IsLockInfoReturned(lockInfo))
- {
throw new Exception($"鏉$爜{lockInfo.CurrentBarcode}宸茬粡鍥炲簱锛屾棤娉曞彇娑堝垎鎷�");
- }
+
// 鎭㈠閿佸畾淇℃伅
lockInfo.PickedQty -= cancelQty;
if (lockInfo.PickedQty < 0) lockInfo.PickedQty = 0;
- lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ // 鍙湁褰撴嫞閫夋暟閲忓畬鍏ㄥ彇娑堟椂鎵嶆仮澶嶇姸鎬�
+ if (lockInfo.PickedQty == 0)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ }
+
+ lockInfo.Operator = App.User.UserName;
await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鎭㈠閿佸畾淇℃伅 - 閿佸畾ID: {lockInfo.Id}, 鎵e噺鎷i�夋暟閲�: {cancelQty}, 鏂板凡鎷i�夋暟閲�: {lockInfo.PickedQty}");
// 鎭㈠搴撳瓨
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
@@ -958,36 +1086,77 @@
{
stockDetail.StockQuantity += cancelQty;
stockDetail.OutboundQuantity = stockDetail.StockQuantity;
- stockDetail.Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+
+ // 鎭㈠搴撳瓨鐘舵��
+ if (stockDetail.Status == StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+ {
+ stockDetail.Status = StockStatusEmun.鍑哄簱閿佸畾.ObjToInt();
+ }
+
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鎭㈠搴撳瓨 - 鏉$爜: {stockDetail.Barcode}, 鎭㈠鏁伴噺: {cancelQty}, " +
+ $"鏂板簱瀛�: {stockDetail.StockQuantity}, 鏂扮姸鎬�: {stockDetail.Status}");
+ }
+ else
+ {
+ _logger.LogWarning($"鏈壘鍒板簱瀛樿褰� - 鏉$爜: {pickingRecord.Barcode}, 搴撳瓨ID: {pickingRecord.StockId}");
}
}
-
private async Task UpdateOrderDetailOnCancel(int orderDetailId, decimal cancelQty)
{
- // 鑾峰彇鏈�鏂扮殑璁㈠崟鏄庣粏鏁版嵁
+ // 鑾峰彇鏈�鏂扮殑璁㈠崟鏄庣粏鏁版嵁锛堝甫閿侊級
var currentOrderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .With(SqlWith.RowLock)
.FirstAsync(x => x.Id == orderDetailId);
decimal newOverOutQuantity = currentOrderDetail.OverOutQuantity - cancelQty;
decimal newPickedQty = currentOrderDetail.PickedQty - cancelQty;
- // 妫�鏌ュ彇娑堝悗鏁伴噺涓嶄細涓鸿礋鏁�
- if (newOverOutQuantity < 0 || newPickedQty < 0)
+ // 涓ユ牸妫�鏌ュ彇娑堝悗鏁伴噺涓嶄細涓鸿礋鏁�
+ if (newOverOutQuantity < 0)
+ throw new Exception($"鍙栨秷鍒嗘嫞灏嗗鑷村凡鍑哄簱鏁伴噺({newOverOutQuantity})涓鸿礋鏁�");
+
+ if (newPickedQty < 0)
+ throw new Exception($"鍙栨秷鍒嗘嫞灏嗗鑷村凡鎷i�夋暟閲�({newPickedQty})涓鸿礋鏁�");
+
+ // 纭畾鏂扮殑鐘舵��
+ int newStatus;
+ if (newOverOutQuantity >= currentOrderDetail.NeedOutQuantity)
{
- throw new Exception($"鍙栨秷鍒嗘嫞灏嗗鑷村凡鍑哄簱鏁伴噺({newOverOutQuantity})鎴栧凡鎷i�夋暟閲�({newPickedQty})涓鸿礋鏁�");
+ newStatus = OrderDetailStatusEnum.Over.ObjToInt();
+ }
+ else if (newOverOutQuantity > 0)
+ {
+ newStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+ }
+ else
+ {
+ newStatus = OrderDetailStatusEnum.New.ObjToInt();
}
- await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ // 鏇存柊璁㈠崟鏄庣粏
+ var updateResult = await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
.SetColumns(it => new Dt_OutboundOrderDetail
{
PickedQty = newPickedQty,
OverOutQuantity = newOverOutQuantity,
+ OrderDetailStatus = newStatus
})
.Where(it => it.Id == orderDetailId)
.ExecuteCommandAsync();
- }
+ if (updateResult <= 0)
+ throw new Exception("鏇存柊璁㈠崟鏄庣粏澶辫触");
+
+ // 鏇存柊閿佸畾鏁伴噺
+ await UpdateOrderDetailLockQuantity(orderDetailId);
+
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - OrderDetailId: {orderDetailId}, " +
+ $"鎵e噺宸插嚭搴�: {cancelQty}, 鏂板凡鍑哄簱: {newOverOutQuantity}, " +
+ $"鎵e噺宸叉嫞閫�: {cancelQty}, 鏂板凡鎷i��: {newPickedQty}, " +
+ $"鏂扮姸鎬�: {newStatus}");
+ }
#endregion
#region 鍥炲簱鎿嶄綔绉佹湁鏂规硶
@@ -1030,7 +1199,7 @@
return task;
}
-
+
private async Task<decimal> CalculateSplitReturnQuantity(List<Dt_SplitPackageRecord> splitRecords, int stockId)
{
decimal totalQty = 0;
@@ -1038,11 +1207,14 @@
foreach (var splitRecord in splitRecords)
{
+ if (splitRecord.Status != (int)SplitPackageStatusEnum.宸叉挙閿�)
+ continue;
// 妫�鏌ュ師鏉$爜
if (!processedBarcodes.Contains(splitRecord.OriginalBarcode))
{
var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .Where(it => it.Barcode == splitRecord.OriginalBarcode && it.StockId == stockId)
+ .Where(it => it.Barcode == splitRecord.OriginalBarcode && it.StockId == stockId &&
+ it.Status != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
.FirstAsync();
if (originalStock != null && originalStock.StockQuantity > 0)
@@ -1056,7 +1228,7 @@
if (!processedBarcodes.Contains(splitRecord.NewBarcode))
{
var newStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .Where(it => it.Barcode == splitRecord.NewBarcode && it.StockId == stockId)
+ .Where(it => it.Barcode == splitRecord.NewBarcode && it.StockId == stockId && it.Status != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
.FirstAsync();
if (newStock != null && newStock.StockQuantity > 0)
@@ -1104,11 +1276,13 @@
else
{
locationtype = stockInfo.LocationType;
+ _stockInfoService.DeleteData(stockInfo);
}
var targetAddress = originalTask.TargetAddress;
await CleanupZeroStockData(stockInfoId);
+
var emptystockInfo = new Dt_StockInfo() { PalletType = PalletTypeEnum.Empty.ObjToInt(), StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt(), PalletCode = palletCode, LocationType = locationtype };
emptystockInfo.Details = new List<Dt_StockInfoDetail>();
@@ -1116,7 +1290,7 @@
//绌烘墭鐩樺浣曞鐞� 杩樻湁涓�涓嚭搴撲换鍔¤澶勭悊銆�
originalTask.PalletType = PalletTypeEnum.Empty.ObjToInt();
- await CreateReturnTaskAndHandleESS(orderNo, palletCode, originalTask, TaskTypeEnum.InEmpty);
+ await CreateReturnTaskAndHandleESS(orderNo, palletCode, originalTask, TaskTypeEnum.InEmpty, PalletTypeEnum.Empty.ObjToInt());
}
catch (Exception ex)
@@ -1136,25 +1310,157 @@
{
await HandleRemainingLocksReturn(analysis.RemainingLocks, stockInfo.Id);
- // await UpdateOrderDetailsOnReturn(analysis.RemainingLocks);
- }
+ // await UpdateOrderDetailsOnReturn(analysis.RemainingLocks);
+ }
// 澶勭悊鎵樼洏涓婂叾浠栧簱瀛樿揣鐗�
if (analysis.HasPalletStockGoods)
{
- await HandlePalletStockGoodsReturn(analysis.PalletStockGoods);
+ var validStockGoods = analysis.PalletStockGoods
+ .Where(x => x.Status != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+ .ToList();
+
+ if (validStockGoods.Any())
+ {
+ await HandlePalletStockGoodsReturn(analysis.PalletStockGoods);
+ }
+ else
+ {
+ _logger.LogInformation("娌℃湁鏈夋晥鐨勫簱瀛樿揣鐗╅渶瑕佸洖搴�");
+ }
}
// 澶勭悊鎷嗗寘璁板綍
if (analysis.HasSplitRecords)
{
- await HandleSplitRecordsReturn(analysis.SplitRecords, orderNo, palletCode);
+ var validSplitRecords = analysis.SplitRecords
+ .Where(x => x.Status != (int)SplitPackageStatusEnum.宸叉嫞閫�)
+ .ToList();
+
+ if (validSplitRecords.Any())
+ {
+ await HandleSplitRecordsReturn(analysis.SplitRecords, orderNo, palletCode);
+ }
+ else
+ {
+ _logger.LogInformation("娌℃湁鏈夋晥鐨勬媶鍖呰褰曢渶瑕佸鐞�");
+ }
}
// 鏇存柊搴撳瓨涓昏〃鐘舵��
await UpdateStockInfoStatus(stockInfo);
}
+ /// <summary>
+ /// 瀹屽叏閲婃斁閿佸畾锛屽厑璁搁噸鏂板垎閰嶅簱瀛�
+ /// </summary>
+ private async Task ReleaseAllLocksForReallocation(string orderNo, string palletCode, PalletStatusAnalysis analysis)
+ {
+ _logger.LogInformation($"寮�濮嬮噴鏀鹃攣瀹氫互渚块噸鏂板垎閰� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+
+ // 1. 澶勭悊鏈垎鎷g殑鍑哄簱閿佸畾璁板綍 - 瀹屽叏閲婃斁
+ if (analysis.HasRemainingLocks)
+ {
+ await ReleaseRemainingLocks(analysis.RemainingLocks);
+ }
+
+ // 2. 澶勭悊宸插洖搴撶殑閿佸畾璁板綍 - 鍒犻櫎鎴栨爣璁颁负鏃犳晥
+ await CleanupReturnedLocks(orderNo, palletCode);
+
+ // 3. 閲嶇疆璁㈠崟鏄庣粏鐨勯攣瀹氭暟閲�
+ await ResetOrderDetailLockQuantities(analysis);
+
+ _logger.LogInformation($"閿佸畾閲婃斁瀹屾垚 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}");
+ }
+
+ /// <summary>
+ /// 閲婃斁鏈垎鎷g殑閿佸畾璁板綍
+ /// </summary>
+ private async Task ReleaseRemainingLocks(List<Dt_OutStockLockInfo> remainingLocks)
+ {
+ var lockIds = remainingLocks.Select(x => x.Id).ToList();
+
+ // 灏嗛攣瀹氳褰曠姸鎬佹敼涓�"宸查噴鏀�"锛屾垨鑰呯洿鎺ュ垹闄�
+ // 鏍囪涓哄凡閲婃斁
+ await _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
+ .SetColumns(it => new Dt_OutStockLockInfo
+ {
+ Status = (int)OutLockStockStatusEnum.宸查噴鏀�, // 闇�瑕佹柊澧炶繖涓姸鎬�
+ // ReleaseTime = DateTime.Now,
+ Operator = App.User.UserName
+ })
+ .Where(it => lockIds.Contains(it.Id))
+ .ExecuteCommandAsync();
+
+ // 鐩存帴鍒犻櫎锛堟洿褰诲簳锛�
+ // await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
+ // .Where(it => lockIds.Contains(it.Id))
+ // .ExecuteCommandAsync();
+
+ _logger.LogInformation($"閲婃斁{remainingLocks.Count}鏉℃湭鍒嗘嫞閿佸畾璁板綍");
+ }
+
+ /// <summary>
+ /// 娓呯悊宸插洖搴撶殑閿佸畾璁板綍
+ /// </summary>
+ private async Task CleanupReturnedLocks(string orderNo, string palletCode)
+ {
+ // 鏌ユ壘鎵�鏈夌姸鎬佷负鍥炲簱涓殑閿佸畾璁板綍骞堕噴鏀�
+ var returnedLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(it => it.OrderNo == orderNo &&
+ it.PalletCode == palletCode &&
+ it.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�)
+ .ToListAsync();
+
+ if (returnedLocks.Any())
+ {
+ var returnedLockIds = returnedLocks.Select(x => x.Id).ToList();
+
+ await _outStockLockInfoService.Db.Updateable<Dt_OutStockLockInfo>()
+ .SetColumns(it => new Dt_OutStockLockInfo
+ {
+ Status = (int)OutLockStockStatusEnum.宸查噴鏀�,
+ //ReleaseTime = DateTime.Now,
+ Operator = App.User.UserName
+ })
+ .Where(it => returnedLockIds.Contains(it.Id))
+ .ExecuteCommandAsync();
+
+ _logger.LogInformation($"娓呯悊{returnedLocks.Count}鏉″洖搴撲腑閿佸畾璁板綍");
+ }
+ }
+
+ /// <summary>
+ /// 閲嶇疆璁㈠崟鏄庣粏鐨勯攣瀹氭暟閲�
+ /// </summary>
+ private async Task ResetOrderDetailLockQuantities(PalletStatusAnalysis analysis)
+ {
+ // 鏀堕泦鎵�鏈夊彈褰卞搷鐨勮鍗曟槑缁咺D
+ var affectedOrderDetailIds = new HashSet<int>();
+
+ if (analysis.HasRemainingLocks)
+ {
+ foreach (var lockInfo in analysis.RemainingLocks)
+ {
+ affectedOrderDetailIds.Add(lockInfo.OrderDetailId);
+ }
+ }
+
+ // 閲嶇疆杩欎簺璁㈠崟鏄庣粏鐨勯攣瀹氭暟閲�
+ foreach (var orderDetailId in affectedOrderDetailIds)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(it => new Dt_OutboundOrderDetail
+ {
+ LockQuantity = 0, // 閲嶇疆閿佸畾鏁伴噺
+ OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt() // 閲嶇疆鐘舵�佷负鏂板缓
+ })
+ .Where(it => it.Id == orderDetailId)
+ .ExecuteCommandAsync();
+ }
+
+ _logger.LogInformation($"閲嶇疆{affectedOrderDetailIds.Count}涓鍗曟槑缁嗙殑閿佸畾鏁伴噺");
+ }
private async Task HandleRemainingLocksReturn(List<Dt_OutStockLockInfo> remainingLocks, int stockId)
{
var lockIds = remainingLocks.Select(x => x.Id).ToList();
@@ -1172,7 +1478,13 @@
foreach (var lockInfo in remainingLocks)
{
decimal returnQty = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ if (returnQty <= 0)
+ {
+ _logger.LogWarning($"閿佸畾璁板綍{lockInfo.Id}鏃犻渶鍥炲簱锛屽垎閰嶆暟閲�: {lockInfo.AssignQuantity}, 宸叉嫞閫�: {lockInfo.PickedQty}");
+ continue;
+ }
+ _logger.LogInformation($"澶勭悊閿佸畾璁板綍鍥炲簱 - 閿佸畾ID: {lockInfo.Id}, 鏉$爜: {lockInfo.CurrentBarcode}, 鍥炲簱鏁伴噺: {returnQty}");
// 鏌ユ壘瀵瑰簲鐨勫簱瀛樻槑缁�
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.Where(it => it.Barcode == lockInfo.CurrentBarcode && it.StockId == lockInfo.StockId)
@@ -1180,6 +1492,7 @@
if (stockDetail != null)
{
+ stockDetail.StockQuantity += returnQty;
// 鎭㈠搴撳瓨鐘舵��
stockDetail.OutboundQuantity = Math.Max(0, stockDetail.OutboundQuantity - returnQty);
stockDetail.Status = StockStatusEmun.鍏ュ簱纭.ObjToInt();
@@ -1187,26 +1500,54 @@
}
else
{
+ _logger.LogWarning($"鏈壘鍒板搴旂殑搴撳瓨鏄庣粏 - 鏉$爜: {lockInfo.CurrentBarcode}, 搴撳瓨ID: {lockInfo.StockId}");
// 鍒涘缓鏂扮殑搴撳瓨璁板綍
- var newStockDetail = new Dt_StockInfoDetail
+ //var newStockDetail = new Dt_StockInfoDetail
+ //{
+ // StockId = lockInfo.StockId,
+ // MaterielCode = lockInfo.MaterielCode,
+ // MaterielName = lockInfo.MaterielName,
+ // OrderNo = lockInfo.OrderNo,
+ // BatchNo = lockInfo.BatchNo,
+ // StockQuantity = returnQty,
+ // OutboundQuantity = 0,
+ // Barcode = lockInfo.CurrentBarcode,
+ // InboundOrderRowNo = "",
+ // Status = StockStatusEmun.鍏ュ簱纭.ObjToInt(),
+ // SupplyCode = lockInfo.SupplyCode,
+ // WarehouseCode = lockInfo.WarehouseCode,
+ // Unit = lockInfo.Unit,
+ //};
+ //await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
+ }
+ try
+ {
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+
+ if (orderDetail != null)
{
- StockId = lockInfo.StockId,
- MaterielCode = lockInfo.MaterielCode,
- MaterielName = lockInfo.MaterielName,
- OrderNo = lockInfo.OrderNo,
- BatchNo = lockInfo.BatchNo,
- StockQuantity = returnQty,
- OutboundQuantity = 0,
- Barcode = lockInfo.CurrentBarcode,
- InboundOrderRowNo = "",
- Status = StockStatusEmun.鍏ュ簱纭.ObjToInt(),
- SupplyCode = lockInfo.SupplyCode,
- WarehouseCode = lockInfo.WarehouseCode,
- Unit = lockInfo.Unit,
- };
- await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
+ decimal newLockQuantity = Math.Max(0, orderDetail.LockQuantity - returnQty);
+
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(it => new Dt_OutboundOrderDetail
+ {
+ LockQuantity = newLockQuantity
+ })
+ .Where(it => it.Id == lockInfo.OrderDetailId)
+ .ExecuteCommandAsync();
+
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏閿佸畾鏁伴噺 - OrderDetailId: {lockInfo.OrderDetailId}, " +
+ $"鎵e噺閿佸畾: {returnQty}, 鏂伴攣瀹氭暟閲�: {newLockQuantity}");
+ }
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鏇存柊璁㈠崟鏄庣粏閿佸畾鏁伴噺澶辫触 - OrderDetailId: {lockInfo.OrderDetailId}, Error: {ex.Message}");
}
}
+
+
}
private async Task UpdateOrderDetailsOnReturn(List<Dt_OutStockLockInfo> remainingLocks)
@@ -1248,23 +1589,41 @@
{
_logger.LogInformation($"寰呭洖搴撹揣鐗� - 鏉$爜: {stockGood.Barcode}, 鏁伴噺: {stockGood.StockQuantity}, 褰撳墠鐘舵��: {stockGood.Status}");
- // 鎭㈠搴撳瓨鐘舵��
- stockGood.OutboundQuantity = 0;
- stockGood.Status = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+ if (stockGood.Status != StockStatusEmun.鍑哄簱瀹屾垚.ObjToInt())
+ {
+ stockGood.OutboundQuantity = 0;
+ stockGood.Status = StockStatusEmun.鍏ュ簱纭.ObjToInt();
+ await _stockInfoDetailService.Db.Updateable(stockGood).ExecuteCommandAsync();
- await _stockInfoDetailService.Db.Updateable(stockGood).ExecuteCommandAsync();
+ _logger.LogInformation($"搴撳瓨璐х墿鍥炲簱瀹屾垚 - 鏉$爜: {stockGood.Barcode}, 鏂扮姸鎬�: {stockGood.Status}");
+ }
+ else
+ {
+ _logger.LogWarning($"璺宠繃宸插嚭搴撳畬鎴愮殑璐х墿 - 鏉$爜: {stockGood.Barcode}");
+ }
}
}
private async Task HandleSplitRecordsReturn(List<Dt_SplitPackageRecord> splitRecords, string orderNo, string palletCode)
{
+ var validRecords = splitRecords.Where(x => x.Status != (int)SplitPackageStatusEnum.宸叉嫞閫�).ToList();
+
+ if (!validRecords.Any())
+ {
+ _logger.LogInformation("娌℃湁闇�瑕佸洖搴撶殑鎷嗗寘璁板綍");
+ return;
+ }
+
+ _logger.LogInformation($"鏇存柊{validRecords.Count}鏉℃媶鍖呰褰曠姸鎬佷负宸插洖搴�");
+
// 鏇存柊鎷嗗寘璁板綍鐘舵��
await _splitPackageService.Db.Updateable<Dt_SplitPackageRecord>()
.SetColumns(x => new Dt_SplitPackageRecord
{
Status = (int)SplitPackageStatusEnum.宸插洖搴�,
+ Operator = App.User.UserName
})
- .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode && !x.IsReverted)
+ .Where(x => validRecords.Select(r => r.Id).Contains(x.Id))
.ExecuteCommandAsync();
}
@@ -1283,7 +1642,7 @@
/// <param name="originalTask"></param>
/// <param name="analysis"></param>
/// <returns></returns>
- private async Task CreateReturnTaskAndHandleESS(string orderNo, string palletCode, Dt_Task originalTask, TaskTypeEnum taskTypeEnum)
+ private async Task CreateReturnTaskAndHandleESS(string orderNo, string palletCode, Dt_Task originalTask, TaskTypeEnum taskTypeEnum, int palletType)
{
var firstLocation = await _locationInfoService.Db.Queryable<Dt_LocationInfo>()
.FirstAsync(x => x.LocationCode == originalTask.SourceAddress);
@@ -1297,13 +1656,14 @@
Grade = 0,
PalletCode = palletCode,
NextAddress = "",
- OrderNo = originalTask.OrderNo,
+ // OrderNo = originalTask.OrderNo,
+ OrderNo = orderNo,
Roadway = newLocation.RoadwayNo,
SourceAddress = stations[originalTask.TargetAddress],
TargetAddress = newLocation.LocationCode,
TaskStatus = TaskStatusEnum.New.ObjToInt(),
TaskType = taskTypeEnum.ObjToInt(),
- PalletType = originalTask.PalletType,
+ PalletType = palletType,
WarehouseId = originalTask.WarehouseId
};
@@ -1339,15 +1699,15 @@
containerCode = palletCode
});
- if (moveResult)
+ //if (moveResult)
+ //{
+ // 2. 鍒涘缓鍥炲簱浠诲姟
+ var essTask = new TaskModel()
{
- // 2. 鍒涘缓鍥炲簱浠诲姟
- var essTask = new TaskModel()
- {
- taskType = "putaway",
- taskGroupCode = "",
- groupPriority = 0,
- tasks = new List<TasksType>{ new() {
+ taskType = "putaway",
+ taskGroupCode = "",
+ groupPriority = 0,
+ tasks = new List<TasksType>{ new() {
taskCode = returnTask.TaskNum.ToString(),
taskPriority = 0,
taskDescribe = new TaskDescribeType
@@ -1361,11 +1721,11 @@
storageTag = ""
}
} }
- };
+ };
- var resultTask = await _eSSApiService.CreateTaskAsync(essTask);
- _logger.LogInformation($"ReturnRemaining 鍒涘缓浠诲姟鎴愬姛: {resultTask}");
- }
+ var resultTask = await _eSSApiService.CreateTaskAsync(essTask);
+ _logger.LogInformation($"ReturnRemaining 鍒涘缓浠诲姟鎴愬姛: {resultTask}");
+ //}
}
catch (Exception ex)
{
@@ -1389,13 +1749,25 @@
.ToListAsync();
bool allCompleted = true;
+ bool hasPartial = false;
+ bool hasLocked = false;
+
foreach (var detail in orderDetails)
{
if (detail.OverOutQuantity < detail.NeedOutQuantity)
{
allCompleted = false;
- break;
}
+
+ if (detail.OrderDetailStatus == OrderDetailStatusEnum.Outbound.ObjToInt())
+ {
+ hasPartial = true;
+ }
+
+ //if (detail.OrderDetailStatus == OrderDetailStatusEnum.Locked.ObjToInt())
+ //{
+ // hasLocked = true;
+ //}
}
var outboundOrder = await _outboundOrderService.Db.Queryable<Dt_OutboundOrder>()
@@ -1403,14 +1775,32 @@
if (outboundOrder == null) return;
- int newStatus = allCompleted ? (int)OutOrderStatusEnum.鍑哄簱瀹屾垚 : (int)OutOrderStatusEnum.鍑哄簱涓�;
+ int newStatus;
+ if (allCompleted)
+ {
+ newStatus = (int)OutOrderStatusEnum.鍑哄簱瀹屾垚;
+ }
+ else if (hasPartial)
+ {
+ newStatus = (int)OutOrderStatusEnum.鍑哄簱涓�;
+ }
+ else
+ {
+ newStatus = (int)OutOrderStatusEnum.鏈紑濮�;
+ }
if (outboundOrder.OrderStatus != newStatus)
{
await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
- .SetColumns(x => x.OrderStatus == newStatus)
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ OrderStatus = newStatus,
+ Operator = App.User.UserName,
+ })
.Where(x => x.OrderNo == orderNo)
.ExecuteCommandAsync();
+
+ _logger.LogInformation($"璁㈠崟鐘舵�佹洿鏂� - OrderNo: {orderNo}, 鏃х姸鎬�: {outboundOrder.OrderStatus}, 鏂扮姸鎬�: {newStatus}");
// 鍙湁姝e父鍒嗘嫞瀹屾垚鏃舵墠鍚慚ES鍙嶉
if (allCompleted && newStatus == (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
@@ -1425,8 +1815,70 @@
}
}
-
+ /// <summary>
+ /// 鏇存柊璁㈠崟鏄庣粏鐘舵�侊紙鍩轰簬宸插嚭搴撴暟閲忥級
+ /// </summary>
+ private async Task UpdateOrderDetailStatus(int orderDetailId)
+ {
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == orderDetailId);
+ if (orderDetail == null) return;
+
+ int newStatus = orderDetail.OrderDetailStatus;
+
+ if (orderDetail.OverOutQuantity >= orderDetail.NeedOutQuantity)
+ {
+ // 宸插嚭搴撴暟閲� >= 闇�姹傛暟閲忥紝鏍囪涓哄畬鎴�
+ newStatus = OrderDetailStatusEnum.Over.ObjToInt();
+ }
+ else if (orderDetail.OverOutQuantity > 0)
+ {
+ // 鏈夐儴鍒嗗嚭搴擄紝浣嗘湭瀹屾垚
+ newStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+ }
+ else if (orderDetail.LockQuantity > 0)
+ {
+ // 鏈夐攣瀹氭暟閲忥紝浣嗘湭鍑哄簱
+ //newStatus = OrderDetailStatusEnum.Locked.ObjToInt();
+ }
+ else
+ {
+ // 鏂板缓鐘舵��
+ newStatus = OrderDetailStatusEnum.New.ObjToInt();
+ }
+
+ // 鍙湁鐘舵�佸彂鐢熷彉鍖栨椂鎵嶆洿鏂�
+ if (orderDetail.OrderDetailStatus != newStatus)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(it => new Dt_OutboundOrderDetail
+ {
+ OrderDetailStatus = newStatus,
+
+ })
+ .Where(it => it.Id == orderDetailId)
+ .ExecuteCommandAsync();
+ }
+ }
+ /// <summary>
+ /// 鏇存柊璁㈠崟鏄庣粏閿佸畾鏁伴噺
+ /// </summary>
+ private async Task UpdateOrderDetailLockQuantity(int orderDetailId)
+ {
+ var totalLockedQty = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderDetailId == orderDetailId &&
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ .SumAsync(x => x.AssignQuantity - x.PickedQty);
+
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(it => new Dt_OutboundOrderDetail
+ {
+ LockQuantity = totalLockedQty
+ })
+ .Where(it => it.Id == orderDetailId)
+ .ExecuteCommandAsync();
+ }
private async Task UpdateOrderStatusForReturn(string orderNo)
{
try
@@ -1457,7 +1909,11 @@
if (outboundOrder.OrderStatus != newStatus)
{
await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
- .SetColumns(x => x.OrderStatus == newStatus)
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ OrderStatus = newStatus,
+ Operator = App.User.UserName,
+ })
.Where(x => x.OrderNo == orderNo)
.ExecuteCommandAsync();
@@ -1473,73 +1929,141 @@
private async Task HandleOrderCompletion(Dt_OutboundOrder outboundOrder, string orderNo)
{
// 璋冩嫧鍑哄簱鍜岄噸妫�鍑哄簱涓嶉渶瑕佸弽棣圡ES
- if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt() ||
- outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
+ if (outboundOrder.OrderType == OutOrderTypeEnum.Allocate.ObjToInt())
{
- return;
- }
-
- try
- {
- var feedmodel = new FeedbackOutboundRequestModel
+ var allocate = _allocateService.Repository.QueryData(x => x.UpperOrderNo == outboundOrder.UpperOrderNo).First();
+ var allocatefeedmodel = new AllocateDto
{
- reqCode = Guid.NewGuid().ToString(),
- reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- business_type = outboundOrder.BusinessType,
- factoryArea = outboundOrder.FactoryArea,
- operationType = 1,
- Operator = App.User.UserName,
- orderNo = outboundOrder.UpperOrderNo,
- documentsNO = outboundOrder.OrderNo,
- status = outboundOrder.OrderStatus,
- details = new List<FeedbackOutboundDetailsModel>()
- };
+ ReqCode = Guid.NewGuid().ToString(),
+ ReqTime = DateTime.Now.ToString(),
+ BusinessType = "3",
+ FactoryArea = outboundOrder.FactoryArea,
+ OperationType = 1,
+ Operator = App.User.UserName,
+ OrderNo = outboundOrder.UpperOrderNo,
+ // documentsNO = outboundOrder.OrderNo,
+ // status = outboundOrder.OrderStatus,
+ fromWarehouse = allocate?.FromWarehouse ?? "",
+ toWarehouse = allocate?.ToWarehouse ?? "",
+ Details = new List<AllocateDtoDetail>()
+
+ };
// 鍙幏鍙栧凡鎷i�夊畬鎴愮殑閿佸畾璁板綍
var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
.Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
.ToListAsync();
var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
- .Select(group => new FeedbackOutboundDetailsModel
+ .Select(group => new AllocateDtoDetail
{
- materialCode = group.Key.MaterielCode,
- lineNo = group.Key.lineNo,
- warehouseCode = group.Key.WarehouseCode,
- qty = group.Sum(x => x.PickedQty),
- currentDeliveryQty = group.Sum(x => x.PickedQty),
- unit = group.Key.Unit,
- barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
+ MaterialCode = group.Key.MaterielCode,
+ LineNo = group.Key.lineNo,
+ WarehouseCode = group.Key.WarehouseCode,
+ Qty = group.Sum(x => x.PickedQty),
+
+ Unit = group.Key.Unit,
+ Barcodes = group.Select(row => new BarcodeInfo
{
- barcode = row.CurrentBarcode,
- supplyCode = row.SupplyCode,
- batchNo = row.BatchNo,
- unit = row.Unit,
- qty = row.PickedQty
+ Barcode = row.CurrentBarcode,
+ SupplyCode = row.SupplyCode,
+ BatchNo = row.BatchNo,
+ Unit = row.Unit,
+ Qty = row.PickedQty
}).ToList()
+
+
}).ToList();
+ allocatefeedmodel.Details = groupedData;
- feedmodel.details = groupedData;
-
- var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+ var result = await _invokeMESService.FeedbackAllocate(allocatefeedmodel);
if (result != null && result.code == 200)
{
await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
- .SetColumns(x => x.ReturnToMESStatus == 1)
- .Where(x => x.OrderId == outboundOrder.Id)
- .ExecuteCommandAsync();
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderId == outboundOrder.Id).ExecuteCommandAsync();
await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
- .SetColumns(x => x.ReturnToMESStatus == 1)
- .Where(x => x.OrderNo == orderNo)
- .ExecuteCommandAsync();
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ ReturnToMESStatus = 1,
+ Operator = App.User.UserName,
+ }).Where(x => x.OrderNo == orderNo).ExecuteCommandAsync();
}
-
- _logger.LogError($"FeedbackOutbound鎴愬姛 - OrderNo: {orderNo}, {JsonSerializer.Serialize(result)}");
}
- catch (Exception ex)
+ else if (outboundOrder.OrderType == OutOrderTypeEnum.ReCheck.ObjToInt())
{
- _logger.LogError($"FeedbackOutbound澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+
+ }
+ else
+ {
+ try
+ {
+ var feedmodel = new FeedbackOutboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+ business_type = outboundOrder.BusinessType,
+ factoryArea = outboundOrder.FactoryArea,
+ operationType = 1,
+ Operator = App.User.UserName,
+ orderNo = outboundOrder.UpperOrderNo,
+ documentsNO = outboundOrder.OrderNo,
+ status = outboundOrder.OrderStatus,
+ details = new List<FeedbackOutboundDetailsModel>()
+ };
+
+ // 鍙幏鍙栧凡鎷i�夊畬鎴愮殑閿佸畾璁板綍
+ var lists = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ .ToListAsync();
+
+ var groupedData = lists.GroupBy(item => new { item.MaterielCode, item.lineNo, item.Unit, item.WarehouseCode })
+ .Select(group => new FeedbackOutboundDetailsModel
+ {
+ materialCode = group.Key.MaterielCode,
+ lineNo = group.Key.lineNo,
+ warehouseCode = group.Key.WarehouseCode,
+ qty = group.Sum(x => x.PickedQty),
+ currentDeliveryQty = group.Sum(x => x.PickedQty),
+ unit = group.Key.Unit,
+ barcodes = group.Select(row => new WIDESEA_DTO.Outbound.BarcodesModel
+ {
+ barcode = row.CurrentBarcode,
+ supplyCode = row.SupplyCode,
+ batchNo = row.BatchNo,
+ unit = row.Unit,
+ qty = row.PickedQty
+ }).ToList()
+ }).ToList();
+
+ feedmodel.details = groupedData;
+
+ var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderId == outboundOrder.Id)
+ .ExecuteCommandAsync();
+
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ ReturnToMESStatus = 1,
+ Operator = App.User.UserName,
+ })
+
+ .Where(x => x.OrderNo == orderNo)
+ .ExecuteCommandAsync();
+ }
+
+ _logger.LogError($"FeedbackOutbound鎴愬姛 - OrderNo: {orderNo}, {JsonSerializer.Serialize(result)}");
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"FeedbackOutbound澶辫触 - OrderNo: {orderNo}, Error: {ex.Message}");
+ }
}
}
@@ -1672,6 +2196,7 @@
if (outboundOrder != null && allCompleted && outboundOrder.OrderStatus != (int)OutOrderStatusEnum.鍑哄簱瀹屾垚)
{
outboundOrder.OrderStatus = (int)OutOrderStatusEnum.鍑哄簱瀹屾垚;
+ outboundOrder.Operator = App.User.UserName;
await _outboundOrderService.Db.Updateable(outboundOrder).ExecuteCommandAsync();
_logger.LogInformation($"璁㈠崟 {orderNo} 宸叉爣璁颁负鍑哄簱瀹屾垚");
@@ -1721,7 +2246,7 @@
StockId = stockId
};
- // 1. 鍒嗘瀽鏈垎鎷g殑鍑哄簱閿佸畾璁板綍
+ // 鍒嗘瀽鏈垎鎷g殑鍑哄簱閿佸畾璁板綍
var remainingLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
.Where(it => it.OrderNo == orderNo &&
it.PalletCode == palletCode &&
@@ -1733,9 +2258,10 @@
result.HasRemainingLocks = true;
result.RemainingLocks = remainingLocks;
result.RemainingLocksReturnQty = remainingLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+ _logger.LogInformation($"鍙戠幇{remainingLocks.Count}鏉℃湭鍒嗘嫞閿佸畾璁板綍锛屾�绘暟閲�: {result.RemainingLocksReturnQty}");
}
- // 2. 鍒嗘瀽鎵樼洏涓婄殑搴撳瓨璐х墿
+ // 鍒嗘瀽鎵樼洏涓婄殑搴撳瓨璐х墿
var palletStockGoods = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.Where(it => it.StockId == stockId &&
(it.Status == StockStatusEmun.鍏ュ簱纭.ObjToInt() ||
@@ -1749,13 +2275,21 @@
result.HasPalletStockGoods = true;
result.PalletStockGoods = palletStockGoods;
result.PalletStockReturnQty = palletStockGoods.Sum(x => x.StockQuantity);
+ _logger.LogInformation($"鍙戠幇{palletStockGoods.Count}涓簱瀛樿揣鐗╋紝鎬绘暟閲�: {result.PalletStockReturnQty}");
+
+ // 璁板綍璇︾粏鐘舵�佸垎甯�
+ var statusGroups = palletStockGoods.GroupBy(x => x.Status);
+ foreach (var group in statusGroups)
+ {
+ _logger.LogInformation($"搴撳瓨鐘舵�亄group.Key}: {group.Count()}涓揣鐗╋紝鏁伴噺: {group.Sum(x => x.StockQuantity)}");
+ }
}
- // 3. 鍒嗘瀽鎷嗗寘璁板綍
+ //鍒嗘瀽鎷嗗寘璁板綍
var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
.Where(it => it.OrderNo == orderNo &&
it.PalletCode == palletCode &&
- !it.IsReverted &&
+ !it.IsReverted && it.Status != (int)SplitPackageStatusEnum.宸叉嫞閫� &&
it.Status != (int)SplitPackageStatusEnum.宸插洖搴�)
.ToListAsync();
@@ -1764,6 +2298,8 @@
result.HasSplitRecords = true;
result.SplitRecords = splitRecords;
result.SplitReturnQty = await CalculateSplitReturnQuantity(splitRecords, stockId);
+
+ _logger.LogInformation($"鍙戠幇{splitRecords.Count}鏉℃湭鎷i�夋媶鍖呰褰曪紝鎬绘暟閲�: {result.SplitReturnQty}");
}
// 4. 璁$畻鎬诲洖搴撴暟閲忓拰绌烘墭鐩樼姸鎬�
@@ -1777,6 +2313,10 @@
x.PalletCode == palletCode &&
x.TaskStatus == (int)TaskStatusEnum.New)
.AnyAsync();
+
+ _logger.LogInformation($"鎵樼洏鐘舵�佸垎鏋愬畬鎴� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, " +
+ $"鎬诲洖搴撴暟閲�: {result.TotalReturnQty}, 鏄惁绌烘墭鐩�: {result.IsEmptyPallet}, " +
+ $"鏈夎繘琛屼腑浠诲姟: {result.HasActiveTasks}");
return result;
}
@@ -1899,6 +2439,8 @@
FactoryArea = originalLock.FactoryArea,
lineNo = originalLock.lineNo,
WarehouseCode = originalLock.WarehouseCode,
+ BarcodeQty = originalLock.BarcodeQty,
+ BarcodeUnit = originalLock.BarcodeUnit,
};
@@ -2004,8 +2546,555 @@
return WebResponseContent.Instance.OK("鎷i�夌‘璁ゆ垚鍔�", new { SplitResults = new List<SplitResult>() });
}
+
+
+ #region 铏氭嫙鍑哄叆搴�
+ public WebResponseContent GetAvailablePurchaseOrders()
+ {
+ List<Dt_InboundOrder> InOders = _inboundOrderRepository.QueryData().Where(x => x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).ToList();
+ List<string> InOderCodes = InOders.Select(x => x.UpperOrderNo).ToList();
+ return WebResponseContent.Instance.OK("鎴愬姛", data: InOderCodes);
+ }
+
+ public WebResponseContent GetAvailablePickingOrders()
+ {
+ List<Dt_OutboundOrder> outOders = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).ToList();
+
+ List<string> outOderCodes = outOders.Select(x => x.UpperOrderNo).ToList();
+ return WebResponseContent.Instance.OK("鎴愬姛", data: outOderCodes);
+
+ }
+ public WebResponseContent BarcodeValidate(NoStockOutModel noStockOut)
+ {
+ try
+ {
+ Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (inboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOut.inOder}");
+ }
+ var matchedDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == noStockOut.barCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (matchedDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOut.inOder} 涓湭鎵惧埌鏉$爜涓� {noStockOut.barCode} 鐨勬槑缁嗐��");
+ }
+ matchedDetail.NoStockOutQty = 0;
+
+ Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOut.outOder && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (outboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOut.inOder}");
+ }
+ var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == matchedDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (matchedCode == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓matchedDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+ }
+ matchedCode.NoStockOutQty = 0;
+
+ //鍓╀綑鍏ュ簱鏁伴噺鍗宠櫄鎷熷嚭鍏ュ簱鍓╀綑鍙嚭鏁伴噺
+ decimal outQuantity = matchedDetail.OrderQuantity - matchedDetail.ReceiptQuantity;
+ if (outQuantity == 0)
+ {
+ return WebResponseContent.Instance.Error($"璇ラ噰璐崟涓殑鏉$爜瀵瑰簲鐨勫彲鍑烘暟閲忎负0");
+ }
+ if (matchedCode.OrderQuantity < outQuantity)
+ {
+ return WebResponseContent.Instance.Error($"璇ラ噰璐崟涓殑鏉$爜瀵瑰簲鐨勫彲鍑烘暟閲忚秴鍑哄嚭搴撳崟鍑哄簱鏁伴噺{matchedDetail.OrderQuantity - matchedCode.OrderQuantity},涓嶆弧瓒虫暣鍖呭嚭搴�");
+ }
+ //鍗曟嵁鍑哄簱閿佸畾鏁伴噺
+ matchedDetail.NoStockOutQty += outQuantity;
+ matchedCode.NoStockOutQty += outQuantity;
+
+ if ((matchedCode.LockQuantity + matchedCode.NoStockOutQty) > matchedCode.OrderQuantity)
+ {
+ return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗘暟閲忔孩鍑簕matchedCode.LockQuantity - matchedCode.OrderQuantity}");
+ }
+ matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+ matchedCode.OrderDetailStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
+
+ _unitOfWorkManage.BeginTran();
+ _inboundOrderDetailService.UpdateData(matchedDetail);
+ _outboundOrderDetailService.UpdateData(matchedCode);
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
+
+
+ public WebResponseContent DeleteBarcode(NoStockOutModel noStockOut)
+ {
+ try
+ {
+ Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (inboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOut.inOder}");
+ }
+ var matchedDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == noStockOut.barCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (matchedDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOut.inOder} 涓湭鎵惧埌鏉$爜涓� {noStockOut.barCode} 鐨勬槑缁嗐��");
+ }
+ matchedDetail.NoStockOutQty = 0;
+
+ if (matchedDetail.ReceiptQuantity == 0 && matchedDetail.OverInQuantity == 0)
+ {
+ matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt();
+ }
+
+ Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOut.outOder && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (outboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOut.inOder}");
+ }
+ var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == matchedDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (matchedCode == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓matchedDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+ }
+ matchedCode.NoStockOutQty = 0;
+ if (matchedCode.LockQuantity == 0 && matchedCode.OverOutQuantity == 0)
+ {
+ matchedCode.OrderDetailStatus = OrderDetailStatusEnum.New.ObjToInt();
+ }
+ _unitOfWorkManage.BeginTran();
+ _inboundOrderDetailService.UpdateData(matchedDetail);
+ _outboundOrderDetailService.UpdateData(matchedCode);
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK();
+
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
+
+ public async Task<WebResponseContent> NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
+ {
+ try
+ {
+ Dt_InboundOrder inboundOrder = _inboundOrderRepository.Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (inboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOutSubmit.InOderSubmit}");
+ }
+ Dt_OutboundOrder outboundOrder = _inboundOrderRepository.Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+ if (outboundOrder == null)
+ {
+ return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOutSubmit.OutOderSubmit}");
+ }
+ List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
+ List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
+ foreach (var BarCode in noStockOutSubmit.BarCodeSubmit)
+ {
+ var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (inboundOrderDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOutSubmit.InOderSubmit} 涓湭鎵惧埌鏉$爜涓� {BarCode} 鐨勬槑缁嗐��");
+ }
+ var outboundOrderDetail = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == inboundOrderDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+ if (outboundOrderDetail == null)
+ {
+ return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓inboundOrderDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+ }
+ inboundOrderDetail.ReceiptQuantity += inboundOrderDetail.NoStockOutQty;
+ inboundOrderDetail.OverInQuantity = inboundOrderDetail.ReceiptQuantity;
+ inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+ inboundOrderDetails.Add(inboundOrderDetail);
+
+ outboundOrderDetail.LockQuantity += outboundOrderDetail.NoStockOutQty;
+ outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
+ if (outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
+ {
+ outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+ }
+ outboundOrderDetails.Add(outboundOrderDetail);
+
+ }
+ //鍒ゆ柇鍏ュ簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
+ int e = inboundOrder.Details.Count();
+ int w = inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+ bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+ if (inoderOver)
+ {
+ inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+ }
+ else
+ {
+ inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱涓�.ObjToInt();
+ }
+ //鍒ゆ柇鍑哄簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
+ bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Where(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+ if (outOderOver)
+ {
+ outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+ }
+ else
+ {
+ outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱涓�.ObjToInt();
+ }
+ //鏁版嵁澶勭悊
+ _unitOfWorkManage.BeginTran();
+ _inboundOrderDetailService.UpdateData(inboundOrderDetails);
+ _outboundOrderDetailService.UpdateData(outboundOrderDetails);
+ _inboundOrderRepository.UpdateData(inboundOrder);
+ _outboundOrderService.UpdateData(outboundOrder);
+ _unitOfWorkManage.CommitTran();
+
+ if (inboundOrder.OrderStatus == InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt())
+ {
+ var feedmodel = new FeedbackInboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString(),
+ business_type = inboundOrder.BusinessType,
+ factoryArea = inboundOrder.FactoryArea,
+ operationType = 1,
+ Operator = inboundOrder.Operator,
+ orderNo = inboundOrder.UpperOrderNo,
+ status = inboundOrder.OrderStatus,
+ details = new List<FeedbackInboundDetailsModel>()
+
+ };
+
+ var groupedData = inboundOrder.Details.GroupBy(item => new { item.MaterielCode, item.SupplyCode, item.BatchNo, item.lineNo, item.BarcodeUnit, item.WarehouseCode })
+ .Select(group => new FeedbackInboundDetailsModel
+ {
+ materialCode = group.Key.MaterielCode,
+ supplyCode = group.Key.SupplyCode,
+ batchNo = group.Key.BatchNo,
+ lineNo = group.Key.lineNo,
+ warehouseCode = group.Key.WarehouseCode,
+ qty = group.Sum(x => x.BarcodeQty),
+ // warehouseCode= "1072",
+ unit = group.Key.BarcodeUnit,
+ barcodes = group.Select(row => new FeedbackBarcodesModel
+ {
+ barcode = row.Barcode,
+ qty = row.BarcodeQty
+ }).ToList()
+ }).ToList();
+ feedmodel.details = groupedData;
+
+ var result = await _invokeMESService.FeedbackInbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ _inboundOrderRepository.Db.Updateable<Dt_InboundOrder>().SetColumns(it => new Dt_InboundOrder { ReturnToMESStatus = 1 })
+ .Where(it => it.Id == inboundOrder.Id).ExecuteCommand();
+ _inboundOrderDetailService.Db.Updateable<Dt_InboundOrderDetail>().SetColumns(it => new Dt_InboundOrderDetail { ReturnToMESStatus = 1 })
+ .Where(it => it.OrderId == inboundOrder.Id).ExecuteCommand();
+ }
+ }
+ if (outboundOrder.OrderStatus == OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt())
+ {
+ var feedmodel = new FeedbackOutboundRequestModel
+ {
+ reqCode = Guid.NewGuid().ToString(),
+ reqTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+ business_type = outboundOrder.BusinessType,
+ factoryArea = outboundOrder.FactoryArea,
+ operationType = 1,
+ Operator = outboundOrder.Operator,
+ orderNo = outboundOrder.UpperOrderNo,
+ documentsNO = outboundOrder.OrderNo,
+ status = outboundOrder.OrderStatus,
+ details = new List<FeedbackOutboundDetailsModel>()
+ };
+
+
+ foreach (var detail in outboundOrder.Details)
+ {
+ // 鑾峰彇璇ユ槑缁嗗搴旂殑鏉$爜淇℃伅锛堜粠閿佸畾璁板綍锛�
+ var detailLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == outboundOrder.OrderNo &&
+ x.OrderDetailId == detail.Id &&
+ x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ .ToListAsync();
+
+ var detailModel = new FeedbackOutboundDetailsModel
+ {
+ materialCode = detail.MaterielCode,
+ lineNo = detail.lineNo, // 娉ㄦ剰锛氳繖閲屽彲鑳介渶瑕佽皟鏁村瓧娈靛悕
+ warehouseCode = detail.WarehouseCode,
+ qty = detail.OverOutQuantity, // 浣跨敤璁㈠崟鏄庣粏鐨勫凡鍑哄簱鏁伴噺
+ currentDeliveryQty = detail.OverOutQuantity,
+ unit = detail.Unit,
+ barcodes = detailLocks.Select(lockInfo => new WIDESEA_DTO.Outbound.BarcodesModel
+ {
+ barcode = lockInfo.CurrentBarcode,
+ supplyCode = lockInfo.SupplyCode,
+ batchNo = lockInfo.BatchNo,
+ unit = lockInfo.Unit,
+ qty = lockInfo.PickedQty // 鏉$爜绾у埆鐨勬暟閲忎粛鐢ㄩ攣瀹氳褰�
+ }).ToList()
+ };
+
+ feedmodel.details.Add(detailModel);
+ }
+ var result = await _invokeMESService.FeedbackOutbound(feedmodel);
+ if (result != null && result.code == 200)
+ {
+ await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.OrderId == outboundOrder.Id)
+ .ExecuteCommandAsync();
+
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => x.ReturnToMESStatus == 1)
+ .Where(x => x.Id == outboundOrder.Id)
+ .ExecuteCommandAsync();
+ }
+ }
+
+
+ return WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
+ #endregion
+
+ public WebResponseContent UnPalletQuantity(string orderNo)
+ {
+ // 鍒濆鍖栬繑鍥濪TO锛堥粯璁ゅ�奸兘涓�0锛岄伩鍏峮ull锛�
+ var resultDTO = new PalletSumQuantityDTO
+ {
+ StockSumQuantity = 0,
+ StockCount = 0,
+ UniqueUnit = ""
+ };
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ if (string.IsNullOrWhiteSpace(orderNo))
+ {
+ return content.Error("浼犲叆鐨勮鍗曞彿orderNo涓虹┖鎴栫┖鐧�");
+ }
+ var orderDetail = Db.Queryable<Dt_PickingRecord>().Where(s => s.OrderNo == orderNo).ToList();
+ if (orderDetail == null)
+ {
+ return content.Error("鏈壘鍒板崟鎹�");
+ }
+ var unitGroups = orderDetail.GroupBy(d => d.BarcodeUnit).ToList();
+ if (unitGroups.Count == 1)
+ {
+ resultDTO.UniqueUnit = unitGroups.First().Key;
+ }
+ else
+ {
+ resultDTO.UniqueUnit = "";
+ }
+ var validDetails = _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>().Where(s => s.OrderNo == orderNo).ToList();
+ resultDTO.StockSumQuantity = orderDetail.Sum(d => d.PickQuantity);
+ resultDTO.StockCount = orderDetail.Count;
+ if (validDetails.Any())
+ {
+ resultDTO.StockSumQuantity -= validDetails.Sum(d => d.StockQuantity);
+ // 鏄庣粏璁板綍鏁帮細绗﹀悎鏉′欢鐨勬湁鏁堣褰曟潯鏁�
+ resultDTO.StockCount -= validDetails.Count;
+ }
+ return content.OK("", resultDTO);
+ }
+ catch (Exception ex)
+ {
+ return content.Error("SumQuantity 缁熻搴撳瓨鏁伴噺澶辫触锛岃鍗曞彿锛歿OrderNo}");
+ }
+ }
+
+ public WebResponseContent BarcodeMaterielGroup(BarcodeMaterielGroupDTO materielGroupDTO)
+ {
+
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ (bool, string, object?) result2 = ModelValidate.ValidateModelData(materielGroupDTO);
+ if (!result2.Item1) return content = WebResponseContent.Instance.Error(result2.Item2);
+
+ // materielGroupDTO.WarehouseCode
+ var code = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>().Where(x => x.Code == materielGroupDTO.WarehouseType).Select(x => x.Code).First();
+ if (string.IsNullOrEmpty(code))
+ {
+ return content = WebResponseContent.Instance.Error($"浠撳簱涓病鏈夎{materielGroupDTO.WarehouseType}缂栧彿銆�");
+ }
+
+
+ // Dt_InboundOrder inboundOrder = GetInboundOrder(materielGroupDTO.OrderNo);
+
+ var dbinboundOrderDetails = Db.Queryable<Dt_PickingRecord>().Where(x => x.OrderNo == materielGroupDTO.OrderNo && !x.IsCancelled && x.Barcode == materielGroupDTO.Barcodes).ToList();
+
+ if (dbinboundOrderDetails != null && !dbinboundOrderDetails.Any())
+ {
+ return content = WebResponseContent.Instance.Error($"鍗曟嵁涓病鏈夎{materielGroupDTO.Barcodes}鏉$爜鏁版嵁銆�");
+ }
+
+ List<string?> materielCodes = dbinboundOrderDetails.GroupBy(x => x.Barcode).Select(x => x.Key).ToList();
+
+ Dt_StockInfo? stockInfo = _stockService.StockInfoService.GetStockByPalletCode(materielGroupDTO.PalletCode);
+
+
+
+ (bool, string, object?) result = CheckMaterielGroupParam(materielGroupDTO, materielCodes, stockInfo);
+ if (!result.Item1) return content = WebResponseContent.Instance.Error(result.Item2);
+
+ if (stockInfo == null)
+ {
+ stockInfo = new Dt_StockInfo() { PalletType = (int)PalletTypeEnum.None, LocationType = materielGroupDTO.locationType.ObjToInt() };
+ stockInfo.Details = new List<Dt_StockInfoDetail>();
+ }
+ var inboindId = 0; Dt_InboundOrder dt_InboundOrder = null;
+ var dbinbound = _inboundOrderRepository.QueryData(x => x.InboundOrderNo == dbinboundOrderDetails.First().OrderNo).First();
+ if (dbinbound == null)
+ {
+ dt_InboundOrder = new Dt_InboundOrder
+ {
+ WarehouseId = 0,
+ InboundOrderNo = dbinboundOrderDetails.First()?.OrderNo,
+ UpperOrderNo = dbinboundOrderDetails.First()?.OrderNo,
+ SupplierId = dbinboundOrderDetails.First()?.SupplyCode,
+ OrderType = InOrderTypeEnum.InternalAllocat.ObjToInt(),
+
+ BusinessType = InOrderTypeEnum.InternalAllocat.ObjToInt().ToString(),
+
+ FactoryArea = dbinboundOrderDetails.First()?.FactoryArea,
+ Remark = "",
+ Details = new List<Dt_InboundOrderDetail>()
+ };
+ inboindId = _inboundOrderRepository.AddData(dt_InboundOrder);
+ }
+ else
+ {
+ dt_InboundOrder = new Dt_InboundOrder { Details = new List<Dt_InboundOrderDetail>() };
+ inboindId = dbinbound.Id;
+ }
+
+ foreach (var item in dbinboundOrderDetails)
+ {
+ stockInfo.Details.Add(new Dt_StockInfoDetail
+ {
+ StockId = stockInfo == null ? 0 : stockInfo.Id,
+ Barcode = item.Barcode,
+ MaterielCode = item.MaterielCode,
+ BatchNo = item.BatchNo,
+ Unit = item.BarcodeUnit,
+ InboundOrderRowNo = item.lineNo,
+ SupplyCode = item.SupplyCode,
+ WarehouseCode = materielGroupDTO.WarehouseType,
+ StockQuantity = item.PickQuantity,
+ BarcodeQty = item.BarcodeQty,
+ BarcodeUnit = item.BarcodeUnit,
+ FactoryArea = item.FactoryArea,
+ Status = 0,
+ OrderNo = item.OrderNo,
+ BusinessType = InOrderTypeEnum.InternalAllocat.ObjToInt().ToString()
+
+ });
+ item.WarehouseCode = item.WarehouseCode;
+
+ dt_InboundOrder.Details.Add(new Dt_InboundOrderDetail
+ {
+ OrderId = inboindId,
+ MaterielCode = item.MaterielCode,
+ MaterielName = "",
+ BatchNo = item.BatchNo,
+ OrderQuantity = item.PickQuantity,
+ ReceiptQuantity = 0,
+ OverInQuantity = 0,
+ Unit = item.BarcodeUnit,
+ RowNo = 0,
+ lineNo = item.lineNo,
+ SupplyCode = item.SupplyCode,
+ WarehouseCode = item.WarehouseCode,
+ Barcode = item.Barcode,
+ OutBoxbarcodes = "",
+ BarcodeQty = (decimal)item.BarcodeQty,
+ BarcodeUnit = item.BarcodeUnit
+ });
+ }
+
+ _inboundOrderDetailService.Db.Insertable<Dt_InboundOrderDetail>(dt_InboundOrder.Details);
+ if (stockInfo.Id == 0)
+ {
+ stockInfo.PalletCode = materielGroupDTO.PalletCode;
+ stockInfo.StockStatus = StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt();
+ }
+ stockInfo.PalletType = (int)PalletTypeEnum.None;
+
+ List<int> updateDetailIds = dbinboundOrderDetails.Select(x => x.Id).ToList();
+
+ try
+ {
+ _unitOfWorkManage.BeginTran();
+
+ _stockService.StockInfoService.AddMaterielGroup(stockInfo);
+ _unitOfWorkManage.CommitTran();
+ return WebResponseContent.Instance.OK();
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
+ catch (Exception ex)
+ {
+ content = WebResponseContent.Instance.Error(ex.Message);
+ }
+ finally
+ {
+
+ }
+ return content;
+
+ }
+
+
+ public (bool, string, object?) CheckMaterielGroupParam(BarcodeMaterielGroupDTO materielGroupDTO, List<string> barcodeCodes, Dt_StockInfo stockInfo)
+ {
+ (bool, string, object?) result = ModelValidate.ValidateModelData(materielGroupDTO);
+ if (!result.Item1) return result;
+
+ if (_taskRepository.QueryFirst(x => x.PalletCode == materielGroupDTO.PalletCode) != null)
+ {
+ return (false, "璇ユ墭鐩樺彿宸叉湁浠诲姟", materielGroupDTO);
+ }
+
+ if (stockInfo != null && !string.IsNullOrEmpty(stockInfo.LocationCode) && stockInfo.StockStatus != StockStatusEmun.缁勭洏鏆傚瓨.ObjToInt())
+ {
+ return (false, "宸蹭笂鏋剁殑鎵樼洏涓嶈兘鍐嶆缁勭洏", materielGroupDTO);
+ }
+
+ if (_stockService.StockInfoDetailService.ExistBarcodes(barcodeCodes))
+ {
+ return (false, $"{barcodeCodes[0]} 鏉$爜鍦ㄥ簱瀛樹腑宸插瓨鍦�", materielGroupDTO);
+ }
+
+
+
+ return (true, "鎴愬姛", materielGroupDTO);
+ }
+
+
#endregion
}
+
+
#region 鏀寔绫诲畾涔�
@@ -2070,12 +3159,20 @@
public bool HasSplitRecords { get; set; }
public decimal RemainingLocksReturnQty { get; set; }
public decimal PalletStockReturnQty { get; set; }
+
public decimal SplitReturnQty { get; set; }
public decimal TotalReturnQty { get; set; }
+
+ // 鏈垎閰嶇殑閿佸畾璁板綍锛堝鑷姩鎷嗗寘浜х敓鐨勶級
+ public bool HasUnallocatedLocks { get; set; }
+ public List<Dt_OutStockLockInfo> UnallocatedLocks { get; set; } = new List<Dt_OutStockLockInfo>();
+ public decimal UnallocatedLocksReturnQty { get; set; }
+
public List<Dt_OutStockLockInfo> RemainingLocks { get; set; } = new List<Dt_OutStockLockInfo>();
public List<Dt_StockInfoDetail> PalletStockGoods { get; set; } = new List<Dt_StockInfoDetail>();
public List<Dt_SplitPackageRecord> SplitRecords { get; set; } = new List<Dt_SplitPackageRecord>();
+ public List<string> AllBarcodes { get; set; } = new List<string>();
// 绌烘墭鐩樼浉鍏冲睘鎬�
public bool IsEmptyPallet { get; set; }
public bool HasActiveTasks { get; set; }
@@ -2084,5 +3181,29 @@
public bool CanReturn => HasItemsToReturn && !HasActiveTasks;
public bool CanRemove => IsEmptyPallet && !HasActiveTasks;
}
+ public class PickingContext
+ {
+ public string OrderNo { get; set; }
+ public string PalletCode { get; set; }
+ public string Barcode { get; set; }
+ public string Operator { get; set; }
+ public Dt_OutStockLockInfo LockInfo { get; set; }
+ public Dt_OutboundOrderDetail OrderDetail { get; set; }
+ public Dt_StockInfoDetail StockDetail { get; set; }
+ public decimal ActualQuantity { get; set; }
+ public string AdjustedReason { get; set; }
+ }
+ public class CancelPickingContext
+ {
+ public string OrderNo { get; set; }
+ public string PalletCode { get; set; }
+ public string Barcode { get; set; }
+ public string Operator { get; set; }
+
+ public decimal CancelQuantity { get; set; }
+ public Dt_PickingRecord PickingRecord { get; set; }
+ public Dt_OutStockLockInfo LockInfo { get; set; }
+ public Dt_OutboundOrderDetail OrderDetail { get; set; }
+ }
#endregion
}
--
Gitblit v1.9.3