From 0a74c490a894b5b8d8ed2dc2add5176380f13bb9 Mon Sep 17 00:00:00 2001 From: xxe Date: Wed, 12 Oct 2022 16:04:35 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKCard.sln | 14 +- HKCardIN/HKCardIN.csproj | 2 +- HKCardOUT/Bootstrapper.cs | 6 +- HKCardOUT/HKCardOUT.csproj | 1 + HKCardOUT/Logic/Model/CardStutas.cs | 23 ++++ HKCardOUT/Logic/RemoteService.cs | 7 +- HKCardOUT/Logic/Service/HKCore.cs | 123 ++++++++++-------- HKCardOUT/MqHandle.cs | 22 ++++ HKCardOUT/options.json | 10 +- HKLib/Configer.cs | 12 ++ HKLib/Dto/CardStutasDto.cs | 18 +++ HKLib/Dto/TimeSpilte.cs | 22 ++++ HKLib/Dto/UserDto.cs | 30 +++++ HKLib/HKLib.csproj | 13 ++ HKLib/Interfaces/HKLibHelper.cs | 66 ++++++++++ HKLib/RabbitMq/Config/AcceptEntity.cs | 28 ++++ HKLib/RabbitMq/Config/IAccept.cs | 13 ++ HKLib/RabbitMq/Config/MQEnum.cs | 26 ++++ HKLib/RabbitMq/Config/MQFactory.cs | 117 +++++++++++++++++ HKLib/RabbitMq/Config/PushEntity.cs | 26 ++++ HKLib/RabbitMq/Config/PushManage.cs | 81 ++++++++++++ HKLib/RabbitMq/Publisher/ServiceQueryPush.cs | 74 +++++++++++ .../RabbitMq/Subscriber/ServiceQueryExcute.cs | 42 ++++++ 23 files changed, 708 insertions(+), 68 deletions(-) create mode 100644 HKCardOUT/Logic/Model/CardStutas.cs create mode 100644 HKCardOUT/MqHandle.cs create mode 100644 HKLib/Configer.cs create mode 100644 HKLib/Dto/CardStutasDto.cs create mode 100644 HKLib/Dto/TimeSpilte.cs create mode 100644 HKLib/Dto/UserDto.cs create mode 100644 HKLib/HKLib.csproj create mode 100644 HKLib/Interfaces/HKLibHelper.cs create mode 100644 HKLib/RabbitMq/Config/AcceptEntity.cs create mode 100644 HKLib/RabbitMq/Config/IAccept.cs create mode 100644 HKLib/RabbitMq/Config/MQEnum.cs create mode 100644 HKLib/RabbitMq/Config/MQFactory.cs create mode 100644 HKLib/RabbitMq/Config/PushEntity.cs create mode 100644 HKLib/RabbitMq/Config/PushManage.cs create mode 100644 HKLib/RabbitMq/Publisher/ServiceQueryPush.cs create mode 100644 HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs diff --git a/HKCard.sln b/HKCard.sln index bfe92d2..b287ba7 100644 --- a/HKCard.sln +++ b/HKCard.sln @@ -13,9 +13,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKControl", "HKControl\HKCo EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HKHelper", "HKHelper\HKHelper.csproj", "{CFA68AF9-1C11-41A3-8A73-34E004660CFC}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UHFHelper", "UHFHelper\UHFHelper.csproj", "{F7A3683F-B767-427C-BCB8-7C5DA507D663}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UHFHelper", "UHFHelper\UHFHelper.csproj", "{F7A3683F-B767-427C-BCB8-7C5DA507D663}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "test", "test\test.csproj", "{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "test", "test\test.csproj", "{3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HKLib", "HKLib\HKLib.csproj", "{471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -81,6 +83,14 @@ Global {3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|Any CPU.Build.0 = Release|Any CPU {3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.ActiveCfg = Release|x86 {3AD252E2-6878-4ABC-8A3E-22CCFCE2E075}.Release|x86.Build.0 = Release|x86 + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|x86.ActiveCfg = Debug|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Debug|x86.Build.0 = Debug|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|Any CPU.Build.0 = Release|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|x86.ActiveCfg = Release|Any CPU + {471F95A5-B9E9-41CF-A8A3-E4B36FFDE84C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HKCardIN/HKCardIN.csproj b/HKCardIN/HKCardIN.csproj index 8e122f9..49f47cb 100644 --- a/HKCardIN/HKCardIN.csproj +++ b/HKCardIN/HKCardIN.csproj @@ -32,10 +32,10 @@ + - diff --git a/HKCardOUT/Bootstrapper.cs b/HKCardOUT/Bootstrapper.cs index 5dc6577..a74312f 100644 --- a/HKCardOUT/Bootstrapper.cs +++ b/HKCardOUT/Bootstrapper.cs @@ -31,9 +31,9 @@ namespace HKCardOUT bool ping = PingHelper.PingTest(); //1.检测网络上下线 bool network = HKHelpers.GetInstance().GetNetworkState(); - if (ping&& network!= DataBus.NetWordState) + if (ping && network != DataBus.NetWordState) { - DataBus.NetWordState = network&& ping; + DataBus.NetWordState = network && ping; if (DataBus.NetWordState) HandyControl.Controls.Growl.InfoGlobal("网络连接成功"); else HandyControl.Controls.Growl.InfoGlobal("系统已离线,请连接网络!!!"); } @@ -69,6 +69,8 @@ namespace HKCardOUT DataBus.PM = configer["PM"]; DataBus.Count = configer["Count"].AsInt(); DataBus.AT = configer["AT"]; + HKLib.Configer.SaasRoute = DataBus.SaasRoute; + HKLib.Configer.MqAddress = configer["MQ"]; DbContext.InitTable(); RemoteService.PullShopInfo(); base.Configure(); diff --git a/HKCardOUT/HKCardOUT.csproj b/HKCardOUT/HKCardOUT.csproj index 46b050f..02192a8 100644 --- a/HKCardOUT/HKCardOUT.csproj +++ b/HKCardOUT/HKCardOUT.csproj @@ -53,6 +53,7 @@ + diff --git a/HKCardOUT/Logic/Model/CardStutas.cs b/HKCardOUT/Logic/Model/CardStutas.cs new file mode 100644 index 0000000..0884c14 --- /dev/null +++ b/HKCardOUT/Logic/Model/CardStutas.cs @@ -0,0 +1,23 @@ +using HKCardOUT.Logic; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Logic.Model +{ + [SugarTable("CardStutas")] + public class CardStutas: BaseEntity + { + /// + /// 卡号 + /// + [SugarColumn(IsNullable = false)] + public string CardNo { get; set; } + /// + /// 卡状态 0.禁用 1.正常 2.挂失 3.作废 + /// + [SugarColumn(IsNullable = false)] + public int Stutas { get; set; } + } +} diff --git a/HKCardOUT/Logic/RemoteService.cs b/HKCardOUT/Logic/RemoteService.cs index a727815..e3245cc 100644 --- a/HKCardOUT/Logic/RemoteService.cs +++ b/HKCardOUT/Logic/RemoteService.cs @@ -19,16 +19,15 @@ namespace HKCardOUT.Logic public class RemoteService { /// - /// 判断卡状态 + /// 获取所有卡状态和卡号 /// /// - public static int CheckCardStuatas(string CardNo) + public static int CheckCardStuatas() { var data = IHttpMultiClient.HttpMulti.AddNode(t => { t.NodePath = ApiRoute.CheckCardStatus; - t.ReqType = MultiType.POST; - t.JsonParam = (new { cardNum = CardNo }).ToJson(); + t.ReqType = MultiType.GET; }).Build().RunStringFirst().ToModel()["data"]["cardState"]; return data != null ? data.ToString().AsInt() : 0; } diff --git a/HKCardOUT/Logic/Service/HKCore.cs b/HKCardOUT/Logic/Service/HKCore.cs index 4c55175..b71a8a9 100644 --- a/HKCardOUT/Logic/Service/HKCore.cs +++ b/HKCardOUT/Logic/Service/HKCore.cs @@ -2,6 +2,7 @@ using HKCardOUT.Helper; using HKCardOUT.Logic.Model; using HKControl; +using Logic.Model; using System; using System.Collections.Generic; using System.Linq; @@ -27,6 +28,14 @@ namespace HKCardOUT.Logic.Service if (Old.Count > 3) return null; return Old; } + + bool GetCardStutas(string CardNo) + { + var data = DbContext.Context.Queryable().First(t => t.CardNo == CardNo); + if (data == null) return false; + if (data.Stutas != 1) return false; + return true; + } /// /// 早上消费 /// @@ -37,6 +46,7 @@ namespace HKCardOUT.Logic.Service { try { + if(!GetCardStutas(input.CardNo)) return false; var Old = Commom(input); if (Old == null) return false; var AM = DataBus.AM.Split(",").Select(t => t.AsInt()).ToList(); @@ -52,29 +62,30 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - //有网络直接同步 - if (DataBus.NetWordState) - { - //先出餐后推数据 - if (DataBus.StartDevice) - { - Main.GetInstance.Start(input.Location.AsInt()); - UHF_RS485_Helper.GetInstance().OpenBeep(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.NetWordState) + //{ + // //先出餐后推数据 + // if (DataBus.StartDevice) + // { + // Main.GetInstance.Start(input.Location.AsInt()); + // UHF_RS485_Helper.GetInstance().OpenBeep(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.StartDevice) { - if (DataBus.StartDevice) - { - Main.GetInstance.Start(input.Location.AsInt()); - UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt()); - } - return true; + Main.GetInstance.Start(input.Location.AsInt()); + UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt()); } + return true; } } return false; @@ -96,6 +107,7 @@ namespace HKCardOUT.Logic.Service { try { + if (!GetCardStutas(input.CardNo)) return false; var Old = Commom(input); if (Old == null) return false; var PM = DataBus.PM.Split(",").Select(t => t.AsInt()).ToList(); @@ -110,29 +122,29 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - //有网络直接同步 - if (DataBus.NetWordState) - { - //先出餐后推数据 - if (DataBus.StartDevice) - { - Main.GetInstance.Start(input.Location.AsInt()); - UHF_RS485_Helper.GetInstance().OpenBeep(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.NetWordState) + //{ + // //先出餐后推数据 + // if (DataBus.StartDevice) + // { + // Main.GetInstance.Start(input.Location.AsInt()); + // UHF_RS485_Helper.GetInstance().OpenBeep(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.StartDevice) { Main.GetInstance.Start(input.Location.AsInt()); UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt()); } return true; - } + //} } } return false; @@ -154,6 +166,7 @@ namespace HKCardOUT.Logic.Service { try { + if (!GetCardStutas(input.CardNo)) return false; var Old = Commom(input); if (Old == null) return false; var AT = DataBus.AT.Split(",").Select(t => t.AsInt()).ToList(); @@ -168,29 +181,29 @@ namespace HKCardOUT.Logic.Service var entity = DbContext.Context.Insertable(input).CallEntityMethod(t => t.Create()).ExecuteReturnEntity(); if (entity.Id != Guid.Empty) { - //有网络直接同步 - if (DataBus.NetWordState) - { - //先出餐后推数据 - if (DataBus.StartDevice) - { - Main.GetInstance.Start(input.Location.AsInt()); - UHF_RS485_Helper.GetInstance().OpenBeep(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.NetWordState) + //{ + // //先出餐后推数据 + // if (DataBus.StartDevice) + // { + // Main.GetInstance.Start(input.Location.AsInt()); + // UHF_RS485_Helper.GetInstance().OpenBeep(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.StartDevice) { Main.GetInstance.Start(input.Location.AsInt()); UHF_RS485_Helper.GetInstance().OpenBeep(input.Location.AsInt()); } return true; - } + //} } } return false; diff --git a/HKCardOUT/MqHandle.cs b/HKCardOUT/MqHandle.cs new file mode 100644 index 0000000..1e4a846 --- /dev/null +++ b/HKCardOUT/MqHandle.cs @@ -0,0 +1,22 @@ +using HKCardOUT.Logic; +using HKLib.Dto; +using HKLib.RabbitMQ.Config; +using Logic.Model; +using System; +using System.Collections.Generic; +using System.Text; +using XExten.Advance.LinqFramework; + +namespace HKCardOUT +{ + public class MqHandle : IAccept + { + public void AcceptMQ(string msg) + { + var dto = msg.ToModel(); + + DbContext.Context.Updateable().SetColumns(t => t.Stutas == dto.Stutas).Where(t => t.CardNo == dto.CardNo).ExecuteCommand(); + + } + } +} diff --git a/HKCardOUT/options.json b/HKCardOUT/options.json index e11dd17..64b8e5d 100644 --- a/HKCardOUT/options.json +++ b/HKCardOUT/options.json @@ -1,7 +1,7 @@ { //服务地址 "SaasRoute": "https://bpa.black-pa.com:21527/kitchen/", -//启动设备调试 + //启动设备调试 "StartDevice": true, //串口 "COM": "COM3", @@ -19,8 +19,10 @@ "PM": "11,14", //下午 "AT": "17,20", - //每个时间段的刷卡次数 - "Count":1, + //每个时间段的刷卡次数 + "Count": 1, //取消单卡刷卡限制 - "Cancel":false + "Cancel": false, + //MQ地址 + "MQ": "host=10.2.1.21:5672;username=guest;password=guest" } diff --git a/HKLib/Configer.cs b/HKLib/Configer.cs new file mode 100644 index 0000000..150c400 --- /dev/null +++ b/HKLib/Configer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib +{ + public class Configer + { + public static string MqAddress { get; set; } + public static string SaasRoute { get; set; } + } +} diff --git a/HKLib/Dto/CardStutasDto.cs b/HKLib/Dto/CardStutasDto.cs new file mode 100644 index 0000000..8f076e1 --- /dev/null +++ b/HKLib/Dto/CardStutasDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Dto +{ + public class CardStutasDto + { + /// + /// 卡号 + /// + public string CardNo { get; set; } + /// + /// 状态 0.禁用 1.正常 2.挂失 3.作废 + /// + public int Stutas { get; set; } + } +} diff --git a/HKLib/Dto/TimeSpilte.cs b/HKLib/Dto/TimeSpilte.cs new file mode 100644 index 0000000..6af9590 --- /dev/null +++ b/HKLib/Dto/TimeSpilte.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Dto +{ + public class TimeSpilte + { + /// + /// 早 例如 8,10 + /// + public string AM { get; set; } + /// + /// 中 例如 11,13 + /// + public string PM { get; set; } + /// + /// 晚 例如 17,19 + /// + public string AT { get; set; } + } +} diff --git a/HKLib/Dto/UserDto.cs b/HKLib/Dto/UserDto.cs new file mode 100644 index 0000000..21d4df9 --- /dev/null +++ b/HKLib/Dto/UserDto.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Dto +{ + public class UserDto + { + /// + /// 机构 + /// + public string Org { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } + /// + /// 手机号 + /// + public string Phone { get; set; } + /// + /// 卡号 + /// + public string CardNo { get; set; } + /// + /// 身份证号 + /// + public string IdCard { get; set; } + } +} diff --git a/HKLib/HKLib.csproj b/HKLib/HKLib.csproj new file mode 100644 index 0000000..3f18926 --- /dev/null +++ b/HKLib/HKLib.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.1 + + + + + + + + + diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs new file mode 100644 index 0000000..8963c6d --- /dev/null +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -0,0 +1,66 @@ +using HKLib.Dto; +using HKLib.RabbitMQ.Config; +using HKLib.RabbitMQ.Publisher; +using XExten.Advance.HttpFramework.MultiCommon; +using XExten.Advance.HttpFramework.MultiFactory; +using XExten.Advance.LinqFramework; +using static RabbitMQ.Client.Logging.RabbitMqClientEventSource; + +namespace HKLib.Interfaces +{ + public class HKLibHelper + { + /// + /// 设置刷卡时间端 + /// + public static void SetTime(TimeSpilte input) + { + IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.JsonParam = input.ToJson(); + t.ReqType = MultiType.POST; + }).Build().RunStringFirst(); + } + + /// + /// 根据用户命获取下拉用户列表 + /// + /// + public static void GetUserList(string keyword) + { + IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}/{keyword}"; + t.ReqType = MultiType.GET; + }).Build().RunStringFirst(); + } + /// + /// 添加用户 + /// + /// + public static void AddUser(UserDto input) + { + IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.ReqType = MultiType.POST; + t.JsonParam = input.ToJson(); + }).Build().RunStringFirst(); + } + /// + /// 变更卡状态 + /// + /// + public static void CardStutasChange(CardStutasDto input) + { + IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.ReqType = MultiType.POST; + t.JsonParam = input.ToJson(); + }).Build().RunStringFirst(); + ServiceQueryPush.QueryPush.PushMQ(input, "CardStutasChanged", MQEnum.Top); + } + } +} diff --git a/HKLib/RabbitMq/Config/AcceptEntity.cs b/HKLib/RabbitMq/Config/AcceptEntity.cs new file mode 100644 index 0000000..444942f --- /dev/null +++ b/HKLib/RabbitMq/Config/AcceptEntity.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Config +{ + public class AcceptEntity + { + /// + /// 队列名称 + /// + public String QueeName { get; set; } + /// + /// 推送模式 + /// + public MQEnum SendType { get; set; } + /// + /// 管道名称 + /// + public String ExchangeName { get; set; } + /// + /// 路由名称 + /// + public String RouteName { get; set; } + } +} diff --git a/HKLib/RabbitMq/Config/IAccept.cs b/HKLib/RabbitMq/Config/IAccept.cs new file mode 100644 index 0000000..df09cb4 --- /dev/null +++ b/HKLib/RabbitMq/Config/IAccept.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Config +{ + public interface IAccept + { + void AcceptMQ(string msg); + } +} diff --git a/HKLib/RabbitMq/Config/MQEnum.cs b/HKLib/RabbitMq/Config/MQEnum.cs new file mode 100644 index 0000000..efe4eea --- /dev/null +++ b/HKLib/RabbitMq/Config/MQEnum.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Text; + +namespace HKLib.RabbitMQ.Config +{ + public enum MQEnum + { + /// + /// 订阅模式 + /// + [Description("订阅模式")] + Sub = 10, + /// + /// 推送模式 + /// + [Description("推送模式")] + Push = 20, + /// + /// 主路由模式 + /// + [Description("主路由模式")] + Top = 30 + } +} diff --git a/HKLib/RabbitMq/Config/MQFactory.cs b/HKLib/RabbitMq/Config/MQFactory.cs new file mode 100644 index 0000000..df084f0 --- /dev/null +++ b/HKLib/RabbitMq/Config/MQFactory.cs @@ -0,0 +1,117 @@ +using EasyNetQ; +using EasyNetQ.Topology; +using HKLib.DataBus.数据缓存; +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Linq.Expressions; +using System.Text; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Config +{ + public class MQFactory + { + private volatile static IBus Bus = null; + /// + /// 创建链接 + /// + /// + public static IBus CreateMQ() + { + if (Bus == null) + Bus = RabbitHutch.CreateBus(Configer.MqAddress); + return Bus; + } + /// + /// 释放链接 + /// + public static void DisposeBus() + { + Bus?.Dispose(); + } + /// + /// 同步执行 + /// + /// + /// + /// + public static bool SendMQ(PushEntity Param) + { + try + { + if (Bus == null) + CreateMQ(); + new PushManage().SendMQ(Param, Bus); + return true; + } + catch (Exception) + { + return false; + } + } + /// + /// 推荐异步执行 + /// + /// + /// + /// + public static async Task SendMQAsync(PushEntity Param) + { + + if (Bus == null) + CreateMQ(); + await new PushManage().SendMQAsync(Param, Bus); + } + /// + /// 订阅消息 + /// + /// + /// + public static void Subscriber(AcceptEntity Args) where TAccept : IAccept, new() + { + try + { + if (Bus == null) + CreateMQ(); + if (string.IsNullOrEmpty(Args.ExchangeName)) + return; + Expression> methodCall; + IExchange EX = null; + if (Args.SendType == MQEnum.Sub) + { + EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Fanout); + } + if (Args.SendType == MQEnum.Push) + { + EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Direct); + } + if (Args.SendType == MQEnum.Top) + { + EX = Bus.Advanced.ExchangeDeclare(Args.ExchangeName, ExchangeType.Topic); + } + IQueue queue = Bus.Advanced.QueueDeclare(Args.QueeName ?? null); + Bus.Advanced.Bind(EX, queue, Args.RouteName); + Bus.Advanced.Consume(queue, (body, properties, info) => Task.Factory.StartNew(() => + { + try + { + var message = Encoding.UTF8.GetString(body); + //处理消息 + methodCall = job => job.AcceptMQ(message); + methodCall.Compile()(new TAccept()); + } + catch (Exception ex) + { + throw ex; + } + })); + } + catch (Exception ex) + { + + } + + } + } +} diff --git a/HKLib/RabbitMq/Config/PushEntity.cs b/HKLib/RabbitMq/Config/PushEntity.cs new file mode 100644 index 0000000..4d9d61f --- /dev/null +++ b/HKLib/RabbitMq/Config/PushEntity.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.RabbitMQ.Config +{ + public class PushEntity + { + /// + /// 推送内容 + /// + public T BodyData { get; set; } + /// + /// 推送模式 + /// + public MQEnum SendType { get; set; } + /// + /// 管道名称 + /// + public String ExchangeName { get; set; } + /// + /// 路由名称 + /// + public String RouteName { get; set; } + } +} diff --git a/HKLib/RabbitMq/Config/PushManage.cs b/HKLib/RabbitMq/Config/PushManage.cs new file mode 100644 index 0000000..2ccc01a --- /dev/null +++ b/HKLib/RabbitMq/Config/PushManage.cs @@ -0,0 +1,81 @@ +using EasyNetQ; +using EasyNetQ.Topology; +using System; +using System.Collections.Generic; +using System.Text; +using Newtonsoft.Json; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Config +{ + public class PushManage + { + /// + /// 发布消息队列异步 + /// + /// + /// + /// + /// + public async Task SendMQAsync(PushEntity Param, IBus Bus) + { + //one to one + var msg = new Message(Param.BodyData); + IExchange EX = null; + if (Param.SendType == MQEnum.Sub) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Fanout); + } + if (Param.SendType == MQEnum.Push) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Direct); + } + if (Param.SendType == MQEnum.Top) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Topic); + } + await Bus.Advanced.PublishAsync(EX, Param.RouteName, false, msg).ContinueWith(t => + { + //消息投递失败 + if (!t.IsCompleted && t.IsFaulted) + { + // //将消息记录到数据库轮询 + // IRepository Repository = new Repository(); + // SystemLog Log = new SystemLog + // { + // LogName = "消息队列", + // Source = "发布队列", + // EventData = JsonConvert.SerializeObject(Param.BodyData) + // }; + // Repository.Insert(Log); + + } + }); + } + /// + /// 发布消息队列同步 + /// + /// + /// + /// + public void SendMQ(PushEntity Param, IBus Bus) + { + //one to one + var msg = new Message(Param.BodyData); + IExchange EX = null; + if (Param.SendType == MQEnum.Sub) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Fanout); + } + if (Param.SendType == MQEnum.Push) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Direct); + } + if (Param.SendType == MQEnum.Top) + { + EX = Bus.Advanced.ExchangeDeclare(Param.ExchangeName, ExchangeType.Topic); + } + Bus.Advanced.Publish(EX, Param.RouteName, false, msg); + } + } +} diff --git a/HKLib/RabbitMq/Publisher/ServiceQueryPush.cs b/HKLib/RabbitMq/Publisher/ServiceQueryPush.cs new file mode 100644 index 0000000..40fd66c --- /dev/null +++ b/HKLib/RabbitMq/Publisher/ServiceQueryPush.cs @@ -0,0 +1,74 @@ +using EasyNetQ; +using HKLib.RabbitMQ.Config; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Publisher +{ + public class ServiceQueryPush + { + public static ServiceQueryPush QueryPush => new Lazy().Value; + public async Task PushMQAsync(T Entity,string Key, MQEnum MQType = MQEnum.Push) + { + //推送模式 + //推送模式下需指定管道名称和路由键值名称 + //消息只会被发送到指定的队列中去 + //订阅模式 + //订阅模式下只需指定管道名称 + //消息会被发送到该管道下的所有队列中 + //主题路由模式 + //路由模式下需指定管道名称和路由值 + //消息会被发送到该管道下,和路由值匹配的队列中去 + PushEntity entity = new PushEntity(); + entity.BodyData = Entity; + entity.SendType = MQType; + if (MQType == MQEnum.Push) + { + entity.ExchangeName = "Message.Direct"; + entity.RouteName = Key; + } + else if (MQType == MQEnum.Sub) + { + entity.ExchangeName = "Message.Fanout"; + } + else + { + entity.ExchangeName = "Message.Topic"; + entity.RouteName = Key; + } + return await MQFactory.SendMQAsync(entity).ContinueWith(t => { return t.IsCompleted ? true : false; }); + } + public bool PushMQ(T Entity, string Key, MQEnum MQType = MQEnum.Push) + { + //推送模式 + //推送模式下需指定管道名称和路由键值名称 + //消息只会被发送到指定的队列中去 + //订阅模式 + //订阅模式下只需指定管道名称 + //消息会被发送到该管道下的所有队列中 + //主题路由模式 + //路由模式下需指定管道名称和路由值 + //消息会被发送到该管道下,和路由值匹配的队列中去 + PushEntity entity = new PushEntity(); + entity.BodyData = Entity; + entity.SendType = MQType; + if (MQType == MQEnum.Push) + { + entity.ExchangeName = "Message.Direct"; + entity.RouteName = Key; + } + else if (MQType == MQEnum.Sub) + { + entity.ExchangeName = "Message.Fanout"; + } + else + { + entity.ExchangeName = "Message.Topic"; + entity.RouteName = Key; + } + return MQFactory.SendMQ(entity); + } + } +} diff --git a/HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs b/HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs new file mode 100644 index 0000000..80a4276 --- /dev/null +++ b/HKLib/RabbitMq/Subscriber/ServiceQueryExcute.cs @@ -0,0 +1,42 @@ +using EasyNetQ; +using HKLib.RabbitMQ.Config; +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; + +namespace HKLib.RabbitMQ.Subscriber +{ + public class ServiceQueryExcute + { + public static ServiceQueryExcute QueryExcute => new Lazy().Value; + public void ExtuteMQ(string Key,MQEnum Type) where TImpl : IAccept, new() + { + Task.Run(() => + { + AcceptEntity accept = new AcceptEntity(); + if (Type == MQEnum.Push) + { + accept.SendType = MQEnum.Push; + accept.ExchangeName = "Message.Direct"; + accept.QueeName = "Meesage.DirectQuene"; + accept.RouteName = Key; + } + else if (Type == MQEnum.Sub) + { + accept.SendType = MQEnum.Sub; + accept.ExchangeName = "Message.Fanout"; + accept.QueeName = "Meesage.FanoutQuene"; + } + else + { + accept.SendType = MQEnum.Top; + accept.ExchangeName = "Message.Topic"; + accept.QueeName = "Meesage.FanoutQuene"; + accept.RouteName = Key; + } + MQFactory.Subscriber(accept); + }); + } + } +} From 19f1fc7ef6b521f9821acc086f435735eef76f8c Mon Sep 17 00:00:00 2001 From: xxe Date: Wed, 12 Oct 2022 16:14:05 +0800 Subject: [PATCH 2/3] 1 --- HKLib/Dto/ReportDto.cs | 30 ++++++++++++++++++++++++++++++ HKLib/Interfaces/HKLibHelper.cs | 15 ++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 HKLib/Dto/ReportDto.cs diff --git a/HKLib/Dto/ReportDto.cs b/HKLib/Dto/ReportDto.cs new file mode 100644 index 0000000..60bb9eb --- /dev/null +++ b/HKLib/Dto/ReportDto.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Dto +{ + public class ReportDto + { + /// + /// 开始时间 + /// + public DateTime STime { get; set; } + /// + /// 结束时间 + /// + public DateTime ETime { get; set; } + /// + /// 姓名 + /// + public string Name { get; set; } + /// + /// 组织 + /// + public string Org { get; set; } + /// + /// 设备位置 + /// + public string Location { get; set; } + } +} diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs index 8963c6d..a5683f2 100644 --- a/HKLib/Interfaces/HKLibHelper.cs +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -49,7 +49,7 @@ namespace HKLib.Interfaces }).Build().RunStringFirst(); } /// - /// 变更卡状态 + /// 变更卡状态 销户 /// /// public static void CardStutasChange(CardStutasDto input) @@ -62,5 +62,18 @@ namespace HKLib.Interfaces }).Build().RunStringFirst(); ServiceQueryPush.QueryPush.PushMQ(input, "CardStutasChanged", MQEnum.Top); } + /// + /// 报表数据 + /// + /// + public static void Report(ReportDto input) + { + IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.ReqType = MultiType.POST; + t.JsonParam = input.ToJson(); + }).Build().RunStringFirst(); + } } } From bdc3db6a27b84fdebf73bd41a342fb9e508f0df7 Mon Sep 17 00:00:00 2001 From: xxe Date: Wed, 12 Oct 2022 16:53:12 +0800 Subject: [PATCH 3/3] 1 --- HKLib/DB/DbContext.cs | 41 +++++++++++++++++++++++++++++++ HKLib/DB/Model/BaseEntity.cs | 20 +++++++++++++++ HKLib/DB/Model/Entity/OrgTable.cs | 21 ++++++++++++++++ HKLib/Dto/ReportDto.cs | 8 ------ HKLib/HKLib.csproj | 1 + HKLib/Interfaces/HKLibHelper.cs | 34 ++++++++++++++++++++++--- HKLib/Logic/ServiceHandler.cs | 35 ++++++++++++++++++++++++++ 7 files changed, 148 insertions(+), 12 deletions(-) create mode 100644 HKLib/DB/DbContext.cs create mode 100644 HKLib/DB/Model/BaseEntity.cs create mode 100644 HKLib/DB/Model/Entity/OrgTable.cs create mode 100644 HKLib/Logic/ServiceHandler.cs diff --git a/HKLib/DB/DbContext.cs b/HKLib/DB/DbContext.cs new file mode 100644 index 0000000..7870807 --- /dev/null +++ b/HKLib/DB/DbContext.cs @@ -0,0 +1,41 @@ +using HKLib.DB.Model; +using SqlSugar; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using XExten.Advance.StaticFramework; + +namespace HKLib.DB +{ + public class DbContext + { + public static SqlSugarScope Context = new SqlSugarScope(new ConnectionConfig() + { + ConnectionString = Route(), + DbType = DbType.Sqlite,//数据库类型 + IsAutoCloseConnection = true //不设成true要手动close + }, db => + { + db.Aop.OnLogExecuting = (sql, pars) => + { + + }; + }); + + static string Route() + { + var dir = SyncStatic.CreateDir(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Database")); + return SyncStatic.CreateFile(Path.Combine(dir, "data.db3")); + } + public static void InitTable() + { + var Tables = Assembly.GetAssembly(typeof(DbContext)) + .GetTypes().Where(t => t.BaseType == typeof(BaseEntity)).ToArray(); + Context.CodeFirst.InitTables(Tables); + } + } +} diff --git a/HKLib/DB/Model/BaseEntity.cs b/HKLib/DB/Model/BaseEntity.cs new file mode 100644 index 0000000..3cd1a4a --- /dev/null +++ b/HKLib/DB/Model/BaseEntity.cs @@ -0,0 +1,20 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.DB.Model +{ + public class BaseEntity + { + [SugarColumn(IsPrimaryKey = true)] + public Guid Id { get; set; } + [SugarColumn(ColumnDataType = "DATETIME")] + public DateTime CreateTime { get; set; } + public void Create() + { + this.Id = Guid.NewGuid(); + this.CreateTime = DateTime.Now; + } + } +} diff --git a/HKLib/DB/Model/Entity/OrgTable.cs b/HKLib/DB/Model/Entity/OrgTable.cs new file mode 100644 index 0000000..7254c47 --- /dev/null +++ b/HKLib/DB/Model/Entity/OrgTable.cs @@ -0,0 +1,21 @@ +using SqlSugar; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.DB.Model.Entity +{ + [SugarTable("Org")] + public class OrgTable : BaseEntity + { + /// + /// 机构名称 + /// + public string Name { get; set; } + + /// + /// 加盟返回的Id + /// + public string SId { get; set; } + } +} diff --git a/HKLib/Dto/ReportDto.cs b/HKLib/Dto/ReportDto.cs index 60bb9eb..1d88b1c 100644 --- a/HKLib/Dto/ReportDto.cs +++ b/HKLib/Dto/ReportDto.cs @@ -18,13 +18,5 @@ namespace HKLib.Dto /// 姓名 /// public string Name { get; set; } - /// - /// 组织 - /// - public string Org { get; set; } - /// - /// 设备位置 - /// - public string Location { get; set; } } } diff --git a/HKLib/HKLib.csproj b/HKLib/HKLib.csproj index 3f18926..e6702eb 100644 --- a/HKLib/HKLib.csproj +++ b/HKLib/HKLib.csproj @@ -9,5 +9,6 @@ + diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs index a5683f2..076fe3e 100644 --- a/HKLib/Interfaces/HKLibHelper.cs +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -1,10 +1,10 @@ using HKLib.Dto; using HKLib.RabbitMQ.Config; using HKLib.RabbitMQ.Publisher; +using Newtonsoft.Json.Linq; using XExten.Advance.HttpFramework.MultiCommon; using XExten.Advance.HttpFramework.MultiFactory; using XExten.Advance.LinqFramework; -using static RabbitMQ.Client.Logging.RabbitMqClientEventSource; namespace HKLib.Interfaces { @@ -23,11 +23,36 @@ namespace HKLib.Interfaces }).Build().RunStringFirst(); } + /// + /// 添加机构 + /// + public static string SetOrg(string input) + { + return IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}/{input}"; + t.ReqType = MultiType.GET; + }).Build().RunStringFirst().ToModel()["data"].ToString(); + } + + /// + /// 修改机构 + /// + public static bool AlterOrg(string input,string Sid) + { + return IHttpMultiClient.HttpMulti.AddNode(t => + { + t.NodePath = $"{Configer.SaasRoute}"; + t.ReqType = MultiType.POST; + t.JsonParam = (new { Name = input, Id = Sid }).ToJson(); + }).Build().RunStringFirst().ToModel()["isSuccess"].ToString().AsBool(); + } + /// /// 根据用户命获取下拉用户列表 /// /// - public static void GetUserList(string keyword) + public static void GetUserList(string keyword) { IHttpMultiClient.HttpMulti.AddNode(t => { @@ -52,7 +77,7 @@ namespace HKLib.Interfaces /// 变更卡状态 销户 /// /// - public static void CardStutasChange(CardStutasDto input) + public static void CardStutasChange(CardStutasDto input) { IHttpMultiClient.HttpMulti.AddNode(t => { @@ -66,7 +91,8 @@ namespace HKLib.Interfaces /// 报表数据 /// /// - public static void Report(ReportDto input) + /// 1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表 + public static void Report(ReportDto input,int type=1) { IHttpMultiClient.HttpMulti.AddNode(t => { diff --git a/HKLib/Logic/ServiceHandler.cs b/HKLib/Logic/ServiceHandler.cs new file mode 100644 index 0000000..83ac556 --- /dev/null +++ b/HKLib/Logic/ServiceHandler.cs @@ -0,0 +1,35 @@ +using HKLib.DB; +using HKLib.DB.Model.Entity; +using HKLib.Interfaces; +using System; +using System.Collections.Generic; +using System.Text; + +namespace HKLib.Logic +{ + public class ServiceHandler + { + #region 机构类 + public static bool AddOrg(string Name) + { + var SiD = HKLibHelper.SetOrg(Name); + return DbContext.Context.Insertable(new OrgTable + { + Name = Name, + SId = SiD + }).CallEntityMethod(t => t.Create()).ExecuteCommand() > 0; + } + public static List GetOrgList() + { + return DbContext.Context.Queryable().ToList(); + } + public static bool AlterOrg(string Name, string Id) + { + var s = HKLibHelper.AlterOrg(Name, Id); + if (s) + return DbContext.Context.Updateable().SetColumns(t => t.Name == Name).Where(t => t.SId == Id).ExecuteCommandHasChange(); + else return false; + } + #endregion + } +}