AddLiquidInterceptor.cs 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. using SHJX.Service.Control.Extends;
  2. namespace SHJX.Service.Control.Pipeline.Nodes.InterceptorNodes
  3. {
  4. public class AddLiquidInterceptor : INode
  5. {
  6. #region Fields
  7. private static TaskExtend _taskExtend;
  8. private static IDataManager _dataManager;
  9. #endregion
  10. public AddLiquidInterceptor(TaskExtend taskExtend, IDataManager dataManager)
  11. {
  12. Name = nameof(AddLiquidInterceptor);
  13. _taskExtend = taskExtend;
  14. _dataManager = dataManager;
  15. }
  16. public override INode Invoke()
  17. {
  18. return this;
  19. }
  20. public override void Next()
  21. {
  22. bool vitriolEnable = true;
  23. bool sodiumHydroxideEnable = true;
  24. bool potassiumPermanganateEnable = true;
  25. LiquidVolume vitriolLiquid = _dataManager.Query<LiquidVolume>().Where(it => it.LiquidName.Equals(EquipmentNames.AddLiquidVitriol)).First();
  26. if (vitriolLiquid is not null)
  27. {
  28. vitriolEnable = vitriolLiquid.Enable;//加液位硫酸
  29. }
  30. LiquidVolume sodiumHydroxideLiquid = _dataManager.Query<LiquidVolume>().Where(it => it.LiquidName.Equals(EquipmentNames.Sodium1Hydroxide)).First();
  31. if (sodiumHydroxideLiquid is not null)
  32. {
  33. sodiumHydroxideEnable = sodiumHydroxideLiquid.Enable;//氢氧化钠
  34. }
  35. LiquidVolume potassiumPermanganateLiquid = _dataManager.Query<LiquidVolume>().Where(it => it.LiquidName.Equals(EquipmentNames.Titration2PotassiumPermanganate)).First();
  36. if (potassiumPermanganateLiquid is not null)
  37. {
  38. potassiumPermanganateEnable = potassiumPermanganateLiquid.Enable;//加液位高锰酸钾
  39. }
  40. if (!(vitriolEnable || sodiumHydroxideEnable || potassiumPermanganateEnable))
  41. {
  42. ReleaseAxis();
  43. ReleaseArea();
  44. _taskExtend.UpdateRoute(CurrentTask);
  45. return;
  46. }
  47. NextNode?.SetTask(CurrentTask)?.Invoke()?.Record()?.Next();
  48. }
  49. private void ReleaseArea()
  50. {
  51. List<EquipmentArea> areas = _dataManager.Query<EquipmentArea>().Where(it => it.PointName.In(CurrentTask.To, CurrentTask.From)).ToList();
  52. areas.ForEach(area =>
  53. {
  54. area.Enable = true;
  55. _dataManager.Update(area);
  56. });
  57. List<PositionHotlist> positions = _dataManager.Query<PositionHotlist>().Where(it => it.PositionName.In(CurrentTask.To, CurrentTask.From)).ToList();
  58. positions.ForEach(position =>
  59. {
  60. position.CurrentOccupy = string.Empty;
  61. position.Enable = true;
  62. _dataManager.Update(position);
  63. });
  64. }
  65. private void ReleaseAxis()
  66. {
  67. List<RouteCache> caches = _dataManager.Query<RouteCache>().Where(it => it.Source.Equals(CurrentTask.Source)).ToList();
  68. if (caches.Any())
  69. {
  70. if (caches.Count == 1)
  71. {
  72. _dataManager.Delete(caches.FirstOrDefault());
  73. }
  74. else
  75. {
  76. foreach (RouteCache cache in caches)
  77. {
  78. if (cache.RouteStep != CurrentTask.RouteStep)
  79. {
  80. _dataManager.Delete(cache);
  81. }
  82. }
  83. }
  84. }
  85. _dataManager.Update<StateMachine>().Invoke(it => it.Status.Set(0))(it => it.Name.Equals(StateMachineName.MOTOR_LOCK));
  86. }
  87. }
  88. }