From 31beeb3d23e658e5aa2bbb9f251b006095eef15a Mon Sep 17 00:00:00 2001 From: czw <selecti@yeah.net> Date: 星期一, 07 七月 2025 11:05:04 +0800 Subject: [PATCH] 1 --- S7/RunTime/Code/自定义类.cs | 183 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 183 insertions(+), 0 deletions(-) diff --git "a/S7/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" "b/S7/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" index 265d273..9a1363e 100644 --- "a/S7/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" +++ "b/S7/RunTime/Code/\350\207\252\345\256\232\344\271\211\347\261\273.cs" @@ -38,6 +38,8 @@ public static List<deviceInfo> deviceInfos { get; set; } = new List<deviceInfo>(); public static string HKbaseUrl { get; set; } + public static string MESbaseUrl { get; set; } + public static string WMSbaseUrl { get; set; } public static readonly HttpHelper apiHelper = new HttpHelper(); public static string GetTimeStamp(DateTime? time = null) @@ -430,6 +432,9 @@ if (sessionId != "") { request.Headers.Set("ASP.NET_SessionId", sessionId); } + + //Authorization: UApGP6WW9FsBUqAlzxRGOw == + request.Headers.Set("Authorization", "UApGP6WW9FsBUqAlzxRGOw=="); StreamReader reader = null; Stream stream = null; WebResponse rsp = null; @@ -608,4 +613,182 @@ #endregion [鑷畾涔夌被][20250417094750211][Utils] } +public class ToWMSMES +{ +#region [鑷畾涔夌被][20250531152402452][ToWMSMES] + //2 wms mes + + + public class CreateTask + { + public string taskType { get; set; } + public string startBit { get; set; } + public string endBit { get; set; } + public string reqCode { get; set; } + public string cntrCode { get; set; } + + internal static ReturnMsg CreatemesTask(CreateTask model) + { + ITaskRepository taskservice = new TaskRepository(); + var task = taskservice.FindEntity(x => x.S_TASK_NO == model.reqCode); + if (task == null) + { + //var i = TaskProcess.CreateTask("", model.startBit, model.endBit, string.IsNullOrEmpty(model.taskType) ? "Mes涓嬪彂" : model.taskType, 5, new List<string> { model.cntrCode }); + TaskEntity wmsTask = new TaskEntity() + { + S_ID = Guid.NewGuid().ToString(), + S_STATE = "缂栬緫", + T_CREATE = DateTime.Now, + T_MODIFY = DateTime.Now, + + S_TASK_NO = model.reqCode, + S_START_LAREA = "", + S_END_LAREA = "", + S_DEPART_NAME = "", + S_START_LOC = model.startBit, + S_END_LOC = model.endBit, + S_TYPE = model.reqCode, + S_SRC_NO = "",// + N_PRIORITY = -1, + S_WORK_MODE = "agv", + S_B_STATE = "MES", + S_CNTRS = model.cntrCode, + N_START_LAYER = 1, + N_END_LAYER = 1, + N_CNTR_COUNT = 1 + }; + ITaskRepository taskserice = new TaskRepository(); + var i = taskserice.Insert(wmsTask) > 0; + return new ReturnMsg { resultCode = (i ? 0 : -1), resultMsg = i ? "" : "浠诲姟鐢熸垚澶辫触銆� }; + } + else + { + return new ReturnMsg { resultCode = -1, resultMsg = "浠诲姟閲嶅涓嬪彂銆� }; + } + } + } + public class ReturnMsg + { + public int resultCode { get; set; } + public string resultMsg { get; set; } + } + + + public static void ResMesTask() + { + ///1. + TaskRepository taskservice = new TaskRepository(); + var tasks = taskservice.FindList(x => x.S_B_STATE == "MES" && x.N_PRIORITY == -88); + var VERXs = Settings.deviceInfos?.FindAll(x => x.deviceName.Contains("鎹风灛鎶撹噦")); + 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 + { + 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); + } + 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"); + + if (ec != null && ec.S_END_LOC == 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_END_LOC, endLoc.S_LOC_CODE, task.S_TYPE + "涓嬬┖", 7, t1.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 VERX = Settings.deviceInfos?.FindAll(x => x.deviceName.Contains("鎹风灛鎶撹噦")); + //if () + ///2 鐪嬬紦瀛樺尯銆�娌℃弧鐨勩� + + + } + + +#endregion [鑷畾涔夌被][20250531152402452][ToWMSMES] +} } \ No newline at end of file -- Gitblit v1.9.1