diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index c6ff493..e867537 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -42,6 +42,9 @@ namespace HKCardOUT DataBus.StoreId = configer["StoreId"]; DataBus.COM = configer["COM"]; DataBus.IsTest = configer["IsTest"].AsBool(); + DataBus.AM = configer["AM"]; + DataBus.PM = configer["PM"]; + DataBus.AT = configer["AT"]; DbContext.InitTable(); RemoteService.PullShopInfo(); base.Configure(); diff --git a/HKCardOUT/Helper/DataBus.cs b/HKCardOUT/Helper/DataBus.cs index e5a7b53..71af5ca 100644 --- a/HKCardOUT/Helper/DataBus.cs +++ b/HKCardOUT/Helper/DataBus.cs @@ -30,6 +30,9 @@ namespace HKCardOUT.Helper public static string StoreId { get; set; } public static string COM { get; set; } public static string SaasRoute { get; set; } + public static string AM { get; set; } + public static string PM { get; set; } + public static string AT { get; set; } public static StoreInfoResponse StoreInfo { get; set; } public static Dictionary AdStatus { get; set; } = new Dictionary(); } diff --git a/HKCardOUT/Logic/Service/HKCore.cs b/HKCardOUT/Logic/Service/HKCore.cs index c22ea72..26e0542 100644 --- a/HKCardOUT/Logic/Service/HKCore.cs +++ b/HKCardOUT/Logic/Service/HKCore.cs @@ -22,26 +22,30 @@ namespace HKCardOUT.Logic.Service { try { - if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false; + //if (RemoteService.CheckCardStuatas(input.CardNo) != 1) return false; if (!DataBus.IsTest) if (!Main.GetInstance.GetIsSwipe(input.Location.AsInt())) return false; - var Old = DbContext.Context.Queryable() - .Where(t => t.CardNo == input.CardNo).OrderByDescending(t => t.CreateTime).First(); - if (Old != null) - { - 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; - } - return false; - } - else + var Old = DbContext.Context.Queryable().Where(t => t.CardNo == input.CardNo).Where(t => t.CreateTime.Day == DateTime.Now.Day).ToList(); + if (Old.Count > 3) return false; + + var AM = DataBus.AM.Split(",").Select(t => t.AsInt()).ToList(); + var PM = DataBus.PM.Split(",").Select(t => t.AsInt()).ToList(); + var AT = DataBus.AT.Split(",").Select(t => t.AsInt()).ToList(); + + var condition1 = (DateTime.Now.Hour >= AM[0] && DateTime.Now.Hour < AM[1]); + var condition2 = (DateTime.Now.Hour >= PM[0] && DateTime.Now.Hour < PM[1]); + var condition3 = (DateTime.Now.Hour >= AT[0] && DateTime.Now.Hour < AT[1]); + + if (condition1 || condition2 || condition1) { + var AMDay = Old.Where(t => t.CreateTime.Hour >= AM[0] && t.CreateTime.Hour < AM[1]).Count(); + if (AMDay > 0) return false; + var PMDay = Old.Where(t => t.CreateTime.Hour >= PM[0] && t.CreateTime.Hour < PM[1]).Count(); + if (PMDay > 0) return false; + var ATDay = Old.Where(t => t.CreateTime.Hour >= AT[0] && t.CreateTime.Hour < AT[1]).Count(); + if (ATDay > 0) return false; + + var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { @@ -51,16 +55,17 @@ namespace HKCardOUT.Logic.Service DbContext.Context.Updateable().SetColumns(t => t.IsSync == true).Where(t => t.Id == entity.Id).ExecuteCommand(); return res; } - return false; - } + else return false; + } + else return false; } catch (Exception ex) { HKLog.HKLogImport.WriteError(ex); return false; } - + } /// /// 获取当天消费前100条展示 diff --git a/HKCardOUT/ViewModels/RootViewModel.cs b/HKCardOUT/ViewModels/RootViewModel.cs index 291976b..676766e 100644 --- a/HKCardOUT/ViewModels/RootViewModel.cs +++ b/HKCardOUT/ViewModels/RootViewModel.cs @@ -2,11 +2,14 @@ using HKCardOUT.Helper; using HKCardOUT.Logic.Model; using HKCardOUT.Logic.Service; +using NStandard; +using SqlSugar.DistributedSystem.Snowflake; using Stylet; using StyletIoC; using System; using System.Collections.ObjectModel; using System.Linq; +using System.Text.RegularExpressions; using System.Threading; using System.Windows.Documents; using UHFHelper; @@ -21,7 +24,7 @@ namespace HKCardOUT.ViewModels public delegate void ReadCardFunc(DKoutput? input); public event ReadCardFunc ReadFunc; private readonly object locker = new object(); - IContainer Container; + private IContainer Container; public RootViewModel(IContainer Container) { this.Container = Container; @@ -30,11 +33,13 @@ namespace HKCardOUT.ViewModels protected override void OnViewLoaded() { - ThreadManage.GetInstance().Start(() => + System.Timers.Timer timer = new System.Timers.Timer(500); + timer.Enabled = true; + timer.Elapsed += (s, e) => { Result = new ObservableCollection(this.Container.Get().PullDaySaleLog()); - Thread.Sleep(500); - }, "消费记录查询"); + }; + timer.Start(); //广告初始化 var Init = DataBus.StoreInfo?.Devices.Join(DataBus.StoreInfo?.Stalls, t => t.GateId, x => x.Id, (t, x) => new AdDTO { @@ -102,22 +107,26 @@ namespace HKCardOUT.ViewModels } if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) HandyControl.Controls.Growl.InfoGlobal("串口打开失败"); - //读取读卡器 - ThreadManage.GetInstance().StartLong(new Action(() => + DataBus.StoreInfo.Devices.ForEach(item => { - DataBus.StoreInfo.Devices.ForEach(async item => + System.Timers.Timer timer = new System.Timers.Timer(500); + timer.Enabled = true; + timer.Elapsed += (sender, eve) => { if (!UHF_RS485_Helper.GetInstance().GetSerialPortState()) return; else { - var x = await UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()); - if (x != null) - ReadFunc?.Invoke(x); + var res = UHF_RS485_Helper.GetInstance().ReadCard(item.Address.AsInt()).Result; + if (res != null) + { + if (!res.ResData.IsMatch(new Regex("0{20}"))) + ReadFunc?.Invoke(res); + } } - }); - Thread.Sleep(500); - }), "循环读取卡片内容", false); + }; + timer.Start(); + }); } #endregion @@ -155,18 +164,11 @@ namespace HKCardOUT.ViewModels { lock (locker) { - var key = input.Address + ":" + input.ResData; - //没有超时第一是刷 - if (Caches.RunTimeCacheGet(key) == null) + Container.Get().DeviceSale(new SaleLog { - Caches.RunTimeCacheSet(key, input, 10, true); - Container.Get().DeviceSale(new SaleLog - { - CardNo = input.ResData.Substring(1, input.ResData.Length - 1), - Location = input.Address.AsInt().ToString() - - }); - } + CardNo = input.ResData.Substring(1, input.ResData.Length - 1), + Location = input.Address.AsInt().ToString() + }); } } #endregion diff --git a/HKCardOUT/options.json b/HKCardOUT/options.json index 66845e7..b644295 100644 --- a/HKCardOUT/options.json +++ b/HKCardOUT/options.json @@ -9,5 +9,11 @@ "StoreId": "a19535e8-119f-4b10-a011-6288fd3ddb37", "ConnectionStrings": { "Sqlite": "HKSQL.db3" - } + }, + //早上 + "AM": "6,11", + //中午 + "PM": "11,14", + //下午 + "AT": "17,20" }