You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

HKLibHelper.cs 9.4 KiB

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