From 3d0d3ed3944dc641a20bd51c1da8e037959313a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A6=82=E6=84=8F=20=E5=BD=AD?= <2417589739@qq.com> Date: Fri, 4 Mar 2022 22:25:33 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A2=E5=8D=95=E5=88=97=E8=A1=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HBLConsole.Abstract/AbstractMessageServer.cs | 8 +- .../HBLConsole.Abstract.csproj | 6 + HBLConsole.Business/{ => Devices}/MORKS.cs | 27 +- HBLConsole.Business/MessageServer/Base.cs | 93 ++++ HBLConsole.Business/MessageServerBase.cs | 53 --- HBLConsole.Business/ServerData.cs | 6 +- HBLConsole.Business/ServerMessage.cs | 22 - HBLConsole.Factory/SimpleFactory.cs | 62 ++- HBLConsole.GVL/HBLConsole.GVL.csproj | 1 + HBLConsole.GVL/InternetInfo.cs | 5 +- HBLConsole.GVL/MORKS.cs | 3 +- HBLConsole.Interface/IBusiness.cs | 13 + HBLConsole.Interface/IGvl.cs | 12 + HBLConsole.MainConsole/Main.cs | 9 +- .../ScrollViewerStyle.xaml | 199 +++++++++ .../APIHelper.cs | 81 ++-- HBLConsole/App.xaml.cs | 3 + .../ResourceDictionarys/BasicStyle.xaml | 197 +++++++++ HBLConsole/View/MessageLogView.xaml | 14 +- HBLConsole/View/OrderStatusView.xaml | 417 +++++++++++------- HBLConsole/ViewModel/OrderStatusViewModel.cs | 56 --- HBLConsole/ViewModel/ViewModelBase.cs | 117 +++-- 22 files changed, 982 insertions(+), 422 deletions(-) rename HBLConsole.Business/{ => Devices}/MORKS.cs (67%) create mode 100644 HBLConsole.Business/MessageServer/Base.cs delete mode 100644 HBLConsole.Business/MessageServerBase.cs delete mode 100644 HBLConsole.Business/ServerMessage.cs create mode 100644 HBLConsole.Interface/IBusiness.cs create mode 100644 HBLConsole.Interface/IGvl.cs create mode 100644 HBLConsole.PryUserControl/ScrollViewerStyle.xaml rename {HBLConsole.Business => HBLConsole.Service}/APIHelper.cs (64%) diff --git a/HBLConsole.Abstract/AbstractMessageServer.cs b/HBLConsole.Abstract/AbstractMessageServer.cs index 5e6926a..b103319 100644 --- a/HBLConsole.Abstract/AbstractMessageServer.cs +++ b/HBLConsole.Abstract/AbstractMessageServer.cs @@ -1,4 +1,5 @@ -using System; +using BPA.Message.Enum; +using System; namespace HBLConsole.Abstract { @@ -6,10 +7,13 @@ namespace HBLConsole.Abstract { public abstract void GetBatchingInfo(T batchingInfo); + public abstract void GetBatchingInfo(int ClientId); + public abstract void AddOrder(T orderInfo); public abstract void GetRecipeBom(T recipeBomInfo); - public abstract void BatchingCountInfo(); + public abstract bool OrderStatusChange(string subOrderId, ORDER_STATUS status); + } } diff --git a/HBLConsole.Abstract/HBLConsole.Abstract.csproj b/HBLConsole.Abstract/HBLConsole.Abstract.csproj index f208d30..fbab18f 100644 --- a/HBLConsole.Abstract/HBLConsole.Abstract.csproj +++ b/HBLConsole.Abstract/HBLConsole.Abstract.csproj @@ -4,4 +4,10 @@ net5.0 + + + D:\BPACommon_output\net5.0\BPA.Message.dll + + + diff --git a/HBLConsole.Business/MORKS.cs b/HBLConsole.Business/Devices/MORKS.cs similarity index 67% rename from HBLConsole.Business/MORKS.cs rename to HBLConsole.Business/Devices/MORKS.cs index e617f4e..48e52a9 100644 --- a/HBLConsole.Business/MORKS.cs +++ b/HBLConsole.Business/Devices/MORKS.cs @@ -1,4 +1,6 @@ using HBLConsole.Communication; +using HBLConsole.Factory; +using HBLConsole.Interface; using HBLConsole.Model; using HBLConsole.Service; using System; @@ -6,19 +8,15 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using HBLConsole.GVL; -using BPA.Message; -namespace HBLConsole.Business +namespace HBLConsole.Business.Devices { - public class MORKS + public class MORKS : IBusiness { private volatile static MORKS _Instance; public static MORKS GetInstance => _Instance ?? (_Instance = new MORKS()); private MORKS() { } - - /// /// 写入配方数据到 PLC /// @@ -47,23 +45,12 @@ namespace HBLConsole.Business }), "ConnectOk"); //获取物料信息 - Json.GetInstance.Base.orderMaterialDelivery = APIHelper.GetInstance.GetBatchingInfo(InternetInfo.GetInstance.ClientId); - Json.GetInstance.Base.orderMaterialDelivery.BatchingInfo.Sort((a, b) => a.BatchingLoc.CompareTo(b.BatchingLoc)); - MessageLog.GetInstance.Show("【物料信息】"); - Json.GetInstance.Base.orderMaterialDelivery?.BatchingInfo?.ForEach(x => - { - MessageLog.GetInstance.Show($"{x.BatchingLoc}号位置:{x.BatchingCount}"); - }); - + SimpleFactory.GetInstance.GetBatchingInfo(); //Modbus Tcp 连接 ModbusTcpHelper.GetInstance.ModbusTcpConnect("127.0.0.1"); } - - - - - - } + } + diff --git a/HBLConsole.Business/MessageServer/Base.cs b/HBLConsole.Business/MessageServer/Base.cs new file mode 100644 index 0000000..cc31c74 --- /dev/null +++ b/HBLConsole.Business/MessageServer/Base.cs @@ -0,0 +1,93 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using HBLConsole.Abstract; +using BPA.Message; +using HBLConsole.Model; +using HBLConsole.Service; +using BPA.Message.Enum; +using HBLConsole.GVL; +using BPA.Utility; +using Newtonsoft.Json; + +namespace HBLConsole.Business.MessageServer +{ + public class Base : AbstractMessageServer + { + public override void AddOrder(T orderInfo) + { + if (orderInfo == null) return; + if (orderInfo is MorkOrderPush morkOrderpush) + { + Json.GetInstance.Base.morkOrderPushes.Add(new OrderData() + { + OrderStatus = ORDER_STATUS.WAIT, + IsSelected = true, + OrderPush = morkOrderpush + }); + ActionManagerment.GetInstance.Send("AddOrder", morkOrderpush); + } + } + + public override void GetBatchingInfo(T batchingInfo) + { + if (batchingInfo == null) return; + if (batchingInfo is OrderMaterialDelivery BatchingInfos) + { + Json.GetInstance.Base.orderMaterialDelivery = BatchingInfos; + } + } + + public override void GetBatchingInfo(int ClientId) + { + string result = string.Empty; + try + { + var jsondata = new { ClientId }; + string header = $"[{InternetInfo.GetInstance.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt(); + string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.StockServer}/GetItemInfo"; + result = APIHelper.GetInstance.HttpRequest(url, header, jsondata, RequestType.POST); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + } + Json.GetInstance.Base.orderMaterialDelivery = JsonConvert.DeserializeObject(result); + + MessageLog.GetInstance.Show("【物料信息】"); + Json.GetInstance.Base.orderMaterialDelivery?.BatchingInfo?.ForEach(x => + { + MessageLog.GetInstance.Show($"{x.BatchingLoc}号位置:{x.BatchingCount}"); + }); + } + + public override void GetRecipeBom(T recipeBomInfo) + { + if (recipeBomInfo == null) return; + if (recipeBomInfo is RecipeBoms recipeBom) + { + Json.GetInstance.Base.recipeBoms = recipeBom; + } + } + + public override bool OrderStatusChange(string subOrderId, ORDER_STATUS status) + { + string result = string.Empty; + OrderStatusChange orderStatusChange = new OrderStatusChange() { CookingStatus = status, SuborderId = subOrderId }; + try + { + string header = $"[{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt(); + string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange"; + result = APIHelper.GetInstance.HttpRequest(url, header, orderStatusChange, RequestType.POST); + } + catch (Exception ex) + { + MessageLog.GetInstance.Show(ex.ToString()); + } + var res = JsonConvert.DeserializeObject(result); + return res?.Result == 2; + } + } +} diff --git a/HBLConsole.Business/MessageServerBase.cs b/HBLConsole.Business/MessageServerBase.cs deleted file mode 100644 index 1ccb65a..0000000 --- a/HBLConsole.Business/MessageServerBase.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HBLConsole.Abstract; -using BPA.Message; -using HBLConsole.Model; -using HBLConsole.Service; -using BPA.Message.Enum; - -namespace HBLConsole.Business -{ - public class MessageServerBase : AbstractMessageServer - { - public override void AddOrder(T orderInfo) - { - if (orderInfo == null) return; - if (orderInfo is MorkOrderPush morkOrderpush) - { - Json.GetInstance.Base.morkOrderPushes.Add(new OrderData() - { - OrderStatus = ORDER_STATUS.WAIT, - IsSelected = true, - OrderPush = morkOrderpush - }); - } - } - - public override void BatchingCountInfo() - { - throw new NotImplementedException(); - } - - public override void GetBatchingInfo(T batchingInfo) - { - if (batchingInfo == null) return; - if (batchingInfo is OrderMaterialDelivery BatchingInfos) - { - Json.GetInstance.Base.orderMaterialDelivery = BatchingInfos; - } - } - - public override void GetRecipeBom(T recipeBomInfo) - { - if (recipeBomInfo == null) return; - if (recipeBomInfo is RecipeBoms recipeBom) - { - Json.GetInstance.Base.recipeBoms = recipeBom; - } - } - } -} diff --git a/HBLConsole.Business/ServerData.cs b/HBLConsole.Business/ServerData.cs index 6a42d06..b420c39 100644 --- a/HBLConsole.Business/ServerData.cs +++ b/HBLConsole.Business/ServerData.cs @@ -22,8 +22,6 @@ namespace HBLConsole.Business ConcurrentQueue receives = new ConcurrentQueue(); - IServerMessage serverMessage = new ServerMessage(); - public void Init() { ThreadManagerment.GetInstance.StartLong(new Action(() => @@ -37,13 +35,13 @@ namespace HBLConsole.Business { if (package.Message != null) { - serverMessage.Universal(SimpleFactory.GetInstance.GetAbsMessageServer, package.Message); + SimpleFactory.GetInstance.MqttMessage(package.Message); } } } } Thread.Sleep(100); - }), ""); + }), "mqtt消息处理"); } diff --git a/HBLConsole.Business/ServerMessage.cs b/HBLConsole.Business/ServerMessage.cs deleted file mode 100644 index 835d114..0000000 --- a/HBLConsole.Business/ServerMessage.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using HBLConsole.Interface; -using BPA.Message; -using HBLConsole.Abstract; - -namespace HBLConsole.Business -{ - public class ServerMessage : IServerMessage - { - public void Universal(AbstractMessageServer abstractMessageServer, IMessage message) - { - abstractMessageServer.AddOrder(message); - abstractMessageServer.GetBatchingInfo(message); - abstractMessageServer.GetRecipeBom(message); - abstractMessageServer.BatchingCountInfo(); - } - } -} diff --git a/HBLConsole.Factory/SimpleFactory.cs b/HBLConsole.Factory/SimpleFactory.cs index ffc77ec..9877ef5 100644 --- a/HBLConsole.Factory/SimpleFactory.cs +++ b/HBLConsole.Factory/SimpleFactory.cs @@ -4,6 +4,8 @@ using System; using System.Reflection; using BPA.Message.Enum; using HBLConsole.GVL; +using BPA.Message; +using HBLConsole.Service; namespace HBLConsole.Factory { @@ -17,15 +19,67 @@ namespace HBLConsole.Factory public AbstractMessageServer GetAbsMessageServer => _GetAbsMessageServer ?? (_GetAbsMessageServer = GetAbstractMessageServer()); private AbstractMessageServer _GetAbsMessageServer; - //public IServerMessage GetIServerMessage => _GetIServerMessage ?? (_GetIServerMessage = new ServerMessage()); - //private IServerMessage _GetIServerMessage; + private string DeviceType => GeneralConfig.GetInstance.DeviceType.ToString(); + + public void MqttMessage(IMessage message) + { + GetAbsMessageServer.AddOrder(message); + GetAbsMessageServer.GetBatchingInfo(message); + GetAbsMessageServer.GetRecipeBom(message); + } + + /// + /// 获取物料信息 + /// + public void GetBatchingInfo() + { + GetAbsMessageServer.GetBatchingInfo(InternetInfo.GetInstance.ClientId); + } + + /// + /// 订单状态更改 + /// + /// + /// + /// + public bool OrderChanged(string subid, ORDER_STATUS status) + { + bool res = GetAbsMessageServer.OrderStatusChange(subid, status); + if (res) + { + ActionManagerment.GetInstance.Send("OrderStatusChange", new OrderStatusChange() + { + CookingStatus = status, + SuborderId = subid + }); + } + return res; + } private AbstractMessageServer GetAbstractMessageServer() { - Type type = Assembly.Load("HBLConsole.Business").GetType($"HBLConsole.Business.{GeneralConfig.GetInstance.DeviceType.ToString()}"); + string NameSpace = "HBLConsole.Business"; + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.{DeviceType}"); if (type == null) - type = Assembly.Load("HBLConsole.Business").GetType($"HBLConsole.Business.MessageServerBase"); + type = Assembly.Load(NameSpace).GetType($"{NameSpace}.MessageServer.Base"); return (AbstractMessageServer)Activator.CreateInstance(type); } + + /// + /// 设备初始化 + /// + public void DeviceInit() + { + string NameSpace = "HBLConsole.Business";//Load 加载的是dll的名称,GetType获取的是全命名空间下的类 + Type type = Assembly.Load(NameSpace).GetType($"{NameSpace}.Devices.{DeviceType}"); + IBusiness business = (IBusiness)type?.GetProperty("GetInstance").GetValue(null); + business?.Init(); + } + + public IGvl GetGvl() + { + Type type = Assembly.Load("HBLConsole.GVL").GetType($"HBLConsole.GVL.{DeviceType}"); + return (IGvl)Activator.CreateInstance(type); + } } } diff --git a/HBLConsole.GVL/HBLConsole.GVL.csproj b/HBLConsole.GVL/HBLConsole.GVL.csproj index bb39151..25caeb4 100644 --- a/HBLConsole.GVL/HBLConsole.GVL.csproj +++ b/HBLConsole.GVL/HBLConsole.GVL.csproj @@ -13,6 +13,7 @@ + diff --git a/HBLConsole.GVL/InternetInfo.cs b/HBLConsole.GVL/InternetInfo.cs index 031dc48..9a886ab 100644 --- a/HBLConsole.GVL/InternetInfo.cs +++ b/HBLConsole.GVL/InternetInfo.cs @@ -22,7 +22,10 @@ namespace HBLConsole.GVL public static InternetInfo GetInstance => _Instance ?? (_Instance = new InternetInfo()); private InternetInfo() { } - public void Init() + /// + /// 配置初始化 + /// + public void ConfigInit() { NetworkConnectState = UniversalHelper.GetInstance.GetNetworkState(); while (!NetworkConnectState) diff --git a/HBLConsole.GVL/MORKS.cs b/HBLConsole.GVL/MORKS.cs index 9b17736..3ca4361 100644 --- a/HBLConsole.GVL/MORKS.cs +++ b/HBLConsole.GVL/MORKS.cs @@ -3,13 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using HBLConsole.Interface; namespace HBLConsole.GVL { /// /// MORKS 设备数据 /// - public class MORKS + public class MORKS : IGvl { /// /// 初始化完成 diff --git a/HBLConsole.Interface/IBusiness.cs b/HBLConsole.Interface/IBusiness.cs new file mode 100644 index 0000000..1326edd --- /dev/null +++ b/HBLConsole.Interface/IBusiness.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Interface +{ + public interface IBusiness + { + void Init(); + } +} diff --git a/HBLConsole.Interface/IGvl.cs b/HBLConsole.Interface/IGvl.cs new file mode 100644 index 0000000..57d8e28 --- /dev/null +++ b/HBLConsole.Interface/IGvl.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HBLConsole.Interface +{ + public interface IGvl + { + } +} diff --git a/HBLConsole.MainConsole/Main.cs b/HBLConsole.MainConsole/Main.cs index 08b1756..256aa42 100644 --- a/HBLConsole.MainConsole/Main.cs +++ b/HBLConsole.MainConsole/Main.cs @@ -9,6 +9,7 @@ using HBLConsole.GVL; using HBLConsole.Communication; using BPA.Message; using HBLConsole.Business; +using HBLConsole.Factory; namespace HBLConsole.MainConsole { @@ -40,15 +41,19 @@ namespace HBLConsole.MainConsole Topics.Add(TOPIC.GetInstance.GetBusinessTopic(GeneralConfig.GetInstance.DeviceType, InternetInfo.GetInstance.ClientId)); ThreadManagerment.GetInstance.Start(new Action(() => { - InternetInfo.GetInstance.Init();//从 consul 获取配置数据 + InternetInfo.GetInstance.ConfigInit();//从 consul 获取配置数据 - MORKS.GetInstance.Init();//设备初始化 + SimpleFactory.GetInstance.DeviceInit();//设备初始化 //MQTT 连接成功 MqttHelper.GetInstance.ConnectOk = new Action(() => { MqttHelper.GetInstance.MqttSubscriptionAsync(Topics.ToArray());//主题订阅 + HeartbeatReport.GetInstance.Init();//心跳上报 + + ServerData.GetInstance.Init();//数据处理初始化 + //接收MQTT消息 MqttHelper.GetInstance.MqttReceive = new Action((receivce) => { diff --git a/HBLConsole.PryUserControl/ScrollViewerStyle.xaml b/HBLConsole.PryUserControl/ScrollViewerStyle.xaml new file mode 100644 index 0000000..10e53f4 --- /dev/null +++ b/HBLConsole.PryUserControl/ScrollViewerStyle.xaml @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HBLConsole.Business/APIHelper.cs b/HBLConsole.Service/APIHelper.cs similarity index 64% rename from HBLConsole.Business/APIHelper.cs rename to HBLConsole.Service/APIHelper.cs index bc88b43..29b20f9 100644 --- a/HBLConsole.Business/APIHelper.cs +++ b/HBLConsole.Service/APIHelper.cs @@ -6,14 +6,11 @@ using System.Linq; using System.Net; using System.Text; using System.Threading.Tasks; -using BPA.Utility; -using HBLConsole.GVL; -using BPA.Message; using System.Web; using Newtonsoft.Json; using HBLConsole.Service; -namespace HBLConsole.Business +namespace HBLConsole.Service { public class APIHelper { @@ -27,46 +24,46 @@ namespace HBLConsole.Business /// /// /// - public OrderMaterialDelivery GetBatchingInfo(int ClientId) - { - string result = string.Empty; - try - { - var jsondata = new { ClientId }; - string header = $"[{InternetInfo.GetInstance.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt(); - string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.StockServer}/GetItemInfo"; - result = HttpRequest(url, header, jsondata, RequestType.POST); - } - catch (Exception ex) - { - MessageLog.GetInstance.Show(ex.ToString()); - } - return JsonConvert.DeserializeObject(result); - } + //public OrderMaterialDelivery GetBatchingInfo(int ClientId) + //{ + // string result = string.Empty; + // try + // { + // var jsondata = new { ClientId }; + // string header = $"[{InternetInfo.GetInstance.StockServer}/GetItemInfo]_[{DateTime.Now.Ticks}]".AESEncrypt(); + // string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.StockServer}/GetItemInfo"; + // result = HttpRequest(url, header, jsondata, RequestType.POST); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // } + // return JsonConvert.DeserializeObject(result); + //} - /// - /// 更改订单状态 - /// - /// - /// - public OrderStatusChangeRsp OrderStatusChange(OrderStatusChange orderStatusChange) - { - string result = string.Empty; - try - { - string header = $"[{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt(); - string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange"; - result = HttpRequest(url, header, orderStatusChange, RequestType.POST); - } - catch (Exception ex) - { - MessageLog.GetInstance.Show(ex.ToString()); - } - return JsonConvert.DeserializeObject(result); - } + ///// + ///// 更改订单状态 + ///// + ///// + ///// + //public OrderStatusChangeRsp OrderStatusChange(OrderStatusChange orderStatusChange) + //{ + // string result = string.Empty; + // try + // { + // string header = $"[{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange]_[{DateTime.Now.Ticks}]".AESEncrypt(); + // string url = $"{InternetInfo.GetInstance.ApiAddress}{InternetInfo.GetInstance.OrderServer}/order/robotstatuschange"; + // result = HttpRequest(url, header, orderStatusChange, RequestType.POST); + // } + // catch (Exception ex) + // { + // MessageLog.GetInstance.Show(ex.ToString()); + // } + // return JsonConvert.DeserializeObject(result); + //} - public static string PostData(string url, string data, string head) + public string PostData(string url, string data, string head) { byte[] b = Encoding.UTF8.GetBytes(data);//把字符串转换为二进制 HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); @@ -88,7 +85,7 @@ namespace HBLConsole.Business return str; } - public static string GetData(string url, string head) + public string GetData(string url, string head) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; diff --git a/HBLConsole/App.xaml.cs b/HBLConsole/App.xaml.cs index be308b9..39329b8 100644 --- a/HBLConsole/App.xaml.cs +++ b/HBLConsole/App.xaml.cs @@ -12,6 +12,8 @@ using System.Diagnostics; using HBLConsole.Service; using HBLConsole.Model; using HBLConsole.MainConsole; +using HBLConsole.GVL; +using BPA.Message.Enum; namespace HBLConsole { @@ -25,6 +27,7 @@ namespace HBLConsole protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); + GeneralConfig.GetInstance.DeviceType = DeviceClientType.MORKS; SystemHelper.GetInstance.AutoStart(false); SystemHelper.GetInstance.CreateDesktopShortcut(); AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; diff --git a/HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml b/HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml index b2b8d3a..4126707 100644 --- a/HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml +++ b/HBLConsole/Resources/ResourceDictionarys/BasicStyle.xaml @@ -196,4 +196,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HBLConsole/View/MessageLogView.xaml b/HBLConsole/View/MessageLogView.xaml index 8700fd1..352bd9a 100644 --- a/HBLConsole/View/MessageLogView.xaml +++ b/HBLConsole/View/MessageLogView.xaml @@ -15,13 +15,23 @@ + + + + + + + + + + HorizontalScrollBarVisibility="Visible" + VerticalScrollBarVisibility="Visible"> - + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - + Text="取餐号" /> - + + + + - - - + Text="开始时间" /> + + + + + + + + + + - - - + Text="完成时间" /> - + + - - + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - + Text="{Binding SortNo}" /> + + + + - - - + Text="开始时间" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - + Text="{Binding SortNo}" /> + + + + + + - - - + Text="开始时间" /> - + + + + - - - - - - + + + + - + + + + + + + + + + + + + + + diff --git a/HBLConsole/ViewModel/OrderStatusViewModel.cs b/HBLConsole/ViewModel/OrderStatusViewModel.cs index 8351152..e3a7103 100644 --- a/HBLConsole/ViewModel/OrderStatusViewModel.cs +++ b/HBLConsole/ViewModel/OrderStatusViewModel.cs @@ -1,5 +1,4 @@ using BPA.Message; -//using BPA.Message.Kafka; using System; using System.Collections.Generic; using System.Linq; @@ -14,61 +13,6 @@ namespace HBLConsole.ViewModel { MqttReceive(); WindowName = "订单状态"; - //orderStatusLists.Add(new OrderStatusList() - //{ - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // EndDateTime = DateTime.Now.ToString("HH:mm:ss"), - // GoodName = "细面", - // OrderStatus = ORDER_STATUS.WAIT, - // SortNo = "0001", - // SubOrderId = "0001", - //}); - - //orderStatusLists.Add(new OrderStatusList() - //{ - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // EndDateTime = DateTime.Now.ToString("HH:mm:ss"), - // GoodName = "细面", - // OrderStatus = ORDER_STATUS.COOKING, - // SortNo = "0002", - // SubOrderId = "0002", - //}); - - - //orderStatusLists.Add(new OrderStatusList() - //{ - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // EndDateTime = DateTime.Now.ToString("HH:mm:ss"), - // GoodName = "细面", - // OrderStatus = ORDER_STATUS.COMPLETED_COOK, - // SortNo = "0003", - // SubOrderId = "0003", - //}); - - //orderStatusLists.Add(new OrderStatusList() - //{ - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // EndDateTime = DateTime.Now.ToString("HH:mm:ss"), - // GoodName = "细面", - // OrderStatus = ORDER_STATUS.COMPLETED_TAKE, - // SortNo = "0004", - // SubOrderId = "0004", - //}); - - //orderStatusLists.Add(new OrderStatusList() - //{ - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // EndDateTime = DateTime.Now.ToString("HH:mm:ss"), - // GoodName = "细面", - // OrderStatus = ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING, - // SortNo = "0005", - // SubOrderId = "0005", - //}); - - - } - - } } diff --git a/HBLConsole/ViewModel/ViewModelBase.cs b/HBLConsole/ViewModel/ViewModelBase.cs index 9581f06..ca5f729 100644 --- a/HBLConsole/ViewModel/ViewModelBase.cs +++ b/HBLConsole/ViewModel/ViewModelBase.cs @@ -11,6 +11,7 @@ using BPA.Message; using Microsoft.Toolkit.Mvvm.ComponentModel; using HBLConsole.Service; using HBLConsole.Model; +using BPA.Message.Enum; namespace HBLConsole.ViewModel { @@ -55,6 +56,11 @@ namespace HBLConsole.ViewModel /// public static ObservableCollection orderStatusLists { get; set; } = new ObservableCollection(); + /// + /// 等待取餐列表 + /// + public static ObservableCollection WaitTakeMeal { get; set; } = new ObservableCollection(); + /// /// 显示当前窗体名称 /// @@ -75,68 +81,55 @@ namespace HBLConsole.ViewModel /// public void MqttReceive() { - //ClientStation.GetInstance.MqttReceive = new Action((m) => - //{ - // if (m is Kafka_BigScreenTakeInfo message) - // { - // App.Current.Dispatcher.Invoke(new Action(() => - // { - // foreach (var item in message.SubOrderInfos) - // { - // var SubOrderInfo = orderStatusLists.FirstOrDefault(p => p.SubOrderId == item.SubOrderId); - // if (SubOrderInfo != null)//大屏取餐有该订单编号 - // { - // //GVL.MessageLogOut.GetInstance.Show($"更改的 订单的ID是= 【{item.SubOrderId}】 状态是:={item.SubOrderStatus}"); - // int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.SubOrderId == item.SubOrderId); - // orderStatusLists.ElementAt(index).OrderStatus = item.SubOrderStatus; - // if (item.SubOrderStatus == ORDER_STATUS.COMPLETED_TAKE) - // { - // orderStatusLists.RemoveAt(index); - // } - // if (item.SubOrderStatus == ORDER_STATUS.COMPLETED_COOK) - // { - // string SortNo = orderStatusLists.FirstOrDefault(p => p.SubOrderId == item.SubOrderId).SortNo; - // if (SortNo != null) - // { - // if (SortNo.Length > 0) - // { - // //GVL_VAR.GetInstance.speacks.Enqueue(SortNo); - // //GVL.MessageLogOut.GetInstance.Show($"语音提示"); - // } - // } - // orderStatusLists.ElementAt(index).EndDateTime = DateTime.Now.ToString("HH:mm:ss"); - // orderStatusLists[index].CompleteDateTime = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDateTime)).TotalSeconds.ToString(); - // } - // if (item.SubOrderStatus == ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING) orderStatusLists.ElementAt(index).OrderStatus = ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING; - // } - // else//大屏取餐界面没有该订单编号 - // { - // if (item.SubOrderStatus == ORDER_STATUS.WAIT) - // { - // MessageLogOut.GetInstance.Show($"添加的 订单编号= 【{item.SortNo}】 的ID是= 【{item.SubOrderId}】"); - - // if (item.SortNo != null) - // { - // if (item.SortNo.Length > 0) - // { - // orderStatusLists.Add(new OrderStatusList() - // { - // SortNo = item.SortNo.Substring(0, 4), - // GoodName = item.GoodName, - // OrderStatus = item.SubOrderStatus, - // SubOrderId = item.SubOrderId, - // StartDateTime = DateTime.Now.ToString("HH:mm:ss"), - // }); - // } - // } - // } - // } - // } - - // })); - // } - - //}); + ActionManagerment.GetInstance.Register(new Action((o) => + { + if (o is MorkOrderPush morkOrderpush) + { + var result = orderStatusLists.FirstOrDefault(p => p.OrderPush.SuborderId == morkOrderpush.SuborderId); + if (result == null) + { + orderStatusLists.Add(new OrderData() + { + OrderPush = morkOrderpush, + OrderStatus = ORDER_STATUS.WAIT, + StartDate = DateTime.Now.ToString("HH:mm:ss") + }); + } + } + }), "AddOrder"); + + ActionManagerment.GetInstance.Register(new Action((o) => + { + if (o is OrderStatusChange orderStatusChange) + { + int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SuborderId); + + if (index >= 0) orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.CookingStatus; + switch (orderStatusChange.CookingStatus) + { + case ORDER_STATUS.COOKING: + + break; + case ORDER_STATUS.COMPLETED_COOK: + if (index >= 0) + { + orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss"); + TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate)); + orderStatusLists.ElementAt(index).CompleteDate = timeSpan.TotalSeconds.ToString(); + WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index)); + orderStatusLists.RemoveAt(index); + } + + break; + case ORDER_STATUS.COMPLETED_TAKE: + var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SuborderId); + if (re != null) WaitTakeMeal.Remove(re); + break; + default: + break; + } + } + }), "OrderStatusChange"); } #endregion }