From f605e806df87095e4f434f5056c619c20d3d009c Mon Sep 17 00:00:00 2001 From: xxe Date: Fri, 30 Sep 2022 11:11:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=90=8C=E6=AD=A5=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCardOUT/Bootstrapper.cs | 14 +++--- HKCardOUT/Logic/RemoteService.cs | 35 ++++++++------ HKCardOUT/Logic/Service/HKCore.cs | 66 +++++++++++++++++++++------ HKCardOUT/QuartzUtil/Job/QuartzJob.cs | 21 ++++++--- HKCardOUT/ViewModels/RootViewModel.cs | 9 ++-- HKCardOUT/options.json | 2 +- 6 files changed, 102 insertions(+), 45 deletions(-) diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index 0421026..4f88dd8 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -73,13 +73,13 @@ namespace HKCardOUT /// protected override void OnLaunch() { - //QuartzCoreFactory.QuartzCore().AddJob(new QuartzMap - //{ - // JobDetail = "定时推送订单", - // Cron = DataBus.Cron, - // JobName = "订单", - // JobGroup = "订单" - //}); + QuartzCoreFactory.QuartzCore().AddJob(new QuartzMap + { + JobDetail = "定时推送订单", + Cron = DataBus.Cron, + JobName = "订单", + JobGroup = "订单" + }); base.OnLaunch(); } diff --git a/HKCardOUT/Logic/RemoteService.cs b/HKCardOUT/Logic/RemoteService.cs index 09b328e..2b54e76 100644 --- a/HKCardOUT/Logic/RemoteService.cs +++ b/HKCardOUT/Logic/RemoteService.cs @@ -37,21 +37,30 @@ namespace HKCardOUT.Logic /// public static bool SyncSaleLog(string CardNo, string StallId) { - var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId; - var data = IHttpMultiClient.HttpMulti.AddNode(t => - { - t.ReqType = MultiType.POST; - t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson(); - t.NodePath = ApiRoute.SyncSaleLog; - }).Build().RunStringFirst(); - HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}"); - var m = bool.Parse(data.ToModel()["data"].ToString()); - if (m) + try + { + var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId; + var data = IHttpMultiClient.HttpMulti.AddNode(t => + { + t.ReqType = MultiType.POST; + t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson(); + t.NodePath = ApiRoute.SyncSaleLog; + }).Build().RunStringFirst(); + HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}"); + var m = bool.Parse(data.ToModel()["data"].ToString()); + if (m) + { + UHF_RS485_Helper.GetInstance().OpenBeep(StallId.AsInt()); + return m; + } + else return false; + } + catch (Exception ex) { - UHF_RS485_Helper.GetInstance().OpenBeep(StallId.AsInt()); - return m; + HKLog.HKLogImport.WriteError(ex); + return false; } - else return false; + } /// /// 获取店铺信息 diff --git a/HKCardOUT/Logic/Service/HKCore.cs b/HKCardOUT/Logic/Service/HKCore.cs index ad682a2..a0ccf68 100644 --- a/HKCardOUT/Logic/Service/HKCore.cs +++ b/HKCardOUT/Logic/Service/HKCore.cs @@ -50,11 +50,23 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); - if (!DataBus.IsTest) - Main.GetInstance.Start(input.Location.AsInt()); - DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); - return res; + //有网络直接同步 + if (DataBus.NetWordState) + { + //先出餐后推数据 + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); + if(res) + DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); + return res; + } + else + { + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + return true; + } } } return false; @@ -90,11 +102,23 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); - if (!DataBus.IsTest) - Main.GetInstance.Start(input.Location.AsInt()); - DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); - return res; + //有网络直接同步 + if (DataBus.NetWordState) + { + //先出餐后推数据 + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); + if (res) + DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); + return res; + } + else + { + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + return true; + } } } return false; @@ -130,11 +154,23 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); - if (!DataBus.IsTest) - Main.GetInstance.Start(input.Location.AsInt()); - DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); - return res; + //有网络直接同步 + if (DataBus.NetWordState) + { + //先出餐后推数据 + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); + if (res) + DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); + return res; + } + else + { + if (!DataBus.IsTest) + Main.GetInstance.Start(input.Location.AsInt()); + return true; + } } } return false; diff --git a/HKCardOUT/QuartzUtil/Job/QuartzJob.cs b/HKCardOUT/QuartzUtil/Job/QuartzJob.cs index 2ce54e8..956ee3e 100644 --- a/HKCardOUT/QuartzUtil/Job/QuartzJob.cs +++ b/HKCardOUT/QuartzUtil/Job/QuartzJob.cs @@ -1,8 +1,6 @@ -using Quartz; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; +using HKCardOUT.Logic; +using HKCardOUT.Logic.Model; +using Quartz; using System.Threading.Tasks; namespace HKCardOUT.QuartzUtil.Job @@ -14,7 +12,18 @@ namespace HKCardOUT.QuartzUtil.Job switch (context.JobDetail.Key.Group) { default: - await Task.CompletedTask; + { + var WaitSync = DbContext.Context.Queryable().Where(t => t.IsSync == false).ToList(); + if (WaitSync.Count > 0) + { + foreach (var input in WaitSync) + { + var res = RemoteService.SyncSaleLog(input.CardNo, input.Location); + if (res) + await DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == input.Id).ExecuteCommandAsync(); + } + } + } break; } } diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index 9588678..c8a052e 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -241,7 +241,8 @@ namespace HKCardOUT.ViewModels Core.DeviceSaleAM(new SaleLog { CardNo = input.ResData.Substring(1, input.ResData.Length - 1), - Location = input.Address.AsInt().ToString() + Location = input.Address.AsInt().ToString(), + IsSync=false }); } if (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1]) @@ -249,7 +250,8 @@ namespace HKCardOUT.ViewModels Core.DeviceSalePM(new SaleLog { CardNo = input.ResData.Substring(1, input.ResData.Length - 1), - Location = input.Address.AsInt().ToString() + Location = input.Address.AsInt().ToString(), + IsSync = false }); } if (DateTime.Now.Hour >= AT[0] && DateTime.Now.Hour < AT[1]) @@ -257,7 +259,8 @@ namespace HKCardOUT.ViewModels Core.DeviceSaleAT(new SaleLog { CardNo = input.ResData.Substring(1, input.ResData.Length - 1), - Location = input.Address.AsInt().ToString() + Location = input.Address.AsInt().ToString(), + IsSync = false }); } //Result = new ObservableCollection(this.Container.Get().PullDaySaleLog()); diff --git a/HKCardOUT/options.json b/HKCardOUT/options.json index cb1fa78..d1989c7 100644 --- a/HKCardOUT/options.json +++ b/HKCardOUT/options.json @@ -4,7 +4,7 @@ "IsTest": true, "COM": "COM4", //定时任务时间表达式 - "Cron": "0 0 11,15 * * ? ", + "Cron": "0 0 0/1 * * ? ", //店铺ID "StoreId": "a19535e8-119f-4b10-a011-6288fd3ddb37", "ConnectionStrings": {