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/ToWCS/Partial/InboundLogic.cs |  102 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 95 insertions(+), 7 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToWCS/Partial/InboundLogic.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToWCS/Partial/InboundLogic.cs"
index 19c31fb..85b069e 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToWCS/Partial/InboundLogic.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/ToWCS/Partial/InboundLogic.cs"
@@ -59,11 +59,15 @@
         public WebResponseContent ReceiveWeightResultFromWCS(SaveModel saveModel)
         {
             WebResponseContent content = new WebResponseContent();
-
             try
             {
                 string barcode = saveModel.MainData["barcode"].ToString();
                 string weight = saveModel.MainData["weight"].ToString();
+
+                if (weight == null || weight == "0")
+                {
+                    throw new Exception($"鎵樼洏鍙凤細銆恵barcode}銆戯紝閲嶉噺涓嶅涓嶇鍚堣瀹�");
+                }
 
                 Dt_taskinfo taskInfo = Dt_taskinfoRepository.Instance.FindFirst(x => x.task_barcode == barcode);
                 if (null == taskInfo)
@@ -73,10 +77,10 @@
                 //娌℃湁缁勭洏淇℃伅锛岃鏄庤閲嶉噺鏄┖鎵樼洏鐨勯噸閲�
                 if (null == boxHead)
                 {
-                    Dt_EmptyPallet dt_Empty= Dt_EmptyPalletRepository.Instance.FindFirst(x => x.EmptyPallet_name == barcode);
+                    Dt_EmptyPallet dt_Empty = Dt_EmptyPalletRepository.Instance.FindFirst(x => x.EmptyPallet_name == barcode);
                     if (null == dt_Empty)
                     {
-                        Dt_EmptyPallet dt_Empty1=new Dt_EmptyPallet();
+                        Dt_EmptyPallet dt_Empty1 = new Dt_EmptyPallet();
                         dt_Empty1.EmptyPallet_name = barcode;
                         dt_Empty1.EmptyPallet_palletweight = weight;
                         dt_Empty1.EmptyPallet_creator = "WMS";
@@ -84,13 +88,12 @@
                         dt_Empty1.EmptyPallet_modifier = "WMS";
                         dt_Empty1.EmptyPallet_modifiertime = DateTime.Now;
                         Dt_EmptyPalletRepository.Instance.Add(dt_Empty1,true);
+                        taskInfo.task_weight = weight;
                     }
                     else
                     {
                         taskInfo.task_weight = dt_Empty.EmptyPallet_palletweight;
                     }
-
-                       
                     Dt_taskinfoRepository.Instance.Update(taskInfo, true);
                 }
                 else//鏈夌粍鐩樹俊鎭紝璇存槑璇ラ噸閲忔槸杞存壙瀹炴墭鐨勯噸閲�
@@ -164,6 +167,23 @@
             }
             Logger.AddLog(Core.Enums.LoggerType.Edit, saveModel, content, content);
             return content;
+        }
+
+        /// <summary>
+        /// 鑾峰彇鍏ュ簱鍖哄煙鍜屽嚭搴撳尯鍩熺殑妯″紡
+        /// </summary>
+        /// <returns></returns>
+        public WebResponseContent GetInorOutMODELS(SaveModel saveModel)
+        {
+            WebResponseContent content = new WebResponseContent();
+            try
+            {
+                return content;
+            }
+            catch (Exception)
+            {
+                throw;
+            }
         }
 
 
@@ -457,8 +477,47 @@
                 }
                 content = Dt_taskinfoRepository.Instance.DbContextBeginTransaction(() =>
                 {
-                    //鑾峰彇绌鸿揣浣�
-                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction();
+                    Dt_locationinfo emptyLocation;
+
+                    int maxRetries = 20;
+                    int retryCount = 0;
+                    bool needRetry;
+                    do
+                    {
+                        needRetry = false;  // 榛樿涓嶉渶瑕侀噸璇�
+                        retryCount++;
+
+                        //鑾峰彇绌鸿揣浣�
+                        emptyLocation = CommonFunction.GetEmptyLocationAction(2);
+                        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} 娆★級");
+                    }
+                    
+
+
+                    LogRecord.WriteLog((int)LogEnum.InBound, $"鎵樼洏鏉$爜锛歿barcode},鍒嗛厤鐨勮揣浣嶅彿{emptyLocation.location_id}锛岃揣浣嶇姸鎬侊細{emptyLocation.location_state}");
 
                     Dt_taskinfo taskinfo = new Dt_taskinfo();
                     taskinfo.task_id = Guid.NewGuid();
@@ -498,6 +557,35 @@
             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;
+            }
+        }
+
     }
 
 }
\ No newline at end of file

--
Gitblit v1.9.3