From 5c640ca754afda2ea725e9fed2ff7bac0c62fa23 Mon Sep 17 00:00:00 2001
From: pan <antony1029@163.com>
Date: 星期日, 30 十一月 2025 10:38:46 +0800
Subject: [PATCH] Merge branch 'master' of http://115.159.85.185:8098/r/ZhongRui/ALDbanyunxiangmu

---
 项目代码/WMS无仓储版/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs |  211 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 210 insertions(+), 1 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
index be0de12..27b0b60 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS\346\227\240\344\273\223\345\202\250\347\211\210/WIDESEA_WMSServer/WIDESEA_OutboundService/OutboundPickingService.cs"
@@ -26,6 +26,7 @@
 using WIDESEA_DTO.Outbound;
 using WIDESEA_IAllocateService;
 using WIDESEA_IBasicService;
+using WIDESEA_IInboundService;
 using WIDESEA_IOutboundService;
 using WIDESEA_IStockService;
 using WIDESEA_Model.Models;
@@ -53,6 +54,9 @@
         private readonly IInvokeMESService _invokeMESService;
         private readonly IDailySequenceService _dailySequenceService;
         private readonly IAllocateService _allocateService;
+        private readonly IRepository<Dt_InboundOrder> _inboundOrderRepository;
+        private readonly IInboundOrderDetailService _inboundOrderDetailService;
+
 
         private readonly ILogger<OutboundPickingService> _logger;
 
@@ -73,7 +77,7 @@
         public OutboundPickingService(IRepository<Dt_PickingRecord> BaseDal, IUnitOfWorkManage unitOfWorkManage, IStockInfoService stockInfoService, IStockService stockService,
             IOutStockLockInfoService outStockLockInfoService, IStockInfoDetailService stockInfoDetailService, ILocationInfoService locationInfoService,
             IOutboundOrderDetailService outboundOrderDetailService, ISplitPackageService splitPackageService, IOutboundOrderService outboundOrderService,
-            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService) : base(BaseDal)
+            IRepository<Dt_Task> taskRepository, IESSApiService eSSApiService, ILogger<OutboundPickingService> logger, IInvokeMESService invokeMESService, IDailySequenceService dailySequenceService, IAllocateService allocateService, IRepository<Dt_InboundOrder> inboundOrderRepository,IInboundOrderDetailService inboundOrderDetailService) : base(BaseDal)
         {
             _unitOfWorkManage = unitOfWorkManage;
             _stockInfoService = stockInfoService;
@@ -90,6 +94,8 @@
             _invokeMESService = invokeMESService;
             _dailySequenceService = dailySequenceService;
             _allocateService = allocateService;
+            _inboundOrderRepository = inboundOrderRepository;
+            _inboundOrderDetailService = inboundOrderDetailService;
         }
 
 
@@ -2395,9 +2401,212 @@
             return WebResponseContent.Instance.OK("鎷i�夌‘璁ゆ垚鍔�", new { SplitResults = new List<SplitResult>() });
         }
 
