From b2cc7bb7740e42e57cf50af02a8ca4b535cad484 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期三, 11 三月 2026 17:02:21 +0800
Subject: [PATCH] 优化WMS接口逻辑

---
 代码管理/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RGVLocationInfoService.cs |   98 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 96 insertions(+), 2 deletions(-)

diff --git "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RGVLocationInfoService.cs" "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RGVLocationInfoService.cs"
index e1707b7..4562f62 100644
--- "a/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RGVLocationInfoService.cs"
+++ "b/\344\273\243\347\240\201\347\256\241\347\220\206/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/RGVLocationInfoService.cs"
@@ -1,10 +1,13 @@
-锘縰sing System;
+锘縰sing SqlSugar;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using WIDESEAWCS_Common.LocationEnum;
 using WIDESEAWCS_Core.BaseRepository;
 using WIDESEAWCS_Core.BaseServices;
+using WIDESEAWCS_Core.Helper;
 using WIDESEAWCS_IBasicInfoService;
 using WIDESEAWCS_Model.Models;
 
@@ -15,7 +18,98 @@
         public RGVLocationInfoService(IRepository<Dt_RGVLocationInfo> BaseDal) : base(BaseDal)
         {
         }
-
+        private Dictionary<string, OrderByType> _emptyAssignOrderBy = new Dictionary<string, OrderByType>()
+        {
+            { nameof(Dt_RGVLocationInfo.Row), OrderByType.Asc },
+            { nameof(Dt_RGVLocationInfo.Depth), OrderByType.Desc },
+            { nameof(Dt_RGVLocationInfo.Layer), OrderByType.Asc },
+            //{ nameof(Dt_RGVLocationInfo.Column), OrderByType.Asc },
+        };
+        private Dictionary<string, OrderByType> _DepthAscOrderBy = new Dictionary<string, OrderByType>()
+        {
+            { nameof(Dt_RGVLocationInfo.Depth), OrderByType.Asc },
+        };
         public IRepository<Dt_RGVLocationInfo> Repository => BaseDal;
+
+        public List<Dt_RGVLocationInfo> GetFreeLocationInfos()
+        {
+            return BaseDal.QueryData(x => x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy);
+        }
+        /// <summary>
+        /// 鏌ユ壘鍏ュ簱鍙敤璐т綅
+        /// </summary>
+        /// <param name="AreaCode"></param>
+        /// <returns></returns>
+        public Dt_RGVLocationInfo? GetInFreeLocationInfo(string AreaCode)
+        {
+            Dt_RGVLocationInfo? rGVLocationInfo = null;
+            Dt_RGVLocationInfo? FreerGVLocationInfo = null;
+            List<Dt_RGVLocationInfo> rGVLocationInfos = BaseDal.QueryData(x => x.WarehouseId.ToString() == AreaCode && x.EnableStatus == EnableStatusEnum.Normal.ObjToInt() && x.LocationStatus == LocationStatusEnum.Free.ObjToInt(), _emptyAssignOrderBy);//鏌ユ壘鎵�鏈夌┖璐т綅
+            if (rGVLocationInfos == null || rGVLocationInfos.Count < 1) return rGVLocationInfo;
+            #region 鍒ゆ柇宸烽亾鏄惁鏈夎揣
+            List<string> LocationCodes = new List<string>();
+            foreach (var items in rGVLocationInfos.GroupBy(x => x.RoadwayNo))//鏍规嵁宸烽亾鍙峰垎缁�
+            {
+                foreach (var item in items)
+                {
+                    List<Dt_RGVLocationInfo> dt_RGVLocationInfos = BaseDal.QueryData(x => x.RoadwayNo == items.Key);//鏌ユ壘褰撳墠宸烽亾鍙疯揣浣�
+                    if (item.LocationType == 1)
+                    {
+                        rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth < item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault();//鍒ゆ柇娴呮繁搴﹁揣浣嶆槸鍚︽湁璐�
+                        if (rGVLocationInfo != null) break;
+                        return item;
+                    }
+                    else
+                    {
+                        rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth < item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).OrderByDescending(x => x.Depth).FirstOrDefault();//鍒ゆ柇娴呮繁搴﹁揣浣嶆槸鍚︽湁璐�
+                        if (rGVLocationInfo != null)
+                        {
+                            rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.Free.ObjToInt()).OrderBy(x => x.Depth).FirstOrDefault();
+                            if (rGVLocationInfo != null)
+                            {
+                                if (dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).Any()) rGVLocationInfo = null;
+                                else return rGVLocationInfo;
+                            }
+                            //var Depth = 0;
+                            //while (item.Depth - rGVLocationInfo.Depth != 0)
+                            //{
+                            //    if (rGVLocationInfo.Depth < item.Depth) Depth = rGVLocationInfo.Depth - 1;
+                            //    else Depth = rGVLocationInfo.Depth + 1;
+                            //    rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth == Depth).FirstOrDefault();
+                            //    if (rGVLocationInfo != null && rGVLocationInfo.LocationStatus == (int)LocationStatusEnum.Free) return rGVLocationInfo;
+                            //}
+                        }//鍒ゆ柇娴呮繁搴﹁揣浣嶆槸鍚︽湁璐�
+                        else return item;
+                    }
+
+                    //if (rGVLocationInfo != null)//娴呮繁搴﹁揣浣嶆湁璐э紝鎵炬繁娣卞害璐т綅鏄惁鏈夎揣
+                    //{
+                    //    if (item.LocationType == 1) break;//宸烽亾绫诲瀷涓哄崟鍚戯紝鐩存帴璺宠繃
+                    //    foreach (var locationInfo in rGVLocationInfos.Where(x => x.RoadwayNo == items.Key).OrderByDescending(x => x.Depth))
+                    //    {
+                    //        if (!dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && x.Depth < locationInfo.Depth).Any()) return locationInfo;
+                    //    }
+                    //    //rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.Free.ObjToInt()).OrderBy(x => x.Depth).FirstOrDefault();//鎵炬祬娣卞害绌鸿揣浣�
+                    //    //if (rGVLocationInfo != null)
+                    //    //{
+                    //    //    if (dt_RGVLocationInfos.Where(x => x.Depth > rGVLocationInfo.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault() == null)//鍒ゆ柇娣辨繁搴﹁揣浣嶆槸鍚︽湁璐�
+                    //    //        return rGVLocationInfo;
+                    //    //}
+                    //}
+                    //if (rGVLocationInfo == null)
+                    //{
+                    //    rGVLocationInfo = dt_RGVLocationInfos.Where(x => x.Depth > item.Depth && x.LocationStatus == LocationStatusEnum.InStock.ObjToInt()).FirstOrDefault();//鍒ゆ柇娴呮繁搴﹁揣浣嶆槸鍚︽湁璐�
+                    //    if (item.LocationType == 1) break;//宸烽亾绫诲瀷涓哄崟鍚戯紝鐩存帴璺宠繃
+                    //    foreach (var locationInfo in rGVLocationInfos.Where(x => x.RoadwayNo == items.Key).OrderByDescending(x => x.Depth))
+                    //    {
+                    //        if (!dt_RGVLocationInfos.Where(x => x.LocationStatus == LocationStatusEnum.InStock.ObjToInt() && x.Depth < locationInfo.Depth).Any()) return locationInfo;
+                    //    }
+                    //}
+                    //else return item;
+                }
+            }
+            #endregion
+            return FreerGVLocationInfo;
+        }
     }
 }

--
Gitblit v1.9.3