您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

270 行
11 KiB

  1. using FastExpressionCompiler.LightExpression;
  2. using HKLib.Dto;
  3. using HKLib.RabbitMQ.Config;
  4. using HKLib.RabbitMQ.Publisher;
  5. using Newtonsoft.Json.Linq;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Threading.Tasks;
  9. using XExten.Advance.HttpFramework.MultiCommon;
  10. using XExten.Advance.HttpFramework.MultiFactory;
  11. using XExten.Advance.LinqFramework;
  12. namespace HKLib.Interfaces
  13. {
  14. public class HKLibHelper
  15. {
  16. static Dictionary<string, string> Header = new Dictionary<string, string> {
  17. {"TenantId",Configer.TenantId }
  18. };
  19. /// <summary>
  20. /// 设置刷卡时间端
  21. /// </summary>
  22. public static async Task<bool> SetTime(TimeSpilte input)
  23. {
  24. TimeSpilteDto dto = new TimeSpilteDto
  25. {
  26. AMEndTime = input.AMEndTime.ToShortTimeString(),
  27. AMStartTime = input.AMStartTime.ToShortTimeString(),
  28. PMEndTime = input.PMEndTime.ToShortTimeString(),
  29. PMStartTime = input.PMStartTime.ToShortTimeString(),
  30. ATEndTime = input.ATEndTime.ToShortTimeString(),
  31. ATStartTime = input.ATStartTime.ToShortTimeString(),
  32. };
  33. var data = await IHttpMultiClient.HttpMulti
  34. .AddHeader(t => t.Headers = Header)
  35. .AddNode(t =>
  36. {
  37. t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval";
  38. t.JsonParam = dto.ToJson();
  39. t.ReqType = MultiType.PUT;
  40. }).Build().RunStringFirstAsync();
  41. var res = data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  42. if (res)
  43. {
  44. Task.Run(() => ServiceQueryPush.QueryPush.PushMQAsync(input, "TimeChanged", MQEnum.Push));
  45. return res;
  46. }
  47. return false;
  48. }
  49. /// <summary>
  50. /// 获取时间
  51. /// </summary>
  52. /// <returns></returns>
  53. public static async Task<TimeSpilte> GetTime()
  54. {
  55. var data = await IHttpMultiClient.HttpMulti.AddNode(t =>
  56. {
  57. t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval";
  58. t.ReqType = MultiType.GET;
  59. }).Build().RunStringFirstAsync();
  60. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
  61. }
  62. /// <summary>
  63. /// 添加机构
  64. /// </summary>
  65. public static async Task<string> SetOrg(string input)
  66. {
  67. var data = await IHttpMultiClient.HttpMulti
  68. .AddHeader(t => t.Headers = Header)
  69. .AddNode(t =>
  70. {
  71. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  72. t.ReqType = MultiType.POST;
  73. t.JsonParam = (new { Name = input }).ToJson();
  74. }).Build().RunStringFirstAsync();
  75. return data.ToModel<JObject>()["data"]["data"]["id"].ToString();
  76. }
  77. /// <summary>
  78. /// 删除机构
  79. /// </summary>
  80. /// <param name="Id"></param>
  81. /// <returns></returns>
  82. public static async Task<bool> DelOrg(string Id)
  83. {
  84. var data = await IHttpMultiClient.HttpMulti
  85. .AddHeader(t => t.Headers = Header)
  86. .AddNode(t =>
  87. {
  88. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag/{Id}";
  89. t.ReqType = MultiType.DELETE;
  90. }).Build().RunStringFirstAsync();
  91. var res = data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  92. return res;
  93. }
  94. /// <summary>
  95. /// /获取机构
  96. /// </summary>
  97. /// <returns></returns>
  98. public static async Task<List<OrgDto>> GetOrg()
  99. {
  100. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  101. {
  102. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag-list";
  103. t.ReqType = MultiType.GET;
  104. }).Build().RunStringFirstAsync();
  105. if (data.IsNullOrEmpty()) return new List<OrgDto>();
  106. var model = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<OrgOutDto>>();
  107. return model.Where(t => !t.Name.IsNullOrEmpty()).Select(t => new OrgDto
  108. {
  109. Name = t.Name,
  110. SId = t.Id
  111. }).ToList();
  112. }
  113. /// <summary>
  114. /// 修改机构
  115. /// </summary>
  116. public static async Task<bool> AlterOrg(string input, string Sid)
  117. {
  118. var param = (new { Name = input, Id = Sid }).ToJson();
  119. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  120. {
  121. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  122. t.ReqType = MultiType.PUT;
  123. t.JsonParam = param;
  124. }).Build().RunStringFirstAsync();
  125. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  126. }
  127. /// <summary>
  128. /// 根据用户命获取下拉用户列表
  129. /// </summary>
  130. /// <param name="keyword"></param>
  131. public static async Task<List<UserListDto>> GetUserList(string keyword)
  132. {
  133. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  134. {
  135. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff-list";
  136. t.ReqType = MultiType.POST;
  137. t.JsonParam = (new { realName = keyword }).ToJson();
  138. }).Build().RunStringFirstAsync();
  139. if (string.IsNullOrEmpty(data))
  140. return new List<UserListDto>();
  141. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<UserListDto>>();
  142. }
  143. /// <summary>
  144. /// 添加用户并绑卡
  145. /// </summary>
  146. /// <param name="input"></param>
  147. /// <returns></returns>
  148. public static async Task<bool> AddUserAndBindCard(UserDto input)
  149. {
  150. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  151. {
  152. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card";
  153. t.ReqType = MultiType.POST;
  154. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone, cardNum = input.CardNo }).ToJson();
  155. }).Build().RunStringFirstAsync();
  156. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  157. }
  158. /// <summary>
  159. /// 删除用户
  160. /// </summary>
  161. /// <returns></returns>
  162. public static async Task<bool> DisableUser(string userName)
  163. {
  164. List<string> a = new List<string>() { userName };
  165. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  166. {
  167. t.NodePath = $"{Configer.SaasRoute}api/one-card/del-staff";
  168. t.ReqType = MultiType.POST;
  169. t.JsonParam = a.ToJson();
  170. }).Build().RunStringFirstAsync();
  171. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  172. }
  173. /// <summary>
  174. /// 添加用户
  175. /// </summary>
  176. /// <param name="input"></param>
  177. public static async Task<bool> AddUser(UserDto input)
  178. {
  179. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  180. {
  181. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff";
  182. t.ReqType = MultiType.POST;
  183. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone }).ToJson();
  184. }).Build().RunStringFirstAsync();
  185. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  186. }
  187. /// <summary>
  188. /// 变更卡状态 销户
  189. /// </summary>
  190. /// <param name="input"></param>
  191. public static async Task<bool> CardStutasChange(CardStutasDto input)
  192. {
  193. input.CardNo = (await GetUserList(input.keywrod)).FirstOrDefault(t => t.Name.Equals(input.keywrod))?.Cards?.FirstOrDefault()?.CardNum;
  194. var res = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  195. {
  196. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card-state";
  197. t.ReqType = MultiType.PUT;
  198. t.JsonParam = (new { CardNum = input.CardNo, State = input.Stutas }).ToJson();
  199. }).Build().RunStringFirstAsync();
  200. var data = res.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  201. if (data)
  202. {
  203. Task.Run(() => ServiceQueryPush.QueryPush.PushMQAsync(input, "CardStutasChanged", MQEnum.Top));
  204. return data;
  205. }
  206. return false;
  207. }
  208. /// <summary>
  209. /// 报表数据
  210. /// type=1 数据参考
  211. ///
  212. /// {
  213. ///"name": "张三",
  214. /// "phone": "18208263734",
  215. /// "date": "2022-09-24",
  216. /// "tag": null,
  217. /// "amCount": 3,
  218. /// "pmCount": 0,
  219. /// "atCount": 0,
  220. /// "totalCount": 3
  221. /// }
  222. ///
  223. /// type=2 数据参考
  224. ///
  225. /// {
  226. ///"name": null,
  227. ///"phone": null,
  228. ///"date": "2022-09-13",
  229. ///"tag": null,
  230. ///"amCount": 3,
  231. ///"pmCount": 1,
  232. ///"atCount": 0,
  233. ///"totalCount": 4
  234. ///}
  235. ///
  236. ///
  237. /// </summary>
  238. /// <param name="input"></param>
  239. /// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
  240. public static async Task<List<ReportCountDto>> Report(ReportDto input, int type = 1)
  241. {
  242. var Route = Configer.SaasRoute;
  243. if (type == 1)
  244. Route += "api/one-card/day-consume-info";
  245. if (type == 2)
  246. Route += "api/one-card/consume-info";
  247. if (type == 3)
  248. Route += "api/one-card/time-interval-consume-info";
  249. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  250. {
  251. t.NodePath = Route;
  252. t.ReqType = MultiType.POST;
  253. t.JsonParam = (new { StartTime = input.StartTime.ToShortDateString(), EndTime = input.EndTime.ToShortDateString() }).ToJson();
  254. }).Build().RunStringFirstAsync();
  255. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<ReportCountDto>>();
  256. }
  257. }
  258. }