终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

165 lines
6.2 KiB

  1. using BPASmartClient.Device;
  2. using BPASmartClient.EventBus;
  3. using BPASmartClient.Lebai;
  4. using BPASmartClient.Message;
  5. using BPASmartClient.Model;
  6. using BPASmartClient.Peripheral;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading.Tasks;
  12. using static BPASmartClient.EventBus.EventBus;
  13. namespace BPASmartClient.MorkT
  14. {
  15. public class Control_MorkT : BaseDevice
  16. {
  17. public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
  18. GLV_MorkT morkT = new GLV_MorkT();
  19. public override void DoMain()
  20. {
  21. ServerInit();
  22. DataParse();
  23. EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  24. {
  25. if (morkT.MakeCoffeeOrder != null)
  26. morkT.MakeCoffeeOrder.OrderStatus = 1;
  27. });
  28. MessageLog.GetInstance.Show("MORKF 设备初始化完成");
  29. }
  30. public override void ResetProgram()
  31. {
  32. morkT = null;
  33. morkT = new GLV_MorkT();
  34. }
  35. public override void MainTask()
  36. {
  37. }
  38. public override void ReadData()
  39. {
  40. morkT.lebai = LebaiRobot.GetInstance.GetValueAsync();
  41. LebaiRobot.GetInstance.GetRobotModeStatus();
  42. }
  43. public override void Stop()
  44. {
  45. }
  46. private void ServerInit()
  47. {
  48. //物料信息
  49. EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  50. {
  51. if (@event == null) return;
  52. if (@event is MaterialDeliveryEvent material)
  53. {
  54. orderMaterialDelivery = material.orderMaterialDelivery;
  55. }
  56. });
  57. //配方数据信息
  58. EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
  59. {
  60. if (@event == null) return;
  61. if (@event is RecipeBomEvent recipe)
  62. {
  63. recipeBoms = recipe.recipeBoms;
  64. }
  65. });
  66. }
  67. /// <summary>
  68. /// 数据解析
  69. /// </summary>
  70. private void DataParse()
  71. {
  72. EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
  73. {
  74. if (@event == null) return;
  75. if (@event is DoOrderEvent order)
  76. {
  77. if (order.MorkOrder.GoodBatchings == null) return;
  78. OrderCount++;
  79. DeviceProcessLogShow($"接收到{OrderCount}次订单");
  80. //构建所有商品物料信息
  81. morkT.batchings = PolymerBatching.BuildAll();
  82. //商品类型
  83. GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
  84. string loc_Goods = string.Empty;
  85. foreach (var item in order.MorkOrder.GoodBatchings)
  86. {
  87. var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
  88. if (res != null)
  89. {
  90. //验证商品是咖啡还是冰淇淋
  91. if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
  92. {
  93. //获取当前物料所属商品类型
  94. currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
  95. }
  96. //获取主料和容器位置
  97. if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
  98. switch (currentGoodsType)
  99. {
  100. case GOODS_TYPE.COFFEE:
  101. if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  102. {
  103. morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
  104. {
  105. SuborderId = order.MorkOrder.SuborderId,
  106. BatchingId = res.BatchingId,
  107. Loc = loc_Goods
  108. });
  109. }
  110. break;
  111. case GOODS_TYPE.ICECREAM:
  112. if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
  113. {
  114. morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
  115. {
  116. SuborderId = order.MorkOrder.SuborderId,
  117. BatchingId = res.BatchingId,
  118. Loc = loc_Goods
  119. });
  120. }
  121. break;
  122. case GOODS_TYPE.NEITHER:
  123. DeviceProcessLogShow("未知的商品类型");
  124. break;
  125. }
  126. }
  127. }
  128. }
  129. });
  130. }
  131. /// <summary>
  132. /// 验证当前是做咖啡还是做冰淇淋
  133. /// </summary>
  134. /// <param name="batchingLoc">物料位置</param>
  135. private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
  136. {
  137. if (morkT.batchings.ContainsKey(batchingLoc))
  138. return morkT.batchings[batchingLoc].GoodsType;
  139. return GOODS_TYPE.NEITHER;
  140. }
  141. }
  142. }