+
+
+        #region 铏氭嫙鍑哄叆搴�
+        public WebResponseContent GetAvailablePurchaseOrders()
+        {
+            List<Dt_InboundOrder> InOders = _inboundOrderRepository.QueryData().Where(x => x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).ToList();
+            List<string> InOderCodes = InOders.Select(x => x.UpperOrderNo).ToList();
+            return WebResponseContent.Instance.OK("鎴愬姛",data: InOderCodes);
+        }
+
+        public WebResponseContent GetAvailablePickingOrders()
+        {
+            List<Dt_OutboundOrder> outOders = _outboundOrderService.Db.Queryable<Dt_OutboundOrder>().Where(x => x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).ToList();
+
+            List<string> outOderCodes = outOders.Select(x => x.UpperOrderNo).ToList();
+            return WebResponseContent.Instance.OK("鎴愬姛", data: outOderCodes);
+
+        }
+        public WebResponseContent BarcodeValidate(NoStockOutModel noStockOut)
+        {
+            try
+            {
+                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if(inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOut.inOder}");
+                }
+                var matchedDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == noStockOut.barCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                if (matchedDetail == null)
+                {
+                    return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOut.inOder} 涓湭鎵惧埌鏉$爜涓� {noStockOut.barCode} 鐨勬槑缁嗐��");
+                }
+                matchedDetail.NoStockOutQty = 0;
+
+                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOut.outOder && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if (outboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOut.inOder}");
+                }
+                var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == matchedDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                if (matchedCode == null)
+                {
+                    return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓matchedDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+                }
+                matchedCode.NoStockOutQty = 0;
+
+                //鍓╀綑鍏ュ簱鏁伴噺鍗宠櫄鎷熷嚭鍏ュ簱鍓╀綑鍙嚭鏁伴噺
+                decimal outQuantity = matchedDetail.OrderQuantity - matchedDetail.ReceiptQuantity;
+                if(outQuantity == 0)
+                {
+                    return WebResponseContent.Instance.Error($"璇ラ噰璐崟涓殑鏉$爜瀵瑰簲鐨勫彲鍑烘暟閲忎负0");
+                }
+                if (matchedCode.OrderQuantity < outQuantity)
+                {
+                    return WebResponseContent.Instance.Error($"璇ラ噰璐崟涓殑鏉$爜瀵瑰簲鐨勫彲鍑烘暟閲忚秴鍑哄嚭搴撳崟鍑哄簱鏁伴噺{matchedDetail.OrderQuantity - matchedCode.OrderQuantity},涓嶆弧瓒虫暣鍖呭嚭搴�");
+                }
+                //鍗曟嵁鍑哄簱閿佸畾鏁伴噺
+                matchedDetail.NoStockOutQty += outQuantity;
+                matchedCode.NoStockOutQty += outQuantity;
+
+                if ((matchedCode.LockQuantity + matchedCode.NoStockOutQty) > matchedCode.OrderQuantity)
+                {
+                   return WebResponseContent.Instance.Error($"鍑哄簱鍗曟槑缁嗘暟閲忔孩鍑簕matchedCode.LockQuantity - matchedCode.OrderQuantity}");
+                }
+                matchedDetail.OrderDetailStatus = OrderDetailStatusEnum.Inbounding.ObjToInt();
+                matchedCode.OrderDetailStatus = OrderDetailStatusEnum.Outbound.ObjToInt();
+
+                _unitOfWorkManage.BeginTran();
+                _inboundOrderDetailService.UpdateData(matchedDetail);
+                _outboundOrderDetailService.UpdateData(matchedCode);
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+            }
+            catch(Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+
+        public WebResponseContent DeleteBarcode(NoStockOutModel noStockOut)
+        {
+            try
+            {
+                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOut.inOder && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOut.inOder}");
+                }
+                var matchedDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == noStockOut.barCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                if (matchedDetail == null)
+                {
+                    return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOut.inOder} 涓湭鎵惧埌鏉$爜涓� {noStockOut.barCode} 鐨勬槑缁嗐��");
+                }
+                matchedDetail.NoStockOutQty = 0;
+
+                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOut.outOder && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if (outboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOut.inOder}");
+                }
+                var matchedCode = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == matchedDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                if (matchedCode == null)
+                {
+                    return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓matchedDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+                }
+                matchedCode.NoStockOutQty = 0;
+                _unitOfWorkManage.BeginTran();
+                _inboundOrderDetailService.UpdateData(matchedDetail);
+                _outboundOrderDetailService.UpdateData(matchedCode);
+                _unitOfWorkManage.CommitTran();
+                return WebResponseContent.Instance.OK();
+
+            }
+            catch(Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+
+        public WebResponseContent NoStockOutSubmit(NoStockOutSubmit noStockOutSubmit)
+        {
+            try
+            {
+                Dt_InboundOrder inboundOrder = Db.Queryable<Dt_InboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.InOderSubmit && x.OrderStatus != InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if (inboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒伴噰璐崟锛歿noStockOutSubmit.InOderSubmit}");
+                }
+                Dt_OutboundOrder outboundOrder = Db.Queryable<Dt_OutboundOrder>().Where(x => x.UpperOrderNo == noStockOutSubmit.OutOderSubmit && x.OrderStatus != OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt()).Includes(x => x.Details).First();
+                if (outboundOrder == null)
+                {
+                    return WebResponseContent.Instance.Error($"鏈壘鍒板嚭搴撳崟锛歿noStockOutSubmit.OutOderSubmit}");
+                }
+                List<Dt_InboundOrderDetail> inboundOrderDetails = new List<Dt_InboundOrderDetail>();
+                List<Dt_OutboundOrderDetail> outboundOrderDetails = new List<Dt_OutboundOrderDetail>();
+                foreach (var BarCode in noStockOutSubmit.BarCodeSubmit)
+                {
+                   var inboundOrderDetail = inboundOrder.Details.FirstOrDefault(detail => detail.Barcode == BarCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                    if(inboundOrderDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"鍦ㄩ噰璐崟 {noStockOutSubmit.InOderSubmit} 涓湭鎵惧埌鏉$爜涓� {BarCode} 鐨勬槑缁嗐��");
+                    }
+                    var outboundOrderDetail = outboundOrder.Details.FirstOrDefault(detail => detail.MaterielCode == inboundOrderDetail.MaterielCode && detail.OrderDetailStatus != OrderDetailStatusEnum.Over.ObjToInt());
+
+                    if (outboundOrderDetail == null)
+                    {
+                        return WebResponseContent.Instance.Error($"鍦ㄥ嚭搴撳崟鐨勭墿鏂欑紪鐮佷腑鏈壘鍒颁笌閲囪喘鍗曚腑鐨剓inboundOrderDetail.MaterielCode} 瀵瑰簲鐨勭墿鏂欍��");
+                    }
+                    inboundOrderDetail.ReceiptQuantity += inboundOrderDetail.NoStockOutQty;
+                    inboundOrderDetail.OverInQuantity = inboundOrderDetail.ReceiptQuantity;
+                    inboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    inboundOrderDetails.Add(inboundOrderDetail);
+
+                    outboundOrderDetail.LockQuantity += outboundOrderDetail.NoStockOutQty;
+                    outboundOrderDetail.OverOutQuantity = outboundOrderDetail.LockQuantity;
+                    if(outboundOrderDetail.OrderQuantity == outboundOrderDetail.OverOutQuantity)
+                    {
+                        outboundOrderDetail.OrderDetailStatus = OrderDetailStatusEnum.Over.ObjToInt();
+                    }
+                    outboundOrderDetails.Add(outboundOrderDetail);
+
+                }
+                //鍒ゆ柇鍏ュ簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
+                bool inoderOver = inboundOrder.Details.Count() == inboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                if (inoderOver)
+                {
+                    inboundOrder.OrderStatus = InOrderStatusEnum.鍏ュ簱瀹屾垚.ObjToInt();
+                }
+                //鍒ゆ柇鍑哄簱鍗曟嵁鏄庣粏鏄惁鍏ㄩ儴鏄畬鎴愮姸鎬�
+                bool outOderOver = outboundOrder.Details.Count() == outboundOrder.Details.Select(x => x.OrderDetailStatus == OrderDetailStatusEnum.Over.ObjToInt()).Count();
+                if (outOderOver)
+                {
+                    outboundOrder.OrderStatus = OutOrderStatusEnum.鍑哄簱瀹屾垚.ObjToInt();
+                }
+                //鏁版嵁澶勭悊
+                _unitOfWorkManage.BeginTran();
+                _inboundOrderDetailService.UpdateData(inboundOrderDetails);
+                _outboundOrderDetailService.UpdateData(outboundOrderDetails);
+                _inboundOrderRepository.UpdateData(inboundOrder);
+                _outboundOrderService.UpdateData(outboundOrder);
+                _unitOfWorkManage.CommitTran();
+
+                return WebResponseContent.Instance.OK();
+            }
+            catch(Exception ex)
+            {
+                _unitOfWorkManage.RollbackTran();
+                return WebResponseContent.Instance.Error(ex.Message);
+            }
+        }
+        #endregion
+
+
         #endregion
     }
 
+   
+
     #region 鏀寔绫诲畾涔�
 
     public class ValidationResult<T>

--
Gitblit v1.9.3