From 267ffc1263e9975adf0d3dcca9ccc5d7dbd239f6 Mon Sep 17 00:00:00 2001 From: zxx <zxx> Date: 星期六, 31 五月 2025 17:54:14 +0800 Subject: [PATCH] jushi --- HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs | 111 ++++++++++++++++++++++++++++-------- HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs | 46 ++++++++++++-- 2 files changed, 124 insertions(+), 33 deletions(-) diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs index cb7fb29..dd55966 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/core/WMSCore.cs @@ -10,6 +10,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Reflection.Emit; using System.Text; using System.Threading.Tasks; using static HH.WCS.JuShi.device.S7Helper; @@ -284,35 +285,34 @@ var reservoirs2 = Settings.ReservoirAreas.Where(s => s.areaName == "6min绌烘墭鍖�).FirstOrDefault(); var linePlcInfo1 = Settings.linePlcInfos.Where(s => s.deviceNo == "1").FirstOrDefault(); var linePlcInfo2 = Settings.linePlcInfos.Where(s => s.deviceNo == "2").FirstOrDefault(); - //鎵惧埌绌烘墭缂撳瓨鍖虹殑鎵�湁璐т綅缂栧彿 - var locList = db.Queryable<Location>() - .Where(s => s.S_AREA_CODE == reservoirs1.areaCode || s.S_AREA_CODE == reservoirs2.areaCode) - .Where(s => s.N_LOCK_STATE == 0) - .OrderByDescending(s => s.N_ROW).OrderByDescending(s => s.N_COL).OrderBy(s => s.N_LAYER) - .Select(s => s.S_CODE) - .ToList(); + ////鎵惧埌绌烘墭缂撳瓨鍖虹殑鎵�湁璐т綅缂栧彿 + //var locList = db.Queryable<Location>() + // .Where(s => s.S_AREA_CODE == reservoirs1.areaCode || s.S_AREA_CODE == reservoirs2.areaCode) + // .Where(s => s.N_LOCK_STATE == 0) + // .OrderByDescending(s => s.N_ROW).OrderByDescending(s => s.N_COL).OrderBy(s => s.N_LAYER) + // .Select(s => s.S_CODE) + // .ToList(); - //鎵惧埌缁戜簡鎵樼洏鐨勮揣浣嶅彿 - var locCntrs = db.Queryable<LocCntrRel>() - .Where(s => locList.Contains(s.S_LOC_CODE.Trim())) - .Select(s => s.S_LOC_CODE) - .ToList(); - if (locCntrs.Any()) + + //鏌ヨ姣忔帓鏈�悗涓�垪鏈夋墭鐩樼殑璐т綅 鏍规嵁琛屽垎鍖�鍐嶆壘姣忎竴琛岀殑鏈�悗涓�垪鏈夎揣鐨勮揣浣�+ var list = db.Queryable<Location>(). + Where(a => a.N_CURRENT_NUM > 0 ).Where(a=> a.S_AREA_CODE.Trim() == reservoirs1.areaCode|| a.S_AREA_CODE.Trim() == reservoirs2.areaCode) + .PartitionBy(a => a.N_ROW) + .OrderByDescending(a => a.N_COL).Take(1).ToList(); + if (list.Count > 0) { - //LogHelper.Info($"绌烘墭缂撳瓨鍖烘湁缁戝畾璐т綅锛歿JsonConvert.SerializeObject(locCntrs)}"); - //var loccode = locCntrs.First(); - foreach (var loccode in locCntrs) + for (int i = 0; i < list.Count; i++) { - var loc = db.Queryable<Location>().Where(s => s.S_CODE == loccode).First(); + //var loc = list[i]; //鍒ゆ柇閫佸線3瀵歌繕鏄�瀵告媶鎵樻満 string endLoc = null; string dev = null; - if (loc.S_AREA_CODE == reservoirs1.areaCode) + if (list[i].S_AREA_CODE == reservoirs1.areaCode) { endLoc = linePlcInfo1.inLoca; dev = "1"; } - else if (loc.S_AREA_CODE == reservoirs2.areaCode) + else if (list[i].S_AREA_CODE == reservoirs2.areaCode) { endLoc = linePlcInfo2.inLoca; dev = "2"; @@ -329,17 +329,17 @@ if ((plcDeviceTable.requestPut1 && dev == "1") || (plcDeviceTable.requestPut2 && dev == "2")) { - var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loccode).First(); + var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == list[i].S_CODE).First(); - LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{loccode}缁堢偣:{endLoc}"); - var res = TaskProcess.CreateTransport(loccode, endLoc, "閫佹墭", locCntrRel.S_CNTR_CODE, 1, 1); + LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{list[i].S_CODE}缁堢偣:{endLoc}"); + var res = TaskProcess.CreateTransport(list[i].S_CODE, endLoc, "閫佹墭", locCntrRel.S_CNTR_CODE, 1, 1); if (res) { - LogHelper.Info($"璧风偣:{loccode}缁堢偣:{endLoc}浠诲姟鍒涘缓鎴愬姛"); + LogHelper.Info($"璧风偣:{list[i].S_CODE}缁堢偣:{endLoc}浠诲姟鍒涘缓鎴愬姛"); } else { - LogHelper.Info($"璧风偣:{loccode}缁堢偣:{endLoc}浠诲姟鍒涘缓澶辫触"); + LogHelper.Info($"璧风偣:{list[i].S_CODE}缁堢偣:{endLoc}浠诲姟鍒涘缓澶辫触"); } } else @@ -347,8 +347,69 @@ LogHelper.Info($"鎷嗘墭鏈簕endLoc}涓嶅厑璁告斁妗�); } } - } + + + + + + ////鎵惧埌缁戜簡鎵樼洏鐨勮揣浣嶅彿 + //var locCntrs = db.Queryable<LocCntrRel>() + // .Where(s => locList.Contains(s.S_LOC_CODE.Trim())) + // .Select(s => s.S_LOC_CODE) + // .ToList(); + //if (locCntrs.Any()) + //{ + // //LogHelper.Info($"绌烘墭缂撳瓨鍖烘湁缁戝畾璐т綅锛歿JsonConvert.SerializeObject(locCntrs)}"); + // //var loccode = locCntrs.First(); + // foreach (var loccode in locCntrs) + // { + // var loc = db.Queryable<Location>().Where(s => s.S_CODE == loccode).First(); + // //鍒ゆ柇閫佸線3瀵歌繕鏄�瀵告媶鎵樻満 + // string endLoc = null; + // string dev = null; + // if (loc.S_AREA_CODE == reservoirs1.areaCode) + // { + // endLoc = linePlcInfo1.inLoca; + // dev = "1"; + // } + // else if (loc.S_AREA_CODE == reservoirs2.areaCode) + // { + // endLoc = linePlcInfo2.inLoca; + // dev = "2"; + // } + // var endLocation = db.Queryable<Location>().Where(s => s.S_CODE == endLoc).First(); + // if (endLocation == null || endLocation.N_LOCK_STATE != 0) + // { + // //LogHelper.Info($"鎷嗘墭鏈鸿揣浣峽endLoc}涓嶅瓨鍦ㄦ垨宸茶閿�); + // return; + // } + // //鏍¢獙鏄惁鍏佽鏀捐揣 + // var plcDeviceTable = S7Helper.plcDeviceTables; + // LogHelper.Info($"鑷姩閫佹墭 鎷嗘墭鏈簕dev}:{plcDeviceTable.requestPut1}"); + // if ((plcDeviceTable.requestPut1 && dev == "1") || + // (plcDeviceTable.requestPut2 && dev == "2")) + // { + // var locCntrRel = db.Queryable<LocCntrRel>().Where(a => a.S_LOC_CODE == loccode).First(); + + // LogHelper.Info($"鍒涘缓浠诲姟 璧风偣:{loccode}缁堢偣:{endLoc}"); + // var res = TaskProcess.CreateTransport(loccode, endLoc, "閫佹墭", locCntrRel.S_CNTR_CODE, 1, 1); + // if (res) + // { + // LogHelper.Info($"璧风偣:{loccode}缁堢偣:{endLoc}浠诲姟鍒涘缓鎴愬姛"); + // } + // else + // { + // LogHelper.Info($"璧风偣:{loccode}缁堢偣:{endLoc}浠诲姟鍒涘缓澶辫触"); + // } + // } + // else + // { + // LogHelper.Info($"鎷嗘墭鏈簕endLoc}涓嶅厑璁告斁妗�); + // } + // } + + //} } catch (Exception ex) diff --git a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs index 5f6880f..7687ea1 100644 --- a/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs +++ b/HH.WCS.Mobox3/HH.WCS.Mobox3.JuShi/process/TaskProcess.cs @@ -824,21 +824,51 @@ { list.RemoveAll(s => loca.Contains(s.S_CODE)); } - //杩囨护涓�笅 鍏佽杩涘叆鐨勬墠鍒嗛厤 - var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "绔嬪簱鍏ュ簱鍖�).FirstOrDefault(); - if (reservoirs.areaCode.Equals(area)) + // 3. 濡傛灉鏄珛搴撳叆搴撳尯锛屾鏌�PLC 鏄惁鍏佽鍗歌浇 + var reservoirs = Settings.ReservoirAreas.FirstOrDefault(s => s.areaName == "绔嬪簱鍏ュ簱鍖�); + if (reservoirs != null && reservoirs.areaCode.Equals(area)) { var plcDeviceTable = S7Helper.plcDeviceTables; - foreach (var l in list) + // 鍏堟敹闆嗚绉婚櫎鐨勮揣浣嶏紝閬垮厤鍦ㄩ亶鍘嗘椂淇敼闆嗗悎 + List<Location> locationsToRemove = new List<Location>(); + + foreach (var location in list) { - var safeInteraction = Settings.SafeInteractions.Where(s => s.location == l.S_CODE).FirstOrDefault(); - var res = int.Parse(plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString().Substring(1, 1)); - if (res!=1) + var safeInteraction = Settings.SafeInteractions.FirstOrDefault(s => s.location == location.S_CODE); + if (safeInteraction != null) { - list.Remove(l); + // 妫�煡 PLC 鏄惁鍏佽鍗歌浇锛堝彇绗簩浣嶆暟瀛楋紝鍒ゆ柇鏄惁涓�1锛�+ string allowUnloadStr = plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString(); + int allowUnload = int.Parse(allowUnloadStr.Substring(1, 1)); + + if (allowUnload != 1) + { + locationsToRemove.Add(location); // 涓嶅厑璁稿嵏杞斤紝鍔犲叆寰呯Щ闄ゅ垪琛�+ } } } + + // 閬嶅巻缁撴潫鍚庯紝鍐嶇粺涓�Щ闄や笉绗﹀悎鏉′欢鐨勮揣浣�+ foreach (var locToRemove in locationsToRemove) + { + list.Remove(locToRemove); + } } + ////杩囨护涓�笅 鍏佽杩涘叆鐨勬墠鍒嗛厤 + //var reservoirs = Settings.ReservoirAreas.Where(s => s.areaName == "绔嬪簱鍏ュ簱鍖�).FirstOrDefault(); + //if (reservoirs.areaCode.Equals(area)) + //{ + // var plcDeviceTable = S7Helper.plcDeviceTables; + // foreach (var l in list) + // { + // var safeInteraction = Settings.SafeInteractions.Where(s => s.location == l.S_CODE).FirstOrDefault(); + // var res = int.Parse(plcDeviceTable.RGVAllowUnload[safeInteraction.code].ToString().Substring(1, 1)); + // if (res!=1) + // { + // list.Remove(l); + // } + // } + //} //绗﹀悎鏉′欢鐨勬帓搴忛�绗竴涓� 鍏堟壘绗竴涓� -- Gitblit v1.9.1