From f8d23dcf8d6501482db1a5180325194232afe96c Mon Sep 17 00:00:00 2001
From: kazelee <1847801760@qq.com>
Date: 星期五, 18 七月 2025 17:30:09 +0800
Subject: [PATCH] 封装部分业务代码,继续优化日志打印流程

---
 wms/WCSHelper.cs |  121 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 117 insertions(+), 4 deletions(-)

diff --git a/wms/WCSHelper.cs b/wms/WCSHelper.cs
index 06549ea..d145c3a 100644
--- a/wms/WCSHelper.cs
+++ b/wms/WCSHelper.cs
@@ -53,11 +53,96 @@
         }
 
         /// <summary>
-        /// 璧风偣鍑哄簱閿侊紙寮哄埗璧嬪�锛屼笉浼氭鏌oc!=null锛岄攣鐘舵�=鏃狅紝闇�浼犲弬鍓嶇‘璁わ級
+        /// ![[寮冪敤|鐞嗙敱:涓嶇伒娲�娑夊強涓氬姟杩囦簬鍏蜂綋]]妫�煡瀹瑰櫒绫诲瀷鏄惁姝g‘
+        /// </summary>
+        /// <param name="cntrCode"></param>
+        /// <param name="cntrType"></param>
+        /// <param name="errMsg"></param>
+        /// <returns></returns>
+        private static bool CheckCntrType(string cntrCode, string cntrType, out string errMsg) {
+            var db = new SqlHelper<object>().GetInstance();
+            errMsg = string.Empty;
+
+            var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == cntrType).First();
+            if (cntr == null) {
+                errMsg = $"瀹瑰櫒'{cntrCode}'鍦╗瀹瑰櫒琛╙涓笉瀛樺湪,璇峰湪鍓嶅彴椤甸潰涓淮鎶�";
+                return false;
+            }
+            if (cntr.S_TYPE != cntrType) {
+                errMsg = $"瀹瑰櫒'{cntrCode}'鍦╗瀹瑰櫒琛╙涓殑绫诲瀷鏄�{cntr.S_TYPE},涓嶆槸'{cntrType}'!";
+                return false;
+            }
+
+            return true;
+        }
+
+        /// <summary>
+        /// 鏍规嵁瀹瑰櫒鍙�鏌ヨ褰撳墠瀹瑰櫒鍏宠仈鐨刐璐т綅/瀹瑰櫒/鐗╂枡]淇℃伅(鍙煡璇�鏉�
+        /// </summary>
+        /// <param name="cntrCode">瀹瑰櫒鍙�/param>
+        /// <param name="skipCgDetail">鏄惁璺宠繃[鐗╂枡琛╙鐨勬煡璇�褰撳鍣ㄥ彿鏉ヨ嚜[鐗╂枡琛╙鏃�</param>
+        /// <returns></returns>
+        public static LocCntrCg GetLocCntrCg(string cntrCode, bool skipCgDetail = false) {
+            var db = new SqlHelper<object>().GetInstance();
+
+            TN_CG_Detail cgDetail = null;
+            if (!skipCgDetail) {
+                cgDetail = db.Queryable<TN_CG_Detail>().Where(d => d.S_CNTR_CODE == cntrCode).First();
+            }
+
+            var locCntrRel = db.Queryable<TN_Loc_Container>().Where(c => c.S_CNTR_CODE == cntrCode).First();
+
+            TN_Location location = null;
+            if (locCntrRel != null) {
+                location = db.Queryable<TN_Location>().Where(l => l.S_CODE == locCntrRel.S_LOC_CODE).First();
+                if (location == null) {
+                    LogHelper.Warn($"");
+                }
+            }
+            if (location != null) {
+                location.N_CURRENT_NUM = 0;
+                location.T_MODIFY = DateTime.Now;
+            }
+
+            return new LocCntrCg {
+                CgDetail = cgDetail,
+                LocCntrRel = locCntrRel,
+                Location = location
+            };
+        }
+
+        /// <summary>
+        /// 缁戝畾[璐т綅-瀹瑰櫒]淇℃伅
+        /// </summary>
+        /// <param name="startLoc"></param>
+        /// <param name="cntrCode"></param>
+        /// <returns></returns>
+        public static TN_Loc_Container BindLocCntr(ref TN_Location startLoc, string cntrCode) {
+            var locCntrRel = new TN_Loc_Container {
+                S_LOC_CODE = startLoc.S_CODE,
+                S_CNTR_CODE = cntrCode,
+            };
+
+            startLoc.N_CURRENT_NUM = 1;
+            startLoc.T_MODIFY = DateTime.Now;
+
+            return locCntrRel;
+        }
+
+        /// <summary>
+        /// 璧风偣鍑哄簱閿�         /// </summary>
         /// <param name="loc"></param>
         /// <param name="lockSource"></param>
         public static void LockStartLoc(ref TN_Location loc, string lockSource = "") {
+            if (loc == null) {
+                throw new ArgumentNullException(); // 鎺ュ彈璐т綅loc涓虹┖鏃剁洿鎺ユ姏寮傚父(閫氬父涓嶄細鍙戠敓)
+            }
+
+            if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "鏃�) {
+                LogHelper.Warn($"璧风偣鍑哄簱閿�绋嬪簭姝e湪灏濊瘯缁欏綋鍓峓閿佺姸鎬乚涓嶆槸'鏃�鐨勮揣浣嶄笂閿�璐т綅='{loc.S_CODE}',閿佺姸鎬�({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})");
+            }
+
             loc.N_LOCK_STATE = 2; // 璧风偣鍑哄簱閿�             loc.S_LOCK_STATE = TN_Location.GetLockStateStr(2); // 璧风偣鍑哄簱閿�             loc.S_LOCK_OP = lockSource;
@@ -65,17 +150,35 @@
         }
 
         /// <summary>
-        /// 缁堢偣鍏ュ簱閿侊紙寮哄埗璧嬪�锛屼笉浼氭鏌oc!=null锛岄攣鐘舵�=鏃狅紝闇�浼犲弬鍓嶇‘璁わ級
+        /// 缁堢偣鍏ュ簱閿�         /// </summary>
         /// <param name="loc"></param>
         /// <param name="lockSource"></param>
         public static void LockEndLoc(ref TN_Location loc, string lockSource = "") {
+            if (loc == null) {
+                throw new ArgumentNullException(); // 鎺ュ彈璐т綅loc涓虹┖鏃剁洿鎺ユ姏寮傚父(閫氬父涓嶄細鍙戠敓)
+            }
+
+            if (loc.N_LOCK_STATE != 0 || loc.S_LOCK_STATE != "鏃�) {
+                LogHelper.Warn($"璧风偣鍑哄簱閿�绋嬪簭姝e湪灏濊瘯缁欏綋鍓峓閿佺姸鎬乚涓嶆槸'鏃�鐨勮揣浣嶄笂閿�璐т綅='{loc.S_CODE}',閿佺姸鎬�({loc.N_LOCK_STATE},{loc.S_LOCK_STATE})");
+            }
+
             loc.N_LOCK_STATE = 1; // 缁堢偣鍑哄簱閿�             loc.S_LOCK_STATE = TN_Location.GetLockStateStr(1); // 缁堢偣鍑哄簱閿�             loc.S_LOCK_OP = lockSource;
             loc.T_MODIFY = System.DateTime.Now;
         }
 
+        /// <summary>
+        /// 鍒涘缓浠诲姟
+        /// </summary>
+        /// <param name="startLoc">璧风偣璐т綅:鑷冲皯鎻愪緵:S_CODE,S_AREA_CODE</param>
+        /// <param name="endLoc">缁堢偣璐т綅:鑷冲皯鎻愪緵:S_CODE,S_AREA_CODE</param>
+        /// <param name="cntId">瀹瑰櫒鍙�/param>
+        /// <param name="type">浠诲姟绫诲瀷(鍚嶇О)</param>
+        /// <param name="pri">浼樺厛绾�/param>
+        /// <param name="agvType">AGV绫诲瀷</param>
+        /// <returns></returns>
         public static TN_Task BuildTask(TN_Location startLoc, TN_Location endLoc, string cntId, string type, int pri = 3, int agvType = 1) {
             TN_Task TN_Task = new TN_Task() {
                 S_CODE = GenerateTaskNo(),
@@ -86,12 +189,13 @@
                 S_TYPE = type,
                 N_PRIORITY = pri,
                 N_SCHEDULE_TYPE = agvType,
-                N_B_STATE = 0, // 浠诲姟鍒涘缓鏃讹紝榛樿绛夊緟
+                N_B_STATE = 0, // 浠诲姟鍒涘缓鏃�榛樿绛夊緟
                 S_CNTR_CODE = cntId,
             };
 
             return TN_Task;
         }
+
 
         internal static bool CheckActionRecordExist(string no, int code) {
             var db = new SqlHelper<TN_Task_Action>().GetInstance();
@@ -122,7 +226,7 @@
         internal static void Fail(TN_Task task) {
             var db = new SqlHelper<TN_Task>().GetInstance();
             if (task != null) {
-                //鍒ゆ柇鏈夋病鏈夊彇璐у畬鎴愶紝娌℃湁灏卞彉鎴愬け璐ャ�鏈夊彇璐у畬鎴愰粯璁ゅ畬鎴愪簡锛堣窡鎹」鐩�瀹氾紝鏈変簺椤圭洰浜哄伐鎷夎蛋浜嗕篃娌℃湁鏀惧埌缁堢偣锛夈�
+                //鍒ゆ柇鏈夋病鏈夊彇璐у畬鎴�娌℃湁灏卞彉鎴愬け璐ャ�鏈夊彇璐у畬鎴愰粯璁ゅ畬鎴愪簡 (璺熸嵁椤圭洰鑰屽畾,鏈変簺椤圭洰浜哄伐鎷夎蛋浜嗕篃娌℃湁鏀惧埌缁堢偣) 銆�                 task.N_B_STATE = 4;
                 task.S_B_STATE = TN_Task.GetStateStr(task.N_B_STATE);
                 db.Updateable(task).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE }).ExecuteCommand();
@@ -146,4 +250,13 @@
             return db.Queryable<TN_Task>().Where(a => a.N_B_STATE == 0 && (a.S_B_STATE == "绛夊緟" || a.S_B_STATE == "寰呮帹閫�)).ToList();
         }
     }
+
+    /// <summary>
+    /// [璐т綅/瀹瑰櫒/鐗╂枡]淇℃伅
+    /// </summary>
+    public class LocCntrCg {
+        public TN_CG_Detail CgDetail { get; set; } = null;
+        public TN_Loc_Container LocCntrRel { get; set; } = null;
+        public TN_Location Location { get; set; } = null;
+    }
 }

--
Gitblit v1.9.1