From dcdb87f1cb6cfd66d3fc01bc2248e4876c37f223 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期日, 30 十一月 2025 18:14:12 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundBatchPickingService.cs | 1852 ++++++++++++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 1,624 insertions(+), 228 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/OutboundBatchPickingService.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/OutboundBatchPickingService.cs"
index 2b85d56..54eab6d 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/OutboundBatchPickingService.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/OutboundBatchPickingService.cs"
@@ -1,16 +1,19 @@
锘縰sing Microsoft.Extensions.Logging;
using SqlSugar;
+using SqlSugar.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEA_BasicService;
+using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
using WIDESEA_Core;
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
+using WIDESEA_DTO.Outbound;
using WIDESEA_IAllocateService;
using WIDESEA_IBasicService;
using WIDESEA_IOutboundService;
@@ -18,6 +21,7 @@
using WIDESEA_Model.Models;
using WIDESEA_Model.Models.Basic;
using WIDESEA_Model.Models.Outbound;
+using static WIDESEA_OutboundService.OutboundBatchPickingService;
namespace WIDESEA_OutboundService
{
@@ -61,7 +65,7 @@
public OutboundBatchPickingService(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) : base(BaseDal)
+ IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_OutboundBatch> outboundBatchRepository) : base(BaseDal)
{
_unitOfWorkManage = unitOfWorkManage;
_stockInfoService = stockInfoService;
@@ -78,9 +82,325 @@
_invokeMESService = invokeMESService;
_dailySequenceService = dailySequenceService;
_allocateService = allocateService;
+ _outboundBatchRepository = outboundBatchRepository;
}
+ // <summary>
+ /// 鑾峰彇鎵樼洏鐨勯攣瀹氫俊鎭�
+ /// </summary>
+ public async Task<List<PalletLockInfoDto>> GetPalletLockInfos(string orderNo, string palletCode)
+ {
+ var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+ .Select(x => new
+ {
+ x.Id,
+ x.OrderNo,
+ x.BatchNo,
+ x.MaterielCode,
+ x.CurrentBarcode,
+ x.AssignQuantity,
+ x.PickedQty,
+ x.Status,
+ x.LocationCode,
+ x.PalletCode
+ }).ToListAsync();
+ var lockInfoDtos = lockInfos.Select(x => new PalletLockInfoDto
+ {
+ Id = x.Id,
+ OrderNo = x.OrderNo,
+ BatchNo = x.BatchNo,
+ MaterielCode = x.MaterielCode,
+ CurrentBarcode = x.CurrentBarcode,
+ AssignQuantity = x.AssignQuantity,
+ PickedQty = x.PickedQty,
+ Status = x.Status,
+ LocationCode = x.LocationCode,
+ PalletCode = x.PalletCode,
+ CanSplit = (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� && x.AssignQuantity - x.PickedQty > 0),
+ CanPick = (x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� && x.PickedQty < x.AssignQuantity)
+ }).ToList();
+
+ return lockInfoDtos;
+ }
+ #region 鏌ヨ鏂规硶
+
+ /// <summary>
+ /// 鑾峰彇鎵樼洏鐨勫凡鎷i�夊垪琛�
+ /// </summary>
+ public async Task<List<PalletPickedInfoDto>> GetPalletPickedList(string orderNo, string palletCode)
+ {
+ var pickedList = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.OrderNo == orderNo &&
+ x.PalletCode == palletCode &&
+ !x.IsCancelled)
+ .Select(x => new PalletPickedInfoDto
+ {
+ Id = x.Id,
+ OrderNo = x.OrderNo,
+ OrderDetailId = x.OrderDetailId,
+ PalletCode = x.PalletCode,
+ Barcode = x.Barcode,
+ MaterielCode = x.MaterielCode,
+ PickedQty = x.PickQuantity,
+ PickTime = x.PickTime,
+ Operator = x.Operator,
+ LocationCode = x.LocationCode
+ })
+ .ToListAsync();
+
+ return pickedList;
+ }
+
+ /// <summary>
+ /// 鑾峰彇鎵樼洏鐘舵��
+ /// </summary>
+ public async Task<PalletStatusDto> GetPalletStatus(string orderNo, string palletCode)
+ {
+ // 鑾峰彇鎵樼洏鐨勯攣瀹氫俊鎭�
+ var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+ .ToListAsync();
+
+ if (!lockInfos.Any())
+ {
+ return new PalletStatusDto
+ {
+ OrderNo = orderNo,
+ PalletCode = palletCode,
+ Status = (int)PalletStatusEnum.鏃犱换鍔�,
+ StatusText = "鏃犱换鍔�",
+ TotalItems = 0,
+ CompletedItems = 0,
+ PendingItems = 0
+ };
+ }
+
+ var totalItems = lockInfos.Count;
+ var completedItems = lockInfos.Count(x => x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�);
+ var pendingItems = lockInfos.Count(x => x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�);
+
+ var status = PalletStatusEnum.鎷i�変腑;
+ if (pendingItems == 0 && completedItems > 0)
+ {
+ status = PalletStatusEnum.宸插畬鎴�;
+ }
+ else if (pendingItems > 0 && completedItems == 0)
+ {
+ status = PalletStatusEnum.鏈紑濮�;
+ }
+ else if (pendingItems > 0 && completedItems > 0)
+ {
+ status = PalletStatusEnum.鎷i�変腑;
+ }
+
+ return new PalletStatusDto
+ {
+ OrderNo = orderNo,
+ PalletCode = palletCode,
+ Status = (int)status,
+ StatusText = GetPalletStatusText(status),
+ TotalItems = totalItems,
+ CompletedItems = completedItems,
+ PendingItems = pendingItems
+ };
+ }
+
+ /// <summary>
+ /// 鑾峰彇鎷嗗寘淇℃伅
+ /// </summary>
+ public async Task<SplitPackageInfoDto> GetSplitPackageInfo(string orderNo, string palletCode, string barcode)
+ {
+ // 鏌ユ壘閿佸畾淇℃伅
+ var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo &&
+ x.PalletCode == palletCode &&
+ x.CurrentBarcode == barcode
+ //&& x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�
+ )
+ .FirstAsync();
+
+ if (lockInfo == null)
+ throw new Exception("鏈壘鍒版湁鏁堢殑閿佸畾淇℃伅");
+
+ // 璁$畻鍓╀綑鍙媶鏁伴噺
+ var remainQuantity = lockInfo.AssignQuantity - lockInfo.PickedQty;
+
+ return new SplitPackageInfoDto
+ {
+ OrderNo = orderNo,
+ PalletCode = palletCode,
+ Barcode = barcode,
+ MaterielCode = lockInfo.MaterielCode,
+ RemainQuantity = remainQuantity,
+ AssignQuantity = lockInfo.AssignQuantity,
+ PickedQty = lockInfo.PickedQty
+ };
+ }
+
+ #endregion
+
+ #region 鍙栬蛋绌虹閫昏緫
+
+
+
+ /// <summary>
+ /// 鍙栬蛋绌虹 - 娓呯悊宸插畬鎴愭嫞閫夌殑鎵樼洏鏁版嵁
+ /// </summary>
+ public async Task<WebResponseContent> RemoveEmptyPallet(string orderNo, string palletCode)
+ {
+ try
+ {
+ _unitOfWorkManage.BeginTran();
+
+ // 楠岃瘉鎵樼洏鏄惁鍙互鍙栬蛋锛堝繀椤诲叏閮ㄥ畬鎴愭嫞閫夛級
+ var validationResult = await ValidateEmptyPalletRemoval(orderNo, palletCode);
+ if (!validationResult.IsValid)
+ return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
+
+ var completedLocks = validationResult.Data;
+
+ // 娓呯悊閿佸畾璁板綍锛堟爣璁颁负宸插畬鎴愶級
+ await CleanupCompletedLocks(completedLocks);
+
+ // 鏇存柊鐩稿叧璁㈠崟鐘舵��
+ await UpdateOrderStatusAfterPalletRemoval(orderNo);
+
+ // 璁板綍鎿嶄綔鍘嗗彶
+ // await RecordEmptyPalletRemoval(orderNo, palletCode, completedLocks);
+
+ _unitOfWorkManage.CommitTran();
+
+ return WebResponseContent.Instance.OK("鍙栬蛋绌虹鎴愬姛");
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError($"鍙栬蛋绌虹澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Error: {ex.Message}");
+ return WebResponseContent.Instance.Error($"鍙栬蛋绌虹澶辫触锛歿ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 楠岃瘉绌虹鍙栬蛋鏉′欢
+ /// </summary>
+ private async Task<ValidationResult<List<Dt_OutStockLockInfo>>> ValidateEmptyPalletRemoval(string orderNo, string palletCode)
+ {
+ // 鑾峰彇鎵樼洏鐨勬墍鏈夐攣瀹氳褰�
+ var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo && x.PalletCode == palletCode)
+ .ToListAsync();
+
+ if (!lockInfos.Any())
+ return ValidationResult<List<Dt_OutStockLockInfo>>.Error("璇ユ墭鐩樻病鏈夐攣瀹氳褰�");
+
+ // 妫�鏌ユ槸鍚︽湁鏈畬鎴愮殑閿佸畾璁板綍
+ var unfinishedLocks = lockInfos.Where(x =>
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
+ x.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�).ToList();
+
+ if (unfinishedLocks.Any())
+ {
+ var unfinishedCount = unfinishedLocks.Count;
+ var unfinishedQty = unfinishedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+ return ValidationResult<List<Dt_OutStockLockInfo>>.Error(
+ $"鎵樼洏杩樻湁{unfinishedCount}鏉℃湭瀹屾垚璁板綍锛屽墿浣欐暟閲弡unfinishedQty}锛屼笉鑳藉彇璧扮┖绠�");
+ }
+
+ // 鑾峰彇宸插畬鎴愮殑閿佸畾璁板綍
+ var completedLocks = lockInfos.Where(x =>
+ x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�).ToList();
+
+ if (!completedLocks.Any())
+ return ValidationResult<List<Dt_OutStockLockInfo>>.Error("璇ユ墭鐩樻病鏈夊凡瀹屾垚鎷i�夌殑璁板綍");
+
+ return ValidationResult<List<Dt_OutStockLockInfo>>.Success(completedLocks);
+ }
+
+ /// <summary>
+ /// 娓呯悊宸插畬鎴愮殑閿佸畾璁板綍
+ /// </summary>
+ private async Task CleanupCompletedLocks(List<Dt_OutStockLockInfo> completedLocks)
+ {
+ foreach (var lockInfo in completedLocks)
+ {
+ // 鏍囪閿佸畾璁板綍涓哄凡鍙栬蛋
+ lockInfo.Status = (int)OutLockStockStatusEnum.宸插彇璧�;
+ lockInfo.Operator = App.User.UserName;
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ // 娓呯悊瀵瑰簲鐨勫簱瀛樿褰曠姸鎬�
+ await CleanupStockInfo(lockInfo);
+ }
+ }
+
+ /// <summary>
+ /// 娓呯悊搴撳瓨淇℃伅
+ /// </summary>
+ private async Task CleanupStockInfo(Dt_OutStockLockInfo lockInfo)
+ {
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
+
+ if (stockDetail != null && stockDetail.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
+ {
+ stockDetail.Status = (int)StockStatusEmun.宸叉竻鐞�;
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ }
+ }
+
+
+ /// <summary>
+ /// 鏇存柊璁㈠崟鐘舵��
+ /// </summary>
+ private async Task UpdateOrderStatusAfterPalletRemoval(string orderNo)
+ {
+ // 妫�鏌ヨ鍗曟槸鍚︽墍鏈夋墭鐩橀兘宸插畬鎴�
+ var allLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo)
+ .ToListAsync();
+
+ var unfinishedPallets = allLocks
+ .GroupBy(x => x.PalletCode)
+ .Where(g => g.Any(x => x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� ||
+ x.Status == (int)OutLockStockStatusEnum.鍥炲簱涓�))
+ .ToList();
+
+ // 濡傛灉娌℃湁鏈畬鎴愮殑鎵樼洏锛屾洿鏂拌鍗曠姸鎬佷负鍑哄簱瀹屾垚
+ if (!unfinishedPallets.Any())
+ {
+ await _outboundOrderService.Db.Updateable<Dt_OutboundOrder>()
+ .SetColumns(x => new Dt_OutboundOrder
+ {
+ OrderStatus = (int)OutOrderStatusEnum.鍑哄簱瀹屾垚,
+ })
+ .Where(x => x.OrderNo == orderNo)
+ .ExecuteCommandAsync();
+ }
+ }
+
+ /// <summary>
+ /// 璁板綍绌虹鍙栬蛋鍘嗗彶
+ /// </summary>
+ private async Task RecordEmptyPalletRemoval(string orderNo, string palletCode, List<Dt_OutStockLockInfo> completedLocks)
+ {
+ var removalRecord = new Dt_EmptyPalletRemoval
+ {
+ OrderNo = orderNo,
+ PalletCode = palletCode,
+ RemovalTime = DateTime.Now,
+ Operator = App.User.UserName,
+ CompletedItemsCount = completedLocks.Count,
+ TotalPickedQuantity = completedLocks.Sum(x => x.PickedQty)
+ };
+
+ await Db.Insertable(removalRecord).ExecuteCommandAsync();
+ }
+
+ #endregion
+
+
#region 鍒嗘壒鍒嗘嫞
/// <summary>
@@ -92,32 +412,68 @@
{
_unitOfWorkManage.BeginTran();
- // 1. 楠岃瘉鍒嗘嫞璇锋眰
+ // 楠岃瘉鍒嗘嫞璇锋眰
var validationResult = await ValidatePickingRequest(orderNo, palletCode, barcode);
if (!validationResult.IsValid)
return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
var (lockInfo, orderDetail, stockDetail, batch) = validationResult.Data;
- // 浣跨敤閿佸畾淇℃伅鐨勫垎閰嶆暟閲忎綔涓哄疄闄呭垎鎷f暟閲�
- var actualPickedQty = lockInfo.AssignQuantity;
+ // 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖�
+ var autoSplitResult = await CheckAndAutoSplitIfNeeded(lockInfo, stockDetail, palletCode);
+ if (autoSplitResult != null)
+ {
+ // 濡傛灉鎵ц浜嗚嚜鍔ㄦ媶鍖咃紝閲嶆柊鑾峰彇鏈�鏂扮殑閿佸畾淇℃伅鍜屽簱瀛樹俊鎭�
+ var refreshedValidation = await ValidatePickingRequest(orderNo, palletCode, barcode);
+ if (!refreshedValidation.IsValid)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(refreshedValidation.ErrorMessage);
+ }
- // 2. 鎵ц鍒嗘嫞閫昏緫
- var pickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, actualPickedQty);
+ (lockInfo, orderDetail, stockDetail, batch) = refreshedValidation.Data;
- // 3. 鏇存柊鎵规鍜岃鍗曟暟鎹�
- await UpdateBatchAndOrderData(batch, orderDetail, actualPickedQty, orderNo);
+ // 閲嶈淇锛氳嚜鍔ㄦ媶鍖呭悗锛岀珛鍗虫墽琛屽師鏉$爜鐨勫垎鎷�
+ var actualPickedQty = lockInfo.AssignQuantity;
+ var pickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, actualPickedQty);
- // 4. 璁板綍鎷i�夊巻鍙�
- await RecordPickingHistory(pickingResult, orderNo, palletCode);
+ // 鏇存柊鎵规鍜岃鍗曟暟鎹�
+ await UpdateBatchAndOrderData(batch, orderDetail, actualPickedQty, orderNo);
+
+ // 璁板綍鎷i�夊巻鍙�
+ await RecordPickingHistory(pickingResult, orderNo, palletCode);
+
+ _unitOfWorkManage.CommitTran();
+
+ return WebResponseContent.Instance.OK("鑷姩鎷嗗寘骞跺垎鎷f垚鍔�", new
+ {
+ AutoSplitted = true,
+ NewBarcode = autoSplitResult.NewBarcode,
+ OriginalBarcode = barcode,
+ SplitQuantity = autoSplitResult.SplitQuantity,
+ PickedQuantity = actualPickedQty,
+ MaterialCode = lockInfo.MaterielCode
+ });
+ }
+
+ // 姝e父鍒嗘嫞娴佺▼锛堜笉闇�瑕佽嚜鍔ㄦ媶鍖咃級
+ var normalPickedQty = lockInfo.AssignQuantity;
+ var normalPickingResult = await ExecutePickingLogic(lockInfo, orderDetail, stockDetail, normalPickedQty);
+
+ // 鏇存柊鎵规鍜岃鍗曟暟鎹�
+ await UpdateBatchAndOrderData(batch, orderDetail, normalPickedQty, orderNo);
+
+ // 璁板綍鎷i�夊巻鍙�
+ await RecordPickingHistory(normalPickingResult, orderNo, palletCode);
_unitOfWorkManage.CommitTran();
return WebResponseContent.Instance.OK("鍒嗘嫞鎴愬姛", new
{
- PickedQuantity = actualPickedQty,
+ PickedQuantity = normalPickedQty,
Barcode = barcode,
- MaterialCode = lockInfo.MaterielCode
+ MaterialCode = lockInfo.MaterielCode,
+ AutoSplitted = false
});
}
catch (Exception ex)
@@ -149,10 +505,10 @@
return WebResponseContent.Instance.Error("鏈壘鍒板垎鎷h褰�");
// 鎭㈠閿佸畾淇℃伅鍜屽簱瀛�
- await RevertPickingData(pickingRecord);
+ var revertResult = await RevertPickingData(pickingRecord);
- //鏇存柊鎵规鍜岃鍗曟暟鎹�
- await RevertBatchAndOrderData(pickingRecord);
+ // 鏇存柊鎵规鍜岃鍗曟暟鎹�
+ await RevertBatchAndOrderData(pickingRecord, revertResult);
// 鏍囪鍒嗘嫞璁板綍涓哄凡鍙栨秷
pickingRecord.IsCancelled = true;
@@ -171,10 +527,11 @@
return WebResponseContent.Instance.Error($"鍙栨秷鍒嗘嫞澶辫触锛歿ex.Message}");
}
}
-
#endregion
#region 鎵嬪姩鎷嗗寘
+
+ #region 鎵嬪姩鎷嗗寘鐩稿叧鏂规硶
/// <summary>
/// 鎵嬪姩鎷嗗寘
@@ -185,15 +542,15 @@
{
_unitOfWorkManage.BeginTran();
- // 楠岃瘉鎷嗗寘璇锋眰
+ // 楠岃瘉鎷嗗寘璇锋眰
var validationResult = await ValidateSplitRequest(orderNo, palletCode, originalBarcode, splitQuantity);
if (!validationResult.IsValid)
return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
var (lockInfo, stockDetail) = validationResult.Data;
- // . 鎵ц鎷嗗寘閫昏緫
- var splitResult = await ExecuteSplitLogic(lockInfo, stockDetail, splitQuantity, palletCode);
+ // 鎵ц鎷嗗寘閫昏緫
+ var splitResult = await ExecuteManualSplitLogic(lockInfo, stockDetail, splitQuantity, palletCode);
_unitOfWorkManage.CommitTran();
@@ -212,12 +569,229 @@
}
}
- #endregion
+ /// <summary>
+ /// 楠岃瘉鎷嗗寘璇锋眰 - 澧炲己鍒嗛厤鏁伴噺鎺у埗
+ /// </summary>
+ private async Task<ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>> ValidateSplitRequest(
+ string orderNo, string palletCode, string originalBarcode, decimal splitQuantity)
+ {
+ _logger.LogInformation($"寮�濮嬮獙璇佹媶鍖呰姹� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鍘熸潯鐮�: {originalBarcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
- #region 鍙栨秷鎷嗗寘
+ // 鏌ユ壘閿佸畾淇℃伅
+ var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderNo == orderNo &&
+ x.PalletCode == palletCode &&
+ x.CurrentBarcode == originalBarcode &&
+ x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ .FirstAsync();
+
+ if (lockInfo == null)
+ {
+ _logger.LogWarning($"鏈壘鍒版湁鏁堢殑閿佸畾淇℃伅 - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鏉$爜: {originalBarcode}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版湁鏁堢殑閿佸畾淇℃伅");
+ }
+
+ _logger.LogInformation($"鎵惧埌閿佸畾淇℃伅 - 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 宸叉嫞閫�: {lockInfo.PickedQty}, 璁㈠崟鏁伴噺: {lockInfo.OrderQuantity}");
+
+ // 鑾峰彇璁㈠崟鏄庣粏
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+
+ if (orderDetail == null)
+ {
+ _logger.LogWarning($"鏈壘鍒拌鍗曟槑缁� - OrderDetailId: {lockInfo.OrderDetailId}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒拌鍗曟槑缁�");
+ }
+
+ _logger.LogInformation($"鎵惧埌璁㈠崟鏄庣粏 - 宸插垎閰嶆暟閲�: {orderDetail.AllocatedQuantity}, 閿佸畾鏁伴噺: {orderDetail.LockQuantity}");
+
+ // 鑾峰彇搴撳瓨淇℃伅
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == originalBarcode && x.StockId == lockInfo.StockId);
+
+ if (stockDetail == null)
+ {
+ _logger.LogWarning($"鏈壘鍒板簱瀛樹俊鎭� - 鏉$爜: {originalBarcode}, StockId: {lockInfo.StockId}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒板搴旂殑搴撳瓨淇℃伅");
+ }
+
+ _logger.LogInformation($"鎵惧埌搴撳瓨淇℃伅 - 搴撳瓨鏁伴噺: {stockDetail.StockQuantity}, 鍑哄簱鏁伴噺: {stockDetail.OutboundQuantity}");
+
+ // 閲嶈淇锛氶獙璇佹媶鍖呮暟閲忎笉鑳藉ぇ浜庡簱瀛樻暟閲�
+ if (stockDetail.StockQuantity < splitQuantity)
+ {
+ _logger.LogWarning($"鎷嗗寘鏁伴噺澶т簬搴撳瓨鏁伴噺 - 鎷嗗寘鏁伴噺: {splitQuantity}, 搴撳瓨鏁伴噺: {stockDetail.StockQuantity}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error($"鎷嗗寘鏁伴噺涓嶈兘澶т簬搴撳瓨鏁伴噺锛屽綋鍓嶅簱瀛橈細{stockDetail.StockQuantity}");
+ }
+
+ // 閲嶈淇锛氶獙璇佹媶鍖呮暟閲忎笉鑳藉ぇ浜庨攣瀹氫俊鎭殑鍒嗛厤鏁伴噺
+ if (lockInfo.AssignQuantity < splitQuantity)
+ {
+ _logger.LogWarning($"鎷嗗寘鏁伴噺澶т簬鍒嗛厤鏁伴噺 - 鎷嗗寘鏁伴噺: {splitQuantity}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error($"鎷嗗寘鏁伴噺涓嶈兘澶т簬鍒嗛厤鏁伴噺锛屽綋鍓嶅垎閰嶆暟閲忥細{lockInfo.AssignQuantity}");
+ }
+
+ // 閲嶈淇锛氶獙璇佹媶鍖呮暟閲忎笉鑳藉ぇ浜庨攣瀹氫俊鎭殑鏈嫞閫夋暟閲�
+ decimal remainingToPick = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ if (remainingToPick < splitQuantity)
+ {
+ _logger.LogWarning($"鎷嗗寘鏁伴噺澶т簬鏈嫞閫夋暟閲� - 鎷嗗寘鏁伴噺: {splitQuantity}, 鏈嫞閫夋暟閲�: {remainingToPick}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error($"鎷嗗寘鏁伴噺涓嶈兘澶т簬鏈嫞閫夋暟閲忥紝褰撳墠鏈嫞閫夛細{remainingToPick}");
+ }
+
+ // 閲嶈淇锛氶獙璇佹媶鍖呭悗鍘熼攣瀹氫俊鎭殑鍒嗛厤鏁伴噺涓嶄細涓鸿礋鏁�
+ if (lockInfo.AssignQuantity - splitQuantity < 0)
+ {
+ _logger.LogWarning($"鎷嗗寘鍚庡垎閰嶆暟閲忎负璐熸暟 - 褰撳墠鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error($"鎷嗗寘鍚庡垎閰嶆暟閲忎笉鑳戒负璐熸暟");
+ }
+
+ // 閲嶈淇锛氶獙璇佽鍗曟槑缁嗙殑鍒嗛厤鏁伴噺鏄惁瓒冲
+ // 娉ㄦ剰锛氭墜鍔ㄦ媶鍖呬笉浼氭敼鍙樿鍗曟槑缁嗙殑鍒嗛厤鏁伴噺锛屽洜涓烘�诲垎閰嶆暟閲忎笉鍙�
+ // 鍙槸浠庝竴涓攣瀹氫俊鎭浆绉诲埌鍙︿竴涓攣瀹氫俊鎭�
+ decimal totalLockAssignQuantity = await GetTotalLockAssignQuantity(orderDetail.Id);
+ if (orderDetail.AllocatedQuantity != totalLockAssignQuantity)
+ {
+ _logger.LogWarning($"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺涓庨攣瀹氫俊鎭笉涓�鑷� - 璁㈠崟鏄庣粏鍒嗛厤鏁伴噺: {orderDetail.AllocatedQuantity}, 閿佸畾淇℃伅鎬诲垎閰嶆暟閲�: {totalLockAssignQuantity}");
+ // 杩欓噷涓嶇洿鎺ヨ繑鍥為敊璇紝鍥犱负鎷嗗寘鎿嶄綔鏈韩涓嶄細瀵艰嚧涓嶄竴鑷达紝鍙槸璁板綍璀﹀憡
+ }
+
+ _logger.LogInformation($"鎷嗗寘楠岃瘉閫氳繃 - 鍘熸潯鐮�: {originalBarcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Success((lockInfo, stockDetail));
+ }
/// <summary>
- /// 鍙栨秷鎷嗗寘
+ /// 鑾峰彇璁㈠崟鏄庣粏鐨勬墍鏈夐攣瀹氫俊鎭殑鎬诲垎閰嶆暟閲�
+ /// </summary>
+ private async Task<decimal> GetTotalLockAssignQuantity(long orderDetailId)
+ {
+ var lockInfos = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.OrderDetailId == orderDetailId)
+ .ToListAsync();
+
+ return lockInfos.Sum(x => x.AssignQuantity);
+ }
+
+ /// <summary>
+ /// 鎵ц鎵嬪姩鎷嗗寘閫昏緫 - 澧炲己鍒嗛厤鏁伴噺鎺у埗
+ /// </summary>
+ private async Task<SplitResultDto> ExecuteManualSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
+ decimal splitQuantity, string palletCode)
+ {
+ _logger.LogInformation($"寮�濮嬫墽琛屾墜鍔ㄦ媶鍖呴�昏緫 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+
+ // 閲嶈淇锛氳幏鍙栬鍗曟槑缁嗗苟楠岃瘉鍒嗛厤鏁伴噺
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+
+ if (orderDetail == null)
+ throw new InvalidOperationException("鏈壘鍒拌鍗曟槑缁�");
+
+ // 楠岃瘉鎷嗗寘鏁伴噺涓嶄細瀵艰嚧鍒嗛厤鏁伴噺涓鸿礋鏁�
+ if (lockInfo.AssignQuantity < splitQuantity)
+ {
+ throw new InvalidOperationException($"鎷嗗寘鏁伴噺瓒呰繃閿佸畾淇℃伅鍒嗛厤鏁伴噺锛屾媶鍖呮暟閲�: {splitQuantity}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}");
+ }
+
+ // 鐢熸垚鏂版潯鐮�
+ string newBarcode = await GenerateNewBarcode();
+
+ // 璁板綍鎷嗗寘鍓嶇殑鍒嗛厤鏁伴噺
+ decimal originalAssignQtyBefore = lockInfo.AssignQuantity;
+ decimal originalOrderQtyBefore = lockInfo.OrderQuantity;
+
+ // 1. 鍒涘缓鏂板簱瀛樻槑缁�
+ var newStockDetail = new Dt_StockInfoDetail
+ {
+ StockId = stockDetail.StockId,
+ MaterielCode = stockDetail.MaterielCode,
+ OrderNo = stockDetail.OrderNo,
+ BatchNo = stockDetail.BatchNo,
+ StockQuantity = splitQuantity,
+ OutboundQuantity = 0,
+ Barcode = newBarcode,
+ Status = (int)StockStatusEmun.鍑哄簱閿佸畾,
+ SupplyCode = stockDetail.SupplyCode,
+ Unit = stockDetail.Unit,
+ BarcodeQty = stockDetail.BarcodeQty,
+ BarcodeUnit = stockDetail.BarcodeUnit,
+ BusinessType = stockDetail.BusinessType,
+ InboundOrderRowNo = stockDetail.InboundOrderRowNo,
+ };
+ await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁� - 鏉$爜: {newBarcode}, 搴撳瓨鏁伴噺: {splitQuantity}");
+
+ // 2. 鏇存柊鍘熷簱瀛樻槑缁�
+ decimal originalStockQtyBefore = stockDetail.StockQuantity;
+ stockDetail.StockQuantity -= splitQuantity;
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鏇存柊鍘熷簱瀛樻槑缁� - 搴撳瓨鏁伴噺浠� {originalStockQtyBefore} 鍑忓皯鍒� {stockDetail.StockQuantity}");
+
+ // 3. 鍒涘缓鏂伴攣瀹氫俊鎭�
+ var newLockInfo = new Dt_OutStockLockInfo
+ {
+ OrderNo = lockInfo.OrderNo,
+ OrderDetailId = lockInfo.OrderDetailId,
+ OutboundBatchNo = lockInfo.OutboundBatchNo,
+ MaterielCode = lockInfo.MaterielCode,
+ MaterielName = lockInfo.MaterielName,
+ StockId = lockInfo.StockId,
+ OrderQuantity = splitQuantity,
+ AssignQuantity = splitQuantity,
+ PickedQty = 0,
+ LocationCode = lockInfo.LocationCode,
+ PalletCode = lockInfo.PalletCode,
+ TaskNum = lockInfo.TaskNum,
+ Status = (int)OutLockStockStatusEnum.鍑哄簱涓�,
+ Unit = lockInfo.Unit,
+ SupplyCode = lockInfo.SupplyCode,
+ OrderType = lockInfo.OrderType,
+ CurrentBarcode = newBarcode,
+ IsSplitted = 1,
+ ParentLockId = lockInfo.Id,
+ Operator = App.User.UserName,
+ FactoryArea = lockInfo.FactoryArea,
+ lineNo = lockInfo.lineNo,
+ WarehouseCode = lockInfo.WarehouseCode,
+ BarcodeQty = lockInfo.BarcodeQty,
+ BarcodeUnit = lockInfo.BarcodeUnit,
+ };
+
+ await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏂伴攣瀹氫俊鎭� - 鏉$爜: {newBarcode}, 鍒嗛厤鏁伴噺: {splitQuantity}");
+
+ // 4. 鏇存柊鍘熼攣瀹氫俊鎭�
+ lockInfo.AssignQuantity -= splitQuantity;
+ lockInfo.OrderQuantity -= splitQuantity;
+
+ _logger.LogInformation($"鏇存柊鍘熼攣瀹氫俊鎭� - 鍒嗛厤鏁伴噺浠� {originalAssignQtyBefore} 鍑忓皯鍒� {lockInfo.AssignQuantity}");
+ _logger.LogInformation($"鏇存柊鍘熼攣瀹氫俊鎭� - 璁㈠崟鏁伴噺浠� {originalOrderQtyBefore} 鍑忓皯鍒� {lockInfo.OrderQuantity}");
+
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ // 閲嶈淇锛氭墜鍔ㄦ媶鍖呬笉浼氭敼鍙樿鍗曟槑缁嗙殑鍒嗛厤鏁伴噺锛屽洜涓烘�诲垎閰嶆暟閲忎笉鍙�
+ // 鍙槸浠庝竴涓攣瀹氫俊鎭浆绉诲埌鍙︿竴涓攣瀹氫俊鎭�
+ _logger.LogInformation($"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺淇濇寔涓嶅彉 - 宸插垎閰嶆暟閲�: {orderDetail.AllocatedQuantity}");
+
+ // 5. 璁板綍鎷嗗寘鍘嗗彶
+ await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, false);
+
+ _logger.LogInformation($"鎵嬪姩鎷嗗寘閫昏緫鎵ц瀹屾垚");
+
+ return new SplitResultDto { NewBarcode = newBarcode };
+ }
+
+ #endregion
+
+ #endregion
+
+
+
+ #region 鍙栨秷鎷嗗寘
+
+ /// <summary>
+ /// 鍙栨秷鎷嗗寘
/// </summary>
public async Task<WebResponseContent> CancelSplitPackage(string orderNo, string palletCode, string newBarcode)
{
@@ -225,15 +799,29 @@
{
_unitOfWorkManage.BeginTran();
- // 鏌ユ壘鎷嗗寘璁板綍骞堕獙璇�
+ // 1. 鏌ユ壘鎷嗗寘璁板綍骞堕獙璇�
var validationResult = await ValidateCancelSplitRequest(orderNo, palletCode, newBarcode);
if (!validationResult.IsValid)
return WebResponseContent.Instance.Error(validationResult.ErrorMessage);
var (splitRecord, newLockInfo, newStockDetail) = validationResult.Data;
- // 鎵ц鍙栨秷鎷嗗寘閫昏緫
- await ExecuteCancelSplitLogic(splitRecord, newLockInfo, newStockDetail);
+ // 2. 鏌ユ壘鍘熷閿佸畾淇℃伅
+ var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == splitRecord.OutStockLockInfoId);
+
+ // 3. 妫�鏌ヨ鏉$爜鏄惁琚啀娆℃媶鍖�
+ var childSplitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.OriginalBarcode == newBarcode && !x.IsReverted)
+ .ToListAsync();
+
+ if (childSplitRecords.Any())
+ {
+ return WebResponseContent.Instance.Error("璇ユ潯鐮佸凡琚啀娆℃媶鍖咃紝璇峰厛鍙栨秷鍚庣画鐨勬媶鍖呮搷浣�");
+ }
+
+ // 4. 鎵ц鍙栨秷鎷嗗寘閫昏緫
+ await ExecuteCancelSplitLogic(splitRecord, originalLockInfo, newLockInfo, newStockDetail);
_unitOfWorkManage.CommitTran();
@@ -242,13 +830,551 @@
catch (Exception ex)
{
_unitOfWorkManage.RollbackTran();
- _logger.LogError($"鍙栨秷鎷嗗寘澶辫触 - OrderNo: {orderNo}, Barcode: {newBarcode}, Error: {ex.Message}");
+ _logger.LogError($"鍙栨秷鎷嗗寘澶辫触 - OrderNo: {orderNo}, PalletCode: {palletCode}, Barcode: {newBarcode}, Error: {ex.Message}");
return WebResponseContent.Instance.Error($"鍙栨秷鎷嗗寘澶辫触锛歿ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鎵ц鍙栨秷鎷嗗寘閫昏緫
+ /// </summary>
+ private async Task ExecuteCancelSplitLogic(Dt_SplitPackageRecord splitRecord,
+ Dt_OutStockLockInfo originalLockInfo, Dt_OutStockLockInfo newLockInfo,
+ Dt_StockInfoDetail newStockDetail)
+ {
+ _logger.LogInformation($"寮�濮嬫墽琛屽彇娑堟媶鍖呴�昏緫 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}, 鎷嗗寘鏁伴噺: {splitRecord.SplitQty}");
+
+ // 鎭㈠鍘熼攣瀹氫俊鎭�
+ decimal originalAssignQtyBefore = originalLockInfo.AssignQuantity;
+ decimal originalOrderQtyBefore = originalLockInfo.OrderQuantity;
+
+ // 閲嶈淇锛氭仮澶嶅垎閰嶆暟閲忓拰璁㈠崟鏁伴噺
+ originalLockInfo.AssignQuantity += splitRecord.SplitQty;
+ originalLockInfo.OrderQuantity += splitRecord.SplitQty;
+
+ _logger.LogInformation($"鎭㈠鍘熼攣瀹氫俊鎭� - 鍒嗛厤鏁伴噺浠� {originalAssignQtyBefore} 澧炲姞鍒� {originalLockInfo.AssignQuantity}");
+ _logger.LogInformation($"鎭㈠鍘熼攣瀹氫俊鎭� - 璁㈠崟鏁伴噺浠� {originalOrderQtyBefore} 澧炲姞鍒� {originalLockInfo.OrderQuantity}");
+
+ // 濡傛灉鍘熼攣瀹氫俊鎭殑鐘舵�佹槸鎷i�夊畬鎴愶紝闇�瑕侀噸鏂拌缃负鍑哄簱涓�
+ if (originalLockInfo.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ {
+ originalLockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ _logger.LogInformation($"鍘熼攣瀹氫俊鎭姸鎬佷粠鎷i�夊畬鎴愭仮澶嶄负鍑哄簱涓�");
+ }
+
+ await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+
+ // 鎭㈠鍘熷簱瀛樻槑缁�
+ var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == splitRecord.StockId);
+
+ if (originalStock != null)
+ {
+ decimal originalStockQtyBefore = originalStock.StockQuantity;
+ originalStock.StockQuantity += splitRecord.SplitQty;
+
+ _logger.LogInformation($"鎭㈠鍘熷簱瀛樻槑缁� - 搴撳瓨鏁伴噺浠� {originalStockQtyBefore} 澧炲姞鍒� {originalStock.StockQuantity}");
+
+ // 濡傛灉鍘熷簱瀛樼姸鎬佹槸鍑哄簱瀹屾垚锛岄渶瑕侀噸鏂拌缃负鍑哄簱閿佸畾
+ if (originalStock.Status == (int)StockStatusEmun.鍑哄簱瀹屾垚)
+ {
+ originalStock.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ _logger.LogInformation($"鍘熷簱瀛樼姸鎬佷粠鍑哄簱瀹屾垚鎭㈠涓哄嚭搴撻攣瀹�");
+ }
+
+ await _stockInfoDetailService.Db.Updateable(originalStock).ExecuteCommandAsync();
+ }
+
+ // 鍒犻櫎鏂伴攣瀹氫俊鎭�
+ _logger.LogInformation($"鍒犻櫎鏂伴攣瀹氫俊鎭� - 鏉$爜: {newLockInfo.CurrentBarcode}, 鍒嗛厤鏁伴噺: {newLockInfo.AssignQuantity}");
+ await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
+ .Where(x => x.Id == newLockInfo.Id)
+ .ExecuteCommandAsync();
+
+ // 鍒犻櫎鏂板簱瀛樻槑缁�
+ _logger.LogInformation($"鍒犻櫎鏂板簱瀛樻槑缁� - 鏉$爜: {newStockDetail.Barcode}, 搴撳瓨鏁伴噺: {newStockDetail.StockQuantity}");
+ await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
+ .Where(x => x.Barcode == newLockInfo.CurrentBarcode)
+ .ExecuteCommandAsync();
+
+ // 鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢
+ splitRecord.IsReverted = true;
+ splitRecord.RevertTime = DateTime.Now;
+ splitRecord.RevertOperator = App.User.UserName;
+ await _splitPackageService.Db.Updateable(splitRecord).ExecuteCommandAsync();
+ _logger.LogInformation($"鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢");
+
+ // 妫�鏌ュ苟鏇存柊鎵规鍜岃鍗曠姸鎬�
+ await CheckAndUpdateBatchStatus(originalLockInfo.BatchNo);
+ await CheckAndUpdateOrderStatus(originalLockInfo.OrderNo);
+
+ _logger.LogInformation($"鍙栨秷鎷嗗寘閫昏緫鎵ц瀹屾垚");
+ }
+
+ /// <summary>
+ /// 楠岃瘉鍙栨秷鎷嗗寘璇锋眰
+ /// </summary>
+ private async Task<ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>> ValidateCancelSplitRequest(
+ string orderNo, string palletCode, string newBarcode)
+ {
+ _logger.LogInformation($"寮�濮嬮獙璇佸彇娑堟媶鍖呰姹� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鏉$爜: {newBarcode}");
+
+ // 鏌ユ壘鎷嗗寘璁板綍
+ var splitRecord = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.NewBarcode == newBarcode &&
+ x.OrderNo == orderNo &&
+ !x.IsReverted)
+ .FirstAsync();
+
+ if (splitRecord == null)
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版媶鍖呰褰�");
+
+ _logger.LogInformation($"鎵惧埌鎷嗗寘璁板綍 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}, 鎷嗗寘鏁伴噺: {splitRecord.SplitQty}");
+
+ // 鏌ユ壘鏂伴攣瀹氫俊鎭�
+ var newLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.CurrentBarcode == newBarcode &&
+ x.PalletCode == palletCode &&
+ x.OrderNo == orderNo)
+ .FirstAsync();
+
+ if (newLockInfo == null)
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版柊閿佸畾淇℃伅");
+
+ _logger.LogInformation($"鎵惧埌鏂伴攣瀹氫俊鎭� - 鐘舵��: {newLockInfo.Status}, 宸叉嫞閫�: {newLockInfo.PickedQty}, 鍒嗛厤鏁伴噺: {newLockInfo.AssignQuantity}");
+
+ // 閲嶈淇锛氭鏌ユ柊鏉$爜鏄惁宸茶鍒嗘嫞
+ var newBarcodePickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == newBarcode && x.OrderNo == orderNo && !x.IsCancelled)
+ .ToListAsync();
+
+ if (newBarcodePickingRecords.Any())
+ {
+ var totalPickedQty = newBarcodePickingRecords.Sum(x => x.PickQuantity);
+ _logger.LogWarning($"鏂版潯鐮� {newBarcode} 宸茶鍒嗘嫞锛屾�绘嫞閫夋暟閲�: {totalPickedQty}");
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error(
+ $"鏂版潯鐮佸凡琚垎鎷o紙宸叉嫞閫夋暟閲忥細{totalPickedQty}锛夛紝璇峰厛鍙栨秷鍒嗘嫞锛岀劧鍚庡啀鍙栨秷鎷嗗寘");
+ }
+
+ // 閲嶈淇锛氭鏌ュ師鏉$爜鏄惁宸茶鍒嗘嫞
+ var originalBarcodePickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == splitRecord.OriginalBarcode && x.OrderNo == orderNo && !x.IsCancelled)
+ .ToListAsync();
+
+ if (originalBarcodePickingRecords.Any())
+ {
+ var totalPickedQty = originalBarcodePickingRecords.Sum(x => x.PickQuantity);
+ _logger.LogWarning($"鍘熸潯鐮� {splitRecord.OriginalBarcode} 宸茶鍒嗘嫞锛屾�绘嫞閫夋暟閲�: {totalPickedQty}");
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error(
+ $"鍘熸潯鐮佸凡琚垎鎷o紙宸叉嫞閫夋暟閲忥細{totalPickedQty}锛夛紝璇峰厛鍙栨秷鍒嗘嫞锛岀劧鍚庡啀鍙栨秷鎷嗗寘");
+ }
+
+ _logger.LogInformation($"鏂版棫鏉$爜鍧囨湭琚垎鎷o紝鍙互鍙栨秷鎷嗗寘");
+
+ // 妫�鏌ユ柊鏉$爜鏄惁琚啀娆℃媶鍖�
+ var childSplitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.OriginalBarcode == newBarcode && !x.IsReverted)
+ .ToListAsync();
+
+ if (childSplitRecords.Any())
+ {
+ var childBarcodes = string.Join(", ", childSplitRecords.Select(x => x.NewBarcode));
+ _logger.LogWarning($"鏉$爜 {newBarcode} 宸茶鍐嶆鎷嗗寘锛岀敓鎴愮殑鏂版潯鐮�: {childBarcodes}");
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error(
+ $"璇ユ潯鐮佸凡琚啀娆℃媶鍖咃紝鐢熸垚鐨勬柊鏉$爜锛歿childBarcodes}锛岃鍏堝彇娑堝悗缁媶鍖�");
+ }
+
+ var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == newBarcode);
+
+ if (newStockDetail == null)
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版柊搴撳瓨鏄庣粏");
+
+ _logger.LogInformation($"鍙栨秷鎷嗗寘楠岃瘉閫氳繃 - 鏉$爜: {newBarcode}");
+
+ return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Success((splitRecord, newLockInfo, newStockDetail));
+ }
+
+ #endregion
+
+ #region 鎵归噺鍙栨秷鎷嗗寘閾�
+
+ /// <summary>
+ /// 鎵归噺鍙栨秷鎷嗗寘閾� - 鍙栨秷鏌愪釜鏉$爜鍙婂叾鎵�鏈夊悗缁媶鍖�
+ /// </summary>
+ public async Task<WebResponseContent> CancelSplitPackageChain(string orderNo, string palletCode, string startBarcode)
+ {
+ try
+ {
+ _unitOfWorkManage.BeginTran();
+
+ // 1. 鏌ユ壘鎵�鏈夌浉鍏崇殑鎷嗗寘璁板綍锛堝舰鎴愭媶鍖呴摼锛�
+ var splitChain = await GetSplitPackageChain(orderNo, startBarcode);
+
+ if (!splitChain.Any())
+ return WebResponseContent.Instance.Error("鏈壘鍒版媶鍖呰褰�");
+
+ _logger.LogInformation($"鎵惧埌鎷嗗寘閾撅紝鍏� {splitChain.Count} 鏉¤褰�");
+
+ // 2. 鏀堕泦鎷嗗寘閾句腑娑夊強鐨勬墍鏈夋潯鐮侊紙鍖呮嫭鍘熸潯鐮佸拰鏂版潯鐮侊級
+ var allBarcodesInChain = new List<string> { startBarcode };
+ allBarcodesInChain.AddRange(splitChain.Select(x => x.NewBarcode));
+
+ // 3. 妫�鏌ユ媶鍖呴摼涓槸鍚︽湁宸茶鍒嗘嫞鐨勬潯鐮�
+ var pickedBarcodesInfo = await GetPickedBarcodesInfo(orderNo, allBarcodesInChain);
+
+ if (pickedBarcodesInfo.Any())
+ {
+ var pickedBarcodes = string.Join(", ", pickedBarcodesInfo.Select(x => $"{x.Barcode}(宸叉嫞閫墈x.PickedQty})"));
+ return WebResponseContent.Instance.Error(
+ $"浠ヤ笅鏉$爜宸茶鍒嗘嫞锛岃鍏堝彇娑堝垎鎷o細{pickedBarcodes}");
+ }
+
+ // 4. 鎸夋媶鍖呴『搴忓�掑簭鍙栨秷锛堜粠鏈�鏂扮殑寮�濮嬪彇娑堬級
+ var reversedChain = splitChain.OrderByDescending(x => x.SplitTime).ToList();
+
+ foreach (var splitRecord in reversedChain)
+ {
+ _logger.LogInformation($"鍙栨秷鎷嗗寘璁板綍 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}");
+ await CancelSingleSplitPackage(splitRecord, palletCode);
+ }
+
+ _unitOfWorkManage.CommitTran();
+
+ return WebResponseContent.Instance.OK($"鎴愬姛鍙栨秷鎷嗗寘閾撅紝鍏眥reversedChain.Count}娆℃媶鍖呮搷浣�");
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ _logger.LogError($"鍙栨秷鎷嗗寘閾惧け璐� - OrderNo: {orderNo}, StartBarcode: {startBarcode}, Error: {ex.Message}");
+ return WebResponseContent.Instance.Error($"鍙栨秷鎷嗗寘閾惧け璐ワ細{ex.Message}");
+ }
+ }
+
+ /// <summary>
+ /// 鑾峰彇鏉$爜鐨勬媶鍖呭拰鎷i�夌姸鎬�
+ /// </summary>
+ public async Task<WebResponseContent> GetBarcodeSplitAndPickStatus(string orderNo, string barcode)
+ {
+ try
+ {
+ // 1. 鑾峰彇鎷嗗寘淇℃伅
+ var splitChain = await GetSplitPackageChain(orderNo, barcode);
+ var isOriginalBarcode = !splitChain.Any(x => x.NewBarcode == barcode);
+
+ // 2. 鑾峰彇鎷i�変俊鎭�
+ var pickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == barcode && x.OrderNo == orderNo && !x.IsCancelled)
+ .ToListAsync();
+
+ var totalPickedQty = pickingRecords.Sum(x => x.PickQuantity);
+
+ // 3. 鑾峰彇閿佸畾淇℃伅
+ var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.CurrentBarcode == barcode && x.OrderNo == orderNo)
+ .FirstAsync();
+
+ // 4. 鑾峰彇搴撳瓨淇℃伅
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .Where(x => x.Barcode == barcode)
+ .FirstAsync();
+
+ var statusInfo = new BarcodeStatusInfoDto
+ {
+ Barcode = barcode,
+ OrderNo = orderNo,
+ IsOriginalBarcode = isOriginalBarcode,
+ SplitChainCount = splitChain.Count,
+ HasBeenPicked = pickingRecords.Any(),
+ TotalPickedQuantity = totalPickedQty,
+ PickRecordCount = pickingRecords.Count,
+ LockInfoStatus = lockInfo?.Status ?? 0,
+ LockInfoPickedQty = lockInfo?.PickedQty ?? 0,
+ LockInfoAssignQty = lockInfo?.AssignQuantity ?? 0,
+ StockQuantity = stockDetail?.StockQuantity ?? 0,
+ StockStatus = stockDetail?.Status ?? 0,
+ CanCancelSplit = !pickingRecords.Any(), // 鏈鍒嗘嫞鎵嶈兘鍙栨秷鎷嗗寘
+ NeedCancelPickFirst = pickingRecords.Any() // 闇�瑕佸厛鍙栨秷鍒嗘嫞
+ };
+
+ // 5. 鑾峰彇鎿嶄綔寤鸿
+ statusInfo.OperationSuggestions = GetOperationSuggestions(statusInfo);
+
+ return WebResponseContent.Instance.OK("鑾峰彇鐘舵�佹垚鍔�", statusInfo);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鑾峰彇鏉$爜鐘舵�佸け璐� - OrderNo: {orderNo}, Barcode: {barcode}, Error: {ex.Message}");
+ return WebResponseContent.Instance.Error("鑾峰彇鏉$爜鐘舵�佸け璐�");
+ }
+ }
+ /// <summary>
+ /// 鑾峰彇鎿嶄綔寤鸿
+ /// </summary>
+ private List<string> GetOperationSuggestions(BarcodeStatusInfoDto statusInfo)
+ {
+ var suggestions = new List<string>();
+
+ if (statusInfo.HasBeenPicked)
+ {
+ suggestions.Add($"璇ユ潯鐮佸凡琚垎鎷o紙鏁伴噺锛歿statusInfo.TotalPickedQuantity}锛夛紝濡傞渶鍙栨秷鎷嗗寘锛岃鍏堝彇娑堝垎鎷�");
+
+ if (statusInfo.IsOriginalBarcode)
+ {
+ suggestions.Add("杩欐槸鍘熸潯鐮侊紝鍙栨秷鍒嗘嫞鍚庡皢鎭㈠涓哄彲鍒嗘嫞鐘舵��");
+ }
+ else
+ {
+ suggestions.Add("杩欐槸鎷嗗寘鐢熸垚鐨勬柊鏉$爜锛屽彇娑堝垎鎷e悗鎵嶈兘鍙栨秷鎷嗗寘");
+ }
+ }
+ else
+ {
+ if (statusInfo.IsOriginalBarcode && statusInfo.SplitChainCount > 0)
+ {
+ suggestions.Add("杩欐槸鍘熸潯鐮侊紝鍙互鍙栨秷鎷嗗寘閾�");
+ }
+ else if (!statusInfo.IsOriginalBarcode)
+ {
+ suggestions.Add("杩欐槸鎷嗗寘鐢熸垚鐨勬柊鏉$爜锛屽彲浠ュ崟鐙彇娑堟媶鍖�");
+ }
+ }
+
+ if (statusInfo.LockInfoStatus == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ {
+ suggestions.Add("閿佸畾鐘舵�侊細鎷i�夊畬鎴�");
+ }
+ else if (statusInfo.LockInfoStatus == (int)OutLockStockStatusEnum.鍑哄簱涓�)
+ {
+ suggestions.Add("閿佸畾鐘舵�侊細鍑哄簱涓�");
+ }
+
+ return suggestions;
+ }
+ /// <summary>
+ /// 鑾峰彇宸茶鍒嗘嫞鐨勬潯鐮佷俊鎭�
+ /// </summary>
+ private async Task<List<PickedBarcodeInfo>> GetPickedBarcodesInfo(string orderNo, List<string> barcodes)
+ {
+ var pickedBarcodes = new List<PickedBarcodeInfo>();
+
+ foreach (var barcode in barcodes)
+ {
+ var pickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == barcode && x.OrderNo == orderNo && !x.IsCancelled)
+ .ToListAsync();
+
+ if (pickingRecords.Any())
+ {
+ var totalPickedQty = pickingRecords.Sum(x => x.PickQuantity);
+ pickedBarcodes.Add(new PickedBarcodeInfo
+ {
+ Barcode = barcode,
+ PickedQty = totalPickedQty,
+ PickRecordCount = pickingRecords.Count
+ });
+ }
+ }
+
+ return pickedBarcodes;
+ }
+ /// <summary>
+ /// 鑾峰彇鎷嗗寘閾� - 鏌ユ壘鏌愪釜鏉$爜鐨勬墍鏈夋媶鍖呰褰曪紙鍖呮嫭鍚庣画鎷嗗寘锛�
+ /// </summary>
+ public async Task<List<Dt_SplitPackageRecord>> GetSplitPackageChain(string orderNo, string startBarcode)
+ {
+ var allSplitRecords = new List<Dt_SplitPackageRecord>();
+ var visitedBarcodes = new HashSet<string>(); // 闃叉寰幆寮曠敤
+
+ // 浣跨敤闃熷垪杩涜骞垮害浼樺厛鎼滅储
+ var queue = new Queue<string>();
+ queue.Enqueue(startBarcode);
+ visitedBarcodes.Add(startBarcode);
+
+ while (queue.Count > 0)
+ {
+ var currentBarcode = queue.Dequeue();
+
+ // 鏌ユ壘浠ュ綋鍓嶆潯鐮佷负鍘熸潯鐮佺殑鎵�鏈夋媶鍖呰褰�
+ var splitRecords = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.OriginalBarcode == currentBarcode &&
+ x.OrderNo == orderNo &&
+ !x.IsReverted)
+ .ToListAsync();
+
+ foreach (var record in splitRecords)
+ {
+ // 閬垮厤閲嶅澶勭悊
+ if (!visitedBarcodes.Contains(record.NewBarcode))
+ {
+ allSplitRecords.Add(record);
+ queue.Enqueue(record.NewBarcode);
+ visitedBarcodes.Add(record.NewBarcode);
+ }
+ }
+ }
+
+ return allSplitRecords;
+ }
+
+ /// <summary>
+ /// 鍙栨秷鍗曚釜鎷嗗寘璁板綍
+ /// </summary>
+ private async Task CancelSingleSplitPackage(Dt_SplitPackageRecord splitRecord, string palletCode)
+ {
+ _logger.LogInformation($"寮�濮嬪彇娑堝崟涓媶鍖呰褰� - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}");
+
+ // 鍐嶆楠岃瘉鍒嗘嫞鐘舵�侊紙闃叉骞跺彂鎿嶄綔锛�
+ var newBarcodePickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == splitRecord.NewBarcode && !x.IsCancelled)
+ .ToListAsync();
+
+ if (newBarcodePickingRecords.Any())
+ {
+ throw new InvalidOperationException($"鏂版潯鐮� {splitRecord.NewBarcode} 鍦ㄩ獙璇佸悗琚垎鎷o紝鏃犳硶鍙栨秷鎷嗗寘");
+ }
+
+ var originalBarcodePickingRecords = await Db.Queryable<Dt_PickingRecord>()
+ .Where(x => x.Barcode == splitRecord.OriginalBarcode && !x.IsCancelled)
+ .ToListAsync();
+
+ if (originalBarcodePickingRecords.Any())
+ {
+ throw new InvalidOperationException($"鍘熸潯鐮� {splitRecord.OriginalBarcode} 鍦ㄩ獙璇佸悗琚垎鎷o紝鏃犳硶鍙栨秷鎷嗗寘");
+ }
+
+ // 鏌ユ壘鐩稿叧鏁版嵁
+ var newLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.CurrentBarcode == splitRecord.NewBarcode &&
+ x.PalletCode == palletCode)
+ .FirstAsync();
+
+ var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == splitRecord.NewBarcode);
+
+ var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == splitRecord.OutStockLockInfoId);
+
+ // 鎵ц鍙栨秷閫昏緫
+ await ExecuteCancelSplitLogic(splitRecord, originalLockInfo, newLockInfo, newStockDetail);
+
+ _logger.LogInformation($"鍙栨秷鍗曚釜鎷嗗寘璁板綍瀹屾垚 - 鍘熸潯鐮�: {splitRecord.OriginalBarcode}, 鏂版潯鐮�: {splitRecord.NewBarcode}");
+ }
+ #endregion
+
+ #region 鎷嗗寘淇℃伅鏌ヨ澧炲己
+
+ /// <summary>
+ /// 鑾峰彇鎷嗗寘閾句俊鎭�
+ /// </summary>
+ public async Task<WebResponseContent> GetSplitPackageChainInfo(string orderNo, string barcode)
+ {
+ try
+ {
+ var splitChain = await GetSplitPackageChain(orderNo, barcode);
+
+ var chainInfo = new SplitPackageChainInfoDto
+ {
+ OriginalBarcode = barcode,
+ TotalSplitTimes = splitChain.Count,
+ SplitChain = splitChain.Select(x => new SplitChainItemDto
+ {
+ SplitTime = x.SplitTime,
+ OriginalBarcode = x.OriginalBarcode,
+ NewBarcode = x.NewBarcode,
+ SplitQuantity = x.SplitQty,
+ Operator = x.Operator,
+ IsReverted = x.IsReverted ,
+ IsAutoSplit = x.IsAutoSplit
+ }).ToList()
+ };
+
+ return WebResponseContent.Instance.OK("鑾峰彇鎴愬姛", chainInfo);
+ }
+ catch (Exception ex)
+ {
+ _logger.LogError($"鑾峰彇鎷嗗寘閾句俊鎭け璐� - OrderNo: {orderNo}, Barcode: {barcode}, Error: {ex.Message}");
+ return WebResponseContent.Instance.Error("鑾峰彇鎷嗗寘閾句俊鎭け璐�");
+ }
+ }
+
+
+ /// <summary>
+ /// 鏌ユ壘鏍规潯鐮�
+ /// </summary>
+ public async Task<string> FindRootBarcode(string orderNo, string startBarcode)
+ {
+ var currentBarcode = startBarcode;
+ var visited = new HashSet<string>();
+
+ while (!string.IsNullOrEmpty(currentBarcode) && !visited.Contains(currentBarcode))
+ {
+ visited.Add(currentBarcode);
+
+ // 鏌ユ壘褰撳墠鏉$爜鏄惁鏄敱鍏朵粬鏉$爜鎷嗗寘鑰屾潵
+ var parentRecord = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
+ .Where(x => x.NewBarcode == currentBarcode &&
+ x.OrderNo == orderNo &&
+ !x.IsReverted)
+ .FirstAsync();
+
+ if (parentRecord == null)
+ {
+ // 娌℃湁鐖剁骇鎷嗗寘璁板綍锛岃鏄庤繖鏄牴鏉$爜
+ return currentBarcode;
+ }
+
+ currentBarcode = parentRecord.OriginalBarcode;
+ }
+
+ // 濡傛灉鍑虹幇寰幆寮曠敤锛岃繑鍥炶捣濮嬫潯鐮�
+ return startBarcode;
+ }
+ #endregion
+
+ #region 鏇存柊鎵规鐘舵�佹鏌�
+
+ /// <summary>
+ /// 妫�鏌ュ苟鏇存柊鎵规鐘舵��
+ /// </summary>
+ private async Task CheckAndUpdateBatchStatus(string batchNo)
+ {
+ var batch = await _outboundBatchRepository.Db.Queryable<Dt_OutboundBatch>()
+ .FirstAsync(x => x.BatchNo == batchNo);
+
+ if (batch != null)
+ {
+ // 閲嶆柊璁$畻鎵规瀹屾垚鏁伴噺
+ var batchLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .Where(x => x.BatchNo == batchNo)
+ .ToListAsync();
+
+ var completedQuantity = batchLocks.Where(x => x.Status == (int)OutLockStockStatusEnum.鎷i�夊畬鎴�)
+ .Sum(x => x.PickedQty);
+
+ batch.CompletedQuantity = completedQuantity;
+
+ // 鏇存柊鎵规鐘舵��
+ if (batch.CompletedQuantity >= batch.BatchQuantity)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.宸插畬鎴�;
+ }
+ else if (batch.CompletedQuantity > 0)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
+ }
+ else
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鍒嗛厤涓�;
+ }
+
+ await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
}
}
#endregion
+
#region 鍒嗘壒鍥炲簱
/// <summary>
@@ -260,7 +1386,7 @@
{
_unitOfWorkManage.BeginTran();
- // 鏌ユ壘鎵樼洏涓婃湭瀹屾垚鐨勯攣瀹氳褰�
+ // 鏌ユ壘鎵樼洏涓婃湭瀹屾垚鐨勯攣瀹氳褰曪紙鍙鐞嗗嚭搴撲腑鐨勮褰曪級
var unfinishedLocks = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
.Where(x => x.OrderNo == orderNo &&
x.PalletCode == palletCode &&
@@ -270,12 +1396,12 @@
if (!unfinishedLocks.Any())
return WebResponseContent.Instance.Error("璇ユ墭鐩樻病鏈夋湭瀹屾垚鐨勯攣瀹氳褰�");
- // 鎸夋壒娆″垎缁勫鐞�
- var batchGroups = unfinishedLocks.GroupBy(x => x.BatchNo);
+ // 鎸夊嚭搴撴壒娆″垎缁勫鐞�
+ var batchGroups = unfinishedLocks.GroupBy(x => x.OutboundBatchNo); // 浣跨敤 OutboundBatchNo
foreach (var batchGroup in batchGroups)
{
- var batchNo = batchGroup.Key;
+ var outboundBatchNo = batchGroup.Key;
var batchLocks = batchGroup.ToList();
// 閲婃斁搴撳瓨鍜岄攣瀹氳褰�
@@ -285,7 +1411,7 @@
}
// 鏇存柊鎵规鐘舵��
- await UpdateBatchStatusForReturn(batchNo, batchLocks);
+ await UpdateBatchStatusForReturn(outboundBatchNo, batchLocks);
// 鏇存柊璁㈠崟鏄庣粏鐨勫凡鍒嗛厤鏁伴噺
await UpdateOrderDetailAfterReturn(batchLocks);
@@ -302,13 +1428,14 @@
return WebResponseContent.Instance.Error($"鍒嗘壒鍥炲簱澶辫触锛歿ex.Message}");
}
}
-
#endregion
#region 楠岃瘉鏂规硶
private async Task<ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>> ValidatePickingRequest(
- string orderNo, string palletCode, string barcode)
+ string orderNo, string palletCode, string barcode)
{
+ _logger.LogInformation($"寮�濮嬮獙璇佸垎鎷h姹� - 璁㈠崟: {orderNo}, 鎵樼洏: {palletCode}, 鏉$爜: {barcode}");
+
// 鏌ユ壘閿佸畾淇℃伅
var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
.Where(x => x.OrderNo == orderNo &&
@@ -320,6 +1447,8 @@
if (lockInfo == null)
return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error("鏈壘鍒版湁鏁堢殑閿佸畾淇℃伅");
+ _logger.LogInformation($"鎵惧埌閿佸畾淇℃伅 - 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 宸叉嫞閫�: {lockInfo.PickedQty}");
+
// 妫�鏌ユ槸鍚﹀凡缁忓垎鎷e畬鎴�
if (lockInfo.PickedQty >= lockInfo.AssignQuantity)
return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error("璇ユ潯鐮佸凡鍒嗘嫞瀹屾垚");
@@ -328,146 +1457,100 @@
var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
.FirstAsync(x => x.Id == lockInfo.OrderDetailId);
+ if (orderDetail == null)
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error("鏈壘鍒拌鍗曟槑缁�");
+
+ _logger.LogInformation($"鎵惧埌璁㈠崟鏄庣粏 - 宸插垎閰嶆暟閲�: {orderDetail.AllocatedQuantity}, 閿佸畾鏁伴噺: {orderDetail.LockQuantity}");
+
+ // 閲嶈淇锛氭鏌ヨ鍗曟槑缁嗙殑宸插垎閰嶆暟閲忔槸鍚﹁冻澶�
+ decimal remainingToPick = lockInfo.AssignQuantity - lockInfo.PickedQty;
+ if (orderDetail.AllocatedQuantity < remainingToPick)
+ {
+ _logger.LogWarning($"璁㈠崟鏄庣粏宸插垎閰嶆暟閲忎笉瓒� - 闇�瑕佹嫞閫�: {remainingToPick}, 鍙敤鍒嗛厤鏁伴噺: {orderDetail.AllocatedQuantity}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error(
+ $"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫夛細{remainingToPick}锛屽彲鐢ㄥ垎閰嶆暟閲忥細{orderDetail.AllocatedQuantity}");
+ }
+
+ // 閲嶈淇锛氭鏌ラ攣瀹氭暟閲忔槸鍚﹁冻澶�
+ if (orderDetail.LockQuantity < remainingToPick)
+ {
+ _logger.LogWarning($"璁㈠崟鏄庣粏閿佸畾鏁伴噺涓嶈冻 - 闇�瑕佹嫞閫�: {remainingToPick}, 鍙敤閿佸畾鏁伴噺: {orderDetail.LockQuantity}");
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error(
+ $"璁㈠崟鏄庣粏閿佸畾鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫夛細{remainingToPick}锛屽彲鐢ㄩ攣瀹氭暟閲忥細{orderDetail.LockQuantity}");
+ }
+
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.FirstAsync(x => x.Barcode == barcode && x.StockId == lockInfo.StockId);
- // 楠岃瘉搴撳瓨鏁伴噺
- if (stockDetail.StockQuantity < lockInfo.AssignQuantity)
- return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error(
- $"搴撳瓨鏁伴噺涓嶈冻锛岄渶瑕侊細{lockInfo.AssignQuantity}锛屽疄闄咃細{stockDetail.StockQuantity}");
+ if (stockDetail == null)
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error("鏈壘鍒板搴旂殑搴撳瓨淇℃伅");
+ // 楠岃瘉搴撳瓨鏁伴噺
+ if (stockDetail.StockQuantity < remainingToPick)
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error(
+ $"搴撳瓨鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫夛細{remainingToPick}锛屽疄闄呭簱瀛橈細{stockDetail.StockQuantity}");
+
+ // 楠岃瘉搴撳瓨鐘舵��
+ if (stockDetail.Status != (int)StockStatusEmun.鍑哄簱閿佸畾)
+ {
+ return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Error(
+ $"搴撳瓨鐘舵�佸紓甯革紝褰撳墠鐘舵�侊細{stockDetail.Status}锛屾湡鏈涚姸鎬侊細鍑哄簱閿佸畾");
+ }
+
+ // 浣跨敤 OutboundBatchNo 鏌ユ壘鎵规
var batch = await _outboundBatchRepository.Db.Queryable<Dt_OutboundBatch>()
- .FirstAsync(x => x.BatchNo == lockInfo.BatchNo);
+ .FirstAsync(x => x.BatchNo == lockInfo.OutboundBatchNo);
+
+ _logger.LogInformation($"鍒嗘嫞楠岃瘉閫氳繃 - 鏉$爜: {barcode}, 鍓╀綑闇�鎷i��: {remainingToPick}, 鍙敤搴撳瓨: {stockDetail.StockQuantity}");
return ValidationResult<(Dt_OutStockLockInfo, Dt_OutboundOrderDetail, Dt_StockInfoDetail, Dt_OutboundBatch)>.Success((lockInfo, orderDetail, stockDetail, batch));
}
-
- private async Task<ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>> ValidateSplitRequest(
- string orderNo, string palletCode, string originalBarcode, decimal splitQuantity)
+
+
+ /// <summary>
+ /// 妫�鏌ュ苟鎵ц鑷姩鎷嗗寘锛堝鏋滈渶瑕侊級
+ /// </summary>
+ private async Task<AutoSplitResult> CheckAndAutoSplitIfNeeded(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail, string palletCode)
{
- var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.OrderNo == orderNo &&
- x.PalletCode == palletCode &&
- x.CurrentBarcode == originalBarcode &&
- x.Status == (int)OutLockStockStatusEnum.鍑哄簱涓�)
- .FirstAsync();
+ // 妫�鏌ユ槸鍚﹂渶瑕佽嚜鍔ㄦ媶鍖呯殑鏉′欢锛�
+ // 1. 搴撳瓨鏁伴噺澶т簬鍒嗛厤鏁伴噺
+ // 2. 閿佸畾淇℃伅鐘舵�佷负鍑哄簱涓�
+ // 3. 鏈嫞閫夋暟閲忕瓑浜庡垎閰嶆暟閲忥紙琛ㄧず杩樻湭寮�濮嬫嫞閫夛級
+ bool needAutoSplit = stockDetail.StockQuantity > lockInfo.AssignQuantity &&
+ lockInfo.Status == (int)OutLockStockStatusEnum.鍑哄簱涓� &&
+ lockInfo.PickedQty == 0;
- if (lockInfo == null)
- return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版湁鏁堢殑閿佸畾淇℃伅");
+ if (!needAutoSplit)
+ return null;
- var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == originalBarcode && x.StockId == lockInfo.StockId);
+ // 璁$畻鎷嗗寘鏁伴噺 = 搴撳瓨鏁伴噺 - 鍒嗛厤鏁伴噺
+ decimal splitQuantity = stockDetail.StockQuantity - lockInfo.AssignQuantity;
- if (stockDetail.StockQuantity < splitQuantity)
- return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鎷嗗寘鏁伴噺涓嶈兘澶т簬搴撳瓨鏁伴噺");
+ // 鎵ц鑷姩鎷嗗寘
+ var splitResult = await ExecuteAutoSplitLogic(lockInfo, stockDetail, splitQuantity, palletCode);
- if (lockInfo.AssignQuantity - lockInfo.PickedQty < splitQuantity)
- return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鎷嗗寘鏁伴噺涓嶈兘澶т簬鏈嫞閫夋暟閲�");
-
- return ValidationResult<(Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Success((lockInfo, stockDetail));
- }
-
- private async Task<ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>> ValidateCancelSplitRequest(
- string orderNo, string palletCode, string newBarcode)
- {
- var splitRecord = await _splitPackageService.Db.Queryable<Dt_SplitPackageRecord>()
- .Where(x => x.NewBarcode == newBarcode &&
- x.OrderNo == orderNo &&
- !x.IsReverted)
- .FirstAsync();
-
- if (splitRecord == null)
- return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版媶鍖呰褰�");
-
- var newLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .Where(x => x.CurrentBarcode == newBarcode &&
- x.PalletCode == palletCode &&
- x.OrderNo == orderNo)
- .FirstAsync();
-
- if (newLockInfo == null)
- return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("鏈壘鍒版柊閿佸畾淇℃伅");
-
- // 妫�鏌ユ柊鏉$爜鏄惁宸茶鍒嗘嫞
- var pickingRecord = await Db.Queryable<Dt_PickingRecord>()
- .Where(x => x.Barcode == newBarcode && !x.IsCancelled)
- .FirstAsync();
-
- if (pickingRecord != null)
- return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Error("璇ユ潯鐮佸凡琚垎鎷o紝鏃犳硶鍙栨秷鎷嗗寘");
-
- var newStockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == newBarcode);
-
- return ValidationResult<(Dt_SplitPackageRecord, Dt_OutStockLockInfo, Dt_StockInfoDetail)>.Success((splitRecord, newLockInfo, newStockDetail));
- }
-
- #endregion
-
- #region 鏍稿績閫昏緫鏂规硶
-
- private async Task<PickingResult> ExecutePickingLogic(
- Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail,
- Dt_StockInfoDetail stockDetail, decimal actualPickedQty)
- {
- // 鏇存柊閿佸畾淇℃伅
- lockInfo.PickedQty += actualPickedQty;
- if (lockInfo.PickedQty >= lockInfo.AssignQuantity)
+ return new AutoSplitResult
{
- lockInfo.Status = (int)OutLockStockStatusEnum.鎷i�夊畬鎴�;
- }
- await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
-
- // 鏇存柊搴撳瓨
- stockDetail.StockQuantity -= actualPickedQty;
- stockDetail.OutboundQuantity += actualPickedQty;
-
- if (stockDetail.StockQuantity <= 0)
- {
- stockDetail.Status = (int)StockStatusEmun.鍑哄簱瀹屾垚;
- }
- await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
-
- return new PickingResult
- {
- FinalLockInfo = lockInfo,
- ActualPickedQty = actualPickedQty
+ NewBarcode = splitResult.NewBarcode,
+ SplitQuantity = splitQuantity
};
}
-
- private async Task<RevertPickingResult> RevertPickingData(Dt_PickingRecord pickingRecord)
- {
- // 鎭㈠閿佸畾淇℃伅
- var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .FirstAsync(x => x.Id == pickingRecord.OutStockLockId);
-
- lockInfo.PickedQty -= pickingRecord.PickQuantity;
- lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
- await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
-
- // 鎭㈠搴撳瓨
- var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == pickingRecord.Barcode);
-
- stockDetail.StockQuantity += pickingRecord.PickQuantity;
- stockDetail.OutboundQuantity -= pickingRecord.PickQuantity;
- stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
- await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
-
- return new RevertPickingResult
- {
- LockInfo = lockInfo,
- StockDetail = stockDetail
- };
- }
-
- private async Task<SplitResultDto> ExecuteSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
+ /// <summary>
+ /// 鎵ц鑷姩鎷嗗寘閫昏緫
+ /// </summary>
+ private async Task<SplitResultDto> ExecuteAutoSplitLogic(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail,
decimal splitQuantity, string palletCode)
{
+ _logger.LogInformation($"寮�濮嬫墽琛岃嚜鍔ㄦ媶鍖呴�昏緫 - 鍘熸潯鐮�: {stockDetail.Barcode}, 鎷嗗寘鏁伴噺: {splitQuantity}");
+
// 鐢熸垚鏂版潯鐮�
string newBarcode = await GenerateNewBarcode();
- // 鍒涘缓鏂板簱瀛樻槑缁�
+ // 閲嶈淇锛氳褰曟媶鍖呭墠鐨勫垎閰嶆暟閲�
+ decimal originalAssignQtyBefore = lockInfo.AssignQuantity;
+ decimal originalOrderQtyBefore = lockInfo.OrderQuantity;
+
+ // 1. 鍒涘缓鏂板簱瀛樻槑缁嗭紙鍓╀綑閮ㄥ垎锛�
var newStockDetail = new Dt_StockInfoDetail
{
StockId = stockDetail.StockId,
@@ -479,162 +1562,410 @@
Barcode = newBarcode,
Status = (int)StockStatusEmun.鍑哄簱閿佸畾,
SupplyCode = stockDetail.SupplyCode,
- Unit = stockDetail.Unit
+ Unit = stockDetail.Unit,
+ BarcodeQty = stockDetail.BarcodeQty,
+ BarcodeUnit = stockDetail.BarcodeUnit,
+ BusinessType = stockDetail.BusinessType,
+ InboundOrderRowNo = stockDetail.InboundOrderRowNo,
};
await _stockInfoDetailService.Db.Insertable(newStockDetail).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏂板簱瀛樻槑缁� - 鏉$爜: {newBarcode}, 搴撳瓨鏁伴噺: {splitQuantity}");
- // 鏇存柊鍘熷簱瀛樻槑缁�
- stockDetail.StockQuantity -= splitQuantity;
- await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+ // 2. 鏇存柊鍘熷簱瀛樻槑缁�
+ // 閲嶈淇锛氬師搴撳瓨鏁伴噺璁剧疆涓哄垎閰嶆暟閲忥紙淇濇寔涓嶅彉锛�
+ decimal originalStockQtyBefore = stockDetail.StockQuantity;
+ // 娉ㄦ剰锛氳嚜鍔ㄦ媶鍖呮椂锛屽師搴撳瓨鏁伴噺淇濇寔涓嶅彉锛屽洜涓烘垜浠鍒嗘嫞鐨勫氨鏄垎閰嶆暟閲�
+ // stockDetail.StockQuantity 淇濇寔涓嶅彉
- // 鍒涘缓鏂伴攣瀹氫俊鎭�
+ _logger.LogInformation($"鍘熷簱瀛樻槑缁嗕繚鎸佷笉鍙� - 搴撳瓨鏁伴噺: {stockDetail.StockQuantity}");
+
+ // 3. 鍒涘缓鏂伴攣瀹氫俊鎭紙鍓╀綑閮ㄥ垎锛�
var newLockInfo = new Dt_OutStockLockInfo
{
OrderNo = lockInfo.OrderNo,
OrderDetailId = lockInfo.OrderDetailId,
OutboundBatchNo = lockInfo.OutboundBatchNo,
MaterielCode = lockInfo.MaterielCode,
+ MaterielName = lockInfo.MaterielName,
StockId = lockInfo.StockId,
OrderQuantity = splitQuantity,
AssignQuantity = splitQuantity,
PickedQty = 0,
LocationCode = lockInfo.LocationCode,
- PalletCode = palletCode,
+ PalletCode = lockInfo.PalletCode,
+ TaskNum = lockInfo.TaskNum,
Status = (int)OutLockStockStatusEnum.鍑哄簱涓�,
+ Unit = lockInfo.Unit,
+ SupplyCode = lockInfo.SupplyCode,
+ OrderType = lockInfo.OrderType,
CurrentBarcode = newBarcode,
+ IsSplitted = 1,
+ ParentLockId = lockInfo.Id,
Operator = App.User.UserName,
+ FactoryArea = lockInfo.FactoryArea,
+ lineNo = lockInfo.lineNo,
+ WarehouseCode = lockInfo.WarehouseCode,
+ BarcodeQty = lockInfo.BarcodeQty,
+ BarcodeUnit = lockInfo.BarcodeUnit,
};
+
await _outStockLockInfoService.Db.Insertable(newLockInfo).ExecuteCommandAsync();
+ _logger.LogInformation($"鍒涘缓鏂伴攣瀹氫俊鎭� - 鏉$爜: {newBarcode}, 鍒嗛厤鏁伴噺: {splitQuantity}");
- // 鏇存柊鍘熼攣瀹氫俊鎭�
- lockInfo.AssignQuantity -= splitQuantity;
- lockInfo.OrderQuantity -= splitQuantity;
- await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+ // 4. 閲嶈淇锛氳嚜鍔ㄦ媶鍖呮椂锛屽師閿佸畾淇℃伅鐨勫垎閰嶆暟閲忎繚鎸佷笉鍙�
+ // 鍥犱负鑷姩鎷嗗寘鍚庯紝鍘熸潯鐮佷粛鐒堕渶瑕佽鍒嗘嫞锛屽垎閰嶆暟閲忎笉搴旇鏀瑰彉
+ _logger.LogInformation($"鍘熼攣瀹氫俊鎭繚鎸佷笉鍙� - 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 璁㈠崟鏁伴噺: {lockInfo.OrderQuantity}");
- // 璁板綍鎷嗗寘鍘嗗彶
- await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode);
+ // 5. 璁板綍鎷嗗寘鍘嗗彶
+ await RecordSplitHistory(lockInfo, stockDetail, splitQuantity, newBarcode, true, originalStockQtyBefore);
+
+ _logger.LogInformation($"鑷姩鎷嗗寘閫昏緫鎵ц瀹屾垚");
return new SplitResultDto { NewBarcode = newBarcode };
}
- private async Task ExecuteCancelSplitLogic(Dt_SplitPackageRecord splitRecord, Dt_OutStockLockInfo newLockInfo, Dt_StockInfoDetail newStockDetail)
+
+ #endregion
+
+ #region 鏍稿績閫昏緫鏂规硶
+
+ private async Task<PickingResult> ExecutePickingLogic(
+ Dt_OutStockLockInfo lockInfo, Dt_OutboundOrderDetail orderDetail,
+ Dt_StockInfoDetail stockDetail, decimal actualPickedQty)
{
- // 鎭㈠鍘熷簱瀛�
- var originalStock = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
- .FirstAsync(x => x.Barcode == splitRecord.OriginalBarcode && x.StockId == splitRecord.StockId);
+ _logger.LogInformation($"寮�濮嬫墽琛屽垎鎷i�昏緫 - 鏉$爜: {stockDetail.Barcode}, 鍒嗛厤鏁伴噺: {lockInfo.AssignQuantity}, 瀹為檯鎷i��: {actualPickedQty}");
- originalStock.StockQuantity += splitRecord.SplitQty;
- await _stockInfoDetailService.Db.Updateable(originalStock).ExecuteCommandAsync();
+ // 閲嶈淇锛氬啀娆¢獙璇佽鍗曟槑缁嗙殑鍒嗛厤鏁伴噺锛堥槻姝㈠苟鍙戞搷浣滐級
+ if (orderDetail.AllocatedQuantity < actualPickedQty)
+ {
+ throw new InvalidOperationException($"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫� {actualPickedQty}锛屽彲鐢ㄥ垎閰嶆暟閲� {orderDetail.AllocatedQuantity}");
+ }
- // 鎭㈠鍘熼攣瀹氫俊鎭�
- var originalLockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
- .FirstAsync(x => x.Id == splitRecord.OutStockLockInfoId);
+ if (orderDetail.LockQuantity < actualPickedQty)
+ {
+ throw new InvalidOperationException($"璁㈠崟鏄庣粏閿佸畾鏁伴噺涓嶈冻锛岄渶瑕佹嫞閫� {actualPickedQty}锛屽彲鐢ㄩ攣瀹氭暟閲� {orderDetail.LockQuantity}");
+ }
- originalLockInfo.AssignQuantity += splitRecord.SplitQty;
- originalLockInfo.OrderQuantity += splitRecord.SplitQty;
- await _outStockLockInfoService.Db.Updateable(originalLockInfo).ExecuteCommandAsync();
+ // 1. 鏇存柊閿佸畾淇℃伅
+ lockInfo.PickedQty += actualPickedQty;
+ _logger.LogInformation($"鏇存柊閿佸畾淇℃伅 - 宸叉嫞閫夋暟閲忎粠 {lockInfo.PickedQty - actualPickedQty} 澧炲姞鍒� {lockInfo.PickedQty}");
- // 鍒犻櫎鏂板簱瀛樻槑缁�
- await _stockInfoDetailService.Db.Deleteable<Dt_StockInfoDetail>()
- .Where(x => x.Barcode == newLockInfo.CurrentBarcode)
- .ExecuteCommandAsync();
+ // 鍑嗙‘鍒ゆ柇鎷i�夊畬鎴愮姸鎬�
+ if (Math.Abs(lockInfo.PickedQty - lockInfo.AssignQuantity) < 0.001m)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.鎷i�夊畬鎴�;
+ _logger.LogInformation($"閿佸畾淇℃伅鐘舵�佹洿鏂颁负鎷i�夊畬鎴�");
+ }
+ else if (lockInfo.PickedQty > 0)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ _logger.LogInformation($"閿佸畾淇℃伅鐘舵�佷繚鎸佷负鍑哄簱涓紙閮ㄥ垎鎷i�夛級");
+ }
- // 鍒犻櫎鏂伴攣瀹氫俊鎭�
- await _outStockLockInfoService.Db.Deleteable<Dt_OutStockLockInfo>()
- .Where(x => x.Id == newLockInfo.Id)
- .ExecuteCommandAsync();
+ lockInfo.Operator = App.User.UserName;
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
- // 鏍囪鎷嗗寘璁板綍涓哄凡鎾ら攢
- splitRecord.IsReverted = true;
- splitRecord.RevertTime = DateTime.Now;
- splitRecord.RevertOperator = App.User.UserName;
- await _splitPackageService.Db.Updateable(splitRecord).ExecuteCommandAsync();
+ // 2. 鏇存柊搴撳瓨淇℃伅
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+
+ stockDetail.StockQuantity -= actualPickedQty;
+ stockDetail.OutboundQuantity += actualPickedQty;
+
+ _logger.LogInformation($"鏇存柊搴撳瓨淇℃伅 - 搴撳瓨鏁伴噺浠� {originalStockQty} 鍑忓皯鍒� {stockDetail.StockQuantity}");
+ _logger.LogInformation($"鏇存柊搴撳瓨淇℃伅 - 鍑哄簱鏁伴噺浠� {originalOutboundQty} 澧炲姞鍒� {stockDetail.OutboundQuantity}");
+
+ // 鍑嗙‘鍒ゆ柇搴撳瓨鐘舵��
+ if (stockDetail.StockQuantity <= 0)
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱瀹屾垚;
+ _logger.LogInformation($"搴撳瓨鐘舵�佹洿鏂颁负鍑哄簱瀹屾垚");
+ }
+ else
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ _logger.LogInformation($"搴撳瓨鐘舵�佷繚鎸佷负鍑哄簱閿佸畾");
+ }
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鍒嗘嫞閫昏緫鎵ц瀹屾垚 - 鏉$爜: {stockDetail.Barcode}");
+
+ return new PickingResult
+ {
+ FinalLockInfo = lockInfo,
+ ActualPickedQty = actualPickedQty
+ };
}
+ private async Task<RevertPickingResult> RevertPickingData(Dt_PickingRecord pickingRecord)
+ {
+ _logger.LogInformation($"寮�濮嬫仮澶嶆嫞閫夋暟鎹� - 鎷i�夎褰旾D: {pickingRecord.Id}, 鏉$爜: {pickingRecord.Barcode}, 鎷i�夋暟閲�: {pickingRecord.PickQuantity}");
+
+ // 1. 鎭㈠閿佸畾淇℃伅
+ var lockInfo = await _outStockLockInfoService.Db.Queryable<Dt_OutStockLockInfo>()
+ .FirstAsync(x => x.Id == pickingRecord.OutStockLockId);
+
+ if (lockInfo == null)
+ {
+ throw new InvalidOperationException($"鏈壘鍒板搴旂殑閿佸畾淇℃伅锛孖D: {pickingRecord.OutStockLockId}");
+ }
+
+ decimal originalPickedQty = lockInfo.PickedQty;
+ decimal originalAssignQty = lockInfo.AssignQuantity; // 璁板綍鍘熷鍒嗛厤鏁伴噺
+
+ // 閲嶈淇锛氬彧鎭㈠宸叉嫞閫夋暟閲忥紝涓嶄慨鏀瑰垎閰嶆暟閲�
+ lockInfo.PickedQty -= pickingRecord.PickQuantity;
+
+ // 纭繚宸叉嫞閫夋暟閲忎笉浼氫负璐熸暟
+ if (lockInfo.PickedQty < 0)
+ {
+ _logger.LogWarning($"宸叉嫞閫夋暟閲忓嚭鐜拌礋鏁帮紝閲嶇疆涓�0銆傚師鍊�: {lockInfo.PickedQty + pickingRecord.PickQuantity}, 鎭㈠鏁伴噺: {pickingRecord.PickQuantity}");
+ lockInfo.PickedQty = 0;
+ }
+
+ _logger.LogInformation($"鎭㈠閿佸畾淇℃伅 - 宸叉嫞閫夋暟閲忎粠 {originalPickedQty} 鍑忓皯鍒� {lockInfo.PickedQty}");
+ _logger.LogInformation($"閿佸畾淇℃伅鍒嗛厤鏁伴噺淇濇寔涓嶅彉: {originalAssignQty}");
+
+ // 鎭㈠閿佸畾鐘舵��
+ if (lockInfo.PickedQty <= 0)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�;
+ _logger.LogInformation($"閿佸畾淇℃伅鐘舵�佹仮澶嶄负鍑哄簱涓�");
+ }
+ else if (lockInfo.PickedQty < lockInfo.AssignQuantity)
+ {
+ lockInfo.Status = (int)OutLockStockStatusEnum.鍑哄簱涓�; // 閮ㄥ垎鎷i�夌姸鎬�
+ _logger.LogInformation($"閿佸畾淇℃伅鐘舵�佹仮澶嶄负鍑哄簱涓紙閮ㄥ垎鎷i�夛級");
+ }
+
+ await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
+
+ // 2. 鎭㈠搴撳瓨淇℃伅
+ var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
+ .FirstAsync(x => x.Barcode == pickingRecord.Barcode);
+
+ if (stockDetail == null)
+ {
+ throw new InvalidOperationException($"鏈壘鍒板搴旂殑搴撳瓨淇℃伅锛屾潯鐮�: {pickingRecord.Barcode}");
+ }
+
+ decimal originalStockQty = stockDetail.StockQuantity;
+ decimal originalOutboundQty = stockDetail.OutboundQuantity;
+
+ stockDetail.StockQuantity += pickingRecord.PickQuantity;
+ stockDetail.OutboundQuantity -= pickingRecord.PickQuantity;
+
+ // 纭繚鍑哄簱鏁伴噺涓嶄細涓鸿礋鏁�
+ if (stockDetail.OutboundQuantity < 0)
+ {
+ _logger.LogWarning($"鍑哄簱鏁伴噺鍑虹幇璐熸暟锛岄噸缃负0銆傚師鍊�: {stockDetail.OutboundQuantity + pickingRecord.PickQuantity}, 鎭㈠鏁伴噺: {pickingRecord.PickQuantity}");
+ stockDetail.OutboundQuantity = 0;
+ }
+
+ _logger.LogInformation($"鎭㈠搴撳瓨淇℃伅 - 搴撳瓨鏁伴噺浠� {originalStockQty} 澧炲姞鍒� {stockDetail.StockQuantity}");
+ _logger.LogInformation($"鎭㈠搴撳瓨淇℃伅 - 鍑哄簱鏁伴噺浠� {originalOutboundQty} 鍑忓皯鍒� {stockDetail.OutboundQuantity}");
+
+ // 鎭㈠搴撳瓨鐘舵��
+ if (stockDetail.StockQuantity > 0)
+ {
+ stockDetail.Status = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ _logger.LogInformation($"搴撳瓨鐘舵�佹仮澶嶄负鍑哄簱閿佸畾");
+ }
+
+ await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
+
+ _logger.LogInformation($"鎭㈠鎷i�夋暟鎹畬鎴� - 鏉$爜: {pickingRecord.Barcode}");
+
+ return new RevertPickingResult
+ {
+ LockInfo = lockInfo,
+ StockDetail = stockDetail
+ };
+ }
+
#endregion
#region 鏁版嵁鏇存柊鏂规硶
private async Task UpdateBatchAndOrderData(Dt_OutboundBatch batch, Dt_OutboundOrderDetail orderDetail, decimal pickedQty, string orderNo)
{
- // 鏇存柊鎵规瀹屾垚鏁伴噺
+ _logger.LogInformation($"寮�濮嬫洿鏂版壒娆″拰璁㈠崟鏁版嵁 - 鎷i�夋暟閲�: {pickedQty}");
+
+ // 閲嶈淇锛氶獙璇佸垎閰嶆暟閲忎笉浼氬彉鎴愯礋鏁�
+ if (orderDetail.AllocatedQuantity < pickedQty)
+ {
+ throw new InvalidOperationException($"鏇存柊璁㈠崟鏁版嵁鏃跺垎閰嶆暟閲忎笉瓒筹紝闇�瑕佸噺灏� {pickedQty}锛屽綋鍓嶅垎閰嶆暟閲� {orderDetail.AllocatedQuantity}");
+ }
+
+ if (orderDetail.LockQuantity < pickedQty)
+ {
+ throw new InvalidOperationException($"鏇存柊璁㈠崟鏁版嵁鏃堕攣瀹氭暟閲忎笉瓒筹紝闇�瑕佸噺灏� {pickedQty}锛屽綋鍓嶉攣瀹氭暟閲� {orderDetail.LockQuantity}");
+ }
+
+ // 1. 鏇存柊鎵规瀹屾垚鏁伴噺
+ decimal originalBatchCompletedQty = batch.CompletedQuantity;
batch.CompletedQuantity += pickedQty;
+
+ _logger.LogInformation($"鏇存柊鎵规瀹屾垚鏁伴噺 - 浠� {originalBatchCompletedQty} 澧炲姞鍒� {batch.CompletedQuantity}");
+
if (batch.CompletedQuantity >= batch.BatchQuantity)
{
batch.BatchStatus = (int)BatchStatusEnum.宸插畬鎴�;
+ _logger.LogInformation($"鎵规鐘舵�佹洿鏂颁负宸插畬鎴�");
}
await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
- // 鏇存柊璁㈠崟鏄庣粏
+ // 2. 鏇存柊璁㈠崟鏄庣粏
+ decimal originalOverOutQty = orderDetail.OverOutQuantity;
+ decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
+ decimal originalLockQty = orderDetail.LockQuantity;
+
orderDetail.OverOutQuantity += pickedQty;
orderDetail.AllocatedQuantity -= pickedQty;
+ // LockQuantity 鍚屾鍑忓皯
+ orderDetail.LockQuantity = orderDetail.AllocatedQuantity;
+
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 宸插嚭搴撴暟閲忎粠 {originalOverOutQty} 澧炲姞鍒� {orderDetail.OverOutQuantity}");
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 宸插垎閰嶆暟閲忎粠 {originalAllocatedQty} 鍑忓皯鍒� {orderDetail.AllocatedQuantity}");
+ _logger.LogInformation($"鏇存柊璁㈠崟鏄庣粏 - 閿佸畾鏁伴噺浠� {originalLockQty} 鍑忓皯鍒� {orderDetail.LockQuantity}");
+
await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
- // 妫�鏌ヨ鍗曠姸鎬�
+ // 3. 妫�鏌ヨ鍗曠姸鎬�
await CheckAndUpdateOrderStatus(orderNo);
+
+ _logger.LogInformation($"鎵规鍜岃鍗曟暟鎹洿鏂板畬鎴�");
}
- private async Task RevertBatchAndOrderData(Dt_PickingRecord pickingRecord)
+ private async Task RevertBatchAndOrderData(Dt_PickingRecord pickingRecord, RevertPickingResult revertResult)
{
- // 鎭㈠鎵规瀹屾垚鏁伴噺
+ _logger.LogInformation($"寮�濮嬫仮澶嶆壒娆″拰璁㈠崟鏁版嵁");
+
+ // 1. 鎭㈠鎵规瀹屾垚鏁伴噺
var batch = await _outboundBatchRepository.Db.Queryable<Dt_OutboundBatch>()
- .FirstAsync(x => x.BatchNo == pickingRecord.BatchNo);
+ .FirstAsync(x => x.BatchNo == revertResult.LockInfo.OutboundBatchNo);
- batch.CompletedQuantity -= pickingRecord.PickQuantity;
- batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
- await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
+ if (batch != null)
+ {
+ decimal originalCompletedQty = batch.CompletedQuantity;
+ batch.CompletedQuantity -= pickingRecord.PickQuantity;
- // 鎭㈠璁㈠崟鏄庣粏
+ _logger.LogInformation($"鎭㈠鎵规瀹屾垚鏁伴噺 - 浠� {originalCompletedQty} 鍑忓皯鍒� {batch.CompletedQuantity}");
+
+ // 閲嶆柊璁$畻鎵规鐘舵��
+ if (batch.CompletedQuantity <= 0)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鍒嗛厤涓�;
+ _logger.LogInformation($"鎵规鐘舵�佹仮澶嶄负鍒嗛厤涓�");
+ }
+ else if (batch.CompletedQuantity < batch.BatchQuantity)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
+ _logger.LogInformation($"鎵规鐘舵�佹仮澶嶄负鎵ц涓�");
+ }
+
+ await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
+ }
+
+ // 2. 鎭㈠璁㈠崟鏄庣粏
var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
.FirstAsync(x => x.Id == pickingRecord.OrderDetailId);
- orderDetail.OverOutQuantity -= pickingRecord.PickQuantity;
- orderDetail.AllocatedQuantity += pickingRecord.PickQuantity;
- await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+ if (orderDetail != null)
+ {
+ decimal originalOverOutQty = orderDetail.OverOutQuantity;
+ decimal originalAllocatedQty = orderDetail.AllocatedQuantity;
+ decimal originalLockQty = orderDetail.LockQuantity;
- // 閲嶆柊妫�鏌ヨ鍗曠姸鎬�
+ // 閲嶈淇锛氬彧鎭㈠鐩稿叧鏁伴噺锛屽垎閰嶆暟閲忎繚鎸佷笉鍙�
+ orderDetail.OverOutQuantity -= pickingRecord.PickQuantity;
+ // 娉ㄦ剰锛欰llocatedQuantity 鍜� LockQuantity 鍦ㄥ彇娑堝垎鎷f椂涓嶅簲璇ユ敼鍙�
+
+ _logger.LogInformation($"鎭㈠璁㈠崟鏄庣粏 - 宸插嚭搴撴暟閲忎粠 {originalOverOutQty} 鍑忓皯鍒� {orderDetail.OverOutQuantity}");
+ _logger.LogInformation($"璁㈠崟鏄庣粏鍒嗛厤鏁伴噺淇濇寔涓嶅彉: {originalAllocatedQty}");
+ _logger.LogInformation($"璁㈠崟鏄庣粏閿佸畾鏁伴噺淇濇寔涓嶅彉: {originalLockQty}");
+
+ await UpdateBatchAllocateStatus(orderDetail);
+ await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+ }
+
+ // 3. 閲嶆柊妫�鏌ヨ鍗曠姸鎬�
await CheckAndUpdateOrderStatus(pickingRecord.OrderNo);
+
+ _logger.LogInformation($"鎭㈠鎵规鍜岃鍗曟暟鎹畬鎴�");
}
+ private async Task UpdateBatchAllocateStatus(Dt_OutboundOrderDetail orderDetail)
+ {
+ if (orderDetail.AllocatedQuantity >= orderDetail.NeedOutQuantity)
+ {
+ orderDetail.BatchAllocateStatus = OrderDetailStatusEnum.AssignOver.ObjToInt();
+ }
+ else if (orderDetail.AllocatedQuantity > 0)
+ {
+ orderDetail.BatchAllocateStatus = OrderDetailStatusEnum.AssignOverPartial.ObjToInt();
+ }
+ else
+ {
+ orderDetail.BatchAllocateStatus = OrderDetailStatusEnum.New.ObjToInt();
+ }
+ }
private async Task ReleaseLockAndStock(Dt_OutStockLockInfo lockInfo)
{
- // 鎭㈠搴撳瓨鐘舵��
+ // 鎭㈠搴撳瓨鐘舵�� - 鍥炲簱鍚庡簱瀛樺彉涓哄彲鐢ㄧ姸鎬�
var stockDetail = await _stockInfoDetailService.Db.Queryable<Dt_StockInfoDetail>()
.FirstAsync(x => x.Barcode == lockInfo.CurrentBarcode && x.StockId == lockInfo.StockId);
if (stockDetail != null)
{
+ // 鍥炲簱鍚庡簱瀛樼姸鎬佹仮澶嶄负鍏ュ簱瀹屾垚锛堝彲鐢ㄧ姸鎬侊級
stockDetail.Status = (int)StockStatusEmun.鍏ュ簱瀹屾垚;
await _stockInfoDetailService.Db.Updateable(stockDetail).ExecuteCommandAsync();
}
- // 鏇存柊閿佸畾璁板綍鐘舵�佷负鍥炲簱
+ // 鏇存柊閿佸畾璁板綍鐘舵�佷负宸插洖搴�
lockInfo.Status = (int)OutLockStockStatusEnum.宸插洖搴�;
+ lockInfo.Operator = App.User.UserName;
await _outStockLockInfoService.Db.Updateable(lockInfo).ExecuteCommandAsync();
}
- private async Task UpdateBatchStatusForReturn(string batchNo, List<Dt_OutStockLockInfo> returnedLocks)
+ /// <summary>
+ /// 鏇存柊鎵规鐘舵�侊紙鍥炲簱锛�
+ /// </summary>
+ private async Task UpdateBatchStatusForReturn(string outboundBatchNo, List<Dt_OutStockLockInfo> returnedLocks)
{
var batch = await _outboundBatchRepository.Db.Queryable<Dt_OutboundBatch>()
- .FirstAsync(x => x.BatchNo == batchNo);
+ .FirstAsync(x => x.BatchNo == outboundBatchNo);
- // 璁$畻鍥炲簱鏁伴噺
- var returnedQty = returnedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
- batch.CompletedQuantity -= returnedQty;
-
- if (batch.CompletedQuantity <= 0)
+ if (batch != null)
{
- batch.BatchStatus = (int)BatchStatusEnum.宸插洖搴�;
- }
- else
- {
- batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
- }
+ // 璁$畻鍥炲簱鏁伴噺锛堟湭鎷i�夌殑閮ㄥ垎锛�
+ var returnedQty = returnedLocks.Sum(x => x.AssignQuantity - x.PickedQty);
+ batch.CompletedQuantity -= returnedQty;
- batch.Operator = App.User.UserName;
- await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
+ // 鏇存柊鎵规鐘舵��
+ if (batch.CompletedQuantity <= 0)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.宸插洖搴�;
+ }
+ else if (batch.CompletedQuantity < batch.BatchQuantity)
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.鎵ц涓�;
+ }
+ else
+ {
+ batch.BatchStatus = (int)BatchStatusEnum.宸插畬鎴�;
+ }
+
+ batch.Operator = App.User.UserName;
+ await _outboundBatchRepository.Db.Updateable(batch).ExecuteCommandAsync();
+ }
}
+ /// <summary>
+ /// 鏇存柊璁㈠崟鏄庣粏锛堝洖搴撳悗锛�
+ /// </summary>
private async Task UpdateOrderDetailAfterReturn(List<Dt_OutStockLockInfo> returnedLocks)
{
var orderDetailGroups = returnedLocks.GroupBy(x => x.OrderDetailId);
@@ -644,13 +1975,21 @@
var orderDetailId = group.Key;
var returnedQty = group.Sum(x => x.AssignQuantity - x.PickedQty);
- await _outboundOrderDetailService.Db.Updateable<Dt_OutboundOrderDetail>()
- .SetColumns(x => x.AllocatedQuantity == x.AllocatedQuantity - returnedQty)
- .Where(x => x.Id == orderDetailId)
- .ExecuteCommandAsync();
+ var orderDetail = await _outboundOrderDetailService.Db.Queryable<Dt_OutboundOrderDetail>()
+ .FirstAsync(x => x.Id == orderDetailId);
+
+ if (orderDetail != null)
+ {
+ orderDetail.AllocatedQuantity -= returnedQty;
+ // LockQuantity 鍚屾鍑忓皯锛屼繚鎸佷笌宸插垎閰嶆暟閲忎竴鑷�
+ orderDetail.LockQuantity = orderDetail.AllocatedQuantity;
+
+ await UpdateBatchAllocateStatus(orderDetail);
+
+ await _outboundOrderDetailService.Db.Updateable(orderDetail).ExecuteCommandAsync();
+ }
}
}
-
#endregion
#region 杈呭姪鏂规硶
@@ -661,7 +2000,7 @@
return "WSLOT" + DateTime.Now.ToString("yyyyMMdd") + seq.ToString().PadLeft(5, '0');
}
- private async Task RecordSplitHistory(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail, decimal splitQty, string newBarcode)
+ private async Task RecordSplitHistory(Dt_OutStockLockInfo lockInfo, Dt_StockInfoDetail stockDetail, decimal splitQty, string newBarcode, bool isAutoSplit, decimal? originalStockQuantity = null)
{
var splitHistory = new Dt_SplitPackageRecord
{
@@ -673,7 +2012,11 @@
NewBarcode = newBarcode,
SplitQty = splitQty,
SplitTime = DateTime.Now,
- Status = (int)SplitPackageStatusEnum.宸叉媶鍖�
+ Status = (int)SplitPackageStatusEnum.宸叉媶鍖�,
+ IsAutoSplit = isAutoSplit ,
+ // SplitType = isAutoSplit ? "鑷姩鎷嗗寘" : "鎵嬪姩鎷嗗寘"
+ OriginalStockQuantity = originalStockQuantity ?? stockDetail.StockQuantity,
+ //RemainingStockQuantity = stockDetail.StockQuantity - splitQty
};
await _splitPackageService.Db.Insertable(splitHistory).ExecuteCommandAsync();
@@ -693,6 +2036,13 @@
PickTime = DateTime.Now,
Operator = App.User.UserName,
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,
// IsCancelled = false
};
@@ -716,10 +2066,56 @@
.Where(x => x.OrderNo == orderNo)
.ExecuteCommandAsync();
}
-
+ private string GetPalletStatusText(PalletStatusEnum status)
+ {
+ return status switch
+ {
+ PalletStatusEnum.鏈紑濮� => "鏈紑濮�",
+ PalletStatusEnum.鎷i�変腑 => "鎷i�変腑",
+ PalletStatusEnum.宸插畬鎴� => "宸插畬鎴�",
+ PalletStatusEnum.鏃犱换鍔� => "鏃犱换鍔�",
+ _ => "鏈煡"
+ };
+ }
#endregion
+
#region DTO绫�
+ /// <summary>
+ /// 鏉$爜鐘舵�佷俊鎭疍TO
+ /// </summary>
+ public class BarcodeStatusInfoDto
+ {
+ public string Barcode { get; set; }
+ public string OrderNo { get; set; }
+ public bool IsOriginalBarcode { get; set; }
+ public int SplitChainCount { get; set; }
+ public bool HasBeenPicked { get; set; }
+ public decimal TotalPickedQuantity { get; set; }
+ public int PickRecordCount { get; set; }
+ public int LockInfoStatus { get; set; }
+ public decimal LockInfoPickedQty { get; set; }
+ public decimal LockInfoAssignQty { get; set; }
+ public decimal StockQuantity { get; set; }
+ public int StockStatus { get; set; }
+ public bool CanCancelSplit { get; set; }
+ public bool NeedCancelPickFirst { get; set; }
+ public List<string> OperationSuggestions { get; set; } = new List<string>();
+ }
+ public class PickedBarcodeInfo
+ {
+ public string Barcode { get; set; }
+ public decimal PickedQty { get; set; }
+ public int PickRecordCount { get; set; }
+ }
+ /// <summary>
+ /// 鑷姩鎷嗗寘缁撴灉
+ /// </summary>
+ public class AutoSplitResult
+ {
+ public string NewBarcode { get; set; }
+ public decimal SplitQuantity { get; set; }
+ }
public class PickingResult
{
--
Gitblit v1.9.3