diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index 0215748..1b418df 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -14,6 +14,8 @@ using ImTools; using XExten.Advance.LinqFramework; using System.Threading; using HKLog; +using HKLib.RabbitMQ.Config; +using HKLib.RabbitMQ.Subscriber; namespace HKCardOUT { @@ -44,7 +46,7 @@ namespace HKCardOUT } Thread.Sleep(3000); }), "循环状态监测线程", false); - HKLog.HKLogImport.Init("HKCardOUT"); + HKLogImport.Init("HKCardOUT"); } protected override void ConfigureIoC(IStyletIoCBuilder builder) @@ -59,6 +61,7 @@ namespace HKCardOUT { var configer = (new ConfigurationBuilder()).AddJsonFile("options.json").Build(); DataBus.ConnectionString = configer.GetConnectionString("Sqlite"); + HKLib.Configer.MqAddress = configer["MQ"]; DataBus.Cron = configer["Cron"]; DataBus.SaasRoute = configer["SaasRoute"]; DataBus.StoreId = configer["StoreId"]; @@ -67,11 +70,14 @@ namespace HKCardOUT DataBus.StartDevice = configer["StartDevice"].AsBool(); DataBus.Cancel = configer["Cancel"].AsBool(); DataBus.Count = configer["Count"].AsInt(); + //初始化表 + DbContext.InitTable(); + ServiceQueryExcute.QueryExcute.ExtuteMQ("CardStutasChanged", MQEnum.Push); + ServiceQueryExcute.QueryExcute.ExtuteMQ("TimeChanged", MQEnum.Push); HKLib.Configer.SaasRoute = DataBus.SaasRoute; - HKLib.Configer.MqAddress = configer["MQ"]; + //服务器拉取数据 RemoteService.SyncTime(); RemoteService.GetCardStuatas(); - DbContext.InitTable(); RemoteService.PullShopInfo(); base.Configure(); } diff --git a/HKCardOUT/MqHandle.cs b/HKCardOUT/CardHandle.cs similarity index 65% rename from HKCardOUT/MqHandle.cs rename to HKCardOUT/CardHandle.cs index 48846bc..bb00d9e 100644 --- a/HKCardOUT/MqHandle.cs +++ b/HKCardOUT/CardHandle.cs @@ -1,4 +1,5 @@ -using HKCardOUT.Logic; +using HKCardOUT.Helper; +using HKCardOUT.Logic; using HKCardOUT.Logic.Model; using HKLib.Dto; using HKLib.RabbitMQ.Config; @@ -9,7 +10,7 @@ using XExten.Advance.LinqFramework; namespace HKCardOUT { - public class MqHandle : IAccept + public class CardHandle : IAccept { public void AcceptMQ(string msg) { @@ -19,4 +20,11 @@ namespace HKCardOUT } } + public class TimeHandle : IAccept + { + public void AcceptMQ(string msg) + { + DataBus.Times = msg.ToModel(); + } + } } diff --git a/HKCardOUT/Helper/DataBus.cs b/HKCardOUT/Helper/DataBus.cs index eea335a..9d07823 100644 --- a/HKCardOUT/Helper/DataBus.cs +++ b/HKCardOUT/Helper/DataBus.cs @@ -40,7 +40,7 @@ namespace HKCardOUT.Helper } public class ApiRoute { - public static string GetTime = "http://192.168.1.22:5000/api/one-card/eat-time-interval"; + public static string GetTime = DataBus.SaasRoute + "api/one-card/eat-time-interval"; /// /// 获取所有卡 /// diff --git a/HKCardOUT/Logic/RemoteService.cs b/HKCardOUT/Logic/RemoteService.cs index 9e302a3..716fb46 100644 --- a/HKCardOUT/Logic/RemoteService.cs +++ b/HKCardOUT/Logic/RemoteService.cs @@ -1,6 +1,7 @@ using HKCardOUT.Helper; using HKCardOUT.Logic.Model; using HKCardOUT.Logic.Service; +using HKLib.Dto; using Logic.RemoteModel; using Newtonsoft.Json.Linq; using System; @@ -26,16 +27,18 @@ namespace HKCardOUT.Logic /// public static int GetCardStuatas() { - var data = IHttpMultiClient.HttpMulti.AddNode(t => - { - t.NodePath = ApiRoute.CheckCardStatus; - t.ReqType = MultiType.GET; - }).Build().RunStringFirst().ToModel()["data"]["data"].ToJson().ToModel(); - HKCore.AddCard(new CardStutas + var res = IHttpMultiClient.HttpMulti.AddNode(t => { - CardNo = data.CardNum, - Stutas = data.State - }); + t.NodePath = ApiRoute.CheckCardStatus; + t.ReqType = MultiType.GET; + }).Build().RunStringFirst(); + var data = res.ToModel()["data"]["data"].ToJson().ToModel>(); + var entity = data.Select(t => new CardStutas + { + CardNo = t.CardNum, + Stutas = t.State + }).ToList(); + HKCore.AddCard(entity); return data != null ? data.ToString().AsInt() : 0; } /// @@ -51,7 +54,7 @@ namespace HKCardOUT.Logic t.NodePath = ApiRoute.GetTime; t.ReqType = MultiType.GET; }).Build().RunStringFirst(); - + DataBus.Times = data.ToModel()["data"]["data"].ToJson().ToModel(); } /// diff --git a/HKCardOUT/Logic/Service/HKCore.cs b/HKCardOUT/Logic/Service/HKCore.cs index d8f9cbd..af330db 100644 --- a/HKCardOUT/Logic/Service/HKCore.cs +++ b/HKCardOUT/Logic/Service/HKCore.cs @@ -35,7 +35,7 @@ namespace HKCardOUT.Logic.Service if (data.Stutas != 1) return false; return true; } - public static void AddCard(CardStutas input) + public static void AddCard(List input) { DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteCommand(); } diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs index 8d42b1f..c131062 100644 --- a/HKLib/Interfaces/HKLibHelper.cs +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -38,7 +38,13 @@ namespace HKLib.Interfaces t.JsonParam = dto.ToJson(); t.ReqType = MultiType.PUT; }).Build().RunStringFirst(); - return data.ToModel()["data"]["isSuccess"].ToString().AsBool(); + var res = data.ToModel()["data"]["isSuccess"].ToString().AsBool(); + if (res) + { + ServiceQueryPush.QueryPush.PushMQ(input, "TimeChanged", MQEnum.Push); + return res; + } + return false; } ///