選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

HKLibHelper.cs 15 KiB

2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
2年前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. using System.Threading.Tasks;
  10. using XExten.Advance.HttpFramework.MultiCommon;
  11. using XExten.Advance.HttpFramework.MultiFactory;
  12. using XExten.Advance.LinqFramework;
  13. using static RabbitMQ.Client.Logging.RabbitMqClientEventSource;
  14. namespace HKLib.Interfaces
  15. {
  16. public class HKLibHelper
  17. {
  18. static Dictionary<string, string> Header = new Dictionary<string, string> {
  19. {"TenantId",Configer.TenantId }
  20. };
  21. /// <summary>
  22. /// 设置刷卡时间端
  23. /// </summary>
  24. public static async Task<bool> SetTime(TimeSpilte input)
  25. {
  26. TimeSpilteDto dto = new TimeSpilteDto
  27. {
  28. AMEndTime = input.AMEndTime.ToShortTimeString(),
  29. AMStartTime = input.AMStartTime.ToShortTimeString(),
  30. PMEndTime = input.PMEndTime.ToShortTimeString(),
  31. PMStartTime = input.PMStartTime.ToShortTimeString(),
  32. ATEndTime = input.ATEndTime.ToShortTimeString(),
  33. ATStartTime = input.ATStartTime.ToShortTimeString(),
  34. };
  35. var data = await IHttpMultiClient.HttpMulti
  36. .AddHeader(t => t.Headers = Header)
  37. .AddNode(t =>
  38. {
  39. t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval";
  40. t.JsonParam = dto.ToJson();
  41. t.ReqType = MultiType.PUT;
  42. }).Build().RunStringFirstAsync();
  43. var res = data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  44. if (res)
  45. {
  46. Task.Run(() => ServiceQueryPush.QueryPush.PushMQAsync(input, "TimeChanged", MQEnum.Push));
  47. return res;
  48. }
  49. return false;
  50. }
  51. /// <summary>
  52. /// 获取时间
  53. /// </summary>
  54. /// <returns></returns>
  55. public static async Task<TimeSpilte> GetTime()
  56. {
  57. var data = await IHttpMultiClient.HttpMulti.AddNode(t =>
  58. {
  59. t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval";
  60. t.ReqType = MultiType.GET;
  61. }).Build().RunStringFirstAsync();
  62. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
  63. }
  64. /// <summary>
  65. /// 添加机构
  66. /// </summary>
  67. public static async Task<string> SetOrg(string input)
  68. {
  69. try
  70. {
  71. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  72. {
  73. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  74. t.ReqType = MultiType.POST;
  75. t.JsonParam = (new { Name = input }).ToJson();
  76. }).Build().RunStringFirstAsync();
  77. return data.ToModel<JObject>()["data"]["data"]["id"].ToString();
  78. }
  79. catch (System.Exception)
  80. {
  81. return string.Empty;
  82. }
  83. }
  84. public static string SetOrgSync(string input)
  85. {
  86. var data = IHttpMultiClient.HttpMulti
  87. .AddHeader(t => t.Headers = Header)
  88. .AddNode(t =>
  89. {
  90. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  91. t.ReqType = MultiType.POST;
  92. t.JsonParam = (new { Name = input }).ToJson();
  93. }).Build().RunStringFirst();
  94. return data.ToModel<JObject>()["data"]["data"]["id"].ToString();
  95. }
  96. /// <summary>
  97. /// 删除机构
  98. /// </summary>
  99. /// <param name="Id"></param>
  100. /// <returns></returns>
  101. public static async Task<bool> DelOrg(string Id)
  102. {
  103. var data = await IHttpMultiClient.HttpMulti
  104. .AddHeader(t => t.Headers = Header)
  105. .AddNode(t =>
  106. {
  107. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag/{Id}";
  108. t.ReqType = MultiType.DELETE;
  109. }).Build().RunStringFirstAsync();
  110. var res = data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  111. return res;
  112. }
  113. /// <summary>
  114. /// /获取机构
  115. /// </summary>
  116. /// <returns></returns>
  117. public static async Task<List<OrgDto>> GetOrg()
  118. {
  119. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  120. {
  121. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag-list";
  122. t.ReqType = MultiType.GET;
  123. }).Build().RunStringFirstAsync();
  124. if (data.IsNullOrEmpty()) return new List<OrgDto>();
  125. var model = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<OrgOutDto>>();
  126. return model.Where(t => !t.Name.IsNullOrEmpty()).Select(t => new OrgDto
  127. {
  128. Name = t.Name,
  129. SId = t.Id
  130. }).ToList();
  131. }
  132. /// <summary>
  133. /// 修改机构
  134. /// </summary>
  135. public static async Task<bool> AlterOrg(string input, string Sid)
  136. {
  137. var param = (new { Name = input, Id = Sid }).ToJson();
  138. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  139. {
  140. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  141. t.ReqType = MultiType.PUT;
  142. t.JsonParam = param;
  143. }).Build().RunStringFirstAsync();
  144. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  145. }
  146. public static async Task<string> GetUserMaxNum()
  147. {
  148. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  149. {
  150. t.NodePath = $"{Configer.SaasRoute}api/one-card/max-num";
  151. t.ReqType = MultiType.GET;
  152. }).Build().RunStringFirstAsync();
  153. var str = data.ToModel<JObject>()["data"]["data"].ToString();
  154. var check = str.IsNullOrEmpty();
  155. if (check) return "0001";
  156. return (str.AsInt() + 1).ToString().PadLeft(4, '0');
  157. }
  158. public static string GetUserMaxNumSync()
  159. {
  160. var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  161. {
  162. t.NodePath = $"{Configer.SaasRoute}api/one-card/max-num";
  163. t.ReqType = MultiType.GET;
  164. }).Build().RunStringFirst();
  165. var str = data.ToModel<JObject>()["data"]["data"].ToString();
  166. var check = str.IsNullOrEmpty();
  167. if (check) return "0001";
  168. return (str.AsInt() + 1).ToString().PadLeft(4, '0');
  169. }
  170. /// <summary>
  171. /// 根据用户命获取下拉用户列表
  172. /// </summary>
  173. /// <param name="keyword"></param>
  174. public static async Task<List<UserListDto>> GetUserList(string keyword)
  175. {
  176. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  177. {
  178. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff-list";
  179. t.ReqType = MultiType.POST;
  180. t.JsonParam = (new { realName = keyword }).ToJson();
  181. }).Build().RunStringFirstAsync();
  182. if (string.IsNullOrEmpty(data))
  183. return new List<UserListDto>();
  184. var res = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<UserListDto>>();
  185. return res.Where(t=>!string.IsNullOrEmpty(t.Name)).OrderByDescending(t=>t.Num).ToList();
  186. }
  187. public static List<UserListDto> GetUserListSync(string keyword)
  188. {
  189. var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  190. {
  191. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff-list";
  192. t.ReqType = MultiType.POST;
  193. t.JsonParam = (new { realName = keyword }).ToJson();
  194. }).Build().RunStringFirst();
  195. if (string.IsNullOrEmpty(data))
  196. return new List<UserListDto>();
  197. var res = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<UserListDto>>();
  198. return res.Where(t => !string.IsNullOrEmpty(t.Name)).OrderBy(t => t.Num).ToList();
  199. }
  200. /// <summary>
  201. /// 添加用户并绑卡
  202. /// </summary>
  203. /// <param name="input"></param>
  204. /// <returns></returns>
  205. public static async Task<bool> AddUserAndBindCard(UserDto input)
  206. {
  207. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  208. {
  209. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card";
  210. t.ReqType = MultiType.POST;
  211. t.JsonParam = (new
  212. {
  213. tagId = input.OrgId,
  214. realName = input.Name,
  215. num = input.Num,
  216. phone = input.Phone,
  217. cardNum = input.CardNo
  218. }).ToJson();
  219. }).Build().RunStringFirstAsync();
  220. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  221. }
  222. public static bool AddUserAndBindCardSync(UserDto input)
  223. {
  224. var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  225. {
  226. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card";
  227. t.ReqType = MultiType.POST;
  228. t.JsonParam = (new
  229. {
  230. tagId = input.OrgId,
  231. realName = input.Name,
  232. num = input.Num,
  233. phone = input.Phone,
  234. cardNum = input.CardNo
  235. }).ToJson();
  236. }).Build().RunStringFirst();
  237. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  238. }
  239. /// <summary>
  240. /// 删除用户
  241. /// </summary>
  242. /// <returns></returns>
  243. public static async Task<bool> DisableUser(string userName)
  244. {
  245. List<string> a = new List<string>() { userName };
  246. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  247. {
  248. t.NodePath = $"{Configer.SaasRoute}api/one-card/del-staff";
  249. t.ReqType = MultiType.POST;
  250. t.JsonParam = a.ToJson();
  251. }).Build().RunStringFirstAsync();
  252. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  253. }
  254. /// <summary>
  255. /// 添加用户
  256. /// </summary>
  257. /// <param name="input"></param>
  258. public static async Task<bool> AddUser(UserDto input)
  259. {
  260. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  261. {
  262. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff";
  263. t.ReqType = MultiType.POST;
  264. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone, num = input.Num }).ToJson();
  265. }).Build().RunStringFirstAsync();
  266. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  267. }
  268. public static bool AddUserSync(UserDto input)
  269. {
  270. var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  271. {
  272. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff";
  273. t.ReqType = MultiType.POST;
  274. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone, num = input.Num }).ToJson();
  275. }).Build().RunStringFirst();
  276. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  277. }
  278. /// <summary>
  279. /// 变更卡状态 销户
  280. /// </summary>
  281. /// <param name="input"></param>
  282. public static async Task<bool> CardStutasChange(CardStutasDto input)
  283. {
  284. input.CardNo = (await GetUserList(input.keywrod)).FirstOrDefault(t => t.Name.Equals(input.keywrod))?.Cards?.FirstOrDefault()?.CardNum;
  285. var res = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  286. {
  287. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card-state";
  288. t.ReqType = MultiType.PUT;
  289. t.JsonParam = (new { CardNum = input.CardNo, State = input.Stutas }).ToJson();
  290. }).Build().RunStringFirstAsync();
  291. var data = res.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  292. if (data)
  293. {
  294. Task.Run(() => ServiceQueryPush.QueryPush.PushMQAsync(input, "CardStutasChanged", MQEnum.Top));
  295. return data;
  296. }
  297. return false;
  298. }
  299. /// <summary>
  300. /// 报表数据
  301. /// type=1 数据参考
  302. ///
  303. /// {
  304. ///"name": "张三",
  305. /// "phone": "18208263734",
  306. /// "date": "2022-09-24",
  307. /// "tag": null,
  308. /// "amCount": 3,
  309. /// "pmCount": 0,
  310. /// "atCount": 0,
  311. /// "totalCount": 3
  312. /// }
  313. ///
  314. /// type=2 数据参考
  315. ///
  316. /// {
  317. ///"name": null,
  318. ///"phone": null,
  319. ///"date": "2022-09-13",
  320. ///"tag": null,
  321. ///"amCount": 3,
  322. ///"pmCount": 1,
  323. ///"atCount": 0,
  324. ///"totalCount": 4
  325. ///}
  326. ///
  327. ///
  328. /// </summary>
  329. /// <param name="input"></param>
  330. /// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
  331. public static async Task<List<ReportCountDto>> Report(ReportDto input, int type = 1)
  332. {
  333. var Route = Configer.SaasRoute;
  334. if (type == 1)
  335. Route += "api/one-card/day-consume-info";
  336. if (type == 2)
  337. Route += "api/one-card/consume-info";
  338. if (type == 3)
  339. Route += "api/one-card/time-interval-consume-info";
  340. var data = await IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  341. {
  342. t.NodePath = Route;
  343. t.ReqType = MultiType.POST;
  344. t.JsonParam = (new { StartTime = input.StartTime.ToShortDateString(), EndTime = input.EndTime.ToShortDateString() }).ToJson();
  345. }).Build().RunStringFirstAsync();
  346. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<ReportCountDto>>();
  347. }
  348. }
  349. }