From 17e3ef45fe0a6b6f8a147b50740834ac734f9317 Mon Sep 17 00:00:00 2001
From: lss <2538410689@qq.com>
Date: 星期二, 15 七月 2025 17:30:13 +0800
Subject: [PATCH] 1111

---
 HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs |  119 +++++++++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 94 insertions(+), 25 deletions(-)

diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs
index 4e70816..41b455f 100644
--- a/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs
+++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.DaYang/wms/LocationHelper.cs
@@ -5,6 +5,7 @@
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using static HH.WCS.DaYang.wms.WMSHelper.AddChangeModel;
 
 namespace HH.WCS.DaYang.wms
 {
@@ -56,31 +57,33 @@
         /// <summary>
         /// 鍏ュ簱绠楁硶
         /// </summary>
-        /// <param name="loc">鍏ュ簱璧风偣</param>
+        /// <param name="itemCode">鐗╂枡缂栫爜</param>
         /// <returns></returns>
-        public static Location InStorage(Location loc)
+        public static Location InStorage(string itemCode)
         {
             var db = new SqlHelper<object>().GetInstance();
             Location location = null;
             List<Location> list = Locations.Values.ToList();
-            string itemCode = "";
-            string areaCode = "";
+
+            string areaCode = "YCLLKQ";
             try
             {
-                //鏍规嵁璧风偣鑾峰彇鎵樼洏鍜屾墭鐩樼墿鏂欑粦瀹氬叧绯�-                var cntrLoc = LocationHelper.GetLocCntr(loc.S_CODE).FirstOrDefault();
-                if (cntrLoc != null)
-                {
-                    //鑾峰彇鎵樼洏鐗╂枡缁戝畾鍏崇郴
-                    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == cntrLoc.S_CNTR_CODE).First();
-                    if (cntrItem != null)
-                    {
-                        itemCode = cntrItem.S_ITEM_CODE;
-                    }
-                }
+                ////鏍规嵁璧风偣鑾峰彇鎵樼洏鍜屾墭鐩樼墿鏂欑粦瀹氬叧绯�+                /// //string itemCode = "";
+                //var cntrLoc = LocationHelper.GetLocCntr(loc.S_CODE).FirstOrDefault();
+                //if (cntrLoc != null)
+                //{
+                //    //鑾峰彇鎵樼洏鐗╂枡缁戝畾鍏崇郴
+                //    var cntrItem = db.Queryable<CntrItemDetail>().Where(a => a.S_CNTR_CODE == cntrLoc.S_CNTR_CODE).First();
+                //    if (cntrItem != null)
+                //    {
+                //        itemCode = cntrItem.S_ITEM_CODE;
+                //    }
+                //}
 
-                //绌烘墭鍏ュ簱锛岀浉鍚岀墿鏂欏唴娴嬫帓鐨勮揣浣�-                var Locs = GetLocByItemCode(areaCode, itemCode, new int[] { 1, 4 }).OrderByDescending(b => b.N_COL).ToList();
+                //鎵樼洏鍏ュ簱锛岀浉鍚岀墿鏂欏唴娴嬫帓鐨勮揣浣�+                var Locs = GetLocByItemCode(areaCode, itemCode, 1).OrderByDescending(b => b.N_COL).ToList();
+
 
                 if (Locs.Count > 0)
                 {
@@ -97,9 +100,15 @@
                             case 4:
                                 row = 3;
                                 break;
+                            case 5:
+                                row = 6;
+                                break;
+                            case 8:
+                                row = 7;
+                                break;
                         }
                         //瀵绘壘澶栦晶璐т綅
-                        var OutLoc = db.Queryable<Location>().Where(a => a.S_AREA_CODE == Locs[i].S_AREA_CODE && a.N_LAYER == Locs[i].N_LAYER && a.N_ROW == row && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0).First();
+                        var OutLoc = db.Queryable<Location>().Where(a => a.S_AREA_CODE == Locs[i].S_AREA_CODE && a.N_LAYER == Locs[i].N_LAYER && a.N_ROW == row && a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.N_ROADWAY == Locs[i].N_ROADWAY).First();
                         if (OutLoc != null)
                         {
                             location = OutLoc;
@@ -115,7 +124,7 @@
                 //濡傛灉娌℃湁鎵惧埌鐩稿悓鐗╂枡鐨勫渚ц揣浣嶏紝鎵句竴涓唴娴嬬┖璐т綅
                 if (location == null)
                 {
-                    location = GetEmptyLocByItemCode(areaCode, new int[] { 1, 4 });
+                    location = GetEmptyLocByItemCode(areaCode, new List<int> { 1, 4 });
                 }
                 return location;
             }
@@ -127,18 +136,64 @@
 
         }
 
-
-
         #endregion
 
         /// <summary>
-        /// 鏍规嵁鐗╂枡鑾峰緱瀵瑰簲鐨勫唴娴嬭揣浣�+        /// 鏍规嵁鐗╂枡鍜屾帓鍙疯幏寰楀搴旂殑鏈攣瀹氭墭鐩樿揣浣�         /// </summary>
         /// <param name="areaCode">搴撳尯缂栫爜</param>
         /// <param name="row">璐т綅鎺�/param>
         /// <param name="ItemCode">鐗╂枡缂栫爜</param>
         /// <returns></returns>
-        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int[] row)
+        internal static Location GetLocByItemCodeOrderyTime(string areaCode, string ItemCode, string soure = "1")
+        {
+            Location loc = null;
+            var db = new SqlHelper<object>().GetInstance();
+
+            try
+            {
+                var loc1 = db.Queryable<Location>()
+                    .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
+                    .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE)
+                    .LeftJoin<Container>((a, b, c, d) => d.S_CODE == c.S_CNTR_CODE)
+                    .Where((a, b, c, d) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode
+                     && c.S_ITEM_CODE == ItemCode && d.S_SOURCE == soure)
+                    .GroupBy((a, b, c) => new { a.S_CODE, c.T_INBOUND_TIME, a.N_POS, a.N_COL })
+                    .OrderBy((a, b, c) => c.T_INBOUND_TIME)
+                    .OrderByDescending((a, b, c) => a.N_POS)
+                    .OrderBy((a, b, c) => a.N_COL)
+                    .Select((a, b, c) => new
+                    {
+                        S_CODE = a.S_CODE,
+                        T_INBOUND_TIME = c.T_INBOUND_TIME,
+                        N_POS = a.N_POS
+                    })
+                    .ToList();
+                // var LocCodes = loc1.Select(a => a.S_CODE).First();
+                if (loc1.Count > 0)
+                {
+                    loc = db.Queryable<Location>().Where(a => a.S_CODE == loc1.First().S_CODE).First();
+                }
+
+
+                return loc;
+            }
+            catch (Exception ex)
+            {
+                LogHelper.Info($"GetLocByItemCode Error:{ex}");
+                throw;
+            }
+
+        }
+
+        /// <summary>
+        /// 鏍规嵁鐗╂枡鍜屾帓鍙疯幏寰楀搴旂殑鏈攣瀹氭墭鐩樿揣浣�骞舵寜鎵樼洏鐗╂枡琛ㄦ椂闂村垎缁�+        /// </summary>
+        /// <param name="areaCode">搴撳尯缂栫爜</param>
+        /// <param name="row">璐т綅鎺�/param>
+        /// <param name="ItemCode">鐗╂枡缂栫爜</param>
+        /// <returns></returns>
+        internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, int pos)
         {
             List<Location> locs;
             var db = new SqlHelper<object>().GetInstance();
@@ -147,7 +202,7 @@
                 var queryable = db.Queryable<Location>()
                    .LeftJoin<LocCntrRel>((a, b) => a.S_CODE == b.S_LOC_CODE)
                    .LeftJoin<CntrItemDetail>((a, b, c) => b.S_CNTR_CODE == c.S_CNTR_CODE)
-                   .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && row.Contains(a.N_ROW) && c.S_ITEM_CODE == ItemCode);
+                   .Where((a, b, c) => a.N_CURRENT_NUM > 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && a.N_POS == pos && c.S_ITEM_CODE == ItemCode && a.N_LOCK_STATE == 0);
 
                 locs = queryable.ToList();
 
