From b2c8747a85762bc32f310a31fe84cad69b61104a Mon Sep 17 00:00:00 2001 From: lss <Lss@HanInfo> Date: 星期二, 10 六月 2025 17:32:46 +0800 Subject: [PATCH] 优化 --- HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs | 159 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 150 insertions(+), 9 deletions(-) diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs index eeff55c..94f4928 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JiaTong/wms/LocationHelper.cs @@ -3,9 +3,11 @@ using NLog.Fluent; using SqlSugar; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using static HH.WCS.JiaTong.dispatch.NDC; @@ -37,7 +39,7 @@ //鍒濆鍖朙ocationExt鍔犲叆鍒伴泦鍚堢紦瀛� LocationExts = new Dictionary<string, LocationExt>(); var exts = GetAllLocExtList(); - // LogHelper.Info($"鑾峰彇璐т綅鎵╁睍琛ㄤ俊鎭細{JsonConvert.SerializeObject(exts)}"); + // LogHelper.Info($"鑾峰彇璐т綅鎵╁睍琛ㄤ俊鎭細{JsonConvert.SerializeObject(exts)}"); if (exts.Count > 0) { exts.ForEach(a => @@ -193,6 +195,14 @@ return result; } + // 瀹氫箟绛夌骇椤哄簭锛堜粠楂樺埌浣庯級 + private static readonly List<string> LevelOrder = new List<string> + { + "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", + "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", + "U", "V", "W", "X", "Y", "Z" + }; + /// <summary> /// 鏍规嵁鐗╂枡鎵炬墭鐩� /// </summary> @@ -202,14 +212,32 @@ /// <returns></returns> internal static List<Location> GetLocByItemCode(string areaCode, string ItemCode, string lev) { + List<Location> locs; + + var db = new SqlHelper<object>().GetInstance(); - 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 && c.S_ITEM_CODE == ItemCode); + .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); + //鍏綅鐮佸尮閰嶅墠鍏綅锛屽叾浠栫殑鍏ㄩ儴閰嶇疆 + if (ItemCode.Trim().Length == 6) + { + queryable = queryable.Where((a, b, c) => c.S_ITEM_CODE.StartsWith(ItemCode)); + } + else + { + queryable = queryable.Where((a, b, c) => c.S_ITEM_CODE == ItemCode); + } + //int targetIndex = LevelOrder.IndexOf(lev); + //// 鑾峰彇鎵�湁浣庝簬鎴栫瓑浜庣洰鏍囩瓑绾х殑绛夌骇 + //var validLevels = LevelOrder + //.Skip(targetIndex) // 璺宠繃楂樹簬鐩爣绛夌骇鐨勭瓑绾�+ //.ToList(); + + LogHelper.Info($"GetLocByItemCode=>鏍规嵁搴撳尯缂栫爜:{areaCode}锛岀墿鏂欑紪鐮�{ItemCode},鐗╂枡浼樺厛绾�{lev}锛岀墿鏂欑瓑绾ц绠楀嚭鏈夋墭鐩樿揣浣峽JsonConvert.SerializeObject(queryable.ToList())}"); //鍒ゆ柇闇�笉闇�鐗╂枡绛夌骇鏌ユ壘锛屽苟浼樺厛鍑哄簱浣欐枡 if (string.IsNullOrEmpty(lev)) { @@ -219,9 +247,28 @@ { locs = queryable.Where((a, b, c) => c.LEV == lev && c.S_BS_TYPE == "浣欐枡").ToList(); } + // LogHelper.Info($"GetLocByItemCode=>鏌ユ壘浣欐枡,{JsonConvert.SerializeObject(locs)}"); + //娌℃湁浣欐枡鍒欏鎵惧叏閮ㄧ墿鏂� if (locs.Count == 0) { + 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); + //鍏綅鐮佸尮閰嶅墠鍏綅锛屽叾浠栫殑鍏ㄩ儴閰嶇疆 + if (ItemCode.Trim().Length == 6) + { + queryable = queryable.Where((a, b, c) => c.S_ITEM_CODE.StartsWith(ItemCode)); + + } + else + { + queryable = queryable.Where((a, b, c) => c.S_ITEM_CODE == ItemCode); + } + LogHelper.Info($"GetLocByItemCode=>鏃犱綑鏂�鏌ユ壘鍏ㄩ儴{JsonConvert.SerializeObject(queryable.ToList())}"); + + if (string.IsNullOrEmpty(lev)) { locs = queryable.ToList(); @@ -230,12 +277,75 @@ { locs = queryable.Where((a, b, c) => c.LEV == lev).ToList(); } + LogHelper.Info($"GetLocByItemCode=>鏃犱綑鏂�鏌ユ壘鍏ㄩ儴{JsonConvert.SerializeObject(locs)}"); } return locs; } + /// <summary> + /// 鏍规嵁搴撳尯鑾峰彇绌烘墭 + /// </summary> + /// <param name="areaCode">搴撳尯缂栫爜</param> + /// <returns></returns> + internal static Location GetLocByAreacode(string areaCode, string type) + { + Location loc = new Location(); + var db = new SqlHelper<object>().GetInstance(); + string CntrCodeWith = ""; + if (type.Trim() == "PM") + { + CntrCodeWith = "MA"; + } + else if (type.Trim() == "PN") + { + CntrCodeWith = "NA"; + } + if (CntrCodeWith == "") + { + LogHelper.Info($"鎵樼洏绫诲瀷{type}涓嶅湪瑙勫畾鑼冨洿"); + } + var query = 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.S_AREA_CODE == areaCode && a.N_CURRENT_NUM == 1 + && a.N_LOCK_STATE == 0 + && b.S_CNTR_CODE != null && b.S_CNTR_CODE.Contains(CntrCodeWith) && c.S_ITEM_CODE == null + ); + loc = query.First(); + + return loc; + } + + /// <summary> + /// 鍒嗛厤鐢垫璐т綅 + /// </summary> + /// <returns></returns> + internal static Location GetElevatorLoc() + { + var db = new SqlHelper<object>().GetInstance(); + Location location = new Location(); + //鏌ユ壘鍏ㄩ儴鐢垫锛屽垎閰嶄换鍔℃渶灏戠殑鐢垫 + var devices = Settings.deviceInfos.Where(a => a.deviceType == 2 && a.enable == 1).ToList(); + string[] state = new string[] { "鎵ц涓�, "寮�鍙栬揣", "鍙栬揣瀹屾垚" }; + Dictionary<int, string> dics = new Dictionary<int, string>(); + foreach (var deviceInfo in devices) + { + int mst = db.Queryable<WCSTask>().Where(a => a.S_TYPE.Contains("鐢垫") && state.Contains(a.S_B_STATE)).Count(); + dics.Add(mst, deviceInfo.TN_Location); + } + if (dics.Count > 0) + { + var dic = dics.OrderBy(a => a.Key).First(); + location = db.Queryable<Location>().Where(a => a.S_CODE == dic.Value).First(); + if (location == null) + { + LogHelper.Info($"鏍规嵁璐т綅缂栫爜:{dic.Value},鏈壘鍒板搴旇揣浣�); + } + } + return location; + } /// <summary> /// 鏍规嵁鐗╂枡缂栫爜锛屼粨搴撶紪鐮佽幏鍙栨墭鐩樻暟閲� /// </summary> @@ -415,15 +525,15 @@ } /// <summary> - /// 鏍规嵁璐т綅闆嗗悎鑾峰彇 娌℃湁瀹瑰櫒 娌℃湁閿佺殑璐т綅 + /// 鏍规嵁璐т綅鑾峰彇璐т綅淇℃伅 /// </summary> /// <param name="loc"></param> /// <returns></returns> - internal static List<Location> GetLocListEmptyFree(List<string> loc) + internal static Location GetLocByLoc(string loc) { //1.0 鏌ヨ揣浣嶅鍣ㄨ〃 var db = new SqlHelper<object>().GetInstance(); - var list = db.Queryable<Location>().Where(a => loc.Contains(a.S_CODE) && a.N_CURRENT_NUM == 0 && a.S_LOCK_STATE.Trim() == "鏃�).ToList(); + var list = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); return list; } @@ -454,7 +564,11 @@ } else { - LogHelper.Info($"閿佸畾璐т綅{loc}鎴愬姛"); + LogHelper.Info($"閿佸畾璐т綅{loc}澶辫触,閲嶆柊閿�); + Task.Run(() => + { + LockLoc(loc, lockState); + }); } return res; } @@ -521,6 +635,33 @@ } return res; } + + /// <summary> + /// 瑙i攣璐т綅 + /// </summary> + /// <param name="loc"></param> + /// <returns></returns> + public static bool UnlockLoc(string loc) + { + var res = false; + var db = new SqlHelper<object>().GetInstance(); + var location = db.Queryable<Location>().Where(a => a.S_CODE.Trim() == loc).First(); + try + { + db.BeginTran(); + var lcrList = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE.Trim() == loc).ToList(); + location.S_LOCK_STATE = "鏃�; + location.N_LOCK_STATE = 0; + db.Updateable(location).UpdateColumns(it => new { it.S_LOCK_STATE, it.N_LOCK_STATE }).ExecuteCommand(); + db.CommitTran(); + res = true; + } + catch (Exception ex) + { + db.RollbackTran(); + } + return res; + } /// <summary> /// 璐т綅缁戝畾瀹瑰櫒 /// </summary> -- Gitblit v1.9.1