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 |   94 +++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 87 insertions(+), 7 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 68c881f..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"
@@ -13,6 +13,7 @@
 using WIDESEA.Services.IServices.ToApp;
 using WIDESEA.Services.Repositories;
 using WIDESEA.Services.Services;
+using WIDESEA_Common.LogEnum;
 using WIDESEA_Entity.DomainModels;
 
 
@@ -54,6 +55,12 @@
                 //鐢熶骇鏃ユ湡
                 string ProductDate = saveModel.MainData["ProductDate"].ToString();
 
+                // 鏍囧噯鍊�
+                string Standard_value = saveModel.MainData["Standard_value"].ToString();
+
+                // 浜у湴
+                string Placeoforigin = saveModel.MainData["Placeoforigin"].ToString();
+
                 if (string.IsNullOrEmpty(madeUnit) || string.IsNullOrEmpty(materielId) || string.IsNullOrEmpty(materielType) || string.IsNullOrEmpty(NewOrOld))
                     throw new Exception($"鍘傚/杞/鍨嬪彿/妫�淇被鍨嬮兘涓嶈兘涓虹┖");
 
@@ -94,9 +101,11 @@
                     throw new Exception($"鎵樼洏鐮�:銆恵rfid}銆戝凡缁忓瓨鍦ㄤ簬绌烘墭鐩樺簱瀛樹腑,璐т綅鍙�:{conInfoEmpty.location_id}");
 
                 //鏌ユ壘璇ユ墭鐩樻槸鍚︿箣鍓嶅叆杩囧簱锛岀粍鐩樿繘搴撶殑鎵樼洏涔嬪墠蹇呴』宸茬粡鍏ヨ繃搴撶殑
-                Dt_EmptyPallet dt_EmptyPallet = Dt_EmptyPalletRepository.Instance.Find(x => x.EmptyPallet_name == rfid).First();
+                Dt_EmptyPallet dt_EmptyPallet = Dt_EmptyPalletRepository.Instance.Find(x => x.EmptyPallet_name == rfid).FirstOrDefault();
                 if (dt_EmptyPallet == null)
                     throw new Exception($"鎵樼洏鐮�:銆恵rfid}銆�,鍦ㄦ墭鐩樼鐞嗕腑锛屾棤璇ユ墭鐩橈紝璇峰厛娣诲姞鎵樼洏淇℃伅");
+
+
 
             
                 //鍒ゆ柇杞存壙鏈夋晥鏈熸槸鍚﹁秴杩�2骞�
@@ -123,7 +132,7 @@
                     newBoxDetail.boxdtl_materielid = materielId;
                     newBoxDetail.boxdtl_qty = "1";
                     newBoxDetail.boxdtl_operator = UserContext.Current.UserTrueName;
-                    newBoxDetail.boxdtl_inboundUnit = "鏅虹菠";
+                    newBoxDetail.boxdtl_inboundUnit = "鍖椾含鍔ㄨ溅娈�";
                     newBoxDetail.boxdtl_standard = NewOrOld;
                     newBoxDetail.boxdtl_carType = materielId;
                     newBoxDetail.boxdtl_type = materielType;
@@ -137,13 +146,12 @@
                     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();
                     info.mesInfo_id = Guid.NewGuid();
-                    info.mesInfo_inUnit = "鏅虹菠";
+                    info.mesInfo_inUnit = "鍖椾含鍔ㄨ溅娈�";
                     info.mesInfo_madeUnit = madeUnit;
                     info.mesInfo_carType = materielId;
                     info.mesInfo_type = materielType;
@@ -153,11 +161,55 @@
                     info.mesInfo_createType = "mes";
                     info.mesInfo_qrCode = qrCode;
                     info.mesInfo_createDate = DateTime.Now;
+                    info.mesInfo_bak_3 = Standard_value; // 浠ュ悗鏍囧噯鍊间粠杩欓噷鑾峰彇 鑲栦郊鏂板
+                    info.mesInfo_bak_4 = Placeoforigin; // 杞存壙鐨勪骇鍦�
 
-                    Dt_mes_goods_infoRepository.Instance.Add(info, true);
 
                     //鑾峰彇绌鸿揣浣�
-                    Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction();
+                    Dt_locationinfo emptyLocation;
+
+                    int maxRetries = 20;
+                    int retryCount = 0;
+                    bool needRetry;
+                    do
+                    {
+                        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);
                     //淇敼璐т綅鐘舵��
@@ -180,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