From 5cb28a17ca74fc0fbb07e25af0c3554951e4c2d9 Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期三, 25 六月 2025 10:46:16 +0800 Subject: [PATCH] 1 --- 2025年6月12日/AuxAllWCS/RunTime/Code/自定义类.cs | 368 +++++++++++++++++++++++++++------------------------- 1 files changed, 192 insertions(+), 176 deletions(-) diff --git "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" index b3035c0..d18a9b7 100644 --- "a/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" +++ "b/2025\345\271\2646\346\234\21012\346\227\245/AuxAllWCS/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" @@ -535,65 +535,69 @@ #region [鑷畾涔夌被][20250325152141671][TaskProcess] internal static bool CreateTask(string no, string from, string to, string taskType, int pri, List<string> cntrs, string workMode = "AGV", int cntrCount = 1, int startLayer = 1, int endLayer = 1) { - - LogHelper.Info($"杈撻�绾縍GV绌烘墭浠诲姟 from:{from}>to {to}寮�鍒涘缓>"); - var cntrInfo = string.Join(",", cntrs); - ILocRepository locc = new LocRepository(); - var fromLoc = locc.FindEntity(x => x.S_LOC_CODE == from); - var endLoc = locc.FindEntity(x => x.S_LOC_CODE == to); - - var s = Settings.deviceInfos.Find(x => x.location.Contains(from)) != null; - var e = Settings.deviceInfos.Find(x => x.location.Contains(to)) != null; - string t = "F01"; - if (s && !e) t = "A002"; - if (!s && e) t = "A003"; - if (s && e) t = "A004"; - try - { - TaskEntity wmsTask = new TaskEntity() - { - S_ID = Guid.NewGuid().ToString(), - S_STATE = "缂栬緫", - T_CREATE = DateTime.Now, - T_MODIFY = DateTime.Now, + LogHelper.Info($"鍒涘缓浠诲姟 from:{from}>to {to}寮�鍒涘缓>"); + var cntrInfo = string.Join(",", cntrs); + ILocRepository locc = new LocRepository(); + var fromLoc = locc.FindEntity(x => x.S_LOC_CODE == from); + var endLoc = locc.FindEntity(x => x.S_LOC_CODE == to); - S_TASK_NO = GenerateTaskNo(), - S_START_LAREA = fromLoc.S_AREA_CODE, - S_END_LAREA = endLoc.S_AREA_CODE, - S_DEPART_NAME = "", - S_START_LOC = from, - S_END_LOC = to, - S_TYPE = taskType, - S_SRC_NO = no,// - N_PRIORITY = pri, - S_WORK_MODE = workMode, - S_B_STATE = "鏈墽琛�, - S_CNTRS = cntrInfo, - N_START_LAYER = startLayer, - N_END_LAYER = endLayer, - N_CNTR_COUNT = cntrCount, - S_INDEX=t, - }; - ITaskRepository taskserice = new TaskRepository(); - taskserice.Insert(wmsTask); - - if (workMode == "AGV") - { - fromLoc.S_LOCK_STATE = "鍑哄簱閿�; - endLoc.S_LOCK_STATE = "鍏ュ簱閿�; - locc.Update(fromLoc); - locc.Update(endLoc); - } - - LogHelper.Info($"杈撻�绾縍GV绌烘墭浠诲姟 from:{from}>to {to} 鍒涘缓{wmsTask.S_TASK_NO}鎴愬姛"); - return true; - } - catch (Exception ex) - { - LogHelper.Error("CreateTask" + ex.Message, ex); - return false; - } + var s = Settings.deviceInfos.Find(x => x.location.Contains(from)) != null; + var e = Settings.deviceInfos.Find(x => x.location.Contains(to)) != null; + string t = ""; + if (workMode == "AGV") + { + t = "F01"; + if (s && !e) t = "A002"; + if (!s && e) t = "A003"; + if (s && e) t = "A004"; + } + try + { + + TaskEntity wmsTask = new TaskEntity() + { + S_ID = Guid.NewGuid().ToString(), + S_STATE = "缂栬緫", + T_CREATE = DateTime.Now, + T_MODIFY = DateTime.Now, + + S_TASK_NO = GenerateTaskNo(), + S_START_LAREA = fromLoc.S_AREA_CODE, + S_END_LAREA = endLoc.S_AREA_CODE, + S_DEPART_NAME = "", + S_START_LOC = from, + S_END_LOC = to, + S_TYPE = taskType, + S_SRC_NO = no,// + N_PRIORITY = pri, + S_WORK_MODE = workMode, + S_B_STATE = "鏈墽琛�, + S_CNTRS = cntrInfo, + N_START_LAYER = startLayer, + N_END_LAYER = endLayer, + N_CNTR_COUNT = cntrCount, + S_INDEX = t, + }; + ITaskRepository taskserice = new TaskRepository(); + taskserice.Insert(wmsTask); + + if (workMode == "AGV") + { + fromLoc.S_LOCK_STATE = "鍑哄簱閿�; + endLoc.S_LOCK_STATE = "鍏ュ簱閿�; + locc.Update(fromLoc); + locc.Update(endLoc); + } + + LogHelper.Info($"鍒涘缓浠诲姟 from:{from}>to {to} 鍒涘缓{wmsTask.S_TASK_NO}鎴愬姛"); + return true; + } + catch (Exception ex) + { + LogHelper.Error("CreateTask" + ex.Message, ex); + return false; + } } @@ -666,7 +670,7 @@ S_DEPART_NAME = "", S_START_LOC = model.startBit, S_END_LOC = model.endBit, - S_TYPE = model.reqCode, + S_TYPE = model.taskType, S_SRC_NO = "",// N_PRIORITY = -88, S_WORK_MODE = "agv", @@ -736,127 +740,139 @@ { ///1. TaskRepository taskservice = new TaskRepository(); - var tasks = taskservice.FindList(x =>( x.S_B_STATE == "MES"|| x.S_B_STATE == "People") && x.N_PRIORITY == -88); - var VERXs = Settings.deviceInfos?.FindAll(x => x.deviceType==2); - //if (VERXs.Any()) - foreach (var task in tasks) - { - var sx = VERXs?.Find(x => x.location.Contains(task.S_END_LOC)); - if (sx == null) - { - //鐩存帴鐢熸垚瀵瑰簲浠诲姟銆�- var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_START_LOC, task.S_END_LOC, task.S_TYPE, 6, task.S_CNTRS.Split(',').ToList()); - if (res) - { - //task.N_PRIORITY = 0; - taskservice.dbcontext.Set<TaskEntity>().Attach(task); - taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).CurrentValue = 0; - taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).IsModified = true; - taskservice.dbcontext.SaveChanges(); - } - } - else - { - var sindex = sx.location.ToList().IndexOf(task.S_END_LOC); - LocRepository locRepository = new LocRepository(); - //鐢熸垚璺宠穬浠诲姟銆� -- 鎵樼洏璐т綅琛ㄣ� - var t1s = taskservice.FindList(x => x.S_SRC_NO == task.S_TASK_NO); - if (t1s.Any()) - { - var t1 = t1s.OrderBy(x => x.T_CREATE).LastOrDefault(); - if (t1.S_END_LOC == task.S_END_LOC) - { - task.N_PRIORITY = 0; - task.S_B_STATE = "MES_瀹屾垚"; - taskservice.Update(task); - continue; - } - if (t1.S_B_STATE == "瀹屾垚") - { - //1.缁堢偣鏄惁鏈夋墭鐩樸� 渚濇嵁鏄粓鐐圭殑浠诲姟鏄�浣滀负缁堢偣锛岃繕鏄捣鐐广� - //var ec = taskservice.FindList(x => (x.S_START_LOC == task.S_START_LOC || x.S_END_LOC == task.S_END_LOC) /*&& DateTime.Now.Subtract(x.T_CREATE).TotalHours < 5*/).OrderByDescending(x => x.T_CREATE).FirstOrDefault();//($"select top 1 * from TN_TASK WHERE S_START_LOC='{task.S_END_LOC}' OR S_END_LOC='{task.S_END_LOC}' ORDER BY T_CREATE DESC"); - //var ec = taskservice.FindList(x => x.S_START_LOC == task.S_START_LOC && x.S_END_LOC == task.S_START_LOC, new Common.Data.Pagination - // { - // page = 1, - // sidx = "T_CREATE", - // sord = "desc", - // rows = 1 - // }).FirstOrDefault(); - TaskEntity ec = null; - var dev = Conn.榛樿Redis.GetValue(sx.deviceName + "." + (sindex == 0 ? "D1224" : "D1225")); - if (dev?.Trim() == "1") - ec = taskservice.FindList(x =>x.S_END_LOC == task.S_END_LOC&&x.S_B_STATE=="瀹屾垚", new Common.Data.Pagination - { - page = 1, - sidx = "T_CREATE", - sord = "desc", - rows = 1 - }).FirstOrDefault(); - if (t1.S_START_LOC == task.S_START_LOC && ec != null)//!= task.S_END_LOC) - { - //绗簩娈点� - LocEntity endLoc = null; - var di = sx; - if (di != null) - { - foreach (var ssloc in di.deviceNo) - { - var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc); - if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "鏃�) - { - endLoc = endloc; - break; - } - } - if (endLoc != null) - { - var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_END_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "涓嬬┖", 7, ec.S_CNTRS.Split(',').ToList()); - if (res) - { - task.N_PRIORITY = 0; taskservice.Update(task); - } - } - } - } - else - { - var res = TaskProcess.CreateTask(task.S_TASK_NO, t1.S_END_LOC, task.S_END_LOC, task.S_TYPE + "琛ユ弧", 6, task.S_CNTRS.Split(',').ToList()); - if (res) - { - task.N_PRIORITY = 0; taskservice.Update(task); - } - } - } - } - else - { - //鐢熸垚绗竴娈点� - LocEntity endLoc = null; - var di = sx; - if (di != null) - { - foreach (var ssloc in di.deviceNo) - { - var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc); - if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "鏃�) - { - endLoc = endloc; - break; - } - } - if (endLoc != null) - { - var res = TaskProcess.CreateTask("", task.S_START_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "婊¤浆", 8, task.S_CNTRS.Split(',').ToList()); - if (res) - { - task.N_PRIORITY = 0; taskservice.Update(task); - } - } - } - } +var tasks = taskservice.FindList(x => (x.S_B_STATE == "MES" || x.S_B_STATE == "People") && x.N_PRIORITY == -88); +var VERXs = Settings.deviceInfos?.FindAll(x => x.deviceType == 2); +//if (VERXs.Any()) +foreach (var task in tasks) +{ + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} "); + var sx = VERXs?.Find(x => x.location.Contains(task.S_END_LOC)); + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} {(sx == null ? "闈� : "鏄�)}鎬昏鏈哄櫒浜轰换鍔�); + if (sx == null) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐩存帴鐢熸垚瀵瑰簲浠诲姟"); + //鐩存帴鐢熸垚瀵瑰簲浠诲姟銆�+ var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_START_LOC, task.S_END_LOC, task.S_TYPE, 6, task.S_CNTRS?.Split(',').ToList() ?? new List<string>()); + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鐩存帴鐢熸垚瀵瑰簲浠诲姟 缁撴灉锛歿res}"); + if (res) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 淇敼鏍囪瘑"); + //task.N_PRIORITY = 0; + taskservice.dbcontext.Set<TaskEntity>().Attach(task); + taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).CurrentValue = 0; + taskservice.dbcontext.Entry(task).Property(x => x.N_PRIORITY).IsModified = true; + taskservice.dbcontext.SaveChanges(); + } + } + else + { + var sindex = sx.location.ToList().IndexOf(task.S_END_LOC); + LocRepository locRepository = new LocRepository(); + //鐢熸垚璺宠穬浠诲姟銆� -- 鎵樼洏璐т綅琛ㄣ� + var t1s = taskservice.FindList(x => x.S_SRC_NO == task.S_TASK_NO); + + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鏌ユ壘鏄惁鏈夊凡鐢熸垚浠诲姟锛歿t1s != null}"); + if (t1s.Any()) + { + var t1 = t1s.OrderBy(x => x.T_CREATE).LastOrDefault(); + if (t1.S_END_LOC == task.S_END_LOC) + { + task.N_PRIORITY = 0; + task.S_B_STATE = "MES_瀹屾垚"; + taskservice.Update(task); + continue; + } + if (t1.S_B_STATE == "瀹屾垚") + { + //1.缁堢偣鏄惁鏈夋墭鐩樸� 渚濇嵁鏄粓鐐圭殑浠诲姟鏄�浣滀负缁堢偣锛岃繕鏄捣鐐广� + //var ec = taskservice.FindList(x => (x.S_START_LOC == task.S_START_LOC || x.S_END_LOC == task.S_END_LOC) /*&& DateTime.Now.Subtract(x.T_CREATE).TotalHours < 5*/).OrderByDescending(x => x.T_CREATE).FirstOrDefault();//($"select top 1 * from TN_TASK WHERE S_START_LOC='{task.S_END_LOC}' OR S_END_LOC='{task.S_END_LOC}' ORDER BY T_CREATE DESC"); + //var ec = taskservice.FindList(x => x.S_START_LOC == task.S_START_LOC && x.S_END_LOC == task.S_START_LOC, new Common.Data.Pagination + // { + // page = 1, + // sidx = "T_CREATE", + // sord = "desc", + // rows = 1 + // }).FirstOrDefault(); + TaskEntity ec = null; + var dev = Conn.榛樿Redis.GetValue(sx.deviceName + "." + (sindex == 0 ? "D1224" : "D1225")); + if (dev?.Trim() == "1") + ec = taskservice.FindList(x => x.S_END_LOC == task.S_END_LOC && x.S_B_STATE == "瀹屾垚", new Common.Data.Pagination + { + page = 1, + sidx = "T_CREATE", + sord = "desc", + rows = 1 + }).FirstOrDefault(); + if (t1.S_START_LOC == task.S_START_LOC && ec != null)//!= task.S_END_LOC) + { + //绗簩娈点� + LocEntity endLoc = null; + var di = sx; + if (di != null) + { + foreach (var ssloc in di.deviceNo) + { + var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc); + if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "鏃�) + { + endLoc = endloc; + break; + } + } + if (endLoc != null) + { + var res = TaskProcess.CreateTask(task.S_TASK_NO, task.S_END_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "涓嬬┖", 7, ec.S_CNTRS.Split(',').ToList()); + if (res) + { + task.N_PRIORITY = 0; taskservice.Update(task); + } + } } } + else + { + var res = TaskProcess.CreateTask(task.S_TASK_NO, t1.S_END_LOC, task.S_END_LOC, task.S_TYPE + "琛ユ弧", 6, task.S_CNTRS.Split(',').ToList()); + if (res) + { + task.N_PRIORITY = 0; taskservice.Update(task); + } + } + } + } + else + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 绛涢�鐢熸垚绗竴娈�浠诲姟銆�); + //鐢熸垚绗竴娈点� + LocEntity endLoc = null; + var di = sx; + if (di != null) + { + foreach (var ssloc in di.deviceNo) + { + var endloc = locRepository.FindEntity(x => x.S_LOC_CODE == ssloc); + if (endloc != null && endloc.N_CURRENT_NUM == 0 && endloc.S_LOCK_STATE == "鏃�) + { + endLoc = endloc; + break; + } + } + if (endLoc != null) + { + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鍒涘缓绗竴娈�浠诲姟銆�); + var res = TaskProcess.CreateTask("", task.S_START_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "婊¤浆", 8, task.S_CNTRS.Split(',').ToList()); + + LogHelper.Info($"瑙i噴MES浠诲姟 ->{task.S_TASK_NO} 鍒涘缓绗竴娈�浠诲姟銆傜粨鏋滐細{res}"); + if (res) + { + task.N_PRIORITY = 0; taskservice.Update(task); + } + } + } + } + + } +} //var VERX = Settings.deviceInfos?.FindAll(x => x.deviceName.Contains("鎹风灛鎶撹噦")); //if () ///2 鐪嬬紦瀛樺尯銆�娌℃弧鐨勩� -- Gitblit v1.9.1