From fc25dda9baf3b5f4df23d35914f3dd343cf492e3 Mon Sep 17 00:00:00 2001 From: kazelee <1847801760@qq.com> Date: 星期一, 28 七月 2025 17:30:21 +0800 Subject: [PATCH] 优化WCSHelper / 序列号生成逻辑 , 添加强制任务处理模块 --- wms/WCSHelper.cs | 88 +++++++++++++++++++++++++++++++++----------- 1 files changed, 66 insertions(+), 22 deletions(-) diff --git a/wms/WCSHelper.cs b/wms/WCSHelper.cs index 63ff4e4..0e73985 100644 --- a/wms/WCSHelper.cs +++ b/wms/WCSHelper.cs @@ -14,20 +14,65 @@ /// <summary> /// [ 閫氱敤涓氬姟 ] 甯姪绫� /// </summary> - internal class WCSHelper { - internal static string GenerateTaskNo() { - var id = SYSHelper.GetSerialNumber("浠诲姟鍙�, "TN"); - var date = DateTime.Now.ToString("yyMMdd"); - return $"TN{date}{id.ToString().PadLeft(4, '0')}"; + public class WCSHelper { + #region LocationHelper + private static Dictionary<string, TN_Location> _locationDict = null; + + static WCSHelper() { + var db = new SqlHelper<object>().GetInstance(); + + try { + //鍒濆鍖朙ocation鍔犲叆鍒板瓧鍏哥紦瀛�+ _locationDict = new Dictionary<string, TN_Location>(); + var locList = db.Queryable<TN_Location>().ToList(); + foreach (var loc in locList) { + if (!_locationDict.ContainsKey(loc.S_CODE)) { + _locationDict.Add(loc.S_CODE, loc); + } + } + } + catch (Exception ex) { + LogHelper.InfoEx(ex, "WCSHelper:鍒濆鍖朙ocation鍒板瓧鍏哥紦瀛�); + } } - internal static bool UpdateStatus(TN_Task task, string status) { + + public static TN_Location GetLocation(string locCode, bool useDict = true) { + if (useDict && _locationDict.Keys.Contains(locCode)) { + return _locationDict[locCode.Trim()]; + } + + var db = new SqlHelper<object>().GetInstance(); + return db.Queryable<TN_Location>().Where(l => l.S_CODE == locCode).First(); + } + + public static string GetAgvSite(string locCode, bool useDict = true) { + if (useDict && _locationDict.Keys.Contains(locCode)) { + return _locationDict[locCode.Trim()].S_AGV_SITE; + } + + 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; + } + #endregion + + #region 浠诲姟鍒涘缓 / 涓嬪彂 / 鏌ヨ + internal static string GenerateTaskNo() { + //var id = SYSHelper.GetSerialNumberResetByDay("浠诲姟鍙�, "TN"); + //var date = DateTime.Now.ToString("yyMMdd"); + //return $"TN{date}{id.ToString().PadLeft(4, '0')}"; + return SYSHelper.GenerateSN("浠诲姟鍙�, "TN", "yyMMdd"); + } + + internal static bool UpdateTaskState(TN_Task task, string state) { var res = false; var db = new SqlHelper<TN_Task>().GetInstance(); - task.S_B_STATE = status; + task.S_B_STATE = state; res = db.Updateable(task).UpdateColumns(it => new { it.S_B_STATE }).ExecuteCommand() > 0; return res; } - internal static bool UpdateStatus(TN_Task task) { + + internal static bool UpdateTaskState(TN_Task task) { var res = false; var db = new SqlHelper<TN_Task>().GetInstance(); task.S_B_STATE = TN_Task.GetStateStr(task.N_B_STATE); @@ -35,25 +80,21 @@ 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) { + + internal static bool UpdateEqTaskNo(TN_Task task) { var res = false; var db = new SqlHelper<TN_Task>().GetInstance(); task.T_MODIFY = DateTime.Now; - db.Updateable(task).UpdateColumns(it => new { it.S_EQ_TASK_CODE, it.T_MODIFY }).ExecuteCommand(); + res = db.Updateable(task).UpdateColumns(it => new { it.S_EQ_TASK_CODE, it.T_MODIFY }).ExecuteCommand() > 0; return res; } - internal static TN_Task GetTask(string no) { + internal static TN_Task GetTask(string taskNo) { var db = new SqlHelper<TN_Task>().GetInstance(); - var task = db.Queryable<TN_Task>().Where(a => a.S_CODE == no).First(); + var task = db.Queryable<TN_Task>().Where(a => a.S_CODE == taskNo).First(); return 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; - } + } + #endregion #region 瀹瑰櫒鐩稿叧淇℃伅 鏌ヨ / 缁戝畾 /// <summary> @@ -217,15 +258,17 @@ /// <param name="pri">浼樺厛绾�/param> /// <param name="agv">AGV 绫诲瀷</param> /// <returns></returns> - public static TN_Task BuildTaskWithLocLock(TN_Location startLoc, TN_Location endLoc, string cntId, string type, int pri = 3, int agv = 1) { + public static TN_Task BuildTaskWithLocLock(TN_Location startLoc, TN_Location endLoc, string cntId, string type, + int pri = 3, int agv = 1) { var task = BuildTask(startLoc, endLoc, cntId, type, pri); LockStartLoc(startLoc, task.S_CODE); LockEndLoc(endLoc, task.S_CODE); return task; - } + } #endregion + #region 浠诲姟鍒嗗彂 / 鎵ц / 璁板綍 internal static bool CheckActionRecordExist(string no, int code) { var db = new SqlHelper<TN_Task_Action>().GetInstance(); return db.Queryable<TN_Task_Action>().Count(a => a.S_TASK_CODE == no && a.N_ACTION_CODE == code) > 0; @@ -277,7 +320,8 @@ internal static List<TN_Task> GetWaitingTaskList() { var db = new SqlHelper<object>().GetInstance(); return db.Queryable<TN_Task>().Where(a => a.N_B_STATE == 0 && (a.S_B_STATE == "绛夊緟" || a.S_B_STATE == "寰呮帹閫�)).ToList(); - } + } + #endregion } /// <summary> -- Gitblit v1.9.1