From 441b6f8d257a01b2998253ef0515a201777d7e68 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期五, 04 七月 2025 14:06:49 +0800
Subject: [PATCH] 修改入库、移库、出库逻辑

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs |   56 ++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 36 insertions(+), 20 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs"
index 095fc47..3b78bf9 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_TaskInfoService/PartialTaskService_Inbound.cs"
@@ -192,6 +192,7 @@
                 Dt_InboundOrder inboundOrder = _inboundService.InbounOrderService.GetInboundOrder(stockInfoDetail.OrderNo);
                 if (inboundOrder == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勫叆搴撳崟淇℃伅");
 
+                var BatchNo = stockInfoDetail.BatchNo;
                 #region 鍒ゆ柇鏄惁鎸囧畾璐т綅
                 Dt_InboundOrderDetail? orderDetail = inboundOrder.Details.FirstOrDefault(x => x.BatchNo == stockInfoDetail.BatchNo);
                 if (orderDetail == null) throw new Exception($"鏈壘鍒版墭鐩榌{lineDTO.Barcode}]鐨勫叆搴撳崟鏄庣粏淇℃伅");
@@ -202,41 +203,43 @@
                 }
                 #endregion
 
-                #region 鍒ゆ柇褰撳墠鍏ュ簱鎵樼洏鎵规鍙锋槸鍚﹀瓨鍦ㄥ凡鍒嗛厤鍏ュ簱
                 else
                 {
+                    #region 鍒ゆ柇褰撳墠鍏ュ簱鎵樼洏鎵规鍙锋槸鍚﹀瓨鍦ㄥ凡鍒嗛厤鍏ュ簱
                     Dt_StockInfo? instockInfo = null;
                     Dt_StockInfoDetail instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo, stockInfoDetail.BatchNo);
                     if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                     if (instockInfo != null)
                     {
                         locationInfo = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);
-                        if (locationInfo.MaxQty <= locationInfo.CurrentQty) locationInfo = null;
+                        if (locationInfo?.MaxQty <= locationInfo?.CurrentQty) locationInfo = null;
                     }
                     #endregion
                     else
                     {
-                        instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo);//鍏ュ簱鍗曞瓨鍦ㄥ簱瀛橈紝鍒ゆ柇璐т綅
+                        instockInfoDetail = _stockService.StockInfoDetailService.Get_StockInfoDetail(stockInfoDetail.OrderNo /*BatchNo*/);//鍏ュ簱鍗曞瓨鍦ㄥ簱瀛橈紝鍒ゆ柇璐т綅
                         if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                         if (instockInfo != null)
                         {
                             Dt_LocationInfo? location = _basicService.LocationInfoService.GetLocation(instockInfo.LocationCode);//鏌ヨ宸插瓨鍦ㄥ簱瀛樿揣浣嶇姸鎬�
                             if (location?.Row == 1)
                             {
-                                var newLocation = Db.Queryable<Dt_LocationInfo>().Where(x => x.Row == 2 && x.Layer == location.Layer && x.Column == location.Column).First();
-                                if (newLocation != null && newLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt() && newLocation.CurrentQty == 0 && (newLocation.EnableStatus == EnableStatusEnum.OnlyIn.ObjToInt() || newLocation.EnableStatus == EnableStatusEnum.Normal.ObjToInt()))
+                                var instockInfos = _stockService.StockInfoService.Repository.GetDt_StockInfos(instockInfo.LocationCode);
+                                List<Dt_StockInfoDetail> Details = new List<Dt_StockInfoDetail>();
+                                foreach (var item in instockInfos)
                                 {
-                                    locationInfo = newLocation;
+                                    Details.AddRange(item.Details);
                                 }
+                                var count = Details.GroupBy(x => x.BatchNo).Count();
+                                if (count <= 1) locationInfo = location;
                             }
                         }
                     }
 
                     if (locationInfo == null)//鍒嗛厤鏂拌揣浣�
                     {
-                        int inboundOrderCount = inboundOrder.Details.Count;
-                        List<Dt_StockInfoDetail> stockInfoDetails = _stockService.StockInfoDetailService.Get_StockInfoDetails(stockInfoDetail.OrderNo);//鑾峰彇宸ュ崟鎵�鏈夊凡鍏ュ簱鎴栧叆搴撲腑搴撳瓨
-                        if (stockInfoDetails != null || stockInfoDetails.Count > 0) inboundOrderCount -= stockInfoDetails.GroupBy(x => x.BatchNo).Count();
+                        List<Dt_InboundOrderDetail> inboundOrderDetailList = inboundOrder.Details.Where(x => /*x.BatchNo.Contains(BatchNo) &&*/ x.OverInQuantity == 0).ToList();
+                        int inboundOrderCount = inboundOrderDetailList.Count;
                         locationInfo = _basicService.LocationInfoService.AssignLocation(inboundOrderCount);//閲嶆柊鍒嗛厤璐т綅
                     }
                 }
@@ -251,20 +254,24 @@
                 task.TargetAddress = task.NextAddress;
                 string[] targetCodes = task.NextAddress.Split("-");
                 var Row = Convert.ToInt16(targetCodes[0]);
-                task.TargetIsPickPlace = Row > 1 ? locationInfo.MaxQty - locationInfo.CurrentQty == 1 : false;
+                task.TargetIsPickPlace = locationInfo.MaxQty - locationInfo.CurrentQty == 1;
                 task.SourceIsPickPlace = false;
                 stockInfo.LocationCode = locationInfo.LocationCode;
                 stockInfo.StockStatus = StockStatusEmun.鍏ュ簱涓�.ObjToInt();
                 stockInfoDetail.Status = StockStatusEmun.鍏ュ簱涓�.ObjToInt();
                 locationInfo.CurrentQty++;
-                if (locationInfo.MaxQty < locationInfo.CurrentQty) throw new Exception();
-                /*if (locationInfo.MaxQty == 12)*/
+                if (locationInfo.MaxQty < locationInfo.CurrentQty) locationInfo.CurrentQty = locationInfo.MaxQty;
+                stockInfo.SerialNumber = locationInfo.CurrentQty;
+                orderDetail.OverInQuantity++;
+                if (orderDetail.OverInQuantity > orderDetail.ReceiptQuantity)
+                    orderDetail.OverInQuantity = orderDetail.ReceiptQuantity;
                 locationInfo.EnableStatus = EnableStatusEnum.OnlyOut.ObjToInt();
                 locationInfo.LocationStatus = LocationStatusEnum.Inbounding.ObjToInt();
 
                 Db.Ado.BeginTran();
                 UpdateData(task);
                 _stockService.StockInfoService.Repository.UpdateData(stockInfo);
+                _inboundService.InboundOrderDetailService.Repository.UpdateData(orderDetail);
                 _stockService.StockInfoDetailService.Repository.UpdateData(stockInfoDetail);
                 _basicService.LocationInfoService.Repository.UpdateData(locationInfo);
                 Db.Ado.CommitTran();
@@ -310,30 +317,39 @@
                 if (instockInfoDetails.Count < 1)
                 {
                     instockInfoDetails = _stockService.StockInfoDetailService.Repository.QueryData(x => x.MaterielCode == stockInfoDetail.MaterielCode && x.Status == StockStatusEmun.宸插叆搴�.ObjToInt());
-                    if (instockInfoDetails != null && instockInfoDetails.Count > 0)
+                    if (instockInfoDetails.Count > 0)
                         instockInfoDetail = instockInfoDetails.OrderByDescending(x => x.CreateDate).First();
                 }
                 if (instockInfoDetail != null) instockInfo = _stockService.StockInfoService.Repository.GetStockInfo(instockInfoDetail.StockId);
                 if (instockInfo != null)//鏃犲簱瀛�
                 {
                     locationInfo = _basicRepository.LocationInfoRepository.QueryFirst(x => x.LocationCode == instockInfo.LocationCode);
-                    if (ChargingStations.Contains(locationInfo.LocationCode))
+                    //if (BaseDal.QueryFirst(x => x.SourceAddress == locationInfo.LocationCode && x.TaskState < OutTaskStatusEnum.SC_OutFinish.ObjToInt()) != null) locationInfo = null;
+                    if (locationInfo != null && ChargingStations.Contains(locationInfo.LocationCode))
                     {
                         if (locationInfo.MaxQty - locationInfo.CurrentQty <= 1) locationInfo = null;
                     }
-                    else if (locationInfo.MaxQty - locationInfo.CurrentQty < 1)
+                    else if (locationInfo != null && locationInfo.MaxQty - locationInfo.CurrentQty < 1)
                     {
                         locationInfo = null;
                     }
                     if (locationInfo == null)
                     {
-                        locationInfo = _basicService.LocationInfoService.GetLocationPallet();
+                        var locationInfos = _basicService.LocationInfoService.GetLocationPallet();
+                        foreach (var item in locationInfos)
+                        {
+                            if (BaseDal.QueryFirst(x => x.SourceAddress == item.LocationCode) == null)
+                            {
+                                locationInfo = item;
+                                break;
+                            }
+                        }
                     }
                 }
-                else
-                {
-                    locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//鏌ユ壘绌挎杞﹀厖鐢佃揣浣�
-                }
+                //else
+                //{
+                //    locationInfo = _basicService.LocationInfoService.AssignLocation(ChargingStations);//鏌ユ壘绌挎杞﹀厖鐢佃揣浣�
+                //}
                 if (locationInfo == null) locationInfo = _basicService.LocationInfoService.AssignLocation(2);//閲嶆柊鍒嗛厤璐т綅
                 if (locationInfo == null) throw new Exception($"鏃犲彲鍏ヨ揣浣�");
                 Dt_LocationInfo? locationInfo1 = null;

--
Gitblit v1.9.3