NoInteractionSystems.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. string putStation = "";
  67. if (task.AddrTo == "8278")
  68. {
  69. switch (task.Tunnel)
  70. {
  71. case "1":
  72. putStation = "8271";
  73. break;
  74. case "2":
  75. putStation = "8272";
  76. break;
  77. case "3":
  78. putStation = "8273";
  79. break;
  80. case "4":
  81. putStation = "8274";
  82. break;
  83. case "5":
  84. putStation = "8275";
  85. break;
  86. }
  87. }
  88. else if (task.AddrTo == "8263" || task.AddrTo == "8257" || task.AddrTo == "8269")
  89. {
  90. switch (task.Tunnel)
  91. {
  92. case "1":
  93. putStation = "8251";
  94. break;
  95. case "2":
  96. putStation = "8248";
  97. break;
  98. case "3":
  99. putStation = "8247";
  100. break;
  101. case "4":
  102. putStation = "8245";
  103. break;
  104. case "5":
  105. putStation = "8242";
  106. break;
  107. }
  108. }
  109. else if (task.AddrTo == "8088" || task.AddrTo == "8094" || task.AddrTo == "8313" || task.BusType == "砝码出库")
  110. {
  111. putStation = "8045";
  112. }
  113. else if (task.AddrTo == "8028")
  114. {
  115. putStation = "8027";
  116. }
  117. //更新任务状态
  118. task.Status = Entity.TaskStatus.WaitingToExecute;
  119. task.SrmStation = putStation;
  120. db.Default.Updateable(task).ExecuteCommand();
  121. task.AddWCS_TASK_DTL(db, task.Device, $"初始化出库任务信息,放货站台:{task.SrmStation}");
  122. }
  123. else if (task.Type == TaskType.Delivery && task.AddrFrom != "8050")
  124. {
  125. task.Status = Entity.TaskStatus.WaitingToExecute;
  126. db.Default.Updateable(task).ExecuteCommand();
  127. task.AddWCS_TASK_DTL(db, task.Device, $"初始化输送任务信息,目标地址:{task.AddrTo}");
  128. }
  129. });
  130. }
  131. catch (Exception ex)
  132. {
  133. World.Log(ex.Message, LogLevelEnum.Mid);
  134. continue;
  135. }
  136. }
  137. }
  138. }
  139. catch (Exception ex)
  140. {
  141. World.Log(ex.Message, LogLevelEnum.Mid);
  142. }
  143. #endregion 处理所有的新增任务
  144. }
  145. finally
  146. {
  147. RedisHub.Default.Del(key);
  148. }
  149. }
  150. public override bool Select(Device dev)
  151. {
  152. return dev.Code == "8271";
  153. }
  154. }
  155. }