From 981a80940e47409300c09847684ca530f75b4a5f Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 10 一月 2025 23:56:33 +0800
Subject: [PATCH] 优化WCS辅料出库逻辑
---
代码管理/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs | 228 ++++++++++++++++++++++++++++++++++++++++++++------------
1 files changed, 179 insertions(+), 49 deletions(-)
diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
index e26a402..67f133f 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/TaskService_Outbound.cs"
@@ -13,18 +13,71 @@
using WIDESEA_Common.TaskEnum;
using WIDESEA_Common.OrderEnum;
using WIDESEA_Common.StockEnum;
+using WIDESEA_Common.CommonEnum;
+using WIDESEA_Common.LocationEnum;
namespace WIDESEA_TaskInfoService
{
public partial class TaskService
{
-
+ /// <summary>
+ /// 閫夋嫨搴撳瓨鐢熸垚鍑哄簱浠诲姟
+ /// </summary>
+ /// <param name="id"></param>
+ /// <returns></returns>
+ public WebResponseContent Outbound(int id)
+ {
+ WebResponseContent content = new WebResponseContent();
+ try
+ {
+ Dt_StockInfo stockInfo = _stockRepository.StockInfoRepository.Db.Queryable<Dt_StockInfo>().Where(x=>x.Id==id).Includes(x=>x.Details).First();
+ if (stockInfo == null)
+ {
+ return content.Error($"鏈壘鍒板簱瀛�");
+ }
+ Dt_LocationInfo locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
+ if (locationInfo!=null && (locationInfo.EnableStatus == EnableStatusEnum.OnlyOut.ObjToInt() || locationInfo.EnableStatus == EnableStatusEnum.Normal.ObjToInt()) && locationInfo.LocationStatus==LocationStatusEnum.InStock.ObjToInt() && stockInfo.StockStatus==StockStatusEmun.鍏ュ簱瀹屾垚.ObjToInt())
+ {
+ List<Dt_Task> tasks = GetTasks(new List<Dt_StockInfo>() { stockInfo }, TaskTypeEnum.Outbound);
+ if (tasks == null || tasks.Count <= 0)
+ {
+ return content.Error($"鐢熸垚浠诲姟澶辫触");
+ }
+ //澶勭悊搴撳瓨鏁版嵁
+ stockInfo.StockStatus = (int)StockStatusEmun.鍑哄簱閿佸畾;
+ LocationStatusEnum locationStatus = (LocationStatusEnum)locationInfo.LocationStatus;
+ locationInfo.LocationStatus = (int)LocationStatusEnum.Lock;
+ //鍒ゆ柇鏄惁鏈夊嚭搴撳崟淇℃伅
+ _unitOfWorkManage.BeginTran();
+ //鏇存柊搴撳瓨鐘舵��
+ _stockRepository.StockInfoRepository.UpdateData(stockInfo);
+ //鏇存柊璐т綅鐘舵��
+ _basicService.LocationInfoService.UpdateLocationStatus(locationInfo, stockInfo.PalletType, LocationStatusEnum.Lock, stockInfo.WarehouseId);
+ //鏂板缓浠诲姟
+ BaseDal.AddData(tasks);
+ //鍔犲叆璐т綅鍙樺姩璁板綍
+ _recordService.LocationStatusChangeRecordSetvice.AddLocationStatusChangeRecord(locationInfo, locationStatus, LocationStatusEnum.Lock, LocationChangeType.OutboundAssignLocation, stockInfo.Details.FirstOrDefault()?.OrderNo ?? "", tasks[0].TaskNum);
+ _unitOfWorkManage.CommitTran();
+ PushTasksToWCS(tasks);
+ content.OK();
+ }
+ else
+ {
+ content.Error($"璐т綅鍑哄簱鏉′欢涓嶆弧瓒�");
+ }
+ }
+ catch (Exception ex)
+ {
+ content.Error(ex.Message);
+ }
+ return content;
+ }
/// <summary>
/// 搴撳瓨鏁版嵁杞嚭搴撲换鍔�
/// </summary>
/// <param name="stockInfos"></param>
/// <returns></returns>
- public List<Dt_Task> GetTasks(List<Dt_StockInfo> stockInfos)
+ public List<Dt_Task> GetTasks(List<Dt_StockInfo> stockInfos, TaskTypeEnum taskType)
{
List<Dt_Task> tasks = new List<Dt_Task>();
for (int i = 0; i < stockInfos.Count; i++)
@@ -34,22 +87,25 @@
if (stockInfo != null)
{
Dt_LocationInfo locationInfo = _basicService.LocationInfoService.Repository.QueryFirst(x => x.LocationCode == stockInfo.LocationCode);
- Dt_Task task = new()
+ if (!tasks.Exists(x => x.PalletCode == stockInfo.PalletCode))
{
- CurrentAddress = stockInfo.LocationCode,
- Grade = 0,
- PalletCode = stockInfo.PalletCode,
- NextAddress = "",
- Roadway = locationInfo.RoadwayNo,
- SourceAddress = stockInfo.LocationCode,
- TargetAddress = "",
- TaskStatus = TaskOutStatusEnum.OutNew.ObjToInt(),
- TaskType = TaskOutboundTypeEnum.Outbound.ObjToInt(),
- TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
- PalletType = stockInfo.PalletType,
- WarehouseId = stockInfo.WarehouseId,
- };
- tasks.Add(task);
+ Dt_Task task = new()
+ {
+ CurrentAddress = stockInfo.LocationCode,
+ Grade = 0,
+ PalletCode = stockInfo.PalletCode,
+ NextAddress = "",
+ Roadway = locationInfo.RoadwayNo,
+ SourceAddress = stockInfo.LocationCode,
+ TargetAddress = "",
+ TaskStatus = TaskStatusEnum.New.ObjToInt(),
+ TaskType = taskType.ObjToInt(),
+ TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)),
+ PalletType = stockInfo.PalletType,
+ WarehouseId = stockInfo.WarehouseId,
+ };
+ tasks.Add(task);
+ }
}
}
return tasks;
@@ -85,7 +141,7 @@
(List<Dt_StockInfo>, Dt_OutboundOrderDetail, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetail, stockSelectViews);
if (result.Item1 != null && result.Item1.Count > 0)
{
- tasks = GetTasks(result.Item1);
+ tasks = GetTasks(result.Item1, TaskTypeEnum.Outbound);
result.Item2.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
result.Item3.ForEach(x =>
{
@@ -108,11 +164,70 @@
if (stockLockInfos != null && stockLockInfos.Count > 0)
{
List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
- tasks = GetTasks(stocks);
+ tasks = GetTasks(stocks, TaskTypeEnum.Outbound);
}
}
return (tasks, stockInfos, orderDetail == null ? null : new List<Dt_OutboundOrderDetail> { orderDetail }, outStockLockInfos, locationInfos);
+ }
+
+ /// <summary>
+ /// 鍑哄簱浠诲姟鏁版嵁澶勭悊
+ /// </summary>
+ /// <param name="orderDetailId"></param>
+ /// <param name="stockSelectViews"></param>
+ /// <returns></returns>
+ /// <exception cref="Exception"></exception>
+ public (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) OutboundTaskDataHandle(int[] keys)
+ {
+ List<Dt_Task> tasks = new List<Dt_Task>();
+ List<Dt_OutboundOrderDetail> outboundOrderDetails = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => keys.Contains(x.Id));
+
+ if (outboundOrderDetails == null || outboundOrderDetails.Count == 0)
+ {
+ throw new Exception("鏈壘鍒板嚭搴撳崟鏄庣粏淇℃伅");
+ }
+
+ List<Dt_StockInfo>? stockInfos = null;
+ List<Dt_OutboundOrderDetail>? orderDetails = null;
+ List<Dt_OutStockLockInfo>? outStockLockInfos = null;
+ List<Dt_LocationInfo>? locationInfos = null;
+ //if (outboundOrderDetail.OrderDetailStatus == OrderDetailStatusEnum.New.ObjToInt())
+ {
+ (List<Dt_StockInfo>, List<Dt_OutboundOrderDetail>, List<Dt_OutStockLockInfo>, List<Dt_LocationInfo>) result = _outboundService.OutboundOrderDetailService.AssignStockOutbound(outboundOrderDetails);
+ if (result.Item1 != null && result.Item1.Count > 0)
+ {
+ tasks = GetTasks(result.Item1, TaskTypeEnum.Outbound);
+ result.Item2.ForEach(x =>
+ {
+ x.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+ });
+ result.Item3.ForEach(x =>
+ {
+ x.Status = OutLockStockStatusEnum.鍑哄簱涓�.ObjToInt();
+ });
+
+ stockInfos = result.Item1;
+ orderDetails = result.Item2;
+ outStockLockInfos = result.Item3;
+ locationInfos = result.Item4;
+ }
+ else
+ {
+ throw new Exception("鏃犲簱瀛�");
+ }
+ }
+ //else
+ //{
+ // List<Dt_OutStockLockInfo> stockLockInfos = _outboundService.OutboundStockLockInfoService.GetByOrderDetailId(outboundOrderDetail.OrderId, OutLockStockStatusEnum.宸插垎閰�);
+ // if (stockLockInfos != null && stockLockInfos.Count > 0)
+ // {
+ // List<Dt_StockInfo> stocks = _stockService.StockInfoService.Repository.GetStockInfosByPalletCodes(stockLockInfos.Select(x => x.PalletCode).Distinct().ToList());
+ // tasks = GetTasks(stocks);
+ // }
+ //}
+
+ return (tasks, stockInfos, orderDetails, outStockLockInfos, locationInfos);
}
/// <summary>
@@ -153,19 +268,15 @@
_unitOfWorkManage.BeginTran();
BaseDal.AddData(tasks);
- if (stockInfos != null && outboundOrderDetails != null && outStockLockInfos != null && locationInfos != null)
+ if (stockInfos != null && stockInfos.Count > 0 && outboundOrderDetails != null && outboundOrderDetails.Count > 0 && outStockLockInfos != null && outStockLockInfos.Count > 0 && locationInfos != null && locationInfos.Count > 0)
{
WebResponseContent content = _outboundService.OutboundOrderDetailService.LockOutboundStockDataUpdate(stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos, tasks: tasks);
- if (content.Status)
- {
- _unitOfWorkManage.CommitTran();
- }
- else
+ if (!content.Status)
{
_unitOfWorkManage.RollbackTran();
+ return content;
}
- return content;
}
else if (outboundOrderDetails != null && outboundOrderDetails.Count > 0)
{
@@ -177,6 +288,7 @@
_outboundService.OutboundOrderDetailService.Repository.UpdateData(outboundOrderDetails);
}
_unitOfWorkManage.CommitTran();
+ PushTasksToWCS(tasks);
return WebResponseContent.Instance.OK();
}
catch (Exception ex)
@@ -190,7 +302,7 @@
/// <summary>
/// 鐢熸垚鍑哄簱浠诲姟
/// </summary>
- /// <param name="keys"></param>
+ /// <param name="keys">鍑哄簱鍗曟槑缁嗕富閿�</param>
/// <returns></returns>
public WebResponseContent GenerateOutboundTask(int[] keys)
{
@@ -202,29 +314,27 @@
List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
List<Dt_OutStockLockInfo> outStockLockInfos = new List<Dt_OutStockLockInfo>();
List<Dt_LocationInfo> locationInfos = new List<Dt_LocationInfo>();
- foreach (int key in keys)
+
+ (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(keys);
+ if (result.Item2 != null && result.Item2.Count > 0)
{
- (List<Dt_Task>, List<Dt_StockInfo>?, List<Dt_OutboundOrderDetail>?, List<Dt_OutStockLockInfo>?, List<Dt_LocationInfo>?) result = OutboundTaskDataHandle(key, stockSelectViews);
- if (result.Item2 != null && result.Item2.Count > 0)
- {
- stockInfos.AddRange(result.Item2);
- }
- if (result.Item3 != null && result.Item3.Count > 0)
- {
- outboundOrderDetails.AddRange(result.Item3);
- }
- if (result.Item4 != null && result.Item4.Count > 0)
- {
- outStockLockInfos.AddRange(result.Item4);
- }
- if (result.Item5 != null && result.Item5.Count > 0)
- {
- locationInfos.AddRange(result.Item5);
- }
- if (result.Item1 != null && result.Item1.Count > 0)
- {
- tasks.AddRange(result.Item1);
- }
+ stockInfos.AddRange(result.Item2);
+ }
+ if (result.Item3 != null && result.Item3.Count > 0)
+ {
+ outboundOrderDetails.AddRange(result.Item3);
+ }
+ if (result.Item4 != null && result.Item4.Count > 0)
+ {
+ outStockLockInfos.AddRange(result.Item4);
+ }
+ if (result.Item5 != null && result.Item5.Count > 0)
+ {
+ locationInfos.AddRange(result.Item5);
+ }
+ if (result.Item1 != null && result.Item1.Count > 0)
+ {
+ tasks.AddRange(result.Item1);
}
WebResponseContent content = GenerateOutboundTaskDataUpdate(tasks, stockInfos, outboundOrderDetails, outStockLockInfos, locationInfos);
@@ -236,5 +346,25 @@
return WebResponseContent.Instance.Error(ex.Message);
}
}
+
+ /// <summary>
+ /// 鐢熸垚鍑哄簱浠诲姟
+ /// </summary>
+ /// <param name="outboundId">鍑哄簱鍗曚富閿�</param>
+ /// <returns></returns>
+ public WebResponseContent GenerateOutboundTaskByHeadId(int outboundId)
+ {
+ try
+ {
+ List<int> keys = _outboundService.OutboundOrderDetailService.Repository.QueryData(x => x.Id, x => x.OrderId == outboundId);
+
+ return GenerateOutboundTask(keys.ToArray());
+ }
+ catch (Exception ex)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return WebResponseContent.Instance.Error(ex.Message);
+ }
+ }
}
}
\ No newline at end of file
--
Gitblit v1.9.3