桁架.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. using Newtonsoft.Json;
  2. using ServiceCenter.Extensions;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.SqlSugars;
  5. using System.ComponentModel;
  6. using WCS.Core;
  7. using WCS.Entity;
  8. using WCS.Entity.Protocol.Station;
  9. using WCS.Entity.Protocol.Truss;
  10. using WCS.WorkEngineering.Extensions;
  11. using WCS.WorkEngineering.Model.WMS;
  12. using WCS.WorkEngineering.WebApi.Controllers;
  13. using WCS.WorkEngineering.Worlds;
  14. using DeviceFlags = WCS.WorkEngineering.Extensions.DeviceFlags;
  15. using WCS_CacheLine = WCS.Entity.WCS_CacheLine;
  16. using WCS_CacheLineLoc = WCS.Entity.WCS_CacheLineLoc;
  17. namespace WCS.WorkEngineering.Systems
  18. {
  19. /// <summary>
  20. /// 桁架
  21. /// </summary>
  22. [BelongTo(typeof(TrussWorld))]
  23. [Description("桁架")]
  24. public class 桁架 : DeviceSystem<Truss>
  25. {
  26. protected override bool ParallelDo => true;
  27. /// <summary>
  28. /// 取货点设备集合
  29. /// </summary>
  30. private readonly Dictionary<Device<IStation524, IStation523>, List<Device<IStation524, IStation523>>> _pickUpDevices = new();
  31. public override void Do(Truss obj)
  32. {
  33. if (obj.Data.VoucherNo != obj.Data2.VoucherNo)
  34. {
  35. World.Log($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}");
  36. return;
  37. }
  38. if (obj.Data2.CmdType == 1)
  39. {
  40. var isFinish = false;
  41. var isEnd = false; //是否强制结盘
  42. SqlSugarHelper.Do(db =>
  43. {
  44. List<int> ids = new List<int>() { obj.Data2.PalletizingRowId1, obj.Data2.PalletizingRowId2 };
  45. var palletizingRow = db.Queryable<WCS_PalletizingRow>().Includes(x => x.CacheLine, c => c.Locations)
  46. .Includes(x => x.Locs)
  47. .Includes(x => x.Palletizing).Where(x => ids.Contains(x.Id)).ToList();
  48. List<WCS.Entity.WCS_CacheLine> deleteCacheLine = new List<WCS.Entity.WCS_CacheLine>();
  49. List<WCS_PalletizingRow> upDateableRow = new List<WCS_PalletizingRow>();
  50. List<WCS_PalletizingLoc> upDateableLoc = new List<WCS_PalletizingLoc>();
  51. List<WCS_CacheLineLoc> deleteLoc = new List<WCS_CacheLineLoc>();
  52. //更新行数据
  53. foreach (var row in palletizingRow)
  54. {
  55. var cacheLine = db.Queryable<WCS.Entity.WCS_CacheLine>().Includes(x => x.Locations).Single(x => x.Id == row.CacheLine.Id);
  56. var outTime = cacheLine.Locations.MinBy(x => x.TimeOut).TimeOut;
  57. //时间超六小时,且缓存线数量与码垛信息行数量不相等时强制结盘
  58. if (cacheLine.AddTime < DateTime.Now.AddHours(-outTime) && cacheLine.Locations.Count(x => x.InStock) != row.QtyMaxCount)
  59. {
  60. isEnd = true;
  61. }
  62. //先更新对应的位信息
  63. try
  64. {
  65. var index = 0;
  66. foreach (var loc in row.Locs.Where(x => !x.IsEmpty).OrderBy(x => x.XYNo))
  67. {
  68. if (index < cacheLine.Locations.Count)
  69. {
  70. var cacheLoc = cacheLine.Locations[index];
  71. cacheLoc = db.Queryable<WCS_CacheLineLoc>().Single(x => x.Id == cacheLoc.Id);
  72. loc.TaskId = cacheLoc.TaskId;
  73. loc.Finish = true;
  74. upDateableLoc.Add(loc);
  75. deleteLoc.Add(cacheLoc);
  76. index++;
  77. }
  78. }
  79. }
  80. catch (Exception a)
  81. {
  82. throw new KnownException(a.Message, LogLevelEnum.High);
  83. }
  84. row.Finish = true;
  85. upDateableRow.Add(row);
  86. deleteCacheLine.Add(cacheLine);
  87. }
  88. //更新层数据
  89. db.UpdateableRowLock(upDateableLoc).UpdateColumns(x => new { x.TaskId, x.Finish }).ExecuteCommand();
  90. db.DeleteableRowLock(deleteLoc).ExecuteCommand();
  91. db.UpdateableRowLock(upDateableRow).UpdateColumns(x => new { x.Finish }).ExecuteCommand();
  92. db.DeleteableRowLock(deleteCacheLine).ExecuteCommand();
  93. var layerId = palletizingRow.FirstOrDefault().PalletizingLayerId;
  94. var layer = db.Queryable<WCS_PalletizingLayer>().Includes(x => x.Rows).Single(x => x.Id == layerId);
  95. if (layer.Rows.All(x => x.Finish || x.IsEmpty))
  96. {
  97. layer.Finish = true;
  98. db.UpdateableRowLock(layer).UpdateColumns(x => new { x.Finish }).ExecuteCommand();
  99. }
  100. //码垛完成后开始绑定托盘
  101. var palletizingId = upDateableRow.First().Palletizing.Id;
  102. var palletizing = db.Queryable<WCS_Palletizing>().Single(x => x.Id == palletizingId);
  103. palletizing.EditTime = DateTime.Now;
  104. db.UpdateableRowLock(palletizing).UpdateColumns(x => new { x.EditTime }).ExecuteCommand();
  105. var taskId = upDateableRow.SelectMany(x => x.Locs).Select(x => x.TaskId).ToList();
  106. var taskList = db.Queryable<WCS_TaskInfo>().RowLock().Where(x => taskId.Contains(x.ID)).Select(x => x.BarCode).ToList();
  107. WmsApi.BingPallet(palletizing.PalleCode, taskList, palletizing.WarehouseCode, palletizing.PalletizingStation, obj.Entity.Code);
  108. isFinish = true;
  109. World.Log($"清除桁架码垛缓存信息:缓存行信息[{JsonConvert.SerializeObject(deleteCacheLine.Select(x => x.Id))}]--对应任务[{JsonConvert.SerializeObject(deleteLoc.Select(x => x.TaskId))}]");
  110. });
  111. if (!isFinish)
  112. {
  113. World.Log("绑盘失败");
  114. return;
  115. }
  116. if (isEnd)
  117. {
  118. try
  119. {
  120. var dev = new Device<ITruss530>(Device.All.First(x => x.Code == obj.Data.TargetPallte1.ToString()), World);
  121. dev.Data.CmdType = TrussCmdType.End1;
  122. }
  123. catch (Exception e)
  124. {
  125. World.Log($"超时托盘自动结盘失败:{e.Message}--{obj.Data.TargetPallte1}");
  126. }
  127. }
  128. obj.Data.CmdType = 1;
  129. obj.Data.DestPosition_1 = 0;
  130. obj.Data.TargetPallte1 = 0;
  131. obj.Data.Task1_1 = 0;
  132. obj.Data.Dest1_1 = 0;
  133. obj.Data.Task1_2 = 0;
  134. obj.Data.Dest1_2 = 0;
  135. obj.Data.Task1_3 = 0;
  136. obj.Data.Dest1_3 = 0;
  137. obj.Data.Task1_4 = 0;
  138. obj.Data.Dest1_4 = 0;
  139. obj.Data.Task1_5 = 0;
  140. obj.Data.Dest1_5 = 0;
  141. obj.Data.TaskSum1 = 0;
  142. obj.Data.PalletizingRowId1 = 0;
  143. obj.Data.DestPosition_2 = 0;
  144. obj.Data.TargetPallte2 = 0;
  145. obj.Data.Task2_1 = 0;
  146. obj.Data.Dest2_1 = 0;
  147. obj.Data.Task2_2 = 0;
  148. obj.Data.Dest2_2 = 0;
  149. obj.Data.Task2_3 = 0;
  150. obj.Data.Dest2_3 = 0;
  151. obj.Data.Task2_4 = 0;
  152. obj.Data.Dest2_4 = 0;
  153. obj.Data.Task2_5 = 0;
  154. obj.Data.Dest2_5 = 0;
  155. obj.Data.TaskSum2 = 0;
  156. obj.Data.PalletizingRowId2 = 0;
  157. }
  158. if (obj.Data2.CmdType == 0 && obj.Data.CmdType != 0) obj.Data.CmdType = 0;
  159. if (obj.Data2.CmdType != 0 || obj.Data.CmdType != 0)
  160. {
  161. World.Log($"完成信号未清除:{obj.Data2.CmdType}--{obj.Data.CmdType}");
  162. return;
  163. }
  164. if (obj.Data2.Status != TrussStatus.Idle)
  165. {
  166. World.Log($"桁架处于{obj.Data2.Status.GetDescription()}");
  167. return;
  168. }
  169. //查找所有的可用开始搬运的线体
  170. var pickUpDevices = _pickUpDevices.Where(v => v.Value.All(x => !x.Data2.Status.HasFlag(StationStatus.Run) && x.Data2.Status.HasFlag(StationStatus.Auto)))
  171. .Select(x => new
  172. {
  173. key = x.Key.Entity.Code,
  174. Count = x.Value.Count(v => v.Data2.Status.HasFlag(StationStatus.PH_Status) && v.Data.TaskNumber > 0),
  175. HPCount = x.Value.Count(v => v.Data2.Status.HasFlag(StationStatus.PH_Status)),
  176. Dev = x
  177. }).Where(x => x.HPCount == x.Count).ToList();
  178. if (!pickUpDevices.Any())
  179. {
  180. World.Log($"没有可用取货点,请在电控触摸屏检查实际可取货点是否每个位置都有光电与任务号");
  181. return;
  182. }
  183. var warehouseCodeKey = "warehouseCode";
  184. var warehouseCode = obj.Entity.GetFlag<string>(warehouseCodeKey); //获取当前侧对应的Key
  185. // 定义常量以避免魔法字符串
  186. const string NORTH = "N";
  187. const string SOUTH = "S";
  188. // 判断当前仓库代码是否为空,若为空则初始化为北侧
  189. if (string.IsNullOrEmpty(warehouseCode))
  190. {
  191. warehouseCode = NORTH;
  192. obj.Entity.SetFlag(warehouseCodeKey, NORTH);
  193. }
  194. // 获取当前侧的执行次数
  195. var quantity = obj.Entity.GetFlag<int>(warehouseCode);
  196. //南北库的默认周期检查比为3:3
  197. var maxQuantity = 3;
  198. List<WCS_PalletizingRow> palletizingRowList = null;
  199. WCS_Palletizing palletizing = null;
  200. SqlSugarHelper.Do(db =>
  201. {
  202. #region 获取当前优先执行侧
  203. try
  204. {
  205. // 获取实体代码的最后一个字符
  206. var lastCodeChar = obj.Entity.Code.Last();
  207. // 构建配置代码
  208. var configCode = $"FjHjNSMaxQuantity{lastCodeChar}{warehouseCode}";
  209. // 从数据库中获取对应的配置项
  210. var fjHjMaxQuantity = db.Queryable<fjSysConfig>().NoLock().First(x => x.Code == configCode);
  211. maxQuantity = fjHjMaxQuantity != null
  212. ? fjHjMaxQuantity.SContent.ToInt()
  213. : maxQuantity; // 设置一个默认值,以防配置未找到
  214. // 检查当前侧的执行次数是否达到或超过最大值
  215. if (quantity >= maxQuantity)
  216. {
  217. // 重置当前侧的执行次数
  218. obj.Entity.SetFlag(warehouseCode, 0);
  219. // 切换到另一侧
  220. warehouseCode = (warehouseCode == NORTH) ? SOUTH : NORTH;
  221. // 获取新侧的执行次数
  222. quantity = obj.Entity.GetFlag<int>(warehouseCode);
  223. // 更新仓库代码标志
  224. obj.Entity.SetFlag(warehouseCodeKey, warehouseCode);
  225. }
  226. }
  227. catch (Exception e)
  228. {
  229. World.Log(e.Message + e.StackTrace, LogLevelEnum.High);
  230. return;
  231. }
  232. #endregion 获取当前优先执行侧
  233. //找到当前桁架所属所有还有层没结束的码垛记录信息,有对应托盘
  234. var palletizingLsit = db.Queryable<WCS_Palletizing>().Includes(x => x.Layers, r => r.Rows, l => l.Locs)
  235. .Where(x => !x.Finish && x.DeviceCode == obj.Entity.Code && x.WarehouseCode.Contains(warehouseCode))
  236. .Where(x => x.Layers.Any(l => !l.Finish) && x.PalletizingStation != null && x.PalleCode != null).ToList();
  237. //筛选出目标位置有光电的码垛记录信息
  238. var devCode = palletizingLsit.Select(x => x.PalletizingStation);
  239. var taskCode = palletizingLsit.Select(x => x.Id);
  240. var devList = Device.All.Where(x => devCode.Contains(x.Code)).Select(x => new Device<IStation521, IStation523, ITruss530, ITruss531>(x, World)).ToList();
  241. devList = devList.Where(x => x.Data2.Status.HasFlag(StationStatus.PH_Status) && taskCode.Contains(x.Data.TaskNumber) && !x.Data4.CmdType.HasFlag(TrussCmdType.End1)
  242. && !x.Data4.CmdType.HasFlag(TrussCmdType.End)).ToList();
  243. devCode = devList.Select(x => x.Entity.Code);
  244. if (!devCode.Any())
  245. {
  246. World.Log($"无可用放货码垛位,请检查实际有货位置的光电是否正常");
  247. obj.Entity.SetFlag(warehouseCode, maxQuantity + 1); //当前侧无满足抓取条件的码垛信息直接进行切侧
  248. return;
  249. }
  250. World.Log($"可用放货位:{JsonConvert.SerializeObject(devCode)}");
  251. palletizingLsit = palletizingLsit.Where(x => devCode.Contains(x.PalletizingStation)).ToList(); //可以放货的目标托盘
  252. //可以取货的码垛信息
  253. var pickUpCode = _pickUpDevices.Select(x => x.Key.Entity.Code.ToShort());
  254. World.Log($"可用取货线体1:{JsonConvert.SerializeObject(pickUpCode)}");
  255. //从缓存线信息找到可以取货的缓存线
  256. var cacheLines = db.Queryable<WCS_CacheLine>().Includes(x => x.Locations).Where(x => pickUpCode.Contains(x.LocationNo)).ToList().Where(
  257. x =>
  258. {
  259. var outTime = x.Locations.MinBy(l => l.TimeOut).TimeOut;
  260. var isTime = x.AddTime < DateTime.Now.AddHours(-outTime);
  261. var isPut = pickUpDevices.Any(p => p.key == x.LocationNo.ToString() && p.Count == x.Quantity);
  262. var count = x.Locations.Count(l => l.InStock);
  263. //满足取货条件,或者是超六小时
  264. return isPut || (pickUpDevices.Any(p => p.key == x.LocationNo.ToString() && p.Count == count) && isTime);
  265. });
  266. if (!cacheLines.Any())
  267. {
  268. World.Log($"无可用取货线体");
  269. obj.Entity.SetFlag(warehouseCode, maxQuantity + 1); //当前侧无满足抓取条件的码垛信息直接进行切侧
  270. return;
  271. }
  272. World.Log($"物理可用取货线体:{JsonConvert.SerializeObject(pickUpDevices.Select(x => x.key).ToList())}");
  273. World.Log($"执行记录:可用取货线体:{JsonConvert.SerializeObject(cacheLines.Select(x => x.LocationNo).ToList())}");
  274. //找到可用缓存线可以去的码垛信息
  275. palletizingLsit = palletizingLsit.Where(x => x.Layers
  276. .Where(w => !w.Finish)
  277. .SelectMany(w => w.Rows)
  278. .Where(v => !v.Finish).Any(w =>
  279. {
  280. return cacheLines.Any(a =>
  281. {
  282. var outTime = a.Locations.MinBy(l => l.TimeOut).TimeOut;
  283. return a.MatCodeList == w.MatCodeList && (a.Quantity == w.QtyMaxCount || (a.AddTime < DateTime.Now.AddHours(-outTime) && a.Quantity <= w.QtyMaxCount)) && a.WarehouseCode == w.WarehouseCode;
  284. });
  285. })).OrderBy(x => x.AddTime).ToList();
  286. if (!palletizingLsit.Any())
  287. {
  288. World.Log($"{warehouseCode}没有可用取货点,码垛信息是否正常");
  289. obj.Entity.SetFlag(warehouseCode, maxQuantity + 1); //当前侧无满足抓取条件的码垛信息直接进行切侧
  290. return;
  291. }
  292. foreach (var palletizingInfo in palletizingLsit)
  293. {
  294. //已分配完成,或无信息。进入下一次迭代
  295. if (palletizingInfo == null || (palletizingRowList != null && palletizing != null)) continue;
  296. //筛选出已经预锁的行
  297. var palletizingRow = palletizingInfo.Layers
  298. .Where(x => x is { Finish: false, IsEmpty: false }) //不空且未结束的层
  299. .MinBy(x => x.LayerNo) //取最下层
  300. .Rows
  301. .Where(x => x is { Finish: false, IsEmpty: false, LineCode: null }) //不空且未结束的行
  302. .Where(x => cacheLines.Any(a =>
  303. {
  304. var outTime = a.Locations.MinBy(l => l.TimeOut).TimeOut;
  305. return a.MatCodeList == x.MatCodeList && (a.Quantity == x.QtyMaxCount || (a.AddTime < DateTime.Now.AddHours(-outTime) && a.Quantity <= x.QtyMaxCount)) && a.WarehouseCode == x.WarehouseCode;
  306. })); //获取可以取货的码垛信息行
  307. //无可用行,进入下一次迭代
  308. if (!palletizingRow.Any())
  309. {
  310. World.Log($"{palletizingInfo.Id}");
  311. continue;
  312. }
  313. var rowIds = new List<int>();
  314. //记录当前放货点可用规格包含的取货信息
  315. cacheLines = cacheLines.Where(x => x.WarehouseCode == palletizingInfo.WarehouseCode && palletizingInfo.MatCodeList.Contains(x.MatCodeList)).ToList();
  316. World.Log($"执行记录:码垛位{palletizingInfo.PalletizingStation}--{JsonConvert.SerializeObject(cacheLines.Select(x => x.LocationNo).ToList())}");
  317. //跟据缓存信息找到对应的可用取货行
  318. var rowList = cacheLines.Select(x =>
  319. {
  320. var row = palletizingRow.Where(w =>
  321. {
  322. var outTime = w.Locs.MinBy(l => l.TimeOut).TimeOut;
  323. return !rowIds.Contains(w.Id)
  324. && x.MatCodeList == w.MatCodeList
  325. && (x.Quantity == w.QtyMaxCount || (x.AddTime < DateTime.Now.AddHours(-outTime) &&
  326. x.Quantity <= w.QtyMaxCount))
  327. && w.WarehouseCode == x.WarehouseCode;
  328. }).MinBy(o => o.RowNo);
  329. if (row != null)
  330. {
  331. rowIds.Add(row.Id);
  332. return new
  333. {
  334. CacheLineId = x.Id,
  335. RowId = row.Id,
  336. x.LocationNo,
  337. row.RowNo,
  338. x.AddTime
  339. };
  340. }
  341. return new
  342. {
  343. CacheLineId = 0,
  344. RowId = 0,
  345. x.LocationNo,
  346. RowNo = 0,
  347. x.AddTime
  348. };
  349. }).Where(x => x.CacheLineId != 0).ToList();
  350. rowList = rowList.OrderBy(x => x.RowNo).Take(2).ToList();
  351. //两个任务取货线体号相同时,只执行一个任务
  352. if (rowList.Count == 2 && rowList[0].LocationNo == rowList[1].LocationNo)
  353. {
  354. World.Log($"单抓拆分:取货线体号相同{rowList[0].LocationNo}-{rowList[1].LocationNo}");
  355. rowList = rowList!.Take(1).ToList();
  356. }
  357. //两个行号,差值大于一时,只执行一个任务
  358. if (rowList.Count == 2 && rowList[0].RowNo + 1 != rowList[1].RowNo)
  359. {
  360. World.Log($"单抓拆分:行号拆分{rowList[0].RowNo}-{rowList[1].RowNo}");
  361. rowList = rowList!.Take(1).ToList();
  362. }
  363. //如果取货行号是在18取货区域,只执行一个任务
  364. if (rowList.Count == 2)
  365. {
  366. var locationNos = rowList.Select(x => x.LocationNo);
  367. var devCodes = Device.All.Where(x => x.HasFlag(DeviceFlags.桁架18取货点)).Select(x => x.Code.ToShort());
  368. if (devCodes.Any(x => locationNos.Contains(x)))
  369. {
  370. World.Log($"单抓拆分:货物为18");
  371. rowList = rowList!.Take(1).ToList();
  372. }
  373. else
  374. {
  375. World.Log($"{obj.Entity.Code}双爪任务");
  376. }
  377. }
  378. // 分拣一强制全部单抓,线体存在干涉
  379. //if (obj.Entity.Code == "Truss1") rowList = rowList!.Take(1).ToList();
  380. var palletizingRows = new List<WCS_PalletizingRow>();
  381. foreach (var row in rowList)
  382. {
  383. //锁定缓存线
  384. var cacheLine = db.Queryable<WCS_CacheLine>().Includes(x => x.Locations).Single(x => x.Id == row.CacheLineId);
  385. cacheLine.IsTruss = true;
  386. cacheLine.PalletizingRowId = row.RowId;
  387. db.UpdateableRowLock(cacheLine).UpdateColumns(x => new { x.IsTruss, x.PalletizingRowId }).ExecuteCommand();
  388. //解锁原有码垛信息
  389. var oldRow = db.Queryable<WCS_PalletizingRow>().First(x => x.CacheLineId == row.CacheLineId);
  390. if (oldRow != null)
  391. {
  392. oldRow.CacheLineId = 0;
  393. oldRow.LineCode = null;
  394. db.UpdateableRowLock(oldRow).UpdateColumns(x => new { x.CacheLineId, x.LineCode }).ExecuteCommand();
  395. }
  396. //锁定现有码垛信息
  397. var wcsRow = db.Queryable<WCS_PalletizingRow>().Includes(x => x.Locs).First(x => x.Id == row.RowId);
  398. wcsRow.CacheLineId = row.CacheLineId;
  399. wcsRow.LineCode = row.LocationNo.ToString();
  400. db.UpdateableRowLock(wcsRow).UpdateColumns(x => new { x.CacheLineId, x.LineCode }).ExecuteCommand();
  401. palletizingRows.Add(wcsRow);
  402. }
  403. palletizingRowList = palletizingRows.OrderBy(x => x.RowNo).ToList();
  404. palletizing = palletizingInfo;
  405. }
  406. });
  407. if (palletizingRowList == null || !palletizingRowList.Any())
  408. {
  409. World.Log($"没有可用任务");
  410. obj.Entity.SetFlag(warehouseCode, maxQuantity + 1); //当前侧无满足抓取条件的码垛信息直接进行切侧
  411. return;
  412. }
  413. obj.Entity.SetFlag(warehouseCode, quantity + 1); //满足抓取条件,当前侧的执行周期加一
  414. for (var i = 0; i < palletizingRowList.Count; i++)
  415. {
  416. var palletizingRow = palletizingRowList[i];
  417. var locs = palletizingRow.Locs.OrderBy(x => x.XYNo.ToInt()).ToArray();
  418. var devs = pickUpDevices.FirstOrDefault(x => x.key == palletizingRow.LineCode).Dev.Value.Where(x => x.Data2.Status.HasFlag(StationStatus.PH_Status))
  419. .OrderBy(x => x.Entity.Code.ToShort()).ToArray();
  420. switch (i)
  421. {
  422. case 0:
  423. obj.Data.DestPosition_1 = palletizingRow.LineCode!.ToShort();
  424. obj.Data.TargetPallte1 = palletizing.PalletizingStation!.ToShort();
  425. if (devs.Length >= 1)
  426. {
  427. obj.Data.Task1_1 = devs[0].Data.TaskNumber;
  428. obj.Data.Dest1_1 = locs[0].XYNo.ToShort();
  429. }
  430. if (devs.Length >= 2)
  431. {
  432. obj.Data.Task1_2 = devs[1].Data.TaskNumber;
  433. obj.Data.Dest1_2 = locs[1].XYNo.ToShort();
  434. }
  435. if (devs.Length >= 3)
  436. {
  437. obj.Data.Task1_3 = devs[2].Data.TaskNumber;
  438. obj.Data.Dest1_3 = locs[2].XYNo.ToShort();
  439. }
  440. if (devs.Length >= 4)
  441. {
  442. obj.Data.Task1_4 = devs[3].Data.TaskNumber;
  443. obj.Data.Dest1_4 = locs[3].XYNo.ToShort();
  444. }
  445. if (devs.Length == 5)
  446. {
  447. obj.Data.Task1_5 = devs[4].Data.TaskNumber;
  448. obj.Data.Dest1_5 = locs[4].XYNo.ToShort();
  449. }
  450. obj.Data.TaskSum1 = devs.Length.ToShort();
  451. obj.Data.PalletizingRowId1 = palletizingRow.Id;
  452. break;
  453. case 1:
  454. obj.Data.DestPosition_2 = palletizingRow.LineCode!.ToShort();
  455. obj.Data.TargetPallte2 = palletizing.PalletizingStation!.ToShort();
  456. if (devs.Length >= 1)
  457. {
  458. obj.Data.Task2_1 = devs[0].Data.TaskNumber;
  459. obj.Data.Dest2_1 = locs[0].XYNo.ToShort();
  460. }
  461. if (devs.Length >= 2)
  462. {
  463. obj.Data.Task2_2 = devs[1].Data.TaskNumber;
  464. obj.Data.Dest2_2 = locs[1].XYNo.ToShort();
  465. }
  466. if (devs.Length >= 3)
  467. {
  468. obj.Data.Task2_3 = devs[2].Data.TaskNumber;
  469. obj.Data.Dest2_3 = locs[2].XYNo.ToShort();
  470. }
  471. if (devs.Length >= 4)
  472. {
  473. obj.Data.Task2_4 = devs[3].Data.TaskNumber;
  474. obj.Data.Dest2_4 = locs[3].XYNo.ToShort();
  475. }
  476. if (devs.Length == 5)
  477. {
  478. obj.Data.Task2_5 = devs[4].Data.TaskNumber;
  479. obj.Data.Dest2_5 = locs[4].XYNo.ToShort();
  480. }
  481. obj.Data.TaskSum2 = devs.Length.ToShort();
  482. obj.Data.PalletizingRowId2 = palletizingRow.Id;
  483. break;
  484. }
  485. }
  486. obj.Data.VoucherNo++;
  487. }
  488. public override bool Select(Device dev)
  489. {
  490. return dev.Code is "Truss1" or "Truss2" or "Truss3";
  491. }
  492. public 桁架()
  493. {
  494. var trussList = Device.All.Where(x => x.HasFlag(DeviceFlags.桁架));
  495. foreach (var truss in trussList)
  496. {
  497. switch (truss.Code)
  498. {
  499. case "Truss1":
  500. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "461"), World), Device.All.Where(x => x.Code is "461" or "462" or "463" or "464" or "465").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  501. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "475"), World), Device.All.Where(x => x.Code is "475" or "476" or "477" or "478" or "479").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  502. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "489"), World), Device.All.Where(x => x.Code is "490" or "491" or "492" or "493" or "489").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  503. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "503"), World), Device.All.Where(x => x.Code is "503" or "504" or "505" or "506" or "507").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  504. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "517"), World), Device.All.Where(x => x.Code is "517" or "518" or "519" or "520" or "521").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  505. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "531"), World), Device.All.Where(x => x.Code is "532" or "533" or "534" or "535" or "531").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  506. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "545"), World), Device.All.Where(x => x.Code is "546" or "547" or "548" or "549" or "545").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  507. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "559"), World), Device.All.Where(x => x.Code is "559" or "560" or "561" or "562" or "563").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  508. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "573"), World), Device.All.Where(x => x.Code is "573" or "574" or "575" or "576" or "577").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  509. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "586"), World), Device.All.Where(x => x.Code is "586" or "587" or "588" or "589" or "590").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  510. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "661"), World), Device.All.Where(x => x.Code is "661" or "662" or "663" or "664" or "665").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  511. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "675"), World), Device.All.Where(x => x.Code is "675" or "676" or "677" or "678" or "679").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  512. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "689"), World), Device.All.Where(x => x.Code is "690" or "691" or "692" or "693" or "689").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  513. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "703"), World), Device.All.Where(x => x.Code is "703" or "704" or "705" or "706" or "707").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  514. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "717"), World), Device.All.Where(x => x.Code is "717" or "718" or "719" or "720" or "721").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  515. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "731"), World), Device.All.Where(x => x.Code is "732" or "733" or "734" or "735" or "731").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  516. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "745"), World), Device.All.Where(x => x.Code is "746" or "747" or "748" or "749" or "745").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  517. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "759"), World), Device.All.Where(x => x.Code is "759" or "760" or "761" or "762" or "763").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  518. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "773"), World), Device.All.Where(x => x.Code is "773" or "774" or "775" or "776" or "777").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  519. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "786"), World), Device.All.Where(x => x.Code is "786" or "787" or "788" or "789" or "790").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  520. break;
  521. case "Truss2":
  522. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "861"), World), Device.All.Where(x => x.Code is "861" or "862" or "863" or "864" or "865").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  523. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "875"), World), Device.All.Where(x => x.Code is "875" or "876" or "877" or "878" or "879").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  524. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "889"), World), Device.All.Where(x => x.Code is "890" or "891" or "892" or "893" or "889").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  525. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "903"), World), Device.All.Where(x => x.Code is "903" or "904" or "905" or "906" or "907").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  526. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "917"), World), Device.All.Where(x => x.Code is "917" or "918" or "919" or "920" or "921").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  527. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "931"), World), Device.All.Where(x => x.Code is "932" or "933" or "934" or "935" or "931").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  528. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "945"), World), Device.All.Where(x => x.Code is "946" or "947" or "948" or "949" or "945").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  529. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "959"), World), Device.All.Where(x => x.Code is "959" or "960" or "961" or "962" or "963").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  530. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "973"), World), Device.All.Where(x => x.Code is "973" or "974" or "975" or "976" or "977").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  531. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "986"), World), Device.All.Where(x => x.Code is "986" or "987" or "988" or "989" or "990").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  532. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1061"), World), Device.All.Where(x => x.Code is "1061" or "1062" or "1063" or "1064" or "1065").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  533. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1075"), World), Device.All.Where(x => x.Code is "1075" or "1076" or "1077" or "1078" or "1079").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  534. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1089"), World), Device.All.Where(x => x.Code is "1090" or "1091" or "1092" or "1093" or "1089").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  535. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1103"), World), Device.All.Where(x => x.Code is "1103" or "1104" or "1105" or "1106" or "1107").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  536. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1117"), World), Device.All.Where(x => x.Code is "1117" or "1118" or "1119" or "1120" or "1121").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  537. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1131"), World), Device.All.Where(x => x.Code is "1132" or "1133" or "1134" or "1135" or "1131").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  538. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1145"), World), Device.All.Where(x => x.Code is "1146" or "1147" or "1148" or "1149" or "1145").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  539. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1159"), World), Device.All.Where(x => x.Code is "1159" or "1160" or "1161" or "1162" or "1163").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  540. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1173"), World), Device.All.Where(x => x.Code is "1173" or "1174" or "1175" or "1176" or "1177").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  541. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1186"), World), Device.All.Where(x => x.Code is "1186" or "1187" or "1188" or "1189" or "1190").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  542. break;
  543. case "Truss3":
  544. //北
  545. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1261"), World), Device.All.Where(x => x.Code is "1261" or "1262" or "1263" or "1264" or "1265").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  546. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1275"), World), Device.All.Where(x => x.Code is "1275" or "1276" or "1277" or "1278" or "1279").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  547. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1289"), World), Device.All.Where(x => x.Code is "1290" or "1291" or "1292" or "1293" or "1289").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  548. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1303"), World), Device.All.Where(x => x.Code is "1303" or "1304" or "1305" or "1306" or "1307").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  549. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1317"), World), Device.All.Where(x => x.Code is "1317" or "1318" or "1319" or "1320" or "1321").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  550. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1331"), World), Device.All.Where(x => x.Code is "1332" or "1333" or "1334" or "1335" or "1331").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  551. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1345"), World), Device.All.Where(x => x.Code is "1346" or "1347" or "1348" or "1349" or "1345").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  552. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1359"), World), Device.All.Where(x => x.Code is "1359" or "1360" or "1361" or "1362" or "1363").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  553. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1373"), World), Device.All.Where(x => x.Code is "1373" or "1374" or "1375" or "1376" or "1377").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  554. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1386"), World), Device.All.Where(x => x.Code is "1386" or "1387" or "1388" or "1389" or "1390").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  555. //南
  556. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1461"), World), Device.All.Where(x => x.Code is "1461" or "1462" or "1463" or "1464" or "1465").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  557. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1475"), World), Device.All.Where(x => x.Code is "1475" or "1476" or "1477" or "1478" or "1479").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  558. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1489"), World), Device.All.Where(x => x.Code is "1490" or "1491" or "1492" or "1493" or "1489").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  559. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1503"), World), Device.All.Where(x => x.Code is "1503" or "1504" or "1505" or "1506" or "1507").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  560. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1517"), World), Device.All.Where(x => x.Code is "1517" or "1518" or "1519" or "1520" or "1521").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  561. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1531"), World), Device.All.Where(x => x.Code is "1532" or "1533" or "1534" or "1535" or "1531").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  562. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1545"), World), Device.All.Where(x => x.Code is "1546" or "1547" or "1548" or "1549" or "1545").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  563. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1559"), World), Device.All.Where(x => x.Code is "1559" or "1560" or "1561" or "1562" or "1563").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  564. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1573"), World), Device.All.Where(x => x.Code is "1573" or "1574" or "1575" or "1576" or "1577").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  565. _pickUpDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "1586"), World), Device.All.Where(x => x.Code is "1586" or "1587" or "1588" or "1589" or "1590").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  566. break;
  567. }
  568. }
  569. }
  570. }
  571. }