From 557f7f6079c30cd6fe8d6005cea3d89468bbcd31 Mon Sep 17 00:00:00 2001
From: heshaofeng <heshaofeng@hnkhzn.com>
Date: 星期一, 09 三月 2026 09:23:13 +0800
Subject: [PATCH] 代码优化
---
项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundService.cs | 181 +++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 172 insertions(+), 9 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/OutboundService.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/OutboundService.cs"
index 6cf7303..96577c1 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/OutboundService.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/OutboundService.cs"
@@ -1,14 +1,16 @@
-锘縰sing System.Reflection.Emit;
-using AutoMapper;
+锘縰sing AutoMapper;
using Dm.filter;
using MailKit.Search;
using Mapster;
using Microsoft.IdentityModel.Tokens;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
+using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
using Org.BouncyCastle.Asn1.Ocsp;
using Org.BouncyCastle.Crypto;
using SqlSugar;
+using System;
+using System.Reflection.Emit;
using WIDESEA_BasicService;
using WIDESEA_Common.CommonEnum;
using WIDESEA_Common.LocationEnum;
@@ -29,6 +31,7 @@
using WIDESEA_IRecordService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
+using WIDESEA_Model.Models.Basic;
using WIDESEA_Model.Models.Check;
using static HslCommunication.Profinet.Knx.KnxCode;
@@ -65,6 +68,8 @@
private readonly IRepository<Dt_AllocateMaterialInfo> _allocateMaterialInfoRepository;
public readonly IRepository<Dt_InboundOrderDetail> _inboundOrderDetailRepository;
public readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+ public readonly IRepository<Dt_WarehouseArea> _warehouseAreaRepository;
+ public readonly IRepository<Dt_LocationType> _locationTypeRepository;
private Dictionary<string, string> stations = new Dictionary<string, string>
{
@@ -78,7 +83,7 @@
{"3-1","3-5" },
};
- public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository)
+ public OutboundService(IMapper mapper, IUnitOfWorkManage unitOfWorkManage, IRepository<Dt_OutboundOrderDetail> detailRepository, IRepository<Dt_OutboundOrder> outboundRepository, IRepository<Dt_OutStockLockInfo> outboundLockInfoRepository, IRepository<Dt_StockInfo> stockInfoRepository, IRepository<Dt_StockInfoDetail> stockDetailRepository, IRepository<Dt_StockQuantityChangeRecord> stockChangeRepository, IRepository<Dt_StockInfoDetail_Hty> stockDetailHistoryRepository, IBasicService basicService, IOutboundOrderDetailService outboundOrderDetailService, IOutboundOrderService outboundOrderService, IOutStockLockInfoService outboundStockLockInfoService, IFeedbackMesService feedbackMesService, IRepository<Dt_Task> taskRepository, ILocationInfoService locationInfoService, IESSApiService eSSApiService, IRepository<Dt_AllocateOrder> allocateOrderRepository, IRepository<Dt_AllocateMaterialInfo> allocateMaterialInfoRepository, IRepository<Dt_InboundOrderDetail> inboundOrderDetailRepository, IRepository<Dt_InboundOrder> inboundOrderRepository, IRepository<Dt_LocationType> locationTypeRepository, IRepository<Dt_WarehouseArea> warehouseAreaRepository)
{
_mapper = mapper;
_unitOfWorkManage = unitOfWorkManage;
@@ -103,6 +108,8 @@
_allocateMaterialInfoRepository = allocateMaterialInfoRepository;
_inboundOrderDetailRepository = inboundOrderDetailRepository;
_inboundOrderRepository = inboundOrderRepository;
+ _locationTypeRepository = locationTypeRepository;
+ _warehouseAreaRepository = warehouseAreaRepository;
}
public WebResponseContent PrintFromData (string barcode)
@@ -144,6 +151,14 @@
PickingOutboundResponseDTO response = new PickingOutboundResponseDTO();
decimal totalNeedAllocate = 0; // 鎬婚渶姹傚垎閰嶉噺
decimal totalActualAllocate = 0; // 瀹為檯鎬诲垎閰嶉噺
+ string targetWarehouse = string.Empty;// 鐩爣浠撳簱
+ string targetLocationCode = string.Empty; // 鐩爣璐т綅
+ bool isWholeCaseOutbound = false; // 鏄惁鏁寸鍑哄簱
+ List<string> wholeCasePallets = new List<string>();
+ Dictionary<string, string> palletLocationMap = new Dictionary<string, string>();
+ Dictionary<string, bool> palletIsWholeCaseMap = new Dictionary<string, bool>();
+ int? targetLocationType = null;
+
try
{
@@ -159,6 +174,7 @@
// 璁板綍鎬婚渶姹傛暟閲�
totalNeedAllocate = calculationResult.MaterielCalculations.Sum(x => x.UnallocatedQuantity);
+
// 2. 澶勭悊鐗╂枡鍒嗛厤
List<PickedStockDetailDTO> pickedDetails = new List<PickedStockDetailDTO>();
Dt_OutboundOrder outboundOrder = calculationResult.OutboundOrder;
@@ -192,11 +208,116 @@
materielCalc.OutStockLockInfos.Add(item);
}
outStockLockInfos.Add(item);
- }
+
+ if (outboundOrder.OrderType == 117)
+ {
+ // 鍖归厤褰撳墠鍗曟嵁鐨勯攣瀹氳褰�
+ if (outboundOrder.OrderNo == item.OrderNo)
+ {
+ // 鏌ヨ搴撳瓨淇℃伅
+ var stockInfo = _stockInfoRepository.QueryFirst(x => x.PalletCode == item.PalletCode);
+ if (stockInfo == null)
+ {
+ content = WebResponseContent.Instance.Error($"鎵樼洏{item.PalletCode}鏈煡璇㈠埌搴撳瓨淇℃伅锛屾棤娉曞鐞嗘暣绠卞嚭搴�");
+ _unitOfWorkManage.RollbackTran();
+ return content;
+ }
+
+ // 璁$畻搴撳瓨鎬婚噺锛屽垽鏂槸鍚︽暣绠憋紙澧炲姞0鍊间繚鎶わ級
+ decimal stockQuantity = _stockDetailRepository.QueryData(x => x.StockId == stockInfo.Id).Sum(x => x.StockQuantity);
+ if (stockQuantity > 0 && stockQuantity == item.AssignQuantity)
+ {
+ // 鏍囪褰撳墠鎵樼洏涓烘暣绠憋紙鏍稿績淇锛氭寜鎵樼洏缁村害璁板綍鐘舵�侊級
+ if (!palletIsWholeCaseMap.ContainsKey(item.PalletCode))
+ {
+ palletIsWholeCaseMap.Add(item.PalletCode, true);
+ }
+ else
+ {
+ palletIsWholeCaseMap[item.PalletCode] = true;
+ }
+
+ // 鐩爣浠撳簱/璐т綅绫诲瀷鍙煡璇竴娆★紙鎬ц兘浼樺寲+绌哄�间繚鎶わ級
+ if (string.IsNullOrEmpty(targetWarehouse))
+ {
+ targetWarehouse = GetToWarehouseByOrderNo(request.OrderNo);
+ if (string.IsNullOrEmpty(targetWarehouse))
+ {
+ content = WebResponseContent.Instance.Error("鏅轰粨璋冩櫤浠撴暣绠卞嚭搴撳崟鎹湭閰嶇疆鐩爣浠撳簱");
+ _unitOfWorkManage.RollbackTran();
+ return content;
+ }
+
+ // 鏇挎崲First()涓篎irstOrDefault()锛岄伩鍏嶇┖鍊煎紓甯�
+ string warehouseAreaName = _warehouseAreaRepository.Db.Queryable<Dt_WarehouseArea>()
+ .Where(x => x.Code == targetWarehouse)
+ .Select(x => x.Name)
+ .First();
+ if (string.IsNullOrEmpty(warehouseAreaName))
+ {
+ content = WebResponseContent.Instance.Error($"鐩爣浠撳簱{targetWarehouse}鏈煡璇㈠埌瀵瑰簲鐨勫簱鍖哄悕绉�");
+ _unitOfWorkManage.RollbackTran();
+ return content;
+ }
+
+ int? locationType = _locationTypeRepository.Db.Queryable<Dt_LocationType>()
+ .Where(x => string.Equals(x.LocationTypeDesc, warehouseAreaName, StringComparison.OrdinalIgnoreCase))
+ .Select(x => x.LocationType)
+ .First();
+ if (!locationType.HasValue)
+ {
+ content = WebResponseContent.Instance.Error($"搴撳尯{warehouseAreaName}鏈尮閰嶅埌瀵瑰簲鐨勮揣浣嶇被鍨�");
+ _unitOfWorkManage.RollbackTran();
+ return content;
+ }
+ targetLocationType = locationType.Value;
+ }
+
+ // 鍒嗛厤鐩爣璐т綅锛堟瘡涓墭鐩樼嫭绔嬭揣浣嶏級
+ if (!palletLocationMap.ContainsKey(item.PalletCode) && targetLocationType.HasValue)
+ {
+ Dt_LocationInfo locationInfo = _locationInfoService.AssignLocation(targetLocationType.Value);
+ if (locationInfo == null || string.IsNullOrEmpty(locationInfo.LocationCode))
+ {
+ content = WebResponseContent.Instance.Error($"璐т綅绫诲瀷{targetLocationType.Value}鏈垎閰嶅埌鍙敤璐т綅锛堟墭鐩橈細{item.PalletCode}锛�");
+ _unitOfWorkManage.RollbackTran();
+ return content;
+ }
+ palletLocationMap.Add(item.PalletCode, locationInfo.LocationCode);
+ }
+
+ // 鍔犲叆鏁寸鎵樼洏鍒楄〃
+ if (!wholeCasePallets.Contains(item.PalletCode))
+ {
+ wholeCasePallets.Add(item.PalletCode);
+ }
+ }
+ else
+ {
+ if (!palletIsWholeCaseMap.ContainsKey(item.PalletCode))
+ {
+ palletIsWholeCaseMap.Add(item.PalletCode, false);
+ }
+ else
+ {
+ palletIsWholeCaseMap[item.PalletCode] = false;
+ }
+ }
+ }
+ }
+ }
// 澶勭悊浠诲姟
foreach (var item in materielPickedDetails.Tasks)
{
+ if (outboundOrder.OrderType == 117
+ && palletIsWholeCaseMap.ContainsKey(item.PalletCode)
+ && palletIsWholeCaseMap[item.PalletCode]
+ && palletLocationMap.ContainsKey(item.PalletCode))
+ {
+ item.TaskType = (int)TaskTypeEnum.Relocation;
+ item.TargetAddress = palletLocationMap[item.PalletCode];
+ }
if (tasks.FirstOrDefault(x => x.PalletCode == item.PalletCode) == null)
tasks.Add(item);
}
@@ -234,8 +355,26 @@
if (tasks.Any()) _taskRepository.AddData(tasks);
-
- _unitOfWorkManage.CommitTran();
+ if (outboundOrder.OrderType == 117 && wholeCasePallets.Any())
+ {
+ foreach (var palletCode in wholeCasePallets)
+ {
+ var completeReq = new OutboundCompletePalletRequestDTO
+ {
+ OrderNo = request.OrderNo,
+ PalletCode = palletCode
+ };
+
+ var res = CompleteOutboundWithPallet(completeReq);
+ if (!res.Status)
+ {
+ _unitOfWorkManage.RollbackTran();
+ return res;
+ }
+ }
+ }
+
+ _unitOfWorkManage.CommitTran();
// 4. 鏋勯�犲搷搴旓細鍖哄垎銆屽叏閮ㄥ垎閰嶃�嶅拰銆岄儴鍒嗗垎閰嶃��
string responseMsg = totalActualAllocate == totalNeedAllocate
@@ -259,6 +398,18 @@
content = WebResponseContent.Instance.Error("澶勭悊鎷h揣鍑哄簱澶辫触锛�" + ex.Message);
}
return content;
+ }
+
+
+ /// <summary>
+ /// 鏍规嵁鍗曟嵁鍙疯幏鍙栫洰鏍囦粨搴�
+ /// </summary>
+ /// <param name="orderNo"></param>
+ /// <returns></returns>
+ public String GetToWarehouseByOrderNo(string orderNo)
+ {
+ var order =_allocateOrderRepository.QueryFirst(x => x.OrderNo == orderNo);
+ return order.ToWarehouse;
}
/// <summary>
@@ -1157,7 +1308,7 @@
}
else
{
- item.CurrentDeliveryQty = item.LockQuantity - item.OverOutQuantity;
+ item.CurrentDeliveryQty += item.LockQuantity - item.OverOutQuantity;
}
item.OverOutQuantity = item.LockQuantity;
}
@@ -1327,9 +1478,15 @@
_stockDetailHistoryRepository.AddData(historyRecords);
// 鍒犻櫎搴撳瓨鏄庣粏璁板綍
- _stockDetailRepository.DeleteData(stockInfo.Details);
+ var orderNo =_outboundRepository.QueryFirst(x => x.OrderNo == request.OrderNo);
+ if(orderNo.OrderType != 117)
+ {
+ _stockDetailRepository.DeleteData(stockInfo.Details);
+ }
_stockChangeRepository.AddData(changeRecords);
}
+
+
#endregion
#region 鎷i��
@@ -1549,6 +1706,10 @@
item.OverOutQuantity = item.LockQuantity;
}
+ if (item.OverOutQuantity == item.OrderQuantity)
+ {
+ item.OrderDetailStatus = (int)OrderDetailStatusEnum.Over;
+ }
updateDetails.Add(item);
List<Barcodes> barcodesList = new List<Barcodes>();
@@ -1643,7 +1804,7 @@
{
UpdateOutboundOrderStatus(request.OrderNo, OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt());
- if (outboundOrder.OrderType != OutOrderTypeEnum.InternalAllocat.ObjToInt() && outboundOrder.CreateType!=OrderCreateTypeEnum.CreateInSystem.ObjToInt())
+ if (outboundOrder.CreateType!=OrderCreateTypeEnum.CreateInSystem.ObjToInt())
{
_feedbackMesService.OutboundFeedback(outboundOrder.OrderNo);
}
@@ -2191,5 +2352,7 @@
}
#endregion
+
+
}
}
--
Gitblit v1.9.3