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 +++++++++--- wms/SYSHelper.cs | 35 +++- api/DebugController.cs | 5 api/ForceController.cs | 77 +++++++++++ /dev/null | 108 --------------- api/ApiHelper.cs | 19 +- App_Start/SwaggerControllerDescProvider.cs | 11 - util/LogHelper.cs | 8 process/TaskProcess.cs | 20 +- core/WCSCore.cs | 8 wms/DbTran.cs | 2 HH.WCS.Mobox3.DSZSH.csproj | 2 12 files changed, 197 insertions(+), 186 deletions(-) diff --git a/App_Start/SwaggerControllerDescProvider.cs b/App_Start/SwaggerControllerDescProvider.cs index 10f7f94..b7f37fc 100644 --- a/App_Start/SwaggerControllerDescProvider.cs +++ b/App_Start/SwaggerControllerDescProvider.cs @@ -15,9 +15,7 @@ private static ConcurrentDictionary<string, SwaggerDocument> _cache = new ConcurrentDictionary<string, SwaggerDocument>(); private readonly string _xmlPath; - /// <summary> - /// - /// </summary> + /// <summary></summary> /// <param name="swaggerProvider"></param> /// <param name="xmlpath">xml鏂囨。璺緞</param> public SwaggerCacheProvider(ISwaggerProvider swaggerProvider, string xmlpath) @@ -34,10 +32,9 @@ { srcDoc = _swaggerProvider.GetSwagger(rootUrl, apiVersion); - srcDoc.vendorExtensions = new Dictionary<string, object> - { - { "ControllerDesc", GetControllerDesc() } - }; + srcDoc.vendorExtensions = new Dictionary<string, object> { + { "ControllerDesc", GetControllerDesc() } + }; _cache.TryAdd(cacheKey, srcDoc); } return srcDoc; diff --git a/HH.WCS.Mobox3.DSZSH.csproj b/HH.WCS.Mobox3.DSZSH.csproj index adf462c..5bc18dd 100644 --- a/HH.WCS.Mobox3.DSZSH.csproj +++ b/HH.WCS.Mobox3.DSZSH.csproj @@ -228,6 +228,7 @@ <Compile Include="api\ApiModel.cs" /> <Compile Include="api\DebugController.cs" /> <Compile Include="api\ErpController.cs" /> + <Compile Include="api\ForceController.cs" /> <Compile Include="api\MesController.cs" /> <Compile Include="api\MoboxController.cs" /> <Compile Include="api\AgvController.cs" /> @@ -272,7 +273,6 @@ <Compile Include="util\LogHelper.cs" /> <Compile Include="util\WebHelper.cs" /> <Compile Include="wms\DbTran.cs" /> - <Compile Include="wms\LocationHelper.cs" /> <Compile Include="wms\LogMsg.cs" /> <Compile Include="wms\DbExpr.cs" /> <Compile Include="wms\SYSHelper.cs" /> diff --git a/api/ApiHelper.cs b/api/ApiHelper.cs index 7328525..08ce187 100644 --- a/api/ApiHelper.cs +++ b/api/ApiHelper.cs @@ -77,7 +77,6 @@ } catch (Exception ex) { return NewSimpleResult(ex, preLog); - } } @@ -239,16 +238,11 @@ var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, model.CntId, taskInfo.TaskName); - if (needUpdateContainer) { - cntr.S_SOURCE = task.S_CODE; // 鐢ㄤ换鍔″彿浣滀负瀹瑰櫒鏇存柊鐨勪緷鎹�- cntr.T_MODIFY = DateTime.Now; - } - else { - cntr = null; - } + cntr.S_SOURCE = task.S_CODE; // 鐢ㄤ换鍔″彿浣滀负瀹瑰櫒鏇存柊鐨勪緷鎹�+ cntr.T_MODIFY = DateTime.Now; (ok, msg) = DbTran.CreateTask(new CreateTaskObj { - ContainerToUpdate = cntr, + ContainerToUpdate = needUpdateContainer ? cntr : null, StartLocToUpdate = startLoc, EndLocToUpdate = endLoc, TaskToInsert = task, @@ -659,9 +653,10 @@ } private static string GenerateOrderNo(string snType, string prefix) { - var id = SYSHelper.GetSerialNumber(snType, prefix); - var date = DateTime.Now.ToString("yyMMdd"); - return $"{prefix}{date}-{id.ToString().PadLeft(4, '0')}"; + //var id = SYSHelper.GetSerialNumberResetByDay(snType, prefix); + //var date = DateTime.Now.ToString("yyMMdd"); + //return $"{prefix}{date}-{id.ToString().PadLeft(4, '0')}"; + return SYSHelper.GenerateSN(snType, prefix, "yyMMdd"); } /// <summary> diff --git a/api/DebugController.cs b/api/DebugController.cs index 73661eb..b91bb2e 100644 --- a/api/DebugController.cs +++ b/api/DebugController.cs @@ -113,7 +113,7 @@ try { // 鏌ヨ璧风偣璐т綅:鏁伴噺=0 var startLoc = db.Queryable<TN_Location>().LeftJoin<TN_Loc_Container>((l, c) => l.S_CODE == c.S_LOC_CODE) - .Where((l,c) => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntrCode).First(); + .Where((l, c) => l.N_LOCK_STATE == 0 && l.S_LOCK_STATE == "鏃� && l.C_ENABLE == "Y" && l.S_CODE == model.StartLoc && l.N_CURRENT_NUM == 1 && c.S_CNTR_CODE == model.CntrCode).First(); if (startLoc == null) { return $"娌℃湁鎵惧埌璧风偣璐т綅'{model.StartLoc}'!瑕佹眰:閿佺姸鎬�'鏃�,褰撳墠瀹瑰櫒鏁伴噺=1"; } @@ -143,12 +143,11 @@ return "鏁版嵁搴撴搷浣滃け璐�"; } - tran.CommitTran() ; + tran.CommitTran(); return "鏁版嵁搴撴搷浣滄垚鍔�; } } catch (Exception ex) { - return ex.Message; } } diff --git a/api/ForceController.cs b/api/ForceController.cs new file mode 100644 index 0000000..8c250b5 --- /dev/null +++ b/api/ForceController.cs @@ -0,0 +1,77 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Http; +using HH.WCS.Mobox3.DSZSH.models; +using HH.WCS.Mobox3.DSZSH.util; +using HH.WCS.Mobox3.DSZSH.wms; + +using static HH.WCS.Mobox3.DSZSH.api.ApiModel; +using static HH.WCS.Mobox3.DSZSH.util.Config; + +namespace HH.WCS.Mobox3.DSZSH.api { + /// <summary> + /// 搴旀�/鐗规畩鎯呭喌鐨勫己鍒舵搷浣滄祦绋�+ /// </summary> + [RoutePrefix("force")] + public class ForceController : ApiController { + /// <summary> + /// 寮哄埗鍒涘缓浠诲姟骞朵笅鍙�+ /// </summary> + /// <param name="model"></param> + /// <returns></returns> + [HttpPost] + [Route("ForceInbound")] + public SimpleResult ForceCreateTask(ForceModel.ForceCreateTaskInfo model) { + return ForceService.ForceCreateTask(model); + } + + public SimpleResult ForceAddCgDetail() { + return NewSimpleResult(0, ""); + } + } + + public class ForceService { + public static SimpleResult ForceCreateTask(ForceModel.ForceCreateTaskInfo model) { + var db = new SqlHelper<object>().GetInstance(); + var (ok, msg) = (false, string.Empty); + var taskInfo = ETask.M婊$涓嬬嚎鍏ュ簱.Info(); + const string preLog = "DEBUG:寮哄埗鍒涘缓浠诲姟:"; + + try { + var startLoc = db.Queryable<TN_Location>().Where(DbExpr.StartLocUnbind(model.StartLoc, taskInfo.StartAreas)).First(); + if (startLoc == null) { + return NewSimpleResult(2, preLog + LogMsg.StartLocUnbindNotFound(model.StartLoc, taskInfo.StartAreas)); + } + + var endLoc = db.Queryable<TN_Location>().Where(DbExpr.EndLoc(areas: taskInfo.EndAreas)) + .OrderBy(l => new { l.N_LAYER }).First(); + if (endLoc == null) { + return NewSimpleResult(3, preLog + LogMsg.EndLocNotFound(areas: taskInfo.EndAreas)); + } + + var task = WCSHelper.BuildTaskWithLocLock(startLoc, endLoc, model.CntId, taskInfo.TaskName); + + (ok, msg) = DbTran.CreateTask(new CreateTaskObj { + StartLocToUpdate = startLoc, + EndLocToUpdate = endLoc, + TaskToInsert = task, + }); + return NewSimpleResult(ok ? 0 : 500, preLog + msg); + } + catch (Exception ex) { + return NewSimpleResult(ex, preLog); + } + } + } + + public class ForceModel { + public class ForceCreateTaskInfo { + public string StartLoc { get; set; } + public string EndLoc { get; set; } + public string CntId { get; set; } // 鍙负绌�+ } + } +} diff --git a/core/WCSCore.cs b/core/WCSCore.cs index 6938961..f197ee2 100644 --- a/core/WCSCore.cs +++ b/core/WCSCore.cs @@ -61,10 +61,10 @@ WCSHelper.Begin(TN_Task, model.forklift_no); // 宸叉帹閫佺殑浠诲姟鐨勭姸鎬佹敼鎴愭墽琛� break; case 3: // 寮�鍙栬揣 - WCSHelper.UpdateStatus(TN_Task, "寮�鍙栬揣"); // 浠诲姟鐘舵�鏀规垚寮�鍙栬揣 + WCSHelper.UpdateTaskState(TN_Task, "寮�鍙栬揣"); // 浠诲姟鐘舵�鏀规垚寮�鍙栬揣 break; case 4: // 鍙栬揣瀹屾垚 - WCSHelper.UpdateStatus(TN_Task, "鍙栬揣瀹屾垚"); // 浠诲姟鐘舵�鏀规垚鍙栬揣瀹屾垚 + WCSHelper.UpdateTaskState(TN_Task, "鍙栬揣瀹屾垚"); // 浠诲姟鐘舵�鏀规垚鍙栬揣瀹屾垚 TaskProcess.OperateStatus(TN_Task, 4); // 璧风偣瀹瑰櫒璐т綅瑙g粦,瑙i攣璧风偣 if (TN_Task.S_TYPE == ETask.C鎴愬搧鑳跺嚭搴�Name()) { @@ -78,10 +78,10 @@ break; case 5: // 寮�鍗歌揣 - WCSHelper.UpdateStatus(TN_Task, "寮�鍗歌揣"); // 浠诲姟鐘舵�鏀规垚寮�鍗歌揣 + WCSHelper.UpdateTaskState(TN_Task, "寮�鍗歌揣"); // 浠诲姟鐘舵�鏀规垚寮�鍗歌揣 break; case 6: // 鍗歌揣瀹屾垚 - WCSHelper.UpdateStatus(TN_Task, "鍗歌揣瀹屾垚"); // 浠诲姟鐘舵�鏀规垚鍗歌揣瀹屾垚 + WCSHelper.UpdateTaskState(TN_Task, "鍗歌揣瀹屾垚"); // 浠诲姟鐘舵�鏀规垚鍗歌揣瀹屾垚 TaskProcess.OperateStatus(TN_Task, 6); // 缁堢偣瀹瑰櫒璐т綅缁戝畾,瑙i攣缁堢偣 break; case 2: // 瀹屾垚 diff --git a/process/TaskProcess.cs b/process/TaskProcess.cs index 314d728..35d6e15 100644 --- a/process/TaskProcess.cs +++ b/process/TaskProcess.cs @@ -283,12 +283,12 @@ var taskType = mst.S_TYPE.Trim(); if (mst.N_B_STATE == 0) { - start = LocationHelper.GetAgvSite(mst.S_START_LOC); - end = LocationHelper.GetAgvSite(mst.S_END_LOC); + start = WCSHelper.GetAgvSite(mst.S_START_LOC); + end = WCSHelper.GetAgvSite(mst.S_END_LOC); LogHelper.Info($"NDC鎺ㄩ�浠诲姟:{mst.S_CODE};start='{start}',end='{end}'"); - var startLoc = LocationHelper.GetLoc(mst.S_START_LOC); - var endLoc = LocationHelper.GetLoc(mst.S_END_LOC); + var startLoc = WCSHelper.GetLocation(mst.S_START_LOC); + var endLoc = WCSHelper.GetLocation(mst.S_END_LOC); var dic = new List<param>(); dic.Add(new param() { name = "IKey", value = "IKey" }); dic.Add(new param() { name = "From", value = start.ToString() }); @@ -301,7 +301,7 @@ //鎺ㄩ�鎴愬姛,淇敼浠诲姟浼樺厛绾� mst.N_B_STATE = 1; mst.S_B_STATE = TN_Task.GetStateStr(1); - WCSHelper.UpdateStatus(mst);//鏇存柊浠诲姟鐘舵� + WCSHelper.UpdateTaskState(mst);//鏇存柊浠诲姟鐘舵� result = true; LogHelper.Info($"NDC鎺ㄩ�浠诲姟鎴愬姛:{mst.S_CODE};start='{mst.S_START_LOC}',end='{mst.S_END_LOC}'"); } @@ -320,8 +320,8 @@ if (mst.N_B_STATE == 0) { //var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = mst.S_START_LOC, dst = mst.S_END_LOC }), "p2p"); - start = LocationHelper.GetAgvSite(mst.S_START_LOC); - end = LocationHelper.GetAgvSite(mst.S_END_LOC); + start = WCSHelper.GetAgvSite(mst.S_START_LOC); + end = WCSHelper.GetAgvSite(mst.S_END_LOC); var code = GZRobot.CreateOrder(mst.S_CODE, mst.N_PRIORITY, JsonConvert.SerializeObject(new { src = start, dst = end }), "p2pdst", "pgapi"); @@ -330,8 +330,8 @@ mst.N_B_STATE = 1; mst.S_B_STATE = TN_Task.GetStateStr(1); mst.S_EQ_TASK_CODE = code.ToString(); - WCSHelper.UpdateStatus(mst); - WCSHelper.UpdateEQNo(mst); + WCSHelper.UpdateTaskState(mst); + WCSHelper.UpdateEqTaskNo(mst); LogHelper.Info($"鍥借嚜鎺ㄩ�浠诲姟鎴愬姛 {mst.S_CODE};" + "start=" + mst.S_START_LOC + "end= " + mst.S_END_LOC); } else { @@ -353,7 +353,7 @@ }; if (HanAo.CreateOrder(model)) { mst.N_B_STATE = 1; - WCSHelper.UpdateStatus(mst); + WCSHelper.UpdateTaskState(mst); LogHelper.Info($"鏉ゥ鎺ㄩ�浠诲姟鎴愬姛 {mst.S_CODE};" + "start=" + model.frmPos + "end= " + model.toPos); return true; } diff --git a/util/LogHelper.cs b/util/LogHelper.cs index f46383d..615f2c1 100644 --- a/util/LogHelper.cs +++ b/util/LogHelper.cs @@ -10,11 +10,10 @@ using NLog.Targets; namespace HH.WCS.Mobox3.DSZSH.util { - public class LogHelper - { + public class LogHelper { public static Dictionary<string, ILogger> loggers = new Dictionary<string, ILogger>(); - #region 鍒濆鏂规硶 + #region 鍒濆鏂规硶 ( Error 榛樿涓嶄娇鐢�) public static void Debug(string message, string name = "") { ILogger logger = null; if (loggers.Keys.Contains(name)) { @@ -92,8 +91,7 @@ #endregion } - internal class LogFactory - { + internal class LogFactory { /// <summary> /// 閫氳繃閰嶇疆鏂囦欢閰嶇疆鏃ュ織 /// </summary> diff --git a/wms/DbTran.cs b/wms/DbTran.cs index 1e8e5d6..ba00c68 100644 --- a/wms/DbTran.cs +++ b/wms/DbTran.cs @@ -20,7 +20,7 @@ /// 鏁版嵁搴撲簨鍔″鐞�( 鍒涘缓浠诲姟 ) /// </summary> /// <remarks><b>[ 瑕佹眰 ]</b> obj 鈮�null<br/> - /// <b>[ 娉ㄦ剰 ]</b> 鎵�湁鐨勬暟鎹簱鎿嶄綔 , 閮戒細鍦ㄥ璞�= null 鏃堕�鎷╄烦杩�, 涓斾笉浼氭姤閿�, 闄や簡 TaskToInsert ; + /// <b>[ 娉ㄦ剰 ]</b> 鎵�湁鐨勬暟鎹簱鎿嶄綔 , 閮戒細鍦ㄥ璞�= null 鏃堕�鎷╄烦杩�, 涓斾笉浼氭姤閿�( 闄や簡 TaskToInsert ) /// <br/>濡傛灉瀛樺湪鏌愪釜蹇呴』瀹屾垚鐨勬暟鎹簱鎿嶄綔 , 闇�湪璋冪敤鏃剁‘淇濊瀵硅薄 鈮�null</remarks> /// <param name="obj"></param> /// <returns></returns> diff --git a/wms/LocationHelper.cs b/wms/LocationHelper.cs deleted file mode 100644 index e8d318e..0000000 --- a/wms/LocationHelper.cs +++ /dev/null @@ -1,108 +0,0 @@ -锘縰sing System; -using System.Collections.Generic; -using System.Linq; - -using HH.WCS.Mobox3.DSZSH.models; -using HH.WCS.Mobox3.DSZSH.util; - -using Newtonsoft.Json; - -using SqlSugar; - -namespace HH.WCS.Mobox3.DSZSH.wms { - /// <summary> - /// 璐т綅甯姪绫�鍖呭惈璐т綅-瀹瑰櫒鍏崇郴鐨勫鐞� - /// </summary> - public class LocationHelper - { - private static Dictionary<string, TN_Location> _locationDict = null; - - static LocationHelper() - { - try - { - //鍒濆鍖朙ocation鍔犲叆鍒板瓧鍏哥紦瀛�- _locationDict = new Dictionary<string, TN_Location>(); - var list = GetAllLocList(); - if (list.Count > 0) - { - list.ForEach(a => - { - if (!_locationDict.ContainsKey(a.S_CODE)) - { - _locationDict.Add(a.S_CODE, a); - } - }); - } - //鍒濆鍖朙ocationExt鍔犲叆鍒伴泦鍚堢紦瀛�- //LocationExts = new Dictionary<string, LocationExt>(); - //var exts = GetAllLocExtList(); - //if (exts.Count > 0) { - // exts.ForEach(a => { - // LocationExts.Add($"{a.S_LOC_CODE.Trim()}_{a.S_PICKUP_POINT.Trim()}", a); - // }); - //} - } - catch (Exception ex) - { - Console.WriteLine(ex.Message); - } - } - - /// <summary> - /// 鑾峰彇鎵�湁璐т綅淇℃伅 - /// </summary> - /// <returns></returns> - internal static List<TN_Location> GetAllLocList() - { - var db = new SqlHelper<object>().GetInstance(); - return db.Queryable<TN_Location>().ToList(); - } - - - internal static TN_Location GetLocation(string loc) - { - if (_locationDict.Keys.Contains(loc)) - { - return _locationDict[loc.Trim()]; - } - return null; - } - - //public static bool IsStartLocFound(string startLocCode, ref ) - - /// <summary> - /// 鑾峰彇璐т綅绔欑偣淇℃伅 - /// </summary> - /// <param name="loc"></param> - /// <param name="isEmpty">鏄惁灞炰簬浜哄伐绌烘墭鍖哄埌绌烘墭缂撳瓨搴撳尯</param> - /// <returns></returns> - internal static string GetAgvSite(string loc, bool isEmpty = false) { - var site = "0"; - if (_locationDict.Keys.Contains(loc.Trim()) && !isEmpty) { - var Location = _locationDict[loc.Trim()]; - site = Location.S_AGV_SITE; - } - else { - var Location = GetLoc(loc.Trim()); - if (Location != null) { - site = Location.S_AGV_SITE; - - if (isEmpty) { - if (Location.N_CURRENT_NUM == 0) { - site = Location.S_AGV_SITE; - } - } - } - } - return site; - } - - internal static TN_Location GetLoc(string code) { - var db = new SqlHelper<object>().GetInstance(); - return db.Queryable<TN_Location>().Where(a => a.S_CODE.Trim() == code).First(); - } - - - } -} diff --git a/wms/SYSHelper.cs b/wms/SYSHelper.cs index 4fca456..9935a0c 100644 --- a/wms/SYSHelper.cs +++ b/wms/SYSHelper.cs @@ -12,24 +12,34 @@ /// <summary> /// [ 搴忓垪鍙风敓鎴�] 甯姪绫� /// </summary> - internal class SYSHelper { + public class SYSHelper { private static object locker = new object(); - internal static int GetSerialNumber(string snType, string prefix) { + /// <summary> + /// <c>"{prefix}-{DateTime.Now.ToString(dateFormat)}-{id.ToString().PadLeft(length, '0')}"</c> + /// </summary> + /// <param name="snType"></param> + /// <param name="prefix"></param> + /// <param name="dateFormat"></param> + /// <param name="length"></param> + /// <returns></returns> + public static string GenerateSN(string snType, string prefix, string dateFormat = "yyMM", int length = 4) { + var header = $"{prefix}{DateTime.Now.ToString(dateFormat)}-"; + var res = GetSerialNumber(snType, header); + if (res == 0) return ""; + else { + return $"{header}{res.ToString().PadLeft(length, '0')}"; + } + } + + private static int GetSerialNumber(string snType, string prefix) { int result = 0; lock (locker) { var db = new SqlHelper<object>().GetInstance(); var sId = db.Queryable<OI_SYS_MAXID>().Where(a => a.CN_S_TYPE.Trim() == snType && a.CN_S_PRE.Trim() == prefix).First(); if (sId != null) { - - if (sId.CN_T_LAST < DateTime.Today) { - sId.CN_N_MAX = 1; - } - else { - sId.CN_N_MAX++; - } - - sId.CN_T_LAST = DateTime.Now; - if (db.Ado.ExecuteCommand($"update OI_SYS_MAXID set CN_N_MAX={sId.CN_N_MAX}, CN_T_LAST='{sId.CN_T_LAST}' where CN_S_TYPE='{snType}' and CN_S_PRE='{prefix}' ") > 0) { + sId.CN_N_MAX++; + if (db.Ado.ExecuteCommand($"update OI_SYS_MAXID set CN_N_MAX={sId.CN_N_MAX} " + + $"where CN_S_TYPE='{snType}' and CN_S_PRE='{prefix}' ") > 0) { result = sId.CN_N_MAX; } } @@ -37,7 +47,6 @@ //鎻掑叆琛� sId = new OI_SYS_MAXID { CN_S_TYPE = snType, CN_S_PRE = prefix, CN_N_MAX = 1 }; result = db.Insertable(sId).ExecuteCommand() > 0 ? 1 : 0; - } } return result; 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