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.

185 lines
7.3 KiB

  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 XExten.Advance.HttpFramework.MultiCommon;
  8. using XExten.Advance.HttpFramework.MultiFactory;
  9. using XExten.Advance.LinqFramework;
  10. namespace HKLib.Interfaces
  11. {
  12. public class HKLibHelper
  13. {
  14. static Dictionary<string, string> Header = new Dictionary<string, string> {
  15. {"TenantId",Configer.TenantId }
  16. };
  17. /// <summary>
  18. /// 设置刷卡时间端
  19. /// </summary>
  20. public static bool SetTime(TimeSpilte input)
  21. {
  22. TimeSpilteDto dto = new TimeSpilteDto
  23. {
  24. AMEndTime = input.AMEndTime.ToShortTimeString(),
  25. AMStartTime = input.AMStartTime.ToShortTimeString(),
  26. PMEndTime = input.PMEndTime.ToShortTimeString(),
  27. PMStartTime = input.PMStartTime.ToShortTimeString(),
  28. ATEndTime = input.ATEndTime.ToShortTimeString(),
  29. ATStartTime = input.ATStartTime.ToShortTimeString(),
  30. };
  31. var data = IHttpMultiClient.HttpMulti
  32. .AddHeader(t => t.Headers = Header)
  33. .AddNode(t =>
  34. {
  35. t.NodePath = $"{Configer.SaasRoute}api/one-card/eat-time-interval";
  36. t.JsonParam = dto.ToJson();
  37. t.ReqType = MultiType.PUT;
  38. }).Build().RunStringFirst();
  39. return data.ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  40. }
  41. /// <summary>
  42. /// 添加机构
  43. /// </summary>
  44. public static string SetOrg(string input)
  45. {
  46. return IHttpMultiClient.HttpMulti
  47. .AddHeader(t => t.Headers = Header)
  48. .AddNode(t =>
  49. {
  50. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  51. t.ReqType = MultiType.POST;
  52. t.JsonParam = (new { Name = input }).ToJson();
  53. }).Build().RunStringFirst().ToModel<JObject>()["data"]["data"]["id"].ToString();
  54. }
  55. /// <summary>
  56. /// 修改机构
  57. /// </summary>
  58. public static bool AlterOrg(string input, string Sid)
  59. {
  60. return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  61. {
  62. t.NodePath = $"{Configer.SaasRoute}api/one-card/member-tag";
  63. t.ReqType = MultiType.PUT;
  64. t.JsonParam = (new { Name = input, Id = Sid }).ToJson();
  65. }).Build().RunStringFirst().ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  66. }
  67. /// <summary>
  68. /// 根据用户命获取下拉用户列表
  69. /// </summary>
  70. /// <param name="keyword"></param>
  71. public static List<UserListDto> GetUserList(string keyword)
  72. {
  73. return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  74. {
  75. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff-list";
  76. t.ReqType = MultiType.POST;
  77. t.JsonParam = (new { realName = keyword }).ToJson();
  78. }).Build().RunStringFirst().ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<UserListDto>>();
  79. }
  80. /// <summary>
  81. /// 添加用户并绑卡
  82. /// </summary>
  83. /// <param name="input"></param>
  84. /// <returns></returns>
  85. public static bool AddUserAndBindCard(UserDto input)
  86. {
  87. return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  88. {
  89. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card";
  90. t.ReqType = MultiType.POST;
  91. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone, cardNum = input.CardNo }).ToJson();
  92. }).Build().RunStringFirst().ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  93. }
  94. /// <summary>
  95. /// 添加用户
  96. /// </summary>
  97. /// <param name="input"></param>
  98. public static bool AddUser(UserDto input)
  99. {
  100. return IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  101. {
  102. t.NodePath = $"{Configer.SaasRoute}api/one-card/staff";
  103. t.ReqType = MultiType.POST;
  104. t.JsonParam = (new { tagId = input.OrgId, realName = input.Name, phone = input.Phone }).ToJson();
  105. }).Build().RunStringFirst().ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  106. }
  107. /// <summary>
  108. /// 变更卡状态 销户
  109. /// </summary>
  110. /// <param name="input"></param>
  111. public static bool CardStutasChange(CardStutasDto input)
  112. {
  113. input.CardNo = GetUserList(input.keywrod).FirstOrDefault(t => t.Name.Equals(input.keywrod)).Cards.FirstOrDefault(t => t.State == 1).CardNum;
  114. var x = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  115. {
  116. t.NodePath = $"{Configer.SaasRoute}api/one-card/mmenber-card-state";
  117. t.ReqType = MultiType.PUT;
  118. t.JsonParam = (new { CardNum = input.CardNo, State = input.Stutas }).ToJson();
  119. }).Build().RunStringFirst().ToModel<JObject>()["data"]["isSuccess"].ToString().AsBool();
  120. if (x)
  121. {
  122. ServiceQueryPush.QueryPush.PushMQ(input, "CardStutasChanged", MQEnum.Top);
  123. return x;
  124. }
  125. return false;
  126. }
  127. /// <summary>
  128. /// 报表数据
  129. /// type=1 数据参考
  130. ///
  131. /// {
  132. ///"name": "张三",
  133. /// "phone": "18208263734",
  134. /// "date": "2022-09-24",
  135. /// "tag": null,
  136. /// "amCount": 3,
  137. /// "pmCount": 0,
  138. /// "atCount": 0,
  139. /// "totalCount": 3
  140. /// }
  141. ///
  142. /// type=2 数据参考
  143. ///
  144. /// {
  145. ///"name": null,
  146. ///"phone": null,
  147. ///"date": "2022-09-13",
  148. ///"tag": null,
  149. ///"amCount": 3,
  150. ///"pmCount": 1,
  151. ///"atCount": 0,
  152. ///"totalCount": 4
  153. ///}
  154. ///
  155. ///
  156. /// </summary>
  157. /// <param name="input"></param>
  158. /// <param name="type">1 计次就餐天消费表(每人),2每月餐段消费报表,3月餐段汇总表</param>
  159. public static List<ReportCountDto> Report(ReportDto input, int type = 1)
  160. {
  161. var Route = Configer.SaasRoute;
  162. if (type == 1)
  163. Route += "api/one-card/day-consume-info";
  164. if (type == 2)
  165. Route += "api/one-card/consume-info";
  166. if (type == 3)
  167. Route += "api/one-card/time-interval-consume-info";
  168. var data = IHttpMultiClient.HttpMulti.AddHeader(t => t.Headers = Header).AddNode(t =>
  169. {
  170. t.NodePath = Route;
  171. t.ReqType = MultiType.POST;
  172. t.JsonParam = (new { StartTime =input.StartTime.ToShortDateString(), EndTime=input.EndTime.ToShortDateString() }).ToJson();
  173. }).Build().RunStringFirst();
  174. return data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<ReportCountDto>>();
  175. }
  176. }
  177. }