From 7ea6d410bc51657f73442aedf7bfc77a9bae3184 Mon Sep 17 00:00:00 2001 From: applelon <380149513@qq.com> Date: Wed, 20 Apr 2022 15:48:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AE=A2=E5=8D=95=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BPASmartClient.Business.csproj | 2 +- BPASmartClient.Business/Plugin/ConfigMgr.cs | 2 +- BPASmartClient.Business/Plugin/MQTTMgr.cs | 2 + BPASmartClient.Business/Plugin/OrderProxy.cs | 54 ++++++++++++++----- BPASmartClient.Device/BaseDevice.cs | 10 +++- BPASmartClient.Device/IDevice.cs | 10 +++- BPASmartClient.EventBus/EventBus.cs | 6 +-- BPASmartClient.EventBus/IEvent.cs | 2 +- BPASmartClient.KLMCoffee/CoffeeMachine.cs | 4 +- .../BPASmartClient.MQTT.csproj | 2 + BPASmartClient.MQTT/MQTTProxy.cs | 16 +++++- .../BPASmartClient.Model.csproj | 4 ++ BPASmartClient.Model/BaseEvent.cs | 2 +- BPASmartClient.Model/DeviceConfigModel.cs | 2 +- BPASmartClient.Model/DoOrderEvent.cs | 21 ++++++++ BPASmartClient.Model/KeepDataBase.cs | 31 +++++++++++ BPASmartClient.Model/OrderData.cs | 34 ++++++++++++ BPASmartClient.Model/ParSet.cs | 29 ++++++++++ BPASmartClient.Model/SimOrderVisibleData.cs | 36 +++++++++++++ BPASmartClient.Peripheral/BasePeripheral.cs | 2 +- BPASmartClient.Peripheral/IPeripheral.cs | 2 +- BPASmartClient/MainWindow.xaml.cs | 6 +-- 22 files changed, 248 insertions(+), 31 deletions(-) create mode 100644 BPASmartClient.Model/DoOrderEvent.cs create mode 100644 BPASmartClient.Model/KeepDataBase.cs create mode 100644 BPASmartClient.Model/OrderData.cs create mode 100644 BPASmartClient.Model/ParSet.cs create mode 100644 BPASmartClient.Model/SimOrderVisibleData.cs diff --git a/BPASmartClient.Business/BPASmartClient.Business.csproj b/BPASmartClient.Business/BPASmartClient.Business.csproj index cd6c83a7..9e70abc5 100644 --- a/BPASmartClient.Business/BPASmartClient.Business.csproj +++ b/BPASmartClient.Business/BPASmartClient.Business.csproj @@ -8,7 +8,7 @@ - + diff --git a/BPASmartClient.Business/Plugin/ConfigMgr.cs b/BPASmartClient.Business/Plugin/ConfigMgr.cs index 6b4b4e7e..f2576e05 100644 --- a/BPASmartClient.Business/Plugin/ConfigMgr.cs +++ b/BPASmartClient.Business/Plugin/ConfigMgr.cs @@ -59,7 +59,7 @@ namespace BPASmartClient.Business DeviceConfig deviceConfig = new DeviceConfig(); deviceConfig.Name = device.Attribute("Name").Value; deviceConfig.Module = device.Attribute("Module").Value; - deviceConfig.DeviceId = device.Attribute("DeviceId").Value; + deviceConfig.DeviceId =int.Parse(device.Attribute("DeviceId").Value); foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) { diff --git a/BPASmartClient.Business/Plugin/MQTTMgr.cs b/BPASmartClient.Business/Plugin/MQTTMgr.cs index e88e1f0b..27d837c0 100644 --- a/BPASmartClient.Business/Plugin/MQTTMgr.cs +++ b/BPASmartClient.Business/Plugin/MQTTMgr.cs @@ -2,6 +2,7 @@ using BPASmartClient.Helper; using BPASmartClient.MQTT; using HBLConsole.Communication; +using Microsoft.Extensions.Configuration; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -33,6 +34,7 @@ namespace BPASmartClient.Business public void Initialize() { + //MQTT 连接成功 mqttProxy.Connected = new Action(() => { diff --git a/BPASmartClient.Business/Plugin/OrderProxy.cs b/BPASmartClient.Business/Plugin/OrderProxy.cs index 9b8413ca..c228b052 100644 --- a/BPASmartClient.Business/Plugin/OrderProxy.cs +++ b/BPASmartClient.Business/Plugin/OrderProxy.cs @@ -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 /// public class OrderProxy : IPlugin { + //订单队列 + private ConcurrentQueue orders = new ConcurrentQueue(); + //运行标识 + private bool running = false; + //设备管理 + private DeviceMgr deviceMgr; /// /// 初始化 /// public void Initialize() { + deviceMgr = Plugin.GetInstance().GetPlugin(); + Plugin.GetInstance().GetPlugin().SetMessageReciveHandler(delegate (IMessage orderInfo) { - //if(orderInfo == null) return; - //if (orderInfo is MorkOrderPush morkOrderpush) - //{ - // OrderData order = Json.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 消息处理"); } /// @@ -40,6 +69,7 @@ namespace BPASmartClient.Business /// public void Dispose() { + running = false; } } } diff --git a/BPASmartClient.Device/BaseDevice.cs b/BPASmartClient.Device/BaseDevice.cs index 9fc760b2..19db1a3b 100644 --- a/BPASmartClient.Device/BaseDevice.cs +++ b/BPASmartClient.Device/BaseDevice.cs @@ -16,7 +16,7 @@ namespace BPASmartClient.Device /// /// 设备ID /// - public string DeviceId { get; set; } + public int DeviceId { get; set; } /// /// 设备所有状态 /// @@ -29,6 +29,14 @@ namespace BPASmartClient.Device /// 设备类型 /// public abstract DeviceClientType DeviceType { get; } + /// + /// 是否忙碌 + /// + public bool IsBusy { get;protected set; } + /// + /// 是否健康 + /// + public bool IsHealth { get; protected set; } public void Initliaze() { diff --git a/BPASmartClient.Device/IDevice.cs b/BPASmartClient.Device/IDevice.cs index 3e7c3956..0aacf986 100644 --- a/BPASmartClient.Device/IDevice.cs +++ b/BPASmartClient.Device/IDevice.cs @@ -16,7 +16,7 @@ namespace BPASmartClient.Device /// /// 设备ID /// - string DeviceId { get; set; } + int DeviceId { get; set; } /// /// 设备名称 /// @@ -30,6 +30,14 @@ namespace BPASmartClient.Device /// DeviceStatus Status { get; set; } /// + /// 是否忙碌 + /// + bool IsBusy { get; } + /// + /// 是否健康 + /// + bool IsHealth { get; } + /// /// 初始化设备加载 /// void Initliaze(List peripherals); diff --git a/BPASmartClient.EventBus/EventBus.cs b/BPASmartClient.EventBus/EventBus.cs index c0a1453f..2c95b099 100644 --- a/BPASmartClient.EventBus/EventBus.cs +++ b/BPASmartClient.EventBus/EventBus.cs @@ -30,13 +30,13 @@ namespace BPASmartClient.EventBus /// /// 事件订阅者集合 /// - private ConcurrentDictionary>> _eventHandls = new ConcurrentDictionary>>(); + private ConcurrentDictionary>> _eventHandls = new ConcurrentDictionary>>(); /// /// 事件订阅 /// - public void Subscribe(string id,EventHandle handle) + public void Subscribe(int id,EventHandle handle) { if (!_eventHandls.ContainsKey(id)) _eventHandls.TryAdd(id, new ConcurrentDictionary>()); @@ -49,7 +49,7 @@ namespace BPASmartClient.EventBus /// /// 事件退订 /// - public void UnSubscribe(string id,EventHandle handle) + public void UnSubscribe(int id,EventHandle handle) { if (_eventHandls.ContainsKey(id)) { diff --git a/BPASmartClient.EventBus/IEvent.cs b/BPASmartClient.EventBus/IEvent.cs index 219ae85d..a52db441 100644 --- a/BPASmartClient.EventBus/IEvent.cs +++ b/BPASmartClient.EventBus/IEvent.cs @@ -5,6 +5,6 @@ /// public interface IEvent { - string Id { get; set; } + int Id { get; set; } } } diff --git a/BPASmartClient.KLMCoffee/CoffeeMachine.cs b/BPASmartClient.KLMCoffee/CoffeeMachine.cs index e3e890a7..2eb67992 100644 --- a/BPASmartClient.KLMCoffee/CoffeeMachine.cs +++ b/BPASmartClient.KLMCoffee/CoffeeMachine.cs @@ -85,7 +85,7 @@ namespace BPASmartClient.KLMCoffee /// private void MainLoop() { - ThreadManage.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance().StartLong(new Action(() => { if (!free) { @@ -94,7 +94,7 @@ namespace BPASmartClient.KLMCoffee Thread.Sleep(200); }),"咖啡机询问线程"); - ThreadManage.GetInstance.StartLong(new Action(() => + ThreadManage.GetInstance().StartLong(new Action(() => { ResolveMsg(); }),"咖啡机解析线程"); diff --git a/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj b/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj index 5f95ecae..259d792a 100644 --- a/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj +++ b/BPASmartClient.MQTT/BPASmartClient.MQTT.csproj @@ -5,7 +5,9 @@ + + diff --git a/BPASmartClient.MQTT/MQTTProxy.cs b/BPASmartClient.MQTT/MQTTProxy.cs index 3ac66923..79b60e26 100644 --- a/BPASmartClient.MQTT/MQTTProxy.cs +++ b/BPASmartClient.MQTT/MQTTProxy.cs @@ -1,5 +1,7 @@ -using System; +using Microsoft.Extensions.Configuration; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -14,9 +16,19 @@ namespace BPASmartClient.MQTT public bool IsConnected { get; set; } + public void Init() + { + + //IConfigurationBuilder configurationBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()); + //IConfiguration config = configurationBuilder.Build(); + //configurationBuilder. + //var mqttBroker = config.GetSection("BrokerHostSettings"); + //MQTT_Config = mqttBroker.Value.FromJSON(); + } + public void Connect(string ip, int port, string clientId) { - + } public void CloseConnect() diff --git a/BPASmartClient.Model/BPASmartClient.Model.csproj b/BPASmartClient.Model/BPASmartClient.Model.csproj index df1a01f9..f32695df 100644 --- a/BPASmartClient.Model/BPASmartClient.Model.csproj +++ b/BPASmartClient.Model/BPASmartClient.Model.csproj @@ -14,4 +14,8 @@ + + + + diff --git a/BPASmartClient.Model/BaseEvent.cs b/BPASmartClient.Model/BaseEvent.cs index 9955a6f9..f1c8b070 100644 --- a/BPASmartClient.Model/BaseEvent.cs +++ b/BPASmartClient.Model/BaseEvent.cs @@ -9,6 +9,6 @@ namespace BPASmartClient.Model { public class BaseEvent : IEvent { - public string Id { get; set; } + public int Id { get; set; } } } diff --git a/BPASmartClient.Model/DeviceConfigModel.cs b/BPASmartClient.Model/DeviceConfigModel.cs index eefd5bc3..0ee55e72 100644 --- a/BPASmartClient.Model/DeviceConfigModel.cs +++ b/BPASmartClient.Model/DeviceConfigModel.cs @@ -15,7 +15,7 @@ namespace BPASmartClient.Model { public string Name { get; set; } public string Module { get; set; } - public string DeviceId { get; set; } + public int DeviceId { get; set; } public List Peripherals { get; set; } = new List(); } diff --git a/BPASmartClient.Model/DoOrderEvent.cs b/BPASmartClient.Model/DoOrderEvent.cs new file mode 100644 index 00000000..e43d689e --- /dev/null +++ b/BPASmartClient.Model/DoOrderEvent.cs @@ -0,0 +1,21 @@ +using BPA.Message; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + /// + /// 订单制作事件 + /// + public class DoOrderEvent : BaseEvent + { + public MorkOrderPush MorkOrder { get; set; } + public static DoOrderEvent Make(MorkOrderPush temp) + { + return new DoOrderEvent() { MorkOrder = temp }; + } + } +} diff --git a/BPASmartClient.Model/KeepDataBase.cs b/BPASmartClient.Model/KeepDataBase.cs new file mode 100644 index 00000000..bcd37792 --- /dev/null +++ b/BPASmartClient.Model/KeepDataBase.cs @@ -0,0 +1,31 @@ + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Collections.ObjectModel; +using System.Collections.Concurrent; + + +namespace BPASmartClient.Model +{ + public class KeepDataBase + { + /// + /// 模拟订单数据的配置 + /// + public ObservableCollection simOrderConfig { get; set; } = new ObservableCollection(); + + /// + /// 需要保存的订单数据 + /// + public ObservableCollection orderLists { get; set; } = new ObservableCollection(); + + /// + /// 参数设置 + /// + public ObservableCollection parSets { get; set; } = new ObservableCollection(); + + } +} diff --git a/BPASmartClient.Model/OrderData.cs b/BPASmartClient.Model/OrderData.cs new file mode 100644 index 00000000..d0d004f3 --- /dev/null +++ b/BPASmartClient.Model/OrderData.cs @@ -0,0 +1,34 @@ +using BPA.Message; +using BPA.Message.Enum; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class OrderData + { + public bool IsSelected { get { return _mIsSelected; } set { _mIsSelected = value; } } + private bool _mIsSelected; + + public MorkOrderPush OrderPush { get { return _mOrderPush; } set { _mOrderPush = value; } } + private MorkOrderPush _mOrderPush = new MorkOrderPush(); + + public ORDER_STATUS OrderStatus { get { return _mOrderStatus; } set { _mOrderStatus = value; } } + private ORDER_STATUS _mOrderStatus; + + public string StartDate { get { return _mStartDate; } set { _mStartDate = value; } } + private string _mStartDate = string.Empty; + + public string EndDate { get { return _mEndDate; } set { _mEndDate = value; } } + private string _mEndDate = string.Empty; + + public string CompleteDate { get { return _mCompleteDate; } set { _mCompleteDate = value; } } + private string _mCompleteDate = string.Empty; + + + + } +} diff --git a/BPASmartClient.Model/ParSet.cs b/BPASmartClient.Model/ParSet.cs new file mode 100644 index 00000000..03261db1 --- /dev/null +++ b/BPASmartClient.Model/ParSet.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class ParSet + { + public ushort Minute { get { return _mMinute; } set { _mMinute = value; } } + private ushort _mMinute; + + public ushort Second { get { return _mSecond; } set { _mSecond = value; } } + private ushort _mSecond; + + + public bool IsShield { get { return _mIsShield; } set { _mIsShield = value; } } + private bool _mIsShield; + + + public string TextBlockContext { get { return _mTextBlockContext; } set { _mTextBlockContext = value; } } + private string _mTextBlockContext; + + public string CheckBoxContext { get { return _mCheckBoxContext; } set { _mCheckBoxContext = value; } } + private string _mCheckBoxContext; + + } +} diff --git a/BPASmartClient.Model/SimOrderVisibleData.cs b/BPASmartClient.Model/SimOrderVisibleData.cs new file mode 100644 index 00000000..53929949 --- /dev/null +++ b/BPASmartClient.Model/SimOrderVisibleData.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class SimOrderVisibleData + { + + //public string ClientDeviceType { get { return _mClientDeviceType; } set { _mClientDeviceType = value; } } + //private string _mClientDeviceType; + + public ushort Loc { get { return _mLoc; } set { _mLoc = value; } } + private ushort _mLoc; + + public bool IsEnable { get { return _mIsEnable; } set { _mIsEnable = value; } } + private bool _mIsEnable; + + public bool IsSelected { get { return _mIsSelected; } set { _mIsSelected = value; IsEnable = !value; } } + private bool _mIsSelected; + + public string Text { get { return _mText; } set { _mText = value; } } + private string _mText; + + public ushort MinValue { get { return _mMinValue; } set { _mMinValue = value; } } + private ushort _mMinValue; + + public ushort MaxValue { get { return _mMaxValue; } set { _mMaxValue = value; } } + private ushort _mMaxValue; + + + + } +} diff --git a/BPASmartClient.Peripheral/BasePeripheral.cs b/BPASmartClient.Peripheral/BasePeripheral.cs index c282e95d..ffc11511 100644 --- a/BPASmartClient.Peripheral/BasePeripheral.cs +++ b/BPASmartClient.Peripheral/BasePeripheral.cs @@ -22,7 +22,7 @@ namespace BPASmartClient.Peripheral /// /// 归属设备Id /// - public string DeviceId { get; set; } + public int DeviceId { get; set; } /// /// 外设状态集合 diff --git a/BPASmartClient.Peripheral/IPeripheral.cs b/BPASmartClient.Peripheral/IPeripheral.cs index 79655400..711340ad 100644 --- a/BPASmartClient.Peripheral/IPeripheral.cs +++ b/BPASmartClient.Peripheral/IPeripheral.cs @@ -14,7 +14,7 @@ namespace BPASmartClient.Peripheral /// /// 设备ID /// - string DeviceId { get; set; } + int DeviceId { get; set; } /// /// 获取指定状态值 /// diff --git a/BPASmartClient/MainWindow.xaml.cs b/BPASmartClient/MainWindow.xaml.cs index 7cc08ad1..247bdc1c 100644 --- a/BPASmartClient/MainWindow.xaml.cs +++ b/BPASmartClient/MainWindow.xaml.cs @@ -33,9 +33,9 @@ namespace BPASmartClient private void Button_Click(object sender, RoutedEventArgs e) { - new Demo_MakeCoffeeEvent() { Id = "1" }.Publish(); - new DRCoffee_MakeCoffeeEvent() { Id = "1", DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish(); - new DRCoffee_CoffeeCommCmdEvent() { Id = "1",CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish(); + new Demo_MakeCoffeeEvent() { Id = 1 }.Publish(); + new DRCoffee_MakeCoffeeEvent() { Id = 1, DrinkCode= DrCoffeeDrinksCode.两杯意式浓缩 }.Publish(); + new DRCoffee_CoffeeCommCmdEvent() { Id = 1,CommCmd = DrCoffeeCommCmd.冲煮系统快速冲洗指令}.Publish(); } }