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/Inbound/Partial/Dt_boxing_headService.cs | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 107 insertions(+), 5 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/Inbound/Partial/Dt_boxing_headService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/Inbound/Partial/Dt_boxing_headService.cs"
index 81bec05..e23f5cf 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/Inbound/Partial/Dt_boxing_headService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA.Services/Services/Inbound/Partial/Dt_boxing_headService.cs"
@@ -145,12 +145,50 @@
//newBoxDetail.boxdtl_text1 =
- Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
- Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
//鑾峰彇绌鸿揣浣�
- Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
+ 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} 娆★級");
+ }
LogRecord.WriteLog((int)LogEnum.InBound, $"鎵樼洏鏉$爜锛歿rfid},鍒嗛厤鐨勮揣浣嶅彿{emptyLocation.location_id}锛岃揣浣嶇姸鎬侊細{emptyLocation.location_state}");
+
+
+ Dt_boxing_headRepository.Instance.Add(newBoxHead, true);
+ Dt_boxing_detailRepository.Instance.Add(newBoxDetail, true);
//鑾峰彇浠诲姟
Dt_taskinfo tmpTaskInfo = CommonFunction.AddWMSTask_BoxPalletIn(emptyLocation,
@@ -174,6 +212,34 @@
}
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;
+ }
}
@@ -200,9 +266,45 @@
VV_ContainerInfo_EmptyPallet emptyCon = VV_ContainerInfo_EmptyPalletRepository.Instance.FindFirst(x => x.containerhead_barcode == barcode);
if (emptyCon != null)
throw new Exception($"搴撳瓨涓瓨鍦ㄦ墭鐩樺彿锛氥�恵barcode}銆戠殑銆愮┖鎵樸�戝簱瀛橈紝璇蜂汉宸ユ牳瀹烇紝鎵�鍦ㄨ揣浣嶏細{emptyCon.location_id}");
+ //鑾峰彇绌鸿揣浣�
+ Dt_locationinfo emptyLocation;
- //璇存槑鏄┖鎵樺叆搴�
- Dt_locationinfo emptyLocation = CommonFunction.GetEmptyLocationAction(1);
+ 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} 娆★級");
+ }
+
LogRecord.WriteLog((int)LogEnum.InBound, $"鎵樼洏鏉$爜锛歿barcode},鍒嗛厤鐨勮揣浣嶅彿{emptyLocation.location_id}锛岃揣浣嶇姸鎬侊細{emptyLocation.location_state}");
--
Gitblit v1.9.3