|
|
@@ -1,7 +1,9 @@ |
|
|
|
using BPA.Message; |
|
|
|
using BPASmartClient.EventBus; |
|
|
|
using BPASmartClient.Helper; |
|
|
|
using HBLConsole.Communication; |
|
|
|
using BPASmartClient.Model; |
|
|
|
using System; |
|
|
|
using System.Collections.Concurrent; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Linq; |
|
|
|
using System.Text; |
|
|
@@ -14,25 +16,52 @@ namespace BPASmartClient.Business |
|
|
|
/// </summary> |
|
|
|
public class OrderProxy : IPlugin |
|
|
|
{ |
|
|
|
//订单队列 |
|
|
|
private ConcurrentQueue<MorkOrderPush> orders = new ConcurrentQueue<MorkOrderPush>(); |
|
|
|
//运行标识 |
|
|
|
private bool running = false; |
|
|
|
//设备管理 |
|
|
|
private DeviceMgr deviceMgr; |
|
|
|
/// <summary> |
|
|
|
/// 初始化 |
|
|
|
/// </summary> |
|
|
|
public void Initialize() |
|
|
|
{ |
|
|
|
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>(); |
|
|
|
|
|
|
|
Plugin.GetInstance().GetPlugin<MQTTMgr>().SetMessageReciveHandler(delegate (IMessage orderInfo) |
|
|
|
{ |
|
|
|
//if(orderInfo == null) return; |
|
|
|
//if (orderInfo is MorkOrderPush morkOrderpush) |
|
|
|
//{ |
|
|
|
// OrderData order = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(par => par.OrderPush?.SuborderId == morkOrderpush.SuborderId); |
|
|
|
// if (order == null)//防止重复订单 |
|
|
|
// { |
|
|
|
// ActionManage.GetInstance.Send("AddOrder", morkOrderpush); |
|
|
|
// GeneralConfig.morkOrderPushes.Enqueue(morkOrderpush); |
|
|
|
// //ActionManage.GetInstance.Send("DataParse", morkOrderpush); |
|
|
|
// } |
|
|
|
//} |
|
|
|
if (orderInfo == null) return; |
|
|
|
if (orderInfo is MorkOrderPush morkOrderpush) |
|
|
|
{ |
|
|
|
orders.Enqueue(morkOrderpush); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
ThreadManage.GetInstance().StartLong(() => |
|
|
|
{ |
|
|
|
while (running) |
|
|
|
{ |
|
|
|
while (orders.Count > 0 && orders.TryDequeue(out MorkOrderPush temp)) |
|
|
|
{ |
|
|
|
var device = deviceMgr.GetDevices().FirstOrDefault(p => p.DeviceId == temp.DeviceId); |
|
|
|
if (null != device) |
|
|
|
{ |
|
|
|
if (!device.IsBusy && device.IsHealth) |
|
|
|
{ |
|
|
|
var orderEvent = DoOrderEvent.Make(temp); |
|
|
|
orderEvent.Id = device.DeviceId; |
|
|
|
orderEvent.Publish(); |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
Thread.Sleep(50); |
|
|
|
} |
|
|
|
}, "MQTT 消息处理"); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary> |
|
|
@@ -40,6 +69,7 @@ namespace BPASmartClient.Business |
|
|
|
/// </summary> |
|
|
|
public void Dispose() |
|
|
|
{ |
|
|
|
running = false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |