From bce2cc310d462ffbe56ee3d9f3d9368abf481aad Mon Sep 17 00:00:00 2001
From: huanghongfeng <huanghongfeng@hnkhzn.com>
Date: 星期四, 06 十一月 2025 16:02:35 +0800
Subject: [PATCH] 最新

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 113 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs"
index 6ee32ef..cc5eca5 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_WMSServer/WIDESEA_BasicService/LocationInfoService.cs"
@@ -243,6 +243,119 @@
                 return null;
             }
         }
+
+
+        /// <summary>
+        /// 搴撲綅鍒嗛厤,鏃犲贩閬撳彿杩涜鍒嗛厤鍙�
+        /// </summary>
+        /// <returns></returns>
+        public Dt_LocationInfo? GetLocationInfo()
+        {
+            lock (_locker)
+            {
+                List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 20).ToList();//鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�5鍒嗛挓鐨勮揣浣�
+                int count = removeItems.Count;
+                for (int i = 0; i < count; i++)
+                {
+                    locationCaches.Remove(removeItems[i]);//绉婚櫎鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�5鍒嗛挓鐨勮揣浣�
+                }
+
+                List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList();
+
+                List<Dt_LocationInfo> locationInfos = BaseDal.QueryData();//鏌ヨ宸烽亾鎵�鏈夎揣浣嶄俊鎭�
+                List<Dt_LocationInfo> emptyLocations = locationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode)).OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ToList();//鏌ヨ绌鸿揣浣嶄俊鎭苟鎺掗櫎5鍒嗛挓鍐呭垎閰嶇殑璐т綅,鏍规嵁灞傘�佸垪銆佹繁搴︺�佽鎺掑簭
+
+
+                for (int i = 0; i < emptyLocations.Count; i++)
+                {
+                    if (emptyLocations[i].Depth == 1)//鍒ゆ柇鏄惁1娣辫揣浣�
+                    {
+                        Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//鏌ヨ2娣辫揣浣嶅搴旂殑1娣辫揣浣嶆槸鍚︿负绌�,闃叉鍑虹幇鍒嗛厤1娣辫揣浣嶈��2娣辫揣浣嶄负绌虹殑鎯呭喌
+                        if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+                        {
+                            locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = sencondDepthLocation.LocationCode });
+                            return sencondDepthLocation;//1娣辫揣浣嶅強2娣辫揣浣嶉兘涓虹┖鐨勬儏鍐典笅,浼樺厛鍒嗛厤2娣辫揣浣�
+                        }
+                        else
+                        {
+                            locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode });
+                            return emptyLocations[i];
+                        }
+                    }
+                    else
+                    {
+                        Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//鏌ヨ2娣辫揣浣嶅搴旂殑1娣辫揣浣嶆槸鍚︿负绌�
+                        if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+                        {
+                            locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode });
+                            return emptyLocations[i];
+                        }
+                    }
+                }
+                return null;
+            }
+        }
+
+        /// <summary>
+        /// 鍒ゆ柇宸烽亾鍐呯Щ搴�,鑾峰彇璐т綅
+        /// </summary>
+        /// <param name="roadway"></param>
+        /// <returns></returns>
+        public Dt_LocationInfo? GetLocation(string roadway)
+        {
+            lock (_locker)
+            {
+                List<LocationCache> removeItems = locationCaches.Where(x => (DateTime.Now - x.DateTime).TotalMinutes > 20).ToList();//鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�20鍒嗛挓鐨勮揣浣�
+                int count = removeItems.Count;
+                for (int i = 0; i < count; i++)
+                {
+                    locationCaches.Remove(removeItems[i]);//绉婚櫎鏌ヨ娣诲姞闈欐�佸彉閲忚秴杩�5鍒嗛挓鐨勮揣浣�
+                }
+
+                List<string> lockLocations = locationCaches.Select(x => x.LocationCode).ToList();
+
+                List<Dt_LocationInfo> locationInfos = BaseDal.QueryData(x => x.RoadwayNo == roadway  && x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode));//鏌ヨ宸烽亾鎵�鏈夎揣浣嶄俊鎭�
+
+
+                List<Dt_LocationInfo> emptyLocations = locationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt() && !lockLocations.Contains(x.LocationCode)).OrderBy(x => x.Layer).ThenBy(x => x.Column).ThenByDescending(x => x.Depth).ThenBy(x => x.Row).ToList();//鏌ヨ绌鸿揣浣嶄俊鎭苟鎺掗櫎20鍒嗛挓鍐呭垎閰嶇殑璐т綅,鏍规嵁灞傘�佸垪銆佹繁搴︺�佽鎺掑簭
+
+
+                for (int i = 0; i < emptyLocations.Count; i++)
+                {
+                    if (emptyLocations[i].Depth == 1)//鍒ゆ柇鏄惁1娣辫揣浣�
+                    {
+                        Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//鏌ヨ2娣辫揣浣嶅搴旂殑1娣辫揣浣嶆槸鍚︿负绌�,闃叉鍑虹幇鍒嗛厤1娣辫揣浣嶈��2娣辫揣浣嶄负绌虹殑鎯呭喌
+                        if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+                        {
+                            locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = sencondDepthLocation.LocationCode });
+                            return sencondDepthLocation;//1娣辫揣浣嶅強2娣辫揣浣嶉兘涓虹┖鐨勬儏鍐典笅,浼樺厛鍒嗛厤2娣辫揣浣�
+                        }
+                        else
+                        {
+                            if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus != LocationStatusEnum.Lock.ObjToInt())   //鍒ゆ柇浜屾繁鏃犱换鍔�
+                            {
+                                locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode });
+                                return emptyLocations[i];
+                            }
+                        }
+                    }
+                    else
+                    {
+                        Dt_LocationInfo? sencondDepthLocation = locationInfos.FirstOrDefault(x => Math.Abs(x.Row - emptyLocations[i].Row) == 1 && x.Layer == emptyLocations[i].Layer && x.Column == emptyLocations[i].Column);//鏌ヨ2娣辫揣浣嶅搴旂殑1娣辫揣浣嶆槸鍚︿负绌�
+
+                        if (sencondDepthLocation != null && sencondDepthLocation.LocationStatus == LocationStatusEnum.Free.ObjToInt())
+                        {
+                            locationCaches.Add(new LocationCache { DateTime = DateTime.Now, LocationCode = emptyLocations[i].LocationCode });
+                            return emptyLocations[i];
+                        }
+                    }
+                }
+                return null;
+            }
+        }
+
+
+
         /// <summary>
         /// 鑾峰彇鍙敤璐т綅
         /// </summary>

--
Gitblit v1.9.3