桁架缓存放行点.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using ServiceCenter.Extensions;
  2. using ServiceCenter.Logs;
  3. using ServiceCenter.SqlSugars;
  4. using System.ComponentModel;
  5. using WCS.Core;
  6. using WCS.Entity;
  7. using WCS.Entity.Protocol.Station;
  8. using WCS.WorkEngineering.Extensions;
  9. using WCS.WorkEngineering.Worlds;
  10. namespace WCS.WorkEngineering.Systems
  11. {
  12. /// <summary>
  13. /// 桁架缓存放行点
  14. /// </summary>
  15. [BelongTo(typeof(SortingPalletizingWorld))]
  16. [Description("桁架缓存放行点")]
  17. public class 桁架缓存放行点 : DeviceSystem<Device<IStation520, IStation521, IStation523>>
  18. {
  19. protected override bool ParallelDo => true;
  20. protected override bool SaveLogsToFile => true;
  21. /// <summary>
  22. /// 取货点设备集合
  23. /// </summary>
  24. private readonly Dictionary<Device<IStation524, IStation523>, List<Device<IStation524, IStation523>>> _cacheDevices = new();
  25. public override void Do(Device<IStation520, IStation521, IStation523> obj)
  26. {
  27. if (obj.Data.VoucherNo != obj.Data2.VoucherNo) throw new KnownException($"凭证号不一致,DB520:{obj.Data.VoucherNo}-DB521:{obj.Data2.VoucherNo}", LogLevelEnum.High);
  28. if (obj.Data3.Status.HasFlag(StationStatus.Run)) throw new KnownException("设备运行中", LogLevelEnum.Low);
  29. if (obj.Data3.Status.HasFlag(StationStatus.PH_Status) && obj.Data2.Request == 0) throw new KnownException("有光电无请求", LogLevelEnum.Mid);
  30. if (!obj.Data3.Status.HasFlag(StationStatus.PH_Status) && obj.Data2.Request == 1) throw new KnownException("无光电有请求", LogLevelEnum.Mid);
  31. if (!obj.Data3.Status.HasFlag(StationStatus.OT_Status)) throw new KnownException("站台货物信息与实际占用不一致", LogLevelEnum.Low);
  32. if (!obj.Data3.Status.HasFlag(StationStatus.PH_Status)) throw new KnownException("无光电", LogLevelEnum.Mid);
  33. if (obj.Data2.Request != 1) throw new KnownException("无请求", LogLevelEnum.Mid);
  34. var nextDev = new Device<IStation524, IStation523>(obj.Entity.Targets.FirstOrDefault()!, World);
  35. if (nextDev.Data2.Status1.HasFlag(StationStatus1.IsLock)) throw new KnownException($"{nextDev.Entity.Code}桁架未取货完成,线体锁定中", LogLevelEnum.Mid);
  36. //获取当前缓存线信息对应设备号的下一个地址
  37. var devCode = Device.All.Single(x => x.Code == obj.Entity.Code).Targets.FirstOrDefault();
  38. var nextCode = obj.Entity.Targets.FirstOrDefault().Code.ToShort();
  39. #region 计算当前缓存线是否已全部分配任务
  40. SqlSugarHelper.Do(_db =>
  41. {
  42. var db = _db.Default;
  43. var cacheLine = db.Queryable<WCS_CacheLine>().Includes(x => x.Locations).Single(x => x.LocationNo == obj.Entity.Code.ToShort());
  44. //是否所有的位已全部分配位置
  45. if (cacheLine != null && cacheLine.Locations.All(x => x is { IsEmpty: false, InStock: true }))
  46. {
  47. //判断下一个地址当前是否有对应的任务
  48. if (db.Queryable<WCS_CacheLine>().Any(x => x.LocationNo == nextCode && x.IsTruss == false)) return;
  49. //没有对应的任务,开始释放缓存
  50. cacheLine.InStock = true;
  51. cacheLine.LocationNo = devCode.Code.ToShort();
  52. cacheLine.EditTime = DateTime.Now;
  53. db.Updateable(cacheLine).ExecuteCommand();
  54. }
  55. });
  56. #endregion 计算当前缓存线是否已全部分配任务
  57. WCS_TaskInfo task = null;
  58. SqlSugarHelper.Do(_db =>
  59. {
  60. var db = _db.Default;
  61. //先找到下一个地址对应的缓存信息
  62. var lineCache = db.Queryable<WCS_CacheLine>().Includes(x => x.Locations).Single(x => x.LocationNo == nextCode && x.Locations.Any(s => s.TaskId == obj.Data2.TaskNumber));
  63. if (lineCache == null) return; //找不到表示当前线体的任务组没有凑齐
  64. //检测实物数量与有货总数是否相等
  65. if (!lineCache.Put)
  66. {
  67. var qty = lineCache.Locations.Count(x => x is { IsEmpty: false, InStock: true });
  68. var devQty = _cacheDevices.FirstOrDefault(x => x.Key.Entity.Code == obj.Entity.Code).Value
  69. .Count(x => x.Data2.Status.HasFlag(StationStatus.PH_Status));
  70. if (qty != devQty) return; //表示当前货物未全部到位
  71. lineCache.Put = true;
  72. db.Updateable(lineCache).ExecuteCommand();
  73. var pr = db.Queryable<WCS_PalletizingRow>().Single(x => x.Id == lineCache.PalletizingRowId);
  74. pr.LineCode = lineCache.LocationNo.ToString();
  75. db.Updateable(pr).ExecuteCommand();
  76. }
  77. var taskInfo = db.Queryable<WCS_TaskInfo>().First(v => v.ID == obj.Data2.TaskNumber && v.Status == Entity.TaskStatus.FinishOfShunt) ?? throw new KnownException("未找到对应的WCS任务", LogLevelEnum.Mid);
  78. taskInfo.Status = Entity.TaskStatus.ConveyorExecution;
  79. taskInfo.AddrNext = obj.Entity.Targets.FirstOrDefault().Code;
  80. taskInfo.EditWho = "WCS";
  81. taskInfo.EditTime = DateTime.Now;
  82. db.Updateable(taskInfo).ExecuteCommand();
  83. taskInfo.AddWCS_TASK_DTL(db, obj.Entity.Code, taskInfo.AddrNext, "桁架缓存放行");
  84. task = taskInfo;
  85. });
  86. if (task == null) return;
  87. obj.Data.TaskNumber = obj.Data2.TaskNumber;
  88. obj.Data.GoodsStart = obj.Entity.Code.ToShort();
  89. obj.Data.GoodsEnd = task.AddrNext.ToShort();
  90. obj.Data.VoucherNo++;
  91. }
  92. public override bool Select(Device dev)
  93. {
  94. return dev.HasFlag(Extensions.DeviceFlags.桁架缓存放行点);
  95. }
  96. public 桁架缓存放行点()
  97. {
  98. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "466"), World), Device.All.Where(x => x.Code is "466" or "467" or "468" or "469" or "470").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  99. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "480"), World), Device.All.Where(x => x.Code is "481" or "482" or "483" or "484" or "480").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  100. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "494"), World), Device.All.Where(x => x.Code is "494" or "495" or "496" or "497" or "498").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  101. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "508"), World), Device.All.Where(x => x.Code is "508" or "509" or "510" or "511" or "512").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  102. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "522"), World), Device.All.Where(x => x.Code is "522" or "523" or "524" or "525" or "526").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  103. _cacheDevices.Add(new Device<IStation524, IStation523>(Device.All.First(x => x.Code == "536"), World), Device.All.Where(x => x.Code is "536" or "537" or "538" or "539" or "540").Select(x => new Device<IStation524, IStation523>(x, World)).ToList());
  104. //_cacheDevices.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());
  105. //_cacheDevices.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());
  106. //_cacheDevices.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());
  107. //_cacheDevices.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());
  108. }
  109. }
  110. }