NoInteractionSystems.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using PlcSiemens.Core.Extension;
  2. using ServiceCenter.Extensions;
  3. using ServiceCenter.Logs;
  4. using ServiceCenter.Redis;
  5. using ServiceCenter.SqlSugars;
  6. using System.ComponentModel;
  7. using WCS.Core;
  8. using WCS.Entity;
  9. using WCS.WorkEngineering.Extensions;
  10. using WCS.WorkEngineering.Worlds;
  11. namespace WCS.WorkEngineering.Systems
  12. {
  13. /// <summary>
  14. /// 无交互系统
  15. /// </summary>
  16. [BelongTo(typeof(MainWorld))]
  17. [Description("无交互系统")]
  18. public class NoInteractionSystems : DeviceSystem<Station>
  19. {
  20. public NoInteractionSystems()
  21. {
  22. }
  23. protected override bool ParallelDo => true;
  24. protected override bool SaveLogsToFile => true;
  25. public override void Do(Station obj)
  26. {
  27. var key = $"WCS:Lock:无交互系统{obj.Entity.Code}";
  28. try
  29. {
  30. if (RedisHub.Default.Get(key) != null)
  31. {
  32. throw new KnownException($"[{obj.Entity.Code}]--触发并发管控", LogLevelEnum.High);
  33. }
  34. RedisHub.Default.Set(key, obj.Entity.Code);
  35. #region 处理所有的新增任务
  36. try
  37. {
  38. List<WCS_TaskInfo> taskInfos = new List<WCS_TaskInfo>();
  39. SqlSugarHelper.Do(db =>
  40. {
  41. taskInfos = db.Default.Queryable<WCS_TaskInfo>().Where(t => t.Status == Entity.TaskStatus.NewBuild).ToList();
  42. });
  43. if (taskInfos.Any())
  44. {
  45. foreach (var item in taskInfos)
  46. {
  47. try
  48. {
  49. SqlSugarHelper.Do(db =>
  50. {
  51. var task = db.Default.Queryable<WCS_TaskInfo>().Where(t => t.ID == item.ID).First() ?? throw new Exception($"未找到对应的WCS任务[{item.ID}]");
  52. if (task.Type == TaskType.EnterDepot)
  53. {
  54. //更新任务状态
  55. task.Status = Entity.TaskStatus.WaitingToExecute;
  56. db.Default.Updateable(task).ExecuteCommand();
  57. task.AddWCS_TASK_DTL(db, task.Device, $"初始化入库任务信息");
  58. }
  59. else if (task.Type == TaskType.OutDepot)
  60. {
  61. if (task.SrmStation.IsNullOrEmpty()) //如果没有指定放货站台
  62. {
  63. if (task.Device.IsNullOrEmpty())
  64. {
  65. task.Device = "SRM" + task.Tunnel.GetLastDigit();
  66. }
  67. //获取堆垛机到目标地址的路径信息
  68. var path = DevicePath.GetPath(task.Device, task.AddrTo);
  69. task.SrmStation = path.Points[1].Code;
  70. }
  71. //更新任务状态
  72. task.Status = Entity.TaskStatus.WaitingToExecute;
  73. db.Default.Updateable(task).ExecuteCommand();
  74. task.AddWCS_TASK_DTL(db, task.Device, $"初始化出库任务信息,放货站台:{task.SrmStation}");
  75. }
  76. else if (task.Type == TaskType.Delivery) //一楼叉车搬运任务
  77. {
  78. }
  79. else if (task.Type == TaskType.EmptyInit)
  80. {
  81. }
  82. });
  83. }
  84. catch (Exception ex)
  85. {
  86. World.Log(ex.Message, LogLevelEnum.Mid);
  87. continue;
  88. }
  89. }
  90. }
  91. }
  92. catch (Exception ex)
  93. {
  94. World.Log(ex.Message, LogLevelEnum.Mid);
  95. }
  96. #endregion 处理所有的新增任务
  97. }
  98. finally
  99. {
  100. RedisHub.Default.Del(key);
  101. }
  102. }
  103. public override bool Select(Device dev)
  104. {
  105. return dev.Code == "2532";
  106. }
  107. }
  108. }