From d32772fd37b60a9bd8f6ee952fb6dae23bf65a9a Mon Sep 17 00:00:00 2001 From: xxe Date: Tue, 6 Dec 2022 14:53:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=A7=E5=B1=8F=E4=B8=8A?= =?UTF-8?q?=E5=A0=B1=E6=95=B8=E6=93=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardOUT/Helper/BigScreen/DataCenter.cs | 197 ++++++++++++----------- HKCardOUT/Helper/DataBus.cs | 49 ------ HKCardOUT/ViewModels/RootViewModel.cs | 6 +- HKCardOUT/options.pro.json | 6 +- 4 files changed, 112 insertions(+), 146 deletions(-) diff --git a/HKCardOUT/Helper/BigScreen/DataCenter.cs b/HKCardOUT/Helper/BigScreen/DataCenter.cs index c3d52a9..04b43ec 100644 --- a/HKCardOUT/Helper/BigScreen/DataCenter.cs +++ b/HKCardOUT/Helper/BigScreen/DataCenter.cs @@ -22,13 +22,14 @@ namespace Helper.BigScreen { public class DataCenter { + readonly object locker = new(); 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() + public void CreateData() { var sender = new ScreenModelSplitMeals(); @@ -63,142 +64,153 @@ namespace Helper.BigScreen 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")) + 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(); + if (model.ContainsKey("6")) { - if (DataBus.SaleLogDtoList["6"].Count > 0) + sender.SplitMeals_CreditCardCount_1 = model["6"]; + if (DataBus.SaleLogDtoList.ContainsKey("6")) { - if (DataBus.SaleLogDtoList["6"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["6"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S1.Count >= 2) + if (DataBus.SaleLogDtoList["6"].TryDequeue(out SaleLogDto info)) { - S1.RemoveAt(0); - S1.Add(Name); + 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]; } - 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")) + sender.SplitMeals_CookType_1 = res; + } + if (model.ContainsKey("5")) { - if (DataBus.SaleLogDtoList["5"].Count > 0) + sender.SplitMeals_CreditCardCount_2 = model["5"]; + if (DataBus.SaleLogDtoList.ContainsKey("5")) { - if (DataBus.SaleLogDtoList["5"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["5"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S2.Count >= 2) + if (DataBus.SaleLogDtoList["5"].TryDequeue(out SaleLogDto info)) { - S2.RemoveAt(0); - S2.Add(Name); + 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]; } - 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_CookType_2 = res; - - sender.SplitMeals_CreditCardCount_3 = model["4"]; - if (DataBus.SaleLogDtoList.ContainsKey("4")) + if (model.ContainsKey("4")) { - if (DataBus.SaleLogDtoList["4"].Count > 0) + sender.SplitMeals_CreditCardCount_3 = model["4"]; + if (DataBus.SaleLogDtoList.ContainsKey("4")) { - if (DataBus.SaleLogDtoList["4"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["4"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S3.Count >= 2) + if (DataBus.SaleLogDtoList["4"].TryDequeue(out SaleLogDto info)) { - S3.RemoveAt(0); - S3.Add(Name); + 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]; } - 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_CookType_3 = res; - - sender.SplitMeals_CreditCardCount_4 = model["3"]; - if (DataBus.SaleLogDtoList.ContainsKey("3")) + if (model.ContainsKey("3")) { - if (DataBus.SaleLogDtoList["3"].Count > 0) + sender.SplitMeals_CreditCardCount_4 = model["3"]; + if (DataBus.SaleLogDtoList.ContainsKey("3")) { - if (DataBus.SaleLogDtoList["3"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["3"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S4.Count >= 2) + if (DataBus.SaleLogDtoList["3"].TryDequeue(out SaleLogDto info)) { - S4.RemoveAt(0); - S4.Add(Name); + 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]; } - 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_CookType_4 = res; - - sender.SplitMeals_CreditCardCount_5 = model["2"]; - if (DataBus.SaleLogDtoList.ContainsKey("2")) + if (model.ContainsKey("2")) { - if (DataBus.SaleLogDtoList["2"].Count > 0) + sender.SplitMeals_CreditCardCount_5 = model["2"]; + if (DataBus.SaleLogDtoList.ContainsKey("2")) { - if (DataBus.SaleLogDtoList["2"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["2"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S5.Count >= 2) + if (DataBus.SaleLogDtoList["2"].TryDequeue(out SaleLogDto info)) { - S5.RemoveAt(0); - S5.Add(Name); + 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]; } - 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_CookType_5 = res; - - sender.SplitMeals_CreditCardCount_6 = model["1"]; - if (DataBus.SaleLogDtoList.ContainsKey("1")) + if (model.ContainsKey("1")) { - if (DataBus.SaleLogDtoList["1"].Count > 0) + sender.SplitMeals_CreditCardCount_6 = model["1"]; + if (DataBus.SaleLogDtoList.ContainsKey("1")) { - if (DataBus.SaleLogDtoList["1"].TryDequeue(out SaleLogDto info)) + if (DataBus.SaleLogDtoList["1"].Count > 0) { - var Name = DataBus.UserListDto.Where(t => t.Cards.Select(x => x.CardNum).Contains(info.CardNo)).Select(x => x.Name).FirstOrDefault(); - if (S6.Count >= 2) + if (DataBus.SaleLogDtoList["1"].TryDequeue(out SaleLogDto info)) { - S6.RemoveAt(0); - S6.Add(Name); + 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]; } - 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.SplitMeals_CookType_6 = res; - - GateId = DataBus.StoreInfo.Devices.Select(t => t.GateId).FirstOrDefault(); var Foods = DataBus.Menu.GateFood.Where(t => t.GateId == GateId)?.Select(t => t.Foods)?.FirstOrDefault(); sender.StatsCount = new List(); foreach (var item in Foods) @@ -209,8 +221,11 @@ namespace Helper.BigScreen Count = model.Values.Sum() }); } - MQTTCon.Send(sender); - Thread.Sleep(10); + lock (locker) + { + MQTTCon.Send(sender); + } + Thread.Sleep(300); }, $"屏幕刷卡信息", true); } public static void InitQueeue() diff --git a/HKCardOUT/Helper/DataBus.cs b/HKCardOUT/Helper/DataBus.cs index 6e31dce..8edb290 100644 --- a/HKCardOUT/Helper/DataBus.cs +++ b/HKCardOUT/Helper/DataBus.cs @@ -149,62 +149,13 @@ namespace HKCardOUT.Helper } } - public static void Send(ScreenModelSplitMeals screenModel) { if (!IsRunningMqtt) return; 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/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index b389010..41e08fa 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -42,7 +42,7 @@ namespace HKCardOUT.ViewModels ProcessCard(); InsertData(); DataCenter.InitQueeue(); - DataCenter.CreateData(); + new DataCenter().CreateData(); } /// @@ -142,13 +142,13 @@ namespace HKCardOUT.ViewModels Ad = new ObservableCollection(Init); var route = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")); SyncStatic.WriteFile(Encoding.UTF8.GetBytes(SyncStatic.Compress(Init.ToJson(), SecurityType.Base64)), route); - AdOpen(); + //AdOpen(); } else { var jsons = SyncStatic.Decompress(SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AD.txt")), SecurityType.Base64); Ad = new ObservableCollection(jsons.ToModel>()); - AdOpen(); + //AdOpen(); } })); diff --git a/HKCardOUT/options.pro.json b/HKCardOUT/options.pro.json index 42a6c9d..afccff3 100644 --- a/HKCardOUT/options.pro.json +++ b/HKCardOUT/options.pro.json @@ -6,8 +6,8 @@ "StartDevice": true, //串口 "COM": "COM7", - //定时任务时间表达式 每隔6小时推送一次 - "Cron": "0 0 0/6 * * ?", + //定时任务时间表达式 每隔20分钟同步一次 + "Cron": "0 0/20 * * * ?", //店铺ID "StoreId": "0c32b2e2-0dc9-4941-b73d-3dc91f7268ab", //加盟商Id @@ -27,7 +27,7 @@ //MQTT "MQTT": "171.221.208.23,11883,admin,public1", //超级卡 - "Admin": [ 6666666666666666666, 8888888888888888888, 9999999999999999999, 1590198360768385024, 1590198442460844032 ], + "Admin": [6666666666666666666,8888888888888888888,9999999999999999999,1590198360768385024,1590198442460844032], //刷卡间隔 "Span": 5 }