diff --git a/HKCard.sln b/HKCard.sln index a17db3b..fa8fe59 100644 --- a/HKCard.sln +++ b/HKCard.sln @@ -21,6 +21,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKLib", "HKLib\HKLib.csproj EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKCardManager", "HKCardManager\HKCardManager.csproj", "{96C17249-7F4A-4D25-B658-507A8E876582}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WpfTest", "WpfTest\WpfTest.csproj", "{8312F839-6DA5-4BF0-8BB3-D1505E194AB5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -101,6 +103,14 @@ Global {96C17249-7F4A-4D25-B658-507A8E876582}.Release|Any CPU.Build.0 = Release|Any CPU {96C17249-7F4A-4D25-B658-507A8E876582}.Release|x86.ActiveCfg = Release|Any CPU {96C17249-7F4A-4D25-B658-507A8E876582}.Release|x86.Build.0 = Release|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Debug|x86.ActiveCfg = Debug|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Debug|x86.Build.0 = Debug|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Release|Any CPU.Build.0 = Release|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Release|x86.ActiveCfg = Release|Any CPU + {8312F839-6DA5-4BF0-8BB3-D1505E194AB5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index 9953b94..4443a5a 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -77,6 +77,7 @@ namespace HKCardOUT DataBus.StartDevice = configer["StartDevice"].AsBool(); DataBus.Cancel = configer["Cancel"].AsBool(); DataBus.Count = configer["Count"].AsInt(); + DataBus.MQTT = configer["MQTT"].ToString(); DataBus.Admin = configer.GetSection("Admin").GetChildren().Select(t => t.Value).ToList(); HKLib.Configer.SaasRoute = DataBus.SaasRoute; RemoteService.PullShopInfo(); @@ -94,6 +95,7 @@ namespace HKCardOUT DataBus.saleLogDtos = new System.Collections.Concurrent.ConcurrentQueue(); RemoteService.GetFoodMenus(); RemoteService.GetRangeCtrl(); + MQTTCon.Connection(); base.Configure(); } diff --git a/HKCardOUT/HKCardOUT.csproj b/HKCardOUT/HKCardOUT.csproj index 25728b2..7b9387d 100644 --- a/HKCardOUT/HKCardOUT.csproj +++ b/HKCardOUT/HKCardOUT.csproj @@ -14,9 +14,9 @@ 1.0.0.0 AnyCPU;x86 - + TRACE;Core @@ -33,7 +33,9 @@ - + + + diff --git a/HKCardOUT/Helper/BigScreen/DataCenter.cs b/HKCardOUT/Helper/BigScreen/DataCenter.cs new file mode 100644 index 0000000..cb3a7c7 --- /dev/null +++ b/HKCardOUT/Helper/BigScreen/DataCenter.cs @@ -0,0 +1,226 @@ +using BPA.Communication; +using BPA.Helper; +using BPA.Message; +using BPASmartClient.CustomResource.Pages.Model; +using BPASmartClient.Model; +using DTO; +using HKCardOUT.Helper; +using HKCardOUT.Logic.Service; +using HKControl; +using HKLib.Dto; +using ImTools; +using Newtonsoft.Json; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; + +namespace Helper.BigScreen +{ + public class DataCenter + { + public static List S1 { get; set; } = new List(2); + public static List S2 { get; set; } = new List(2); + public static List S3 { get; set; } = new List(2); + public static List S4 { get; set; } = new List(2); + public static List S5 { get; set; } = new List(2); + public static List S6 { get; set; } = new List(2); + public static void CreateData() + { + + var sender = new ScreenModelSplitMeals(); + sender.Alarm = new List(); + + AlarmHelper.AddAction = new Action((param) => + { + sender.Alarm.Add(new AlarmModel + { + AlarmMs = param, + AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + }); + }); + + + ThreadManage.GetInstance().StartLong(() => + { + var model = new HKCore().GetDayData(); + + + sender.IsRun = IsRun.运行; + if (!Main.GetInstance.GetIsConnect(6) || !Main.GetInstance.GetIsConnect(5)) + sender.RobotStatu1 = WorkStatus.停止; + if (!Main.GetInstance.GetIsConnect(4) || !Main.GetInstance.GetIsConnect(3)) + sender.RobotStatu2 = WorkStatus.停止; + if (!Main.GetInstance.GetIsConnect(2) || !Main.GetInstance.GetIsConnect(1)) + sender.RobotStatu3 = WorkStatus.停止; + + sender.WorkStatus_1 = Main.GetInstance.GetIsSwipe(6) ? WorkStatus.工作 : WorkStatus.待机; + sender.WorkStatus_2 = Main.GetInstance.GetIsSwipe(5) ? WorkStatus.工作 : WorkStatus.待机; + sender.WorkStatus_3 = Main.GetInstance.GetIsSwipe(4) ? WorkStatus.工作 : WorkStatus.待机; + sender.WorkStatus_4 = Main.GetInstance.GetIsSwipe(3) ? WorkStatus.工作 : WorkStatus.待机; + sender.WorkStatus_5 = Main.GetInstance.GetIsSwipe(2) ? WorkStatus.工作 : WorkStatus.待机; + sender.WorkStatus_6 = Main.GetInstance.GetIsSwipe(1) ? WorkStatus.工作 : WorkStatus.待机; + + sender.SplitMeals_CreditCardCount_1 = model["6"]; + if (DataBus.SaleLogDtoList.ContainsKey("6")) + { + if (DataBus.SaleLogDtoList["6"].Count > 0) + { + if (DataBus.SaleLogDtoList["6"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S1.Count >= 2) + { + S1.RemoveAt(0); + S1.Add(Name); + } + else + S1.Add(Name); + sender.SplitMeals_CreditCardNameBefore_1 = S1[0]; + sender.SplitMeals_CreditCardName_1 = S1.Count >= 2 ? S1[1] : S1[0]; + } + } + } + var GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == $"05" || t.Address == $"06").Select(t => t.GateId).FirstOrDefault(); + var res = DataBus.Menu.GateFood.Where(t => t.GateId == GateId)?.Select(t => t.Foods)?.FirstOrDefault(); + sender.SplitMeals_CookType_1 = res; + + sender.SplitMeals_CreditCardCount_2 = model["5"]; + if (DataBus.SaleLogDtoList.ContainsKey("5")) + { + if (DataBus.SaleLogDtoList["5"].Count > 0) + { + if (DataBus.SaleLogDtoList["5"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S2.Count >= 2) + { + S2.RemoveAt(0); + S2.Add(Name); + } + else + S2.Add(Name); + sender.SplitMeals_CreditCardNameBefore_2 = S2[0]; + sender.SplitMeals_CreditCardName_2 = S2.Count >= 2 ? S2[1] : S2[0]; + } + } + } + sender.SplitMeals_CookType_2 = res; + + sender.SplitMeals_CreditCardCount_3 = model["4"]; + if (DataBus.SaleLogDtoList.ContainsKey("4")) + { + if (DataBus.SaleLogDtoList["4"].Count > 0) + { + if (DataBus.SaleLogDtoList["4"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S3.Count >= 2) + { + S3.RemoveAt(0); + S3.Add(Name); + } + else + S3.Add(Name); + sender.SplitMeals_CreditCardNameBefore_3 = S3[0]; + sender.SplitMeals_CreditCardName_3 = S3.Count >= 2 ? S3[1] : S3[0]; + } + } + } + sender.SplitMeals_CookType_3 = res; + + sender.SplitMeals_CreditCardCount_4 = model["3"]; + if (DataBus.SaleLogDtoList.ContainsKey("3")) + { + if (DataBus.SaleLogDtoList["3"].Count > 0) + { + if (DataBus.SaleLogDtoList["3"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S4.Count >= 2) + { + S4.RemoveAt(0); + S4.Add(Name); + } + else + S4.Add(Name); + sender.SplitMeals_CreditCardNameBefore_4 = S4[0]; + sender.SplitMeals_CreditCardName_4 = S4.Count >= 2 ? S4[1] : S4[0]; + } + } + } + sender.SplitMeals_CookType_4 = res; + + sender.SplitMeals_CreditCardCount_5 = model["2"]; + if (DataBus.SaleLogDtoList.ContainsKey("2")) + { + if (DataBus.SaleLogDtoList["2"].Count > 0) + { + if (DataBus.SaleLogDtoList["2"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S5.Count >= 2) + { + S5.RemoveAt(0); + S5.Add(Name); + } + else + S5.Add(Name); + sender.SplitMeals_CreditCardNameBefore_5 = S5[0]; + sender.SplitMeals_CreditCardName_5 = S5.Count >= 2 ? S5[1] : S5[0]; + } + } + } + sender.SplitMeals_CookType_5 = res; + + sender.SplitMeals_CreditCardCount_6 = model["1"]; + if (DataBus.SaleLogDtoList.ContainsKey("1")) + { + if (DataBus.SaleLogDtoList["1"].Count > 0) + { + if (DataBus.SaleLogDtoList["1"].TryDequeue(out SaleLogDto info)) + { + var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); + if (S6.Count >= 2) + { + S6.RemoveAt(0); + S6.Add(Name); + } + else + S6.Add(Name); + sender.SplitMeals_CreditCardNameBefore_6 = S6[0]; + sender.SplitMeals_CreditCardName_6 = S6.Count >= 2 ? S6[1] : S6[0]; + } + } + } + sender.SplitMeals_CookType_6 = res; + + + + sender.StatsCount = new List { + new StatsModel { } + }; + MQTTCon.Send(sender); + Thread.Sleep(10); + }, $"屏幕刷卡信息", true); + } + public static void InitQueeue() + { + ThreadManage.GetInstance().StartLong(new Action(() => + { + if (DataBus.saleLogDtos.Count > 0) + { + if (DataBus.saleLogDtos.TryDequeue(out SaleLogDto info)) + { + if (!DataBus.SaleLogDtoList.ContainsKey(info.Location)) + DataBus.SaleLogDtoList.TryAdd(info.Location, new ConcurrentQueue()); + DataBus.SaleLogDtoList[info.Location].Enqueue(info); + } + } + Thread.Sleep(100); + }), "刷卡队列分配"); + } + } +} diff --git a/HKCardOUT/Helper/DataBus.cs b/HKCardOUT/Helper/DataBus.cs index 757b17f..9e0b2a9 100644 --- a/HKCardOUT/Helper/DataBus.cs +++ b/HKCardOUT/Helper/DataBus.cs @@ -1,8 +1,13 @@ -using DTO; +using BPA.Communication; +using BPA.Helper; +using BPA.Message.Enum; +using BPA.Message; +using DTO; using HKCardOUT.Logic.Model; using HKCardOUT.Views; using HKLib.Dto; using Logic.RemoteModel; +using Newtonsoft.Json; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -12,7 +17,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Data; +using System.Xml.Linq; using XExten.Advance.StaticFramework; +using static System.Net.Mime.MediaTypeNames; namespace HKCardOUT.Helper { @@ -38,6 +45,7 @@ namespace HKCardOUT.Helper public static string SaasRoute { get; set; } public static int Span { get; set; } public static int Count { get; set; } + public static string MQTT { get; set; } public static List Admin { get; set; } public static TimeSpilte Times { get; set; } public static StoreInfoResponse StoreInfo { get; set; } @@ -92,8 +100,108 @@ namespace HKCardOUT.Helper } } public class MemoryBus - { + { public static List CardStatus { get; set; } = new List(); public static List CardRecord { get; set; } = new List(); } + + public static class MQTTCon + { + static MqttHelper mqttHelper; + static MQTTCon() + { + mqttHelper = new MqttHelper(); + } + /// + /// Mqtt是否运行 + /// + static bool IsRunningMqtt = false; + public static void Connection() + { + try + { + //2.Mqtt连接 + if (!string.IsNullOrEmpty(DataBus.MQTT) && DataBus.MQTT.Contains(',')) + { + string[] mqttcom = DataBus.MQTT.Split(','); + if (mqttcom != null && mqttcom.Count() == 4) + { + mqttHelper.Connect(mqttcom[2], mqttcom[3], mqttcom[0], int.Parse(mqttcom[1]), $"分餐机{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } + } + mqttHelper.Disconnect = new Action(() => + { + IsRunningMqtt = false; + MessageLog.GetInstance.ShowEx($"分餐机MQTT异常断开...."); + }); + mqttHelper.ConnectOk = new Action(() => + { + IsRunningMqtt = true;//连接成功 + }); + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"分餐机初始化连接 MQTT,原因:{ex.Message}"); + } + + } + + public static void Send(ScreenModelSplitMeals screenModel) + { + SendScreenDataModel sendScreenData = new SendScreenDataModel(); + sendScreenData.Name = ScreenDeviceType.分餐机; + sendScreenData.Value = screenModel; + //new ScreenModelSplitMeals + //{ + // IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止, + // WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + // RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + // Alarm = new List { + // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // }, + // FailuresCount = 0, + // StatsCount = new List { + // new StatsModel { Name = name_s[0], Count = new Random().Next(0, 100) }, + // new StatsModel { Name = name_s[1], Count = new Random().Next(0, 100) }, + // new StatsModel { Name = name_s[2], Count = new Random().Next(0, 100) }, + // new StatsModel { Name = name_s[3], Count = new Random().Next(0, 100) }, + // new StatsModel { Name = name_s[4], Count = new Random().Next(0, 100) }, + // }, + // SplitMeals_CreditCardCount_1 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_1 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_1 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_1 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + // SplitMeals_CreditCardCount_2 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_2 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_2 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_2 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + // SplitMeals_CreditCardCount_3 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_3 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_3 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_3 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + // SplitMeals_CreditCardCount_4 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_4 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_4 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_4 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + // SplitMeals_CreditCardCount_5 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_5 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_5 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_5 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + // SplitMeals_CreditCardCount_6 = new Random().Next(0, 100), + // SplitMeals_CreditCardNameBefore_6 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CreditCardName_6 = name_XM[new Random().Next(0, 5)], + // SplitMeals_CookType_6 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + //}; + string message = JsonConvert.SerializeObject(sendScreenData); + mqttHelper.Publish(ScreenTOPIC.GetInstance.GetTopic(ScreenDeviceType.分餐机), message); + } + } } diff --git a/HKCardOUT/Logic/Service/HKCore.cs b/HKCardOUT/Logic/Service/HKCore.cs index 62883a1..e9f1927 100644 --- a/HKCardOUT/Logic/Service/HKCore.cs +++ b/HKCardOUT/Logic/Service/HKCore.cs @@ -292,6 +292,16 @@ namespace HKCardOUT.Logic.Service .WhereIF(screen.Length == 2, t => t.Location == a || t.Location == b).Select(t => t.Location).ToList(); return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count()); } + /// + /// 获取当天的刷卡 + /// + /// + public Dictionary GetDayData() + { + var today = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd 00:00:00")); + var count = DbContext.Context.Queryable().Select(t => t.Location).ToList(); + return count.GroupBy(t => t).ToDictionary(t => t.Key, t => t.Count()); + } public void WriteData() { diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index 5577008..4c4a407 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -1,5 +1,6 @@ using BPA.Helper; using DTO; +using Helper.BigScreen; using HKCardOUT.Helper; using HKCardOUT.Logic.Model; using HKCardOUT.Logic.Service; @@ -39,6 +40,8 @@ namespace HKCardOUT.ViewModels serv.GetAllCardStatus(); ProcessCard(); InsertData(); + DataCenter.InitQueeue(); + DataCenter.CreateData(); } /// @@ -133,7 +136,7 @@ namespace HKCardOUT.ViewModels Device = t.Name, Stalls = x.Name }).ToList(); - if (Init != null) +/* if (Init != null) { Ad = new ObservableCollection(Init); var route = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")); @@ -145,7 +148,7 @@ namespace HKCardOUT.ViewModels var jsons = SyncStatic.Decompress(SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")), SecurityType.Base64); Ad = new ObservableCollection(jsons.ToModel>()); AdOpen(); - } + }*/ })); } diff --git a/HKCardOUT/options.pro.json b/HKCardOUT/options.pro.json index c95b227..1551560 100644 --- a/HKCardOUT/options.pro.json +++ b/HKCardOUT/options.pro.json @@ -24,8 +24,10 @@ //"MQ": "host=10.2.1.21:5672;username=guest;password=guest" //MQ正式地址 "MQ": "host=47.108.65.220;username=root;password=pwd", + //MQTT + "MQTT": "10.2.1.254,1883,admin,public", //超级卡 - "Admin": [6666666666666666666,8888888888888888888,9999999999999999999,1590198360768385024,1590198442460844032], + "Admin": [ 6666666666666666666, 8888888888888888888, 9999999999999999999, 1590198360768385024, 1590198442460844032 ], //刷卡间隔 "Span": 5 } diff --git a/HKControl/Arms/Alarm.cs b/HKControl/Arms/Alarm.cs new file mode 100644 index 0000000..37bde80 --- /dev/null +++ b/HKControl/Arms/Alarm.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.Model +{ + public class Alarm + { + /// + /// ID + /// + [Key] + public int Id + { + get { return _mId; } + set { _mId = value; } + } + private int _mId; + + /// + /// 编号ID + /// + public int NumId { get { return _mNumId; } set { _mNumId = value; } } + private int _mNumId; + + + /// + /// 日期 + /// + public string Date { get { return _mDate; } set { _mDate = value; } } + private string _mDate; + + /// + /// 时间 + /// + public string Time { get { return _mTime; } set { _mTime = value; } } + private string _mTime; + + /// + /// 报警信息 + /// + public string Info { get { return _mInfo; } set { _mInfo = value; } } + private string _mInfo; + + /// + /// 报警值 + /// + public string Value { get { return _mValue; } set { _mValue = value; } } + private string _mValue; + + /// + /// 报警等级 + /// + public string Grade { get { return _mGrade; } set { _mGrade = value; } } + private string _mGrade; + + } +} diff --git a/HKControl/Arms/AlarmAttribute.cs b/HKControl/Arms/AlarmAttribute.cs new file mode 100644 index 0000000..391c094 --- /dev/null +++ b/HKControl/Arms/AlarmAttribute.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.CustomResource.Pages.Model +{ + [AttributeUsage(AttributeTargets.Property)] + public class AlarmAttribute : Attribute + { + public AlarmAttribute(string Info, AlarmTriggerType alarmTriggerType = AlarmTriggerType.Rising, AlarmLevel alarmLevel = AlarmLevel.一般报警) + { + AlarmInfo = Info; + AlarmType = alarmTriggerType; + @AlarmLevel = alarmLevel; + } + + /// + /// 报警信息 + /// + public string AlarmInfo { get; set; } + + /// + /// 告警类型 + /// + public AlarmTriggerType AlarmType { get; set; } + + /// + /// 告警级别 + /// + public AlarmLevel @AlarmLevel { get; set; } + } +} diff --git a/HKControl/Arms/AlarmHelper.cs b/HKControl/Arms/AlarmHelper.cs new file mode 100644 index 0000000..f8ae6b9 --- /dev/null +++ b/HKControl/Arms/AlarmHelper.cs @@ -0,0 +1,272 @@ +using BPA.Helper; +using BPASmartClient.Model; +using System; +using System.Collections.Concurrent; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Reflection; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; + +namespace BPASmartClient.CustomResource.Pages.Model +{ + + public class AlarmHelper where AlarmT : class, new() + { + private volatile static ConcurrentDictionary _Instance; + private static readonly object Obj_Lock = new object(); + public static AlarmT GetInstance(string name = "") + { + lock (Obj_Lock) + { + if (string.IsNullOrEmpty(name)) name = typeof(AlarmT).Name; + if (_Instance == null) _Instance = new ConcurrentDictionary(); + if (!_Instance.ContainsKey(name)) _Instance.TryAdd(name, new AlarmT()); + return _Instance[name]; + } + } + private AlarmHelper() { } + + + public static List Alarms { get; set; } = new List(); + public static List HistoryAlarms { get; set; } = new List(); + static ConcurrentDictionary flagbit = new ConcurrentDictionary(); + static ConcurrentDictionary delays = new ConcurrentDictionary(); + public static Action AddAction { get; set; } + public static Action RemoveAction { get; set; } + public static Action ChangeAction { get; set; } + + //public static AlarmT Alarm { get; set; } = new AlarmT(); + + public static void Init() + { + //AlarmViewModel.AlarmInfos = Alarms; + ThreadManage.GetInstance().StartLong(new Action(() => + { + if (_Instance != null) + { + foreach (var temp in _Instance) + { + foreach (var item in temp.Value.GetType().GetProperties()) + { + if (item.CustomAttributes.Count() > 0) + { + var AlarmModel = item.GetCustomAttribute(); + if (AlarmModel != null) + { + bool value = Convert.ToBoolean(_Instance[temp.Key].GetType().GetProperty(item.Name)?.GetValue(_Instance[temp.Key])); + string text = typeof(AlarmT).Name == temp.Key ? AlarmModel.AlarmInfo : $"{temp.Key}:{AlarmModel.AlarmInfo}"; + EdgeAlarm(value, text, 1, AlarmModel.AlarmLevel, AlarmModel.AlarmType); + } + } + } + } + } + Thread.Sleep(100); + }), $"{typeof(AlarmT).Name},报警通用模块监听"); + + } + + /// + /// 沿报警检测 + /// + /// 触发变量 + /// 报警信息 + /// 触发类型,上升沿 或 下降沿 + private static void EdgeAlarm(bool Trigger, string text, int delay = 2, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising) + { + if (!flagbit.ContainsKey(text)) flagbit.TryAdd(text, false); + if (!delays.ContainsKey(text)) delays.TryAdd(text, Delay.GetInstance(text)); + if (edgeType == AlarmTriggerType.Rising ? delays[text].Start(Trigger, delay) : delays[text].Start(!Trigger, delay)) + { + if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text]) + { + AddAlarm(Trigger, text, alarmLevel); + flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false; + } + } + else RemoveAlarm(text); + if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger; + } + + /// + /// 添加报警信息 + /// + /// 报警信息 + private static void AddAlarm(object value, string AlarmInfo, AlarmLevel alarmLevel) + { + Alarm tempAlarm = new Alarm() + { + NumId = Alarms.Count + 1, + Date = DateTime.Now.ToString("yyyy/MM/dd"), + Grade = alarmLevel.ToString(), + Info = AlarmInfo, + Value = value.ToString(), + Time = DateTime.Now.ToString("HH:mm:ss"), + }; + + var res = Sqlite.GetInstance.Base.Add(tempAlarm); + Sqlite.GetInstance.Save(); + + if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null) + { + Alarms.Insert(0, tempAlarm); + for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } + + AddAction?.Invoke(AlarmInfo);//添加报警通知 + ChangeAction?.Invoke();//更改报警通知 + } + } + + /// + /// 移除报警信息 + /// + /// 报警信息 + private static void RemoveAlarm(string AlarmInfo) + { + var result = Alarms.FirstOrDefault(p => p.Info == AlarmInfo); + if (result != null) + { + Alarms.Remove(result); + for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } + + if (RemoveAction != null) RemoveAction(AlarmInfo); + if (ChangeAction != null) ChangeAction(); + } + } + + } + + //public class AlarmHelper where AlarmT : class, new() + //{ + + + // //private volatile static ConcurrentDictionary _Instance; + // //public static AlarmT GetInstance(string name) + // //{ + // // if (_Instance == null) _Instance = new ConcurrentDictionary(); + // // if (!_Instance.ContainsKey(name)) _Instance.TryAdd(name, new AlarmT()); + // // return _Instance[name]; + // //} + // //private AlarmHelper() { } + + + // public static ObservableCollection Alarms { get; set; } = new ObservableCollection(); + // public static List HistoryAlarms { get; set; } = new List(); + // static ConcurrentDictionary flagbit = new ConcurrentDictionary(); + // static ConcurrentDictionary delays = new ConcurrentDictionary(); + // public static Action AddAction { get; set; } + // public static Action RemoveAction { get; set; } + // public static Action ChangeAction { get; set; } + + // public static AlarmT Alarm { get; set; } = new AlarmT(); + + // public static void Init() + // { + // AlarmViewModel.AlarmInfos = Alarms; + // ThreadManage.GetInstance().StartLong(new Action(() => + // { + // foreach (var item in Alarm.GetType().GetProperties()) + // { + // if (item.CustomAttributes.Count() > 0) + // { + // var AlarmModel = item.GetCustomAttribute(); + // if (AlarmModel != null) + // { + // bool value = Convert.ToBoolean(Alarm.GetType().GetProperty(item.Name)?.GetValue(Alarm)); + // EdgeAlarm(value, AlarmModel.AlarmInfo, 1, AlarmModel.AlarmLevel, AlarmModel.AlarmType); + // } + // } + // } + // Thread.Sleep(100); + // }), $"{typeof(AlarmT).Name},报警通用模块监听"); + + // } + + + // //public static void AnalogAlarm(dynamic Trigger, string info, dynamic HH = null, dynamic H = 0, dynamic L = 0, dynamic LL = 0) + // //{ + + // //} + + + + + // /// + // /// 沿报警检测 + // /// + // /// 触发变量 + // /// 报警信息 + // /// 触发类型,上升沿 或 下降沿 + // private static void EdgeAlarm(bool Trigger, string text, int delay = 2, AlarmLevel alarmLevel = AlarmLevel.一般报警, AlarmTriggerType edgeType = AlarmTriggerType.Rising) + // { + // if (!flagbit.ContainsKey(text)) flagbit.TryAdd(text, false); + // if (!delays.ContainsKey(text)) delays.TryAdd(text, Delay.GetInstance(text)); + // if (edgeType == AlarmTriggerType.Rising ? delays[text].Start(Trigger, delay) : delays[text].Start(!Trigger, delay)) + // { + // if (edgeType == AlarmTriggerType.Rising ? !flagbit[text] : flagbit[text]) + // { + // AddAlarm(Trigger, text, alarmLevel); + // flagbit[text] = edgeType == AlarmTriggerType.Rising ? true : false; + // } + // } + // else RemoveAlarm(text); + // if (edgeType == AlarmTriggerType.Rising ? flagbit[text] : !flagbit[text]) flagbit[text] = Trigger; + // } + + // /// + // /// 添加报警信息 + // /// + // /// 报警信息 + // private static void AddAlarm(object value, string AlarmInfo, AlarmLevel alarmLevel) + // { + // Alarm tempAlarm = new Alarm() + // { + // NumId = Alarms.Count + 1, + // Date = DateTime.Now.ToString("yyyy/MM/dd"), + // Grade = alarmLevel.ToString(), + // Info = AlarmInfo, + // Value = value.ToString(), + // Time = DateTime.Now.ToString("HH:mm:ss"), + // }; + + // var res = Sqlite.GetInstance.Base.Add(tempAlarm); + // Sqlite.GetInstance.Save(); + + // if (Alarms.FirstOrDefault(p => p.Info == AlarmInfo) == null) + // { + // Application.Current.Dispatcher.Invoke(new Action(() => + // { + // Alarms.Insert(0, tempAlarm); + // for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } + // })); + + // AddAction?.Invoke(AlarmInfo);//添加报警通知 + // ChangeAction?.Invoke();//更改报警通知 + // } + // } + + // /// + // /// 移除报警信息 + // /// + // /// 报警信息 + // private static void RemoveAlarm(string AlarmInfo) + // { + // var result = Alarms.FirstOrDefault(p => p.Info == AlarmInfo); + // if (result != null) + // { + // Application.Current.Dispatcher.Invoke(new Action(() => + // { + // Alarms.Remove(result); + // for (int i = 0; i < Alarms.Count; i++) { Alarms.ElementAt(i).NumId = i + 1; } + // })); + + // if (RemoveAction != null) RemoveAction(AlarmInfo); + // if (ChangeAction != null) ChangeAction(); + // } + // } + + //} +} diff --git a/HKControl/Arms/AlarmLevel.cs b/HKControl/Arms/AlarmLevel.cs new file mode 100644 index 0000000..f5e1842 --- /dev/null +++ b/HKControl/Arms/AlarmLevel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.CustomResource.Pages.Model +{ + public enum AlarmLevel + { + 一般报警, + 严重报警 + } +} diff --git a/HKControl/Arms/AlarmTriggerType.cs b/HKControl/Arms/AlarmTriggerType.cs new file mode 100644 index 0000000..2fdb7e7 --- /dev/null +++ b/HKControl/Arms/AlarmTriggerType.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BPASmartClient.CustomResource.Pages.Model +{ + public enum AlarmTriggerType + { + /// + /// 上升沿 + /// + Rising, + /// + /// 下降沿 + /// + Falling + } +} diff --git a/HKControl/DataModel.cs b/HKControl/DataModel.cs index aede8bf..2b637d7 100644 --- a/HKControl/DataModel.cs +++ b/HKControl/DataModel.cs @@ -1,4 +1,5 @@ -using System; +using BPASmartClient.CustomResource.Pages.Model; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,7 +7,7 @@ using System.Threading.Tasks; namespace HKControl { - internal class DataModel + public class DataModel { public WindowDataModel LeftWindowData { get; set; } = new WindowDataModel(); public WindowDataModel RightWindowData { get; set; } = new WindowDataModel(); @@ -33,5 +34,45 @@ namespace HKControl /// 刷卡机编号 /// public string CarNum { get; set; } + + [Alarm("警告左侧机构餐盘无盘")] + public bool L1 { get; set; } + [Alarm("警告左侧升降气缸下降不到位")] + public bool L2 { get; set; } + [Alarm("警告左侧升降气缸中间不到位")] + public bool L3 { get; set; } + [Alarm("警告左侧升降气缸上升不到位")] + public bool L4 { get; set; } + [Alarm("警告左侧升降气缸上升不到位")] + public bool L5 { get; set; } + [Alarm("警告左侧机构推空餐盘不到位")] + public bool L6 { get; set; } + [Alarm("警告左侧出餐推不到位")] + public bool L7 { get; set; } + [Alarm("警告左侧出餐回退不到位")] + public bool L8 { get; set; } + [Alarm("警告左餐盘掉落位置有餐盘")] + public bool L9 { get; set; } + + + [Alarm("警告右侧机构餐盘无盘")] + public bool R1 { get; set; } + [Alarm("警告右侧升降气缸下降不到位")] + public bool R2 { get; set; } + [Alarm("警告右侧升降气缸中间不到位")] + public bool R3 { get; set; } + [Alarm("警告右侧升降气缸上升不到位")] + public bool R4 { get; set; } + [Alarm("警告右侧升降气缸上升不到位")] + public bool R5 { get; set; } + [Alarm("警告右侧机构推空餐盘不到位")] + public bool R6 { get; set; } + [Alarm("警告右侧出餐推不到位")] + public bool R7 { get; set; } + [Alarm("警告右侧出餐回退不到位")] + public bool R8 { get; set; } + [Alarm("警告右餐盘掉落位置有餐盘")] + public bool R9 { get; set; } + } } diff --git a/HKControl/Main.cs b/HKControl/Main.cs index 69874e1..6ffcb90 100644 --- a/HKControl/Main.cs +++ b/HKControl/Main.cs @@ -1,6 +1,7 @@ using System.Collections.Concurrent; using System.Diagnostics; using BPA.Helper; +using BPASmartClient.CustomResource.Pages.Model; using S7.Net; namespace HKControl @@ -131,12 +132,39 @@ namespace HKControl { SiemensDicitonary[item.DeviceNum].ConnectOk = new Action(() => { + AlarmHelper.GetInstance($"{item.DeviceNum}号档口"); + AlarmHelper.Init(); HKLog.HKLogImport.WriteInfo($"{item.DeviceNum}:连接成功"); ThreadManage.GetInstance().StartLong(new Action(() => { try { + var md = AlarmHelper.GetInstance($"{item.DeviceNum}号档口"); var res = SiemensDicitonary[item.DeviceNum].Read("MB7"); + var res1 = SiemensDicitonary[item.DeviceNum].Read("MB10"); + var res2 = SiemensDicitonary[item.DeviceNum].Read("MB11"); + md.LeftWindowData.L1 = Get8bitValue(res1, 2); + md.LeftWindowData.L2 = Get8bitValue(res1, 3); + md.LeftWindowData.L3 = Get8bitValue(res1, 4); + md.LeftWindowData.L4 = Get8bitValue(res1, 5); + md.LeftWindowData.L5 = Get8bitValue(res1, 6); + md.LeftWindowData.L6 = Get8bitValue(res1, 7); + md.LeftWindowData.L7 = Get8bitValue(res1, 8); + md.LeftWindowData.L8 = Get8bitValue(res2, 1); + md.LeftWindowData.L9 = Get8bitValue(res2, 2); + + + var res3 = SiemensDicitonary[item.DeviceNum].Read("MB12"); + var res4 = SiemensDicitonary[item.DeviceNum].Read("MB13"); + md.RightWindowData.R1 = Get8bitValue(res3, 2); + md.RightWindowData.R2 = Get8bitValue(res3, 3); + md.RightWindowData.R3 = Get8bitValue(res3, 4); + md.RightWindowData.R4 = Get8bitValue(res3, 5); + md.RightWindowData.R5 = Get8bitValue(res3, 6); + md.RightWindowData.R6 = Get8bitValue(res3, 7); + md.RightWindowData.R7 = Get8bitValue(res3, 8); + md.RightWindowData.R8 = Get8bitValue(res4, 1); + md.RightWindowData.R9 = Get8bitValue(res4, 2); DataModels[item.DeviceNum].LeftWindowData.IsSwipe = Get8bitValue(res, 1); DataModels[item.DeviceNum].LeftWindowData.Complete = Get8bitValue(res, 2); diff --git a/WpfTest/App.xaml b/WpfTest/App.xaml new file mode 100644 index 0000000..7e56dad --- /dev/null +++ b/WpfTest/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/WpfTest/App.xaml.cs b/WpfTest/App.xaml.cs new file mode 100644 index 0000000..48c85c2 --- /dev/null +++ b/WpfTest/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace WpfTest +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/WpfTest/AssemblyInfo.cs b/WpfTest/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/WpfTest/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[assembly: ThemeInfo( + ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located + //(used if a resource is not found in the page, + // or application resource dictionaries) + ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located + //(used if a resource is not found in the page, + // app, or any theme specific resource dictionaries) +)] diff --git a/WpfTest/MainWindow.xaml b/WpfTest/MainWindow.xaml new file mode 100644 index 0000000..d710fa7 --- /dev/null +++ b/WpfTest/MainWindow.xaml @@ -0,0 +1,13 @@ + + + + + + diff --git a/WpfTest/MainWindow.xaml.cs b/WpfTest/MainWindow.xaml.cs new file mode 100644 index 0000000..41174e5 --- /dev/null +++ b/WpfTest/MainWindow.xaml.cs @@ -0,0 +1,382 @@ +using BPA.Communication; +using BPA.Helper; +using BPA.Message; +using BPA.Message.Enum; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace WpfTest +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + /// + /// MQTT连接信息 + /// + public string MQTTConnection { get; set; } = "10.2.1.254,1883,admin,public"; + + /// + /// Mqtt是否运行 + /// + public bool IsRunningMqtt = false; + /// + /// Mqtt + /// + public MqttHelper mqttHelper = new MqttHelper(); + + public MainWindow() + { + InitializeComponent(); + Connection(); + ThreadServer(); + //Button_Click(null, null); + } + public void ThreadServer() + { + ThreadManage.GetInstance().StartLong(new Action(() => + { + try + { + if (IsRunningMqtt) + { + Send(ScreenDeviceType.大炒); + Thread.Sleep(1000); + Send(ScreenDeviceType.小炒); Thread.Sleep(1000); + + Send(ScreenDeviceType.煮面机); Thread.Sleep(1000); + + Send(ScreenDeviceType.分餐机); Thread.Sleep(1000); + + } + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"{Name}:线程服务异常,原因:{ex.Message}"); + } + Thread.Sleep(100); + }), $"{Name},线程服务"); + } + /// + /// 初始化连接Redis MQTT + /// + public void Connection() + { + try + { + //2.Mqtt连接 + if (!string.IsNullOrEmpty(this.MQTTConnection) && this.MQTTConnection.Contains(',')) + { + string[] mqttcom = this.MQTTConnection.Split(','); + if (mqttcom != null && mqttcom.Count() == 4) + { + mqttHelper.Connect(mqttcom[2], mqttcom[3], mqttcom[0], int.Parse(mqttcom[1]), $"{Name}:{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}"); + } + } + mqttHelper.Disconnect = new Action(() => + { + IsRunningMqtt = false; + MessageLog.GetInstance.ShowEx($"{Name}:MQTT异常断开...."); + }); + mqttHelper.ConnectOk = new Action(() => + { + IsRunningMqtt = true;//连接成功 + }); + } + catch (Exception ex) + { + MessageLog.GetInstance.ShowEx($"{Name}:初始化连接 MQTT,原因:{ex.Message}"); + } + + } + + public void Send(ScreenDeviceType screen) + { + int k2 =new Random().Next(0, 2); + SendScreenDataModel sendScreenData = new SendScreenDataModel(); + + List oRDER_STATUS = new List() { ORDER_STATUS.WAIT, ORDER_STATUS.COOKING, ORDER_STATUS.COMPLETED_COOK, ORDER_STATUS.COMPLETED_TAKE, ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING }; + List name_s = new List() { "回锅肉", "烂肉豇豆", "火爆腰花", "尖椒鸡杂", "回锅肉" }; + List name_s_zm = new List() { "清汤面", "鸡蛋面", "火鸡面", "回锅肉面", "鸡杂面" }; + + List name_XM = new List() { "王权贵", "张哲", "李青古", "龙西", "李富贵" }; + int k = new Random().Next(0, 5); + int M = new Random().Next(0, 5); + if (screen == ScreenDeviceType.大炒) + { + sendScreenData.Name = screen; + sendScreenData.Value = new ScreenModelMaxWok + { + IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止, + WorkStatus_1 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + WorkStatus_2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + // Alarm = new List { + // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //}, + FailuresCount = 0, + StatsCount = new List { + new StatsModel{Name= name_s[0],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[1],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[2],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[3],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[4],Count=new Random().Next(0, 100)}, + }, + MaxWok_Dishes_1 = "回锅肉", + MaxWok_Task_1 = "炒菜中", + MaxWok_Process_1 = new List { + new ProcessModel{ Id=0,Name= "清洗", Status=(M==0) ? ProcessStatus.正在执行:((M>0)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=1,Name= "到菜", Status=(M==1) ? ProcessStatus.正在执行:((M>1)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=2,Name= "翻炒", Status=(M==2) ? ProcessStatus.正在执行:((M>2)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=3,Name= "调料", Status=(M==3) ? ProcessStatus.正在执行:((M>3)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=4,Name= "完成", Status=(M==4) ? ProcessStatus.正在执行:((M>4)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + }, + MaxWok_HeatGear_1 = "1", + MaxWok_StirGear_1 = "2", + MaxWok_FlipSpeed_1 = "30", + MaxWok_Temp_1 = "102", + MaxWok_OrderCount_1 = new Random().Next(0, 100), + MaxWok_ErrorOrderCount_1 = new Random().Next(0, 100), + + MaxWok_Dishes_2 = "烂肉豇豆", + MaxWok_Task_2 = "炒菜中", + MaxWok_Process_2 = new List { + new ProcessModel{ Id=0,Name= "清洗", Status=(k==0) ? ProcessStatus.正在执行:((k>0)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=1,Name= "到菜", Status=(k==1) ? ProcessStatus.正在执行:((k>1)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=2,Name= "翻炒", Status=(k==2) ? ProcessStatus.正在执行:((k>2)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=3,Name= "调料", Status=(k==3) ? ProcessStatus.正在执行:((k>3)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=4,Name= "完成", Status=(k==4) ? ProcessStatus.正在执行:((k>4)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + }, + MaxWok_HeatGear_2 = "2", + MaxWok_StirGear_2 = "3", + MaxWok_FlipSpeed_2 = "32", + MaxWok_Temp_2 = "132", + MaxWok_OrderCount_2 = new Random().Next(0, 100), + MaxWok_ErrorOrderCount_2 = new Random().Next(0, 100), + }; + } + else if (screen == ScreenDeviceType.小炒) + { + sendScreenData.Name = screen; + sendScreenData.Value = new ScreenModelMinWok + { + IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止, + WorkStatus_1 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + WorkStatus_2 = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + // Alarm = new List { + // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //}, + FailuresCount = 0, + StatsCount = new List { + new StatsModel{Name= name_s[0],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[1],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[2],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[3],Count=new Random().Next(0, 100)}, + new StatsModel{Name= name_s[4],Count=new Random().Next(0, 100)}, + }, + MinWok_Dishes_1 = "回锅肉", + MinWok_Task_1 = "炒菜中", + MinWok_Process_1 = new List { + new ProcessModel{ Id=0,Name= "清洗", Status=(M==0) ? ProcessStatus.正在执行:((M>0)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=1,Name= "到菜", Status=(M==1) ? ProcessStatus.正在执行:((M>1)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=2,Name= "翻炒", Status=(M==2) ? ProcessStatus.正在执行:((M>2)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=3,Name= "调料", Status=(M==3) ? ProcessStatus.正在执行:((M>3)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=4,Name= "完成", Status=(M==4) ? ProcessStatus.正在执行:((M>4)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + }, + MinWok_HeatGear_1 = "1", + MinWok_StirGear_1 = "2", + MinWok_FlipSpeed_1 = "30", + MinWok_Temp_1 = "102", + MinWok_OrderCount_1 = new Random().Next(0, 100), + MinWok_ErrorOrderCount_1 = new Random().Next(0, 100), + + MinWok_Dishes_2 = "烂肉豇豆", + MinWok_Task_2 = "炒菜中", + MinWok_Process_2 = new List { + new ProcessModel{ Id=0,Name= "清洗", Status=(k==0) ? ProcessStatus.正在执行:((k>0)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=1,Name= "到菜", Status=(k==1) ? ProcessStatus.正在执行:((k>1)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=2,Name= "翻炒", Status=(k==2) ? ProcessStatus.正在执行:((k>2)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=3,Name= "调料", Status=(k==3) ? ProcessStatus.正在执行:((k>3)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + new ProcessModel{ Id=4,Name= "完成", Status=(k==4) ? ProcessStatus.正在执行:((k>4)?ProcessStatus.执行完成:ProcessStatus.未执行)}, + }, + MinWok_HeatGear_2 = "2", + MinWok_StirGear_2 = "3", + MinWok_FlipSpeed_2 = "32", + MinWok_Temp_2 = "132", + MinWok_OrderCount_2 = new Random().Next(0, 100), + MinWok_ErrorOrderCount_2 = new Random().Next(0, 100), + }; + } + else if (screen == ScreenDeviceType.煮面机) + { + sendScreenData.Name = screen; + sendScreenData.Value = new ScreenModelMorkS + { + IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止, + WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + Alarm = new List { + new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "煮面机警告,水温过低!!!!" }, + //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + }, + FailuresCount = 0, + StatsCount = new List { + new StatsModel { Name = name_s_zm[0], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s_zm[1], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s_zm[2], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s_zm[3], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s_zm[4], Count = new Random().Next(0, 100) }, + }, + MorkS_OrderCount = new Random().Next(0, 100), + MorkS_ErrorOrderCount = new Random().Next(0, 100), + MorkS_NoodleUpOrDown_1 = k2 == 0 ? "true" : "false", + MorkS_NoodleUpOrDown_2 = k2 == 0 ? "true" : "false", + MorkS_NoodleUpOrDown_3 = k2 == 0 ? "true" : "false", + MorkS_NoodleUpOrDown_4 = k2 == 0 ? "true" : "false", + MorkS_NoodleUpOrDown_5 = k2 == 0 ? "true" : "false", + MorkS_NoodleUpOrDown_6 = k2 == 0 ? "true" : "false", + + MorkS_Temp = "false",// k2 == 0 ? "true" : "false", + MorkS_BinLocation = new Random().Next(0, 6).ToString(), + MorkS_SiloMeas = k2 == 0 ? "true" : "false", + MorkS_NoBowMeas = k2 == 0 ? "true" : "false", + MakeOrder = new List { + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="007".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="008".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="009".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="010".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.WAIT, SortNum="011".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_COOK, SortNum="006".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="005".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="004".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="003".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="002".ToString()}, + new OrderMakeModel { GoodName= name_s_zm[new Random().Next(0, 5)], StartTime=DateTime.Now.ToString("HH:mm:ss"), Status=ORDER_STATUS.COMPLETED_TAKE, SortNum="001".ToString()}, + }, + + }; + } + else if (screen == ScreenDeviceType.分餐机) + { + sendScreenData.Name = screen; + sendScreenData.Value = new ScreenModelSplitMeals + { + IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止, + WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机, + //Alarm = new List { + // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" }, + //}, + FailuresCount = 0, + StatsCount = new List { + new StatsModel { Name = name_s[0], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s[1], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s[2], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s[3], Count = new Random().Next(0, 100) }, + new StatsModel { Name = name_s[4], Count = new Random().Next(0, 100) }, + }, + SplitMeals_CreditCardCount_1 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_1 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_1 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_1 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + SplitMeals_CreditCardCount_2 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_2 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_2 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_2 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + SplitMeals_CreditCardCount_3 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_3 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_3 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_3 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + SplitMeals_CreditCardCount_4 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_4 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_4 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_4 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + SplitMeals_CreditCardCount_5 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_5 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_5 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_5 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + SplitMeals_CreditCardCount_6 = new Random().Next(0, 100), + SplitMeals_CreditCardNameBefore_6 = name_XM[new Random().Next(0, 5)], + SplitMeals_CreditCardName_6 = name_XM[new Random().Next(0, 5)], + SplitMeals_CookType_6 = new List() { "回锅肉", "烂肉豇豆", "火爆腰花" }, + + }; + } + + string message = JsonConvert.SerializeObject(sendScreenData); + mqttHelper.Publish(ScreenTOPIC.GetInstance.GetTopic(screen), message); + + System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() => + { + + if (textwb.Text.Length > 100000) + { + textwb.Text = ""; + } + string text = $"{ScreenTOPIC.GetInstance.GetTopic(screen)} {message}\n"; + textwb.Text += text; + })); + + } + + private void Button_Click(object sender, RoutedEventArgs e) + { + int i = 0; + Window1 window1 = new Window1(); + foreach (System.Windows.Forms.Screen scr in System.Windows.Forms.Screen.AllScreens) + { + //if (!scr.Primary) + { + if (i == 1) + { + window1.WindowStartupLocation = WindowStartupLocation.Manual; + + window1.Left = scr.WorkingArea.Left; + window1.Top = scr.WorkingArea.Top; + window1.Width = scr.Bounds.Width; + window1.Height = scr.Bounds.Height; + window1.WindowState = WindowState.Maximized; + window1.ResizeMode = ResizeMode.NoResize; + window1.WindowStyle = WindowStyle.None; + window1.WindowState = WindowState.Normal; + window1.ShowInTaskbar = false; + window1.Show(); + } + else if (i == 2) + { + } + i++; + } + } + + } + } +} diff --git a/WpfTest/Window1.xaml b/WpfTest/Window1.xaml new file mode 100644 index 0000000..49c33aa --- /dev/null +++ b/WpfTest/Window1.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/WpfTest/Window1.xaml.cs b/WpfTest/Window1.xaml.cs new file mode 100644 index 0000000..a918282 --- /dev/null +++ b/WpfTest/Window1.xaml.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Shapes; + +namespace WpfTest +{ + /// + /// Window1.xaml 的交互逻辑 + /// + public partial class Window1 : Window + { + public Window1() + { + InitializeComponent(); + } + } +} diff --git a/WpfTest/WpfTest.csproj b/WpfTest/WpfTest.csproj new file mode 100644 index 0000000..e72a314 --- /dev/null +++ b/WpfTest/WpfTest.csproj @@ -0,0 +1,14 @@ + + + + WinExe + net6.0-windows + enable + true + + + + + + +