NoInteractionSystems.cs 4.5 KB

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