@@ -167,14 +222,25 @@
         /// <param name="areaCode">搴撳尯缂栫爜</param>
         /// <param name="row">璐т綅鎺�/param>
         /// <returns></returns>
-        internal static Location GetEmptyLocByItemCode(string areaCode, int[] row)
+        internal static Location GetEmptyLocByItemCode(string areaCode, List<int> row)
         {
             var db = new SqlHelper<object>().GetInstance();
             Location location = null;
+
             try
             {
+                //鍒ゆ柇褰撳墠鎺掑彲鐢ㄨ揣浣嶅皬浜� 濡傛灉灏忎簬2鍒欎笉鍏佽鍏�+                for (int i = row.Count(); i < 0; i--)
+                {
+                    var locationNum = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && a.N_ROW == row[i]).ToList().Count;
+                    if (locationNum <= 2)
+                    {
+                        row.RemoveAt(i);
+                    }
+                }
 
                 location = db.Queryable<Location>().Where(a => a.N_CURRENT_NUM == 0 && a.N_LOCK_STATE == 0 && a.S_AREA_CODE == areaCode && row.Contains(a.N_ROW)).First();
+
                 return location;
             }
             catch (Exception ex)
@@ -460,6 +526,7 @@
                 model.S_LOCK_STATE = Location.GetLockStateStr(lockState);
                 res = db.Updateable(model).UpdateColumns(it => new { it.N_LOCK_STATE, it.S_LOCK_STATE }).ExecuteCommand() > 0;
             }
+
             return res;
         }
 
@@ -535,6 +602,7 @@
                 db.BeginTran();
                 var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loc).ToList();
                 var count = db.Deleteable<LocCntrRel>().Where(it => cntrs.Contains(it.S_CNTR_CODE) && it.S_LOC_CODE == loc).ExecuteCommand();
+
                 location.N_CURRENT_NUM = lcrList.Count - count;
                 location.S_LOCK_STATE = "鏃�;
                 location.N_LOCK_STATE = 0;
@@ -572,6 +640,7 @@
                         count++;
                     }
                 });
+
                 location.N_CURRENT_NUM = lcrList.Count + count;
                 location.N_LOCK_STATE = 0;
                 location.S_LOCK_STATE = "鏃�;

--
Gitblit v1.9.1