Browse Source

改异步

Lishi
xxe 2 years ago
parent
commit
a7ebda1dc6
1 changed files with 47 additions and 40 deletions
  1. +47
    -40
      HKLib/Interfaces/HKLibHelper.cs

+ 47
- 40
HKLib/Interfaces/HKLibHelper.cs View File

@@ -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
/// <summary>
/// 设置刷卡时间端
/// </summary>
public static bool SetTime(TimeSpilte input)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
if (res)
{
@@ -51,29 +52,30 @@ namespace HKLib.Interfaces
/// 获取时间
/// </summary>
/// <returns></returns>
public static TimeSpilte GetTime()
public static async Task<TimeSpilte> 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<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
}

/// <summary>
/// 添加机构
/// </summary>
public static string SetOrg(string input)
public static async Task<string> 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<JObject>()["data"]["data"]["id"].ToString();
}).Build().RunStringFirstAsync();
return data.ToModel<JObject>()["data"]["data"]["id"].ToString();
}

/// <summary>
@@ -81,15 +83,15 @@ namespace HKLib.Interfaces
/// </summary>
/// <param name="Id"></param>
/// <returns></returns>
public static bool DelOrg(string Id)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
return res;
}
@@ -99,13 +101,13 @@ namespace HKLib.Interfaces
/// /获取机构
/// </summary>
/// <returns></returns>
public static List<OrgDto> GetOrg()
public static async Task<List<OrgDto>> 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<OrgDto>();
var model = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<OrgOutDto>>();
return model.Where(t => !t.Name.IsNullOrEmpty()).Select(t => new OrgDto
@@ -118,15 +120,15 @@ namespace HKLib.Interfaces
/// <summary>
/// 修改机构
/// </summary>
public static bool AlterOrg(string input, string Sid)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
}
@@ -135,14 +137,14 @@ namespace HKLib.Interfaces
/// 根据用户命获取下拉用户列表
/// </summary>
/// <param name="keyword"></param>
public static List<UserListDto> GetUserList(string keyword)
public static async Task<List<UserListDto>> 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<UserListDto>();
return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<UserListDto>>();
@@ -152,60 +154,65 @@ namespace HKLib.Interfaces
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
public static bool AddUserAndBindCard(UserDto input)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
}).Build().RunStringFirstAsync();
return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();

}
/// <summary>
/// 删除用户
/// </summary>
/// <returns></returns>
public static bool DisableUser(string userName)
public static async Task<bool> DisableUser(string userName)
{
List<string> a = new List<string>() { 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
}).Build().RunStringFirstAsync();
return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
}
/// <summary>
/// 添加用户
/// </summary>
/// <param name="input"></param>
public static bool AddUser(UserDto input)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
}).Build().RunStringFirstAsync();
return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
}
/// <summary>
/// 变更卡状态 销户
/// </summary>
/// <param name="input"></param>
public static bool CardStutasChange(CardStutasDto input)
public static async Task<bool> 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<JObject>()["data"]["isSuccess"].ToString().AsBool();
if (x)
}).Build().RunStringFirstAsync();
var data = res.ToModel<JObject>()["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
/// </summary>
/// <param name="input"></param>
/// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
public static List<ReportCountDto> Report(ReportDto input, int type = 1)
public static async Task<List<ReportCountDto>> 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<JObject>()["data"]["data"].ToJson().ToModel<List<ReportCountDto>>();
}
}


Loading…
Cancel
Save