From a7ebda1dc6621c91ca668b3e4f8c4b3cb1fbd6d3 Mon Sep 17 00:00:00 2001 From: xxe Date: Tue, 18 Oct 2022 13:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=BC=82=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HKLib/Interfaces/HKLibHelper.cs | 87 ++++++++++++++++++--------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/HKLib/Interfaces/HKLibHelper.cs b/HKLib/Interfaces/HKLibHelper.cs index 2dd82f0..4847ba4 100644 --- a/HKLib/Interfaces/HKLibHelper.cs +++ b/HKLib/Interfaces/HKLibHelper.cs @@ -1,4 +1,5 @@ -using HKLib.Dto; +using FastExpressionCompiler.LightExpression; +using HKLib.Dto; using HKLib.RabbitMQ.Config; using HKLib.RabbitMQ.Publisher; using Newtonsoft.Json.Linq; @@ -19,7 +20,7 @@ namespace HKLib.Interfaces /// /// 设置刷卡时间端 /// - public static bool SetTime(TimeSpilte input) + public static async Task SetTime(TimeSpilte input) { TimeSpilteDto dto = new TimeSpilteDto { @@ -31,14 +32,14 @@ namespace HKLib.Interfaces ATStartTime = input.ATStartTime.ToShortTimeString(), }; - var data = IHttpMultiClient.HttpMulti + var data = await IHttpMultiClient.HttpMulti .AddHeader(t => t.Headers = Header) .AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval"; t.JsonParam = dto.ToJson(); t.ReqType = MultiType.PUT; - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); var res = data.ToModel()["data"]["isSuccess"].ToString().AsBool(); if (res) { @@ -51,29 +52,30 @@ namespace HKLib.Interfaces /// 获取时间 /// /// - public static TimeSpilte GetTime() + public static async Task GetTime() { - var data = IHttpMultiClient.HttpMulti.AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval"; t.ReqType = MultiType.GET; - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); return data.ToModel()["data"]["data"].ToJson().ToModel(); } /// /// 添加机构 /// - public static string SetOrg(string input) + public static async Task SetOrg(string input) { - return IHttpMultiClient.HttpMulti + var data = await IHttpMultiClient.HttpMulti .AddHeader(t => t.Headers = Header) .AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag"; t.ReqType = MultiType.POST; t.JsonParam = (new { Name = input }).ToJson(); - }).Build().RunStringFirst().ToModel()["data"]["data"]["id"].ToString(); + }).Build().RunStringFirstAsync(); + return data.ToModel()["data"]["data"]["id"].ToString(); } /// @@ -81,15 +83,15 @@ namespace HKLib.Interfaces /// /// /// - public static bool DelOrg(string Id) + public static async Task DelOrg(string Id) { - var data = IHttpMultiClient.HttpMulti + var data = await IHttpMultiClient.HttpMulti .AddHeader(t => t.Headers = Header) .AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag/{Id}"; t.ReqType = MultiType.DELETE; - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); var res = data.ToModel()["data"]["isSuccess"].ToString().AsBool(); return res; } @@ -99,13 +101,13 @@ namespace HKLib.Interfaces /// /获取机构 /// /// - public static List GetOrg() + public static async Task> GetOrg() { - var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag-list"; t.ReqType = MultiType.GET; - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); if (data.IsNullOrEmpty()) return new List(); var model = data.ToModel()["data"]["data"].ToJson().ToModel>(); return model.Where(t => !t.Name.IsNullOrEmpty()).Select(t => new OrgDto @@ -118,15 +120,15 @@ namespace HKLib.Interfaces /// /// 修改机构 /// - public static bool AlterOrg(string input, string Sid) + public static async Task AlterOrg(string input, string Sid) { var param = (new { Name = input, Id = Sid }).ToJson(); - var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag"; t.ReqType = MultiType.PUT; t.JsonParam = param; - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); return data.ToModel()["data"]["isSuccess"].ToString().AsBool(); } @@ -135,14 +137,14 @@ namespace HKLib.Interfaces /// 根据用户命获取下拉用户列表 /// /// - public static List GetUserList(string keyword) + public static async Task> GetUserList(string keyword) { - var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/staff-list"; t.ReqType = MultiType.POST; t.JsonParam = (new { realName = keyword }).ToJson(); - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); if (string.IsNullOrEmpty(data)) return new List(); return data.ToModel()["data"]["data"].ToJson().ToModel>(); @@ -152,60 +154,65 @@ namespace HKLib.Interfaces /// /// /// - public static bool AddUserAndBindCard(UserDto input) + public static async Task AddUserAndBindCard(UserDto input) { - return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card"; t.ReqType = MultiType.POST; t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone, cardNum = input.CardNo }).ToJson(); - }).Build().RunStringFirst().ToModel()["data"]["isSuccess"].ToString().AsBool(); + }).Build().RunStringFirstAsync(); + return data.ToModel()["data"]["isSuccess"].ToString().AsBool(); + } /// /// 删除用户 /// /// - public static bool DisableUser(string userName) + public static async Task DisableUser(string userName) { List a = new List() { userName }; - return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/del-staff"; t.ReqType = MultiType.POST; t.JsonParam = a.ToJson(); - }).Build().RunStringFirst().ToModel()["data"]["isSuccess"].ToString().AsBool(); + }).Build().RunStringFirstAsync(); + return data.ToModel()["data"]["isSuccess"].ToString().AsBool(); } /// /// 添加用户 /// /// - public static bool AddUser(UserDto input) + public static async Task AddUser(UserDto input) { - return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/staff"; t.ReqType = MultiType.POST; t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone }).ToJson(); - }).Build().RunStringFirst().ToModel()["data"]["isSuccess"].ToString().AsBool(); + }).Build().RunStringFirstAsync(); + return data.ToModel()["data"]["isSuccess"].ToString().AsBool(); } /// /// 变更卡状态 销户 /// /// - public static bool CardStutasChange(CardStutasDto input) + public static async Task CardStutasChange(CardStutasDto input) { - input.CardNo = GetUserList(input.keywrod).FirstOrDefault(t => t.Name.Equals(input.keywrod))?.Cards?.FirstOrDefault()?.CardNum; + input.CardNo = (await GetUserList(input.keywrod)).FirstOrDefault(t => t.Name.Equals(input.keywrod))?.Cards?.FirstOrDefault()?.CardNum; - var x = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var res = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card-state"; t.ReqType = MultiType.PUT; t.JsonParam = (new { CardNum = input.CardNo, State = input.Stutas }).ToJson(); - }).Build().RunStringFirst().ToModel()["data"]["isSuccess"].ToString().AsBool(); - if (x) + }).Build().RunStringFirstAsync(); + var data = res.ToModel()["data"]["isSuccess"].ToString().AsBool(); + if (data) { Task.Run(() => ServiceQueryPush.QueryPush.PushMQAsync(input, "CardStutasChanged", MQEnum.Top)); - return x; + return data; } return false; } @@ -241,7 +248,7 @@ namespace HKLib.Interfaces /// /// /// 1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表 - public static List Report(ReportDto input, int type = 1) + public static async Task> Report(ReportDto input, int type = 1) { var Route = Configer.SaasRoute; if (type == 1) @@ -250,12 +257,12 @@ namespace HKLib.Interfaces Route += "api/one-card/consume-info"; if (type == 3) Route += "api/one-card/time-interval-consume-info"; - var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => + var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t => { t.NodePath = Route; t.ReqType = MultiType.POST; t.JsonParam = (new { StartTime = input.StartTime.ToShortDateString(), EndTime = input.EndTime.ToShortDateString() }).ToJson(); - }).Build().RunStringFirst(); + }).Build().RunStringFirstAsync(); return data.ToModel()["data"]["data"].ToJson().ToModel>(); } }