From 70bfe6a531aa17a470a3f9f43275f0cef254916e Mon Sep 17 00:00:00 2001
From: wxw <Administrator@DESKTOP-5BIMHQ3>
Date: 星期五, 12 九月 2025 08:54:28 +0800
Subject: [PATCH] 优化货架库储位分配逻辑

---
 Wms/WMS.BLL/Logic/AllotLocation.cs |   44 ++++++++++++++++++++++++++++++++++----------
 1 files changed, 34 insertions(+), 10 deletions(-)

diff --git a/Wms/WMS.BLL/Logic/AllotLocation.cs b/Wms/WMS.BLL/Logic/AllotLocation.cs
index 8817d57..10284fe 100644
--- a/Wms/WMS.BLL/Logic/AllotLocation.cs
+++ b/Wms/WMS.BLL/Logic/AllotLocation.cs
@@ -43,7 +43,7 @@
             {
                 // 鍒ゆ柇褰撳墠宸烽亾(缁�)鏄惁鏈夌┖浣欏偍浣�
                  
-                var locateCount = db.Queryable<SysStorageLocat>().Count(m => m.Status == "0" && m.Flag == "0" && areaList.Contains(m.AreaNo) && m.RoadwayNo == l);
+                var locateCount = db.Queryable<SysStorageLocat>().Count(m => m.IsDel=="0" && m.Status == "0" && m.Flag == "0" && areaList.Contains(m.AreaNo) && m.RoadwayNo == l);
                 
                 var bindNum = db.Queryable<LogTask>().Where(m => m.IsDel == "0" && (m.Status == "0" || m.Status == "1") && m.EndRoadway == l)
                             .GroupBy(m => m.PalletNo).Select(m => m.PalletNo).Count();
@@ -292,10 +292,14 @@
         /// <param name="areaList">鍖哄煙闆嗗悎</param>
         /// <param name="roadwayNo">宸烽亾鍙�(鍙┖)</param>
         /// <returns></returns>
-        public SysStorageLocat GetSuiTableLocate(string houseNo, List<string> areaList,string roadwayNo = "")
+        public SysStorageLocat GetSuiTableLocate(string houseNo, List<string> areaList,string roadwayNo = "",string ceng = "")
         {
             try
             {
+                if (string.IsNullOrWhiteSpace(ceng))
+                {
+                    throw new Exception($"鐢宠璐ф灦搴撲綅灞傛暟涓嶈兘涓虹┖");
+                }
                 var db = DataContext.Db;
                 /* 1.鍏堝垽鏂粨搴擄紙绔嬪簱鎴栬�呭钩搴擄級
                  * 2.濡傛灉鏄珛搴� 鍐嶅垽鏂槸鍚︽寚瀹氬贩閬撳彿
@@ -308,6 +312,22 @@
 
                 var roadList = db.Queryable<SysStorageLocat>().Where(m => m.WareHouseNo == houseNo && areaList.Contains(m.AreaNo) )
                     .GroupBy(m=>m.RoadwayNo).Select(m=>m.RoadwayNo).ToList();
+
+                if (houseNo == "W02")
+                {
+                    //涓�妤煎贩閬�
+                    var conveyList1 = new List<string>() { "LR01", "LR02", "LR03", "LR04", "LR05", "LR06", "LR07", "LR08" };
+                    //浜屾ゼ宸烽亾
+                    var conveyList2 = new List<string>() { "LR09", "LR10", "LR11", "LR12" };
+                    if (ceng == "1")
+                    {
+                        roadList = roadList.Where(m => conveyList1.Contains(m)).ToList();
+                    }
+                    else if (ceng == "2")
+                    {
+                        roadList = roadList.Where(m => conveyList2.Contains(m)).ToList();
+                    }
+                }
 
                 //鏁版嵁瀛楀吀(鑾峰彇瀛楀吀涓粨搴撶被鍨�)
                 var dic = db.Queryable<SysDictionary>().First(m => m.Id.ToString() == house.Type);
@@ -334,7 +354,7 @@
 
                             //鏌ヨ璇ュ贩閬撳苟涓旀爣蹇椾负姝e父鐨勭殑鍌ㄤ綅
                             roadwayList.Add(roadway);
-                            var locate = GetLocateByRoadways(roadwayList,areaList,true,houseNo);
+                            var locate = GetLocateByRoadways(roadwayList,areaList,true,houseNo, ceng);
                             if (locate == null)
                             {
                                 throw new Exception($"{roadwayNo}宸烽亾娌℃湁鍚堥�傜殑绌哄偍浣�");
@@ -346,7 +366,7 @@
                         {
                             var roadwayList = db.Queryable<SysStorageRoadway>().Where(m => m.WareHouseNo == houseNo && m.Status == "0" && roadList.Contains(m.RoadwayNo)).OrderBy(m => new { m.Priority, m.RoadwayNo }).ToList();
 
-                            var locate = GetLocateByRoadways(roadwayList,areaList,false, houseNo);
+                            var locate = GetLocateByRoadways(roadwayList,areaList,false, houseNo,ceng);
                             if (locate == null)
                             {
                                 throw new Exception($"{houseNo}浠撳簱宸插惎鐢ㄧ殑宸烽亾涓病鏈夊悎閫傜殑绌哄偍浣�");
@@ -380,7 +400,7 @@
         /// <param name="areaList">鍖哄煙闆嗗悎</param>
         /// <param name="isRoadway">鏄惁鎸囧畾宸烽亾</param>
         /// <returns></returns>
-        private SysStorageLocat GetLocateByRoadways(List<SysStorageRoadway> roadways,List<string> areaList,bool isRoadway = false ,string houseNo = "W02")
+        private SysStorageLocat GetLocateByRoadways(List<SysStorageRoadway> roadways,List<string> areaList,bool isRoadway = false ,string houseNo = "W02",string ceng = "")
         {
             try
             {
@@ -469,7 +489,7 @@
                         var count = 0;
                         do
                         {
-                            locate = GetLocateByRoadway(l.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count);
+                            locate = GetLocateByRoadway(l.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count, ceng);
                             if (locate != null)
                             {
                                 break;
@@ -503,7 +523,7 @@
                                 var count = 0;
                                 do
                                 {
-                                    locate = GetLocateByRoadway(log.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count);
+                                    locate = GetLocateByRoadway(log.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count,ceng);
                                     if (locate != null)
                                     {
                                         break;
@@ -531,7 +551,7 @@
                         var count = 0;
                         do
                         {
-                            locate = GetLocateByRoadway(item.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count);
+                            locate = GetLocateByRoadway(item.RoadwayNo, topOrBom, leftOrRight, areaList, list, ref count,ceng);
                             if (locate != null)
                             {
                                 break;
@@ -575,7 +595,7 @@
         /// <param name="areaList">鍖哄煙闆嗗悎</param>
         /// <param name="locateNoStr">鎺掗櫎鐨勫偍浣嶉泦鍚�</param>
         /// <returns></returns>
-        private SysStorageLocat GetLocateByRoadway(string roadwayNo, int topOrBom, int leftOrRight,List<string> areaList,List<string> locateNoStr,ref int count)
+        private SysStorageLocat GetLocateByRoadway(string roadwayNo, int topOrBom, int leftOrRight,List<string> areaList,List<string> locateNoStr,ref int count,string ceng = "")
         {
             var db = DataContext.Db;
             var str = "";
@@ -596,7 +616,11 @@
             
             foreach (var area in areaList)
             {
-                var sql = $@"select * from SysStorageLocat where IsDel = 0 and Flag = 0 and [Status] = 0 and RoadwayNo = '{roadwayNo}' and AreaNo = '{area}' and LocatNo not in({str}) ";
+                var sql = $@"select * from SysStorageLocat where IsDel = 0 and Layer!= '3' and Flag = 0 and [Status] = 0 and RoadwayNo = '{roadwayNo}' and AreaNo = '{area}' and LocatNo not in({str}) ";
+                //if (!string.IsNullOrWhiteSpace(ceng))
+                //{
+                //    sql += $"and Layer = '{ceng}' ";        
+                //}
                 sql += "order by ";
                 sql += topOrBom == 0 ? "Layer desc, " : "Layer, ";
                 sql += leftOrRight == 0 ? "[Column], " : "[Column] desc, ";

--
Gitblit v1.8.0