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 |  248 ++++++++++++++++++++++++++++---------------------
 1 files changed, 143 insertions(+), 105 deletions(-)

diff --git a/wms/WCSHelper.cs b/wms/WCSHelper.cs
index 10eafbf..d145c3a 100644
--- a/wms/WCSHelper.cs
+++ b/wms/WCSHelper.cs
@@ -29,7 +29,7 @@
             var db = new SqlHelper<TN_Task>().GetInstance();
             task.S_B_STATE = TN_Task.GetStateStr(task.N_B_STATE);
             task.T_MODIFY = DateTime.Now;
-            db.Updateable(task).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE, it.T_MODIFY }).ExecuteCommand();
+            res = db.Updateable(task).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE, it.T_MODIFY }).ExecuteCommand() > 0;
             return res;
         }
         internal static bool UpdateEQNo(TN_Task task) {
@@ -46,116 +46,154 @@
             return task;
         }
 
-        public static TN_Task BuildTask(TN_Location startLoc, TN_Location endLoc, string cntId, string type) {
-            TN_Task TN_Task = new TN_Task() {
-                S_CODE = GenerateTaskNo(),
-                S_START_AREA = startLoc.S_AREA_CODE,
-                S_END_AREA = endLoc.S_AREA_CODE,
-                S_START_LOC = startLoc.S_CODE,
-                S_END_LOC = endLoc.S_CODE,
-                S_TYPE = type,
-                N_PRIORITY = 3, // 鍒濆浼樺厛绾ч粯璁や负锛�
-                N_SCHEDULE_TYPE = 1, // NDC
-                N_B_STATE = 0,
-                S_CNTR_CODE = cntId,
-            };
-
-            return TN_Task;
-        }
-
-        public static TN_Task BuildErpTask(TN_Location startLoc, TN_Location endLoc, string cntId, string type, string erpNo) {
-            TN_Task TN_Task = new TN_Task() {
-                S_CODE = GenerateTaskNo(),
-                S_START_AREA = startLoc.S_AREA_CODE,
-                S_END_AREA = endLoc.S_AREA_CODE,
-                S_START_LOC = startLoc.S_CODE,
-                S_END_LOC = endLoc.S_CODE,
-                S_TYPE = type,
-                N_PRIORITY = 3, // 鍒濆浼樺厛绾ч粯璁や负锛�
-                N_SCHEDULE_TYPE = 1, // NDC
-                N_B_STATE = 0,
-                S_CNTR_CODE = cntId,
-                S_BS_NO = erpNo,
-                S_BS_TYPE = "ERP",
-            };
-
-            return TN_Task;
+        public static string GetAgvSite(string locCode) {
+            var db = new SqlHelper<object>().GetInstance();
+            var loc = db.Queryable<TN_Location>().Where(l => l.S_CODE == locCode).First();
+            return loc == null ? "0" : loc.S_AGV_SITE;
         }
 
         /// <summary>
-        /// 鍒涘缓鎼�浠诲姟
+        /// ![[寮冪敤|鐞嗙敱:涓嶇伒娲�娑夊強涓氬姟杩囦簬鍏蜂綋]]妫�煡瀹瑰櫒绫诲瀷鏄惁姝g‘
         /// </summary>
-        /// <param name="no">缂栧彿</param>
-        /// <param name="from">璧风偣</param>
-        /// <param name="to">缁堢偣</param>
-        /// <param name="taskType">浠诲姟绫诲瀷</param>
-        /// <param name="pri">浼樺厛绾�/param>
-        /// <param name="cntrInfo">瀹瑰櫒缂栫爜</param>
+        /// <param name="cntrCode"></param>
+        /// <param name="cntrType"></param>
+        /// <param name="errMsg"></param>
         /// <returns></returns>
-        internal static bool CreateTask(string from, string to, string taskType, int pri, string cntrInfo) {
-            var fromLoc = LocationHelper.GetLocation(from);
-            var endLoc = LocationHelper.GetLocation(to);
-            TN_Task TN_Task = new TN_Task() {
-                S_CODE = GenerateTaskNo(),
-                S_START_AREA = fromLoc.S_AREA_CODE,
-                S_END_AREA = endLoc.S_AREA_CODE,
-                S_START_LOC = from,
-                S_END_LOC = to,
-                S_TYPE = taskType,
-                N_PRIORITY = pri,
-                N_SCHEDULE_TYPE = 1,
-                N_B_STATE = 0,
-                S_CNTR_CODE = cntrInfo,
-            };
+        private static bool CheckCntrType(string cntrCode, string cntrType, out string errMsg) {
+            var db = new SqlHelper<object>().GetInstance();
+            errMsg = string.Empty;
 
-            var log = JsonConvert.SerializeObject(TN_Task);
-            var db = new SqlHelper<TN_Task>().GetInstance();
-            var res = db.Insertable(TN_Task).ExecuteCommand() > 0;
-            if (res) {
-                LogHelper.Info($"鎻掑叆浠诲姟鎴愬姛锛寋log}");
+            var cntr = db.Queryable<TN_Container>().Where(c => c.S_CODE == cntrType).First();
+            if (cntr == null) {
+                errMsg = $"瀹瑰櫒'{cntrCode}'鍦╗瀹瑰櫒琛╙涓笉瀛樺湪,璇峰湪鍓嶅彴椤甸潰涓淮鎶�";
+                return false;
             }
-            else {
-                LogHelper.Info($"鎻掑叆浠诲姟澶辫触锛寋log}");
+            if (cntr.S_TYPE != cntrType) {
+                errMsg = $"瀹瑰櫒'{cntrCode}'鍦╗瀹瑰櫒琛╙涓殑绫诲瀷鏄�{cntr.S_TYPE},涓嶆槸'{cntrType}'!";
+                return false;
             }
-            return res;
 
+            return true;
         }
 
-        public static bool CreateTask(List<CreateTasks> modes) {
-            if (modes != null && modes.Count > 0) {
-                List<TN_Task> tN_Tasks = new List<TN_Task>();
+        /// <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();
 
-                foreach (var item in modes) {
-
-                    var fromLoc = LocationHelper.GetLocation(item.from);
-                    var endLoc = LocationHelper.GetLocation(item.to);
-
-                    tN_Tasks.Add(new TN_Task() {
-                        S_CODE = GenerateTaskNo(),
-                        S_START_AREA = fromLoc.S_AREA_CODE,
-                        S_END_AREA = endLoc.S_AREA_CODE,
-                        S_START_LOC = item.from,
-                        S_END_LOC = item.to,
-                        S_TYPE = item.taskType,
-                        N_PRIORITY = item.pri,
-                        N_SCHEDULE_TYPE = 1,
-                        N_B_STATE = 0,
-                        S_CNTR_CODE = item.cntrInfo,
-                    });
-                }
-                var log = JsonConvert.SerializeObject(tN_Tasks);
-                var db = new SqlHelper<object>().GetInstance();
-                var res = db.Insertable<TN_Task>(tN_Tasks).ExecuteCommand() > 0;
-                if (res) {
-                    LogHelper.Info($"鎻掑叆浠诲姟鎴愬姛锛寋log}");
-                }
-                else {
-                    LogHelper.Info($"鎻掑叆浠诲姟澶辫触锛寋log}");
-                }
-                return res;
+            TN_CG_Detail cgDetail = null;
+            if (!skipCgDetail) {
+                cgDetail = db.Queryable<TN_CG_Detail>().Where(d => d.S_CNTR_CODE == cntrCode).First();
             }
 
-            return false;
+            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;
+            loc.T_MODIFY = System.DateTime.Now;
+        }
+
+        /// <summary>
+        /// 缁堢偣鍏ュ簱閿�+        /// </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(),
+                S_START_AREA = startLoc.S_AREA_CODE,
+                S_END_AREA = endLoc.S_AREA_CODE,
+                S_START_LOC = startLoc.S_CODE,
+                S_END_LOC = endLoc.S_CODE,
+                S_TYPE = type,
+                N_PRIORITY = pri,
+                N_SCHEDULE_TYPE = agvType,
+                N_B_STATE = 0, // 浠诲姟鍒涘缓鏃�榛樿绛夊緟
+                S_CNTR_CODE = cntId,
+            };
+
+            return TN_Task;
         }
 
 
@@ -174,7 +212,6 @@
                     task.S_EQ_NO = forklift_no;
                     db.Updateable(task).UpdateColumns(it => new { it.N_B_STATE, it.S_B_STATE, it.T_START_TIME, it.S_EQ_NO }).ExecuteCommand();
                 }
-
             }
         }
         internal static void End(TN_Task task) {
@@ -189,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();
@@ -214,11 +251,12 @@
         }
     }
 
-    public class CreateTasks {
-        public string from { set; get; }
-        public string to { set; get; }
-        public string taskType { set; get; }
-        public int pri { set; get; }
-        public string cntrInfo { set; get; }
+    /// <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