|
- using BPASmartClient.Device;
- using BPASmartClient.EventBus;
- using BPASmartClient.Lebai;
- using BPASmartClient.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Peripheral;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using static BPASmartClient.EventBus.EventBus;
-
- namespace BPASmartClient.MorkT
- {
- public class Control_MorkT : BaseDevice
- {
- public override global::BPA.Message.Enum.DeviceClientType DeviceType { get { return BPA.Message.Enum.DeviceClientType.MORKT; } }
-
- GLV_MorkT morkT = new GLV_MorkT();
-
-
-
- public override void DoMain()
- {
- ServerInit();
- DataParse();
- EventBus.EventBus.GetInstance().Subscribe<DRCoffee_CoffeEndCookEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (morkT.MakeCoffeeOrder != null)
- morkT.MakeCoffeeOrder.OrderStatus = 1;
- });
- MessageLog.GetInstance.Show("MORKF 设备初始化完成");
- }
-
- public override void ResetProgram()
- {
- morkT = null;
- morkT = new GLV_MorkT();
- }
-
- public override void MainTask()
- {
- }
-
- public override void ReadData()
- {
- morkT.lebai = LebaiRobot.GetInstance.GetValueAsync();
- LebaiRobot.GetInstance.GetRobotModeStatus();
- }
-
-
-
- public override void Stop()
- {
- }
-
-
- private void ServerInit()
- {
- //物料信息
- EventBus.EventBus.GetInstance().Subscribe<MaterialDeliveryEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is MaterialDeliveryEvent material)
- {
- orderMaterialDelivery = material.orderMaterialDelivery;
- }
- });
-
- //配方数据信息
- EventBus.EventBus.GetInstance().Subscribe<RecipeBomEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBack)
- {
- if (@event == null) return;
- if (@event is RecipeBomEvent recipe)
- {
- recipeBoms = recipe.recipeBoms;
- }
- });
- }
-
- /// <summary>
- /// 数据解析
- /// </summary>
- private void DataParse()
- {
- EventBus.EventBus.GetInstance().Subscribe<DoOrderEvent>(DeviceId, delegate (IEvent @event, EventCallBackHandle callBackHandle)
- {
- if (@event == null) return;
- if (@event is DoOrderEvent order)
- {
- if (order.MorkOrder.GoodBatchings == null) return;
- OrderCount++;
- DeviceProcessLogShow($"接收到{OrderCount}次订单");
- //构建所有商品物料信息
- morkT.batchings = PolymerBatching.BuildAll();
- //商品类型
- GOODS_TYPE currentGoodsType = GOODS_TYPE.NEITHER;
- string loc_Goods = string.Empty;
- foreach (var item in order.MorkOrder.GoodBatchings)
- {
- var res = orderMaterialDelivery?.BatchingInfo?.FirstOrDefault(p => p.BatchingId == item.BatchingId);
- if (res != null)
- {
- //验证商品是咖啡还是冰淇淋
- if (ValidateGoodsByBatching(res.BatchingLoc) != GOODS_TYPE.NEITHER)
- {
- //获取当前物料所属商品类型
- currentGoodsType = ValidateGoodsByBatching(res.BatchingLoc);
- }
-
- //获取主料和容器位置
- if (morkT.batchings[res.BatchingLoc].BatchingClass == BATCHING_CLASS.MAIN_MATERIAL) loc_Goods = res.BatchingLoc;
-
- switch (currentGoodsType)
- {
- case GOODS_TYPE.COFFEE:
- if (morkT.morkOrderPushesCoffee.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkT.morkOrderPushesCoffee.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = loc_Goods
- });
- }
- break;
- case GOODS_TYPE.ICECREAM:
- if (morkT.morkOrderPushesIceCream.FirstOrDefault(p => p.SuborderId == order.MorkOrder.SuborderId) == null)
- {
- morkT.morkOrderPushesIceCream.Enqueue(new OrderLocInfo()
- {
- SuborderId = order.MorkOrder.SuborderId,
- BatchingId = res.BatchingId,
- Loc = loc_Goods
- });
- }
- break;
- case GOODS_TYPE.NEITHER:
- DeviceProcessLogShow("未知的商品类型");
- break;
- }
- }
- }
-
- }
- });
- }
-
- /// <summary>
- /// 验证当前是做咖啡还是做冰淇淋
- /// </summary>
- /// <param name="batchingLoc">物料位置</param>
- private GOODS_TYPE ValidateGoodsByBatching(string batchingLoc)
- {
- if (morkT.batchings.ContainsKey(batchingLoc))
- return morkT.batchings[batchingLoc].GoodsType;
- return GOODS_TYPE.NEITHER;
- }
-
-
-
- }
- }
|