作者 | SHA1 | 備註 | 提交日期 |
---|---|---|---|
applelon | b47bd4d986 | Merge branch 'master' of http://10.2.1.24:10244/applelon/BPASmartClient | 2 年之前 |
applelon | 7ea6d410bc | 修改订单处理 | 2 年之前 |
@@ -8,7 +8,7 @@ | |||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="BPA.ApolloClient" Version="1.0.9" /> | <PackageReference Include="BPA.ApolloClient" Version="1.0.9" /> | ||||
<PackageReference Include="BPA.Message" Version="1.0.9" /> | |||||
<PackageReference Include="BPA.Message" Version="1.0.10" /> | |||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | <PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | ||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" /> | <PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" /> | ||||
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" /> | <PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" /> | ||||
@@ -59,7 +59,7 @@ namespace BPASmartClient.Business | |||||
DeviceConfig deviceConfig = new DeviceConfig(); | DeviceConfig deviceConfig = new DeviceConfig(); | ||||
deviceConfig.Name = device.Attribute("Name").Value; | deviceConfig.Name = device.Attribute("Name").Value; | ||||
deviceConfig.Module = device.Attribute("Module").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")) | foreach (var peripheralEl in device.XPathSelectElements("//Peripheral")) | ||||
{ | { | ||||
@@ -2,6 +2,7 @@ | |||||
using BPASmartClient.Helper; | using BPASmartClient.Helper; | ||||
using BPASmartClient.MQTT; | using BPASmartClient.MQTT; | ||||
using HBLConsole.Communication; | using HBLConsole.Communication; | ||||
using Microsoft.Extensions.Configuration; | |||||
using System; | using System; | ||||
using System.Collections.Concurrent; | using System.Collections.Concurrent; | ||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
@@ -33,6 +34,7 @@ namespace BPASmartClient.Business | |||||
public void Initialize() | public void Initialize() | ||||
{ | { | ||||
//MQTT 连接成功 | //MQTT 连接成功 | ||||
mqttProxy.Connected = new Action(() => | mqttProxy.Connected = new Action(() => | ||||
{ | { | ||||
@@ -1,7 +1,9 @@ | |||||
using BPA.Message; | using BPA.Message; | ||||
using BPASmartClient.EventBus; | |||||
using BPASmartClient.Helper; | using BPASmartClient.Helper; | ||||
using HBLConsole.Communication; | |||||
using BPASmartClient.Model; | |||||
using System; | using System; | ||||
using System.Collections.Concurrent; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
@@ -14,25 +16,52 @@ namespace BPASmartClient.Business | |||||
/// </summary> | /// </summary> | ||||
public class OrderProxy : IPlugin | public class OrderProxy : IPlugin | ||||
{ | { | ||||
//订单队列 | |||||
private ConcurrentQueue<MorkOrderPush> orders = new ConcurrentQueue<MorkOrderPush>(); | |||||
//运行标识 | |||||
private bool running = false; | |||||
//设备管理 | |||||
private DeviceMgr deviceMgr; | |||||
/// <summary> | /// <summary> | ||||
/// 初始化 | /// 初始化 | ||||
/// </summary> | /// </summary> | ||||
public void Initialize() | public void Initialize() | ||||
{ | { | ||||
deviceMgr = Plugin.GetInstance().GetPlugin<DeviceMgr>(); | |||||
Plugin.GetInstance().GetPlugin<MQTTMgr>().SetMessageReciveHandler(delegate (IMessage orderInfo) | 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> | /// <summary> | ||||
@@ -40,6 +69,7 @@ namespace BPASmartClient.Business | |||||
/// </summary> | /// </summary> | ||||
public void Dispose() | public void Dispose() | ||||
{ | { | ||||
running = false; | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -16,7 +16,7 @@ namespace BPASmartClient.Device | |||||
/// <summary> | /// <summary> | ||||
/// 设备ID | /// 设备ID | ||||
/// </summary> | /// </summary> | ||||
public string DeviceId { get; set; } | |||||
public int DeviceId { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// 设备所有状态 | /// 设备所有状态 | ||||
/// </summary> | /// </summary> | ||||
@@ -29,6 +29,14 @@ namespace BPASmartClient.Device | |||||
/// 设备类型 | /// 设备类型 | ||||
/// </summary> | /// </summary> | ||||
public abstract DeviceClientType DeviceType { get; } | public abstract DeviceClientType DeviceType { get; } | ||||
/// <summary> | |||||
/// 是否忙碌 | |||||
/// </summary> | |||||
public bool IsBusy { get;protected set; } | |||||
/// <summary> | |||||
/// 是否健康 | |||||
/// </summary> | |||||
public bool IsHealth { get; protected set; } | |||||
public void Initliaze() | public void Initliaze() | ||||
{ | { | ||||
@@ -16,7 +16,7 @@ namespace BPASmartClient.Device | |||||
/// <summary> | /// <summary> | ||||
/// 设备ID | /// 设备ID | ||||
/// </summary> | /// </summary> | ||||
string DeviceId { get; set; } | |||||
int DeviceId { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// 设备名称 | /// 设备名称 | ||||
/// </summary> | /// </summary> | ||||
@@ -30,6 +30,14 @@ namespace BPASmartClient.Device | |||||
/// </summary> | /// </summary> | ||||
DeviceStatus Status { get; set; } | DeviceStatus Status { get; set; } | ||||
/// <summary> | /// <summary> | ||||
/// 是否忙碌 | |||||
/// </summary> | |||||
bool IsBusy { get; } | |||||
/// <summary> | |||||
/// 是否健康 | |||||
/// </summary> | |||||
bool IsHealth { get; } | |||||
/// <summary> | |||||
/// 初始化设备加载 | /// 初始化设备加载 | ||||
/// </summary> | /// </summary> | ||||
void Initliaze(List<IPeripheral> peripherals); | void Initliaze(List<IPeripheral> peripherals); | ||||
@@ -30,13 +30,13 @@ namespace BPASmartClient.EventBus | |||||
/// <summary> | /// <summary> | ||||
/// 事件订阅者集合 | /// 事件订阅者集合 | ||||
/// </summary> | /// </summary> | ||||
private ConcurrentDictionary<string, ConcurrentDictionary<Type, List<EventHandle>>> _eventHandls = new ConcurrentDictionary<string, ConcurrentDictionary<Type, List<EventHandle>>>(); | |||||
private ConcurrentDictionary<int, ConcurrentDictionary<Type, List<EventHandle>>> _eventHandls = new ConcurrentDictionary<int, ConcurrentDictionary<Type, List<EventHandle>>>(); | |||||
/// <summary> | /// <summary> | ||||
/// 事件订阅 | /// 事件订阅 | ||||
/// </summary> | /// </summary> | ||||
public void Subscribe<TEvent>(string id,EventHandle handle) | |||||
public void Subscribe<TEvent>(int id,EventHandle handle) | |||||
{ | { | ||||
if (!_eventHandls.ContainsKey(id)) | if (!_eventHandls.ContainsKey(id)) | ||||
_eventHandls.TryAdd(id, new ConcurrentDictionary<Type, List<EventHandle>>()); | _eventHandls.TryAdd(id, new ConcurrentDictionary<Type, List<EventHandle>>()); | ||||
@@ -49,7 +49,7 @@ namespace BPASmartClient.EventBus | |||||
/// <summary> | /// <summary> | ||||
/// 事件退订 | /// 事件退订 | ||||
/// </summary> | /// </summary> | ||||
public void UnSubscribe<TEvent>(string id,EventHandle handle) | |||||
public void UnSubscribe<TEvent>(int id,EventHandle handle) | |||||
{ | { | ||||
if (_eventHandls.ContainsKey(id)) | if (_eventHandls.ContainsKey(id)) | ||||
{ | { | ||||
@@ -5,6 +5,6 @@ | |||||
/// </summary> | /// </summary> | ||||
public interface IEvent | public interface IEvent | ||||
{ | { | ||||
string Id { get; set; } | |||||
int Id { get; set; } | |||||
} | } | ||||
} | } |
@@ -5,7 +5,9 @@ | |||||
</PropertyGroup> | </PropertyGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
<PackageReference Include="BPA.MQTTClient" Version="1.0.9" /> | |||||
<PackageReference Include="BPA.MQTTnet" Version="1.0.3" /> | <PackageReference Include="BPA.MQTTnet" Version="1.0.3" /> | ||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" /> | |||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | <ItemGroup> | ||||
@@ -1,5 +1,7 @@ | |||||
using System; | |||||
using Microsoft.Extensions.Configuration; | |||||
using System; | |||||
using System.Collections.Generic; | using System.Collections.Generic; | ||||
using System.IO; | |||||
using System.Linq; | using System.Linq; | ||||
using System.Text; | using System.Text; | ||||
using System.Threading.Tasks; | using System.Threading.Tasks; | ||||
@@ -14,9 +16,19 @@ namespace BPASmartClient.MQTT | |||||
public bool IsConnected { get; set; } | 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<MQTT_Entity>(); | |||||
} | |||||
public void Connect(string ip, int port, string clientId) | public void Connect(string ip, int port, string clientId) | ||||
{ | { | ||||
} | } | ||||
public void CloseConnect() | public void CloseConnect() | ||||
@@ -14,4 +14,8 @@ | |||||
<Folder Include="机器人\Enum\" /> | <Folder Include="机器人\Enum\" /> | ||||
</ItemGroup> | </ItemGroup> | ||||
<ItemGroup> | |||||
<PackageReference Include="BPA.Message" Version="1.0.9" /> | |||||
</ItemGroup> | |||||
</Project> | </Project> |
@@ -9,6 +9,6 @@ namespace BPASmartClient.Model | |||||
{ | { | ||||
public class BaseEvent : IEvent | public class BaseEvent : IEvent | ||||
{ | { | ||||
public string Id { get; set; } | |||||
public int Id { get; set; } | |||||
} | } | ||||
} | } |
@@ -15,7 +15,7 @@ namespace BPASmartClient.Model | |||||
{ | { | ||||
public string Name { get; set; } | public string Name { get; set; } | ||||
public string Module { get; set; } | public string Module { get; set; } | ||||
public string DeviceId { get; set; } | |||||
public int DeviceId { get; set; } | |||||
public List<Peripheral> Peripherals { get; set; } = new List<Peripheral>(); | public List<Peripheral> Peripherals { get; set; } = new List<Peripheral>(); | ||||
} | } | ||||
@@ -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 | |||||
{ | |||||
/// <summary> | |||||
/// 订单制作事件 | |||||
/// </summary> | |||||
public class DoOrderEvent : BaseEvent | |||||
{ | |||||
public MorkOrderPush MorkOrder { get; set; } | |||||
public static DoOrderEvent Make(MorkOrderPush temp) | |||||
{ | |||||
return new DoOrderEvent() { MorkOrder = temp }; | |||||
} | |||||
} | |||||
} |
@@ -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 | |||||
{ | |||||
/// <summary> | |||||
/// 模拟订单数据的配置 | |||||
/// </summary> | |||||
public ObservableCollection<SimOrderVisibleData> simOrderConfig { get; set; } = new ObservableCollection<SimOrderVisibleData>(); | |||||
/// <summary> | |||||
/// 需要保存的订单数据 | |||||
/// </summary> | |||||
public ObservableCollection<OrderData> orderLists { get; set; } = new ObservableCollection<OrderData>(); | |||||
/// <summary> | |||||
/// 参数设置 | |||||
/// </summary> | |||||
public ObservableCollection<ParSet> parSets { get; set; } = new ObservableCollection<ParSet>(); | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
} |
@@ -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; | |||||
} | |||||
} |
@@ -22,7 +22,7 @@ namespace BPASmartClient.Peripheral | |||||
/// <summary> | /// <summary> | ||||
/// 归属设备Id | /// 归属设备Id | ||||
/// </summary> | /// </summary> | ||||
public string DeviceId { get; set; } | |||||
public int DeviceId { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// 外设状态集合 | /// 外设状态集合 | ||||
@@ -14,7 +14,7 @@ namespace BPASmartClient.Peripheral | |||||
/// <summary> | /// <summary> | ||||
/// 设备ID | /// 设备ID | ||||
/// </summary> | /// </summary> | ||||
string DeviceId { get; set; } | |||||
int DeviceId { get; set; } | |||||
/// <summary> | /// <summary> | ||||
/// 获取指定状态值 | /// 获取指定状态值 | ||||
/// </summary> | /// </summary> | ||||
@@ -47,9 +47,9 @@ namespace BPASmartClient | |||||
private void Button_Click(object sender, RoutedEventArgs e) | 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(); | |||||
} | } | ||||
} | } | ||||