From c99808261b1b1460d22a7f7db5955a65080c3b4b Mon Sep 17 00:00:00 2001
From: Admin <Admin@ADMIN>
Date: 星期一, 27 四月 2026 08:58:57 +0800
Subject: [PATCH] 优化货位查找

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs |   81 ++++++++++++++++++++++++++++++++++------
 1 files changed, 69 insertions(+), 12 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs"
index 5a60fc4..68682db 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToAPP/InboundBoxingAction.cs"
@@ -146,8 +146,7 @@
                     newBoxDetail.boxdtl_text2 = LotNumber;
                     newBoxDetail.boxdtl_text3 = ProductDate;
 
-                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
-                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
+                    
 
 
                     Dt_mes_goods_info info = new Dt_mes_goods_info();
@@ -165,21 +164,51 @@
                     info.mesInfo_bak_3 = Standard_value; // 浠ュ悗鏍囧噯鍊间粠杩欓噷鑾峰彇 鑲栦郊鏂板
                     info.mesInfo_bak_4 = Placeoforigin; // 杞存壙鐨勪骇鍦�
 
-                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
-
-
-
 
                     //鑾峰彇绌鸿揣浣�
-                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
+                    Dt_locationinfo emptyLocation;
 
-                    VV_ContainerInfo_EmptyPallet SelectLocation = VV_ContainerInfo_EmptyPalletRepository.Instance.FindFirst(x => x.location_id == emptyLocation.location_id);
-                    VV_ContainerInfo conInfohw = VV_ContainerInfoRepository.Instance.FindFirst(x => x.location_id == emptyLocation.location_id);
-                    if (SelectLocation != null || conInfohw != null)
+                    int maxRetries = 20;
+                    int retryCount = 0;
+                    bool needRetry;
+                    do
                     {
-                        LogRecord.WriteLog((int)LogEnum.InBound, $"鍒嗛厤鐨勮揣浣嶅凡鏈夎揣,璐т綅鍙穥emptyLocation.location_id}");
-                        throw new Exception($"鍒嗛厤鐨勮揣浣嶅凡鏈夎揣,璐т綅鍙穥SelectLocation.location_id}");
+                        needRetry = false;  // 榛樿涓嶉渶瑕侀噸璇�
+                        retryCount++;
+
+                        //鑾峰彇绌鸿揣浣�
+                        emptyLocation = CommonFunction.GetEmptyLocationAction(1);
+                        if (emptyLocation == null)
+                        {
+                            return content.Error("鏃犳硶鑾峰彇搴撲綅");
+                        }
+
+                        // 2. 妫�鏌ュ簱瀛�
+                        if (IsEmptyPalletLocation(emptyLocation.location_id))
+                        {
+                            needRetry = true;
+                            continue;  // 鐩存帴杩涘叆涓嬩竴娆″惊鐜紙閲嶈瘯锛�
+                        }
+
+                        // 3. 妫�鏌ヤ换鍔�
+                        if (Dt_taskinfoRepository.Instance.Find(x => x.task_endstation == emptyLocation.location_id).FirstOrDefault() != null)
+                        {
+                            needRetry = true;
+                            continue;
+                        }
+
+                    } while (needRetry && retryCount < maxRetries);
+                    // 妫�鏌ユ槸鍚﹁秴杩囨渶澶ч噸璇曟鏁�
+                    if (retryCount >= maxRetries)
+                    {
+                        return content.Error($"鏃犳硶鎵惧埌鍙敤搴撲綅锛堝凡灏濊瘯 {retryCount} 娆★級");
                     }
+
+
+
+                    Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
+                    Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
+                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
 
                     //鑾峰彇浠诲姟
                     Dt_taskinfo tmpTaskInfo = CommonFunction.AddWMSTask_BoxPalletIn(emptyLocation, rfid, materielId, qrCode, materielType);
@@ -203,5 +232,33 @@
             Logger.AddLog(LoggerType.Add, saveModel, content, content);
             return content;
         }
+
+        /// <summary>
+        /// 妫�鏌ユ寚瀹氳揣浣嶆槸鍚︿负绌烘墭鐩樿揣浣�
+        /// </summary>
+        /// <param name="locationId">璐т綅ID</param>
+        /// <returns>true: 鏄┖鎵樼洏璐т綅, false: 涓嶆槸绌烘墭鐩樿揣浣�</returns>
+        public bool IsEmptyPalletLocation(string locationId)
+        {
+            try
+            {
+                // 鏌ヨ绌烘墭鐩樿揣浣嶄俊鎭�
+                var emptyPalletLocation = VV_ContainerInfo_EmptyPalletRepository.Instance
+                    .Find(x => x.location_id == locationId).FirstOrDefault();
+
+                // 鏌ヨ璐т綅涓婄殑瀹瑰櫒淇℃伅
+                var containerInfo = VV_ContainerInfoRepository.Instance
+                    .Find(x => x.location_id == locationId).FirstOrDefault();
+
+                bool isEmptyPallet = emptyPalletLocation != null || containerInfo != null;
+
+                return isEmptyPallet;
+            }
+            catch (Exception ex)
+            {
+                LogRecord.WriteLog((int)LogEnum.Errer, $"妫�鏌ョ┖鎵樼洏璐т綅澶辫触锛岃揣浣岻D锛歿locationId}锛岄敊璇細{ex.Message}");
+                return false;
+            }
+        }
     }
 }

--
Gitblit v1.9.3