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.

174 lines
6.0 KiB

  1. using DTO;
  2. using HKCardOUT.Helper;
  3. using HKCardOUT.Logic.Model;
  4. using HKCardOUT.Logic.Service;
  5. using HKLib.Dto;
  6. using Logic.RemoteModel;
  7. using Newtonsoft.Json.Linq;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text;
  13. using System.Threading.Tasks;
  14. using System.Windows.Markup;
  15. using UHFHelper;
  16. using XExten.Advance.HttpFramework.MultiCommon;
  17. using XExten.Advance.HttpFramework.MultiFactory;
  18. using XExten.Advance.LinqFramework;
  19. using XExten.Advance.StaticFramework;
  20. namespace HKCardOUT.Logic
  21. {
  22. public class RemoteService
  23. {
  24. private static readonly object locker = new();
  25. /// <summary>
  26. /// 获取所有卡状态和卡号
  27. /// </summary>
  28. /// <param name="input"></param>
  29. public static int GetCardStuatas()
  30. {
  31. var res = IHttpMultiClient.HttpMulti.AddNode(t =>
  32. {
  33. t.NodePath = ApiRoute.CheckCardStatus;
  34. t.ReqType = MultiType.GET;
  35. }).Build().RunStringFirst();
  36. var data = res.ToModel<JObject>()["data"]["data"].ToJson().ToModel<List<CardInfo>>();
  37. var entity = data.Select(t => new CardStutas
  38. {
  39. CardNo = t.CardNum,
  40. Stutas = t.State
  41. }).ToList();
  42. HKCore.AddCard(entity);
  43. return data != null ? data.ToString().AsInt() : 0;
  44. }
  45. /// <summary>
  46. /// 同步时间段
  47. /// </summary>
  48. public static void SyncTime()
  49. {
  50. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  51. {
  52. t.NodePath = ApiRoute.GetTime;
  53. t.ReqType = MultiType.GET;
  54. }).Build().RunStringFirst();
  55. DataBus.Times = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
  56. }
  57. /// <summary>
  58. /// 同步消费记录
  59. /// </summary>
  60. /// <param name="CardNo"></param>
  61. /// <param name="Money"></param>
  62. public static bool SyncSaleLog(string CardNo, string StallId)
  63. {
  64. try
  65. {
  66. var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
  67. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  68. {
  69. t.ReqType = MultiType.POST;
  70. t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
  71. t.NodePath = ApiRoute.SyncSaleLog;
  72. }).Build().RunStringFirst();
  73. HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
  74. return bool.Parse(data.ToModel<JObject>()["data"].ToString());
  75. }
  76. catch (Exception ex)
  77. {
  78. HKLog.HKLogImport.WriteError(ex);
  79. return false;
  80. }
  81. }
  82. /// <summary>
  83. /// 批量同步同步消费记录
  84. /// </summary>
  85. /// <returns></returns>
  86. public static List<FailDto> SyncSaleLogList(List<SaleDto> dto)
  87. {
  88. try
  89. {
  90. lock (locker)
  91. {
  92. var Ids = dto.Select(t => t.Id).ToList();
  93. var check = DbContext.Context.Queryable<SaleLog>().Where(t => Ids.Contains(t.Id)).Any(t => t.IsSync);
  94. if (check) return null ;
  95. var data = IHttpMultiClient.HttpMulti.AddHeader(t =>
  96. {
  97. t.HeaderKey = "TenantId";
  98. t.HeaderValue = DataBus.TenantId;
  99. }).AddNode(t =>
  100. {
  101. t.ReqType = MultiType.POST;
  102. t.JsonParam = dto.ToJson();
  103. t.NodePath = ApiRoute.SyncSaleLogList;
  104. }).Build().RunStringFirst();
  105. HKLog.HKLogImport.WriteInfo($"批量同步同步消费记录调用:{data}");
  106. return data.ToModel<JObject>()["data"].ToString().ToModel<JObject>()["failList"].ToJson().ToModel<List<FailDto>>();
  107. }
  108. }
  109. catch (Exception ex)
  110. {
  111. HKLog.HKLogImport.WriteError(ex);
  112. return null;
  113. }
  114. }
  115. /// <summary>
  116. /// 获取店铺信息
  117. /// </summary>
  118. public static void PullShopInfo()
  119. {
  120. if (DataBus.NetWordState)
  121. {
  122. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  123. {
  124. t.NodePath = ApiRoute.PullShopInfo;
  125. }).Build().RunStringFirst()
  126. .ToModel<JObject>()["data"].ToJson().ToModel<StoreInfoResponse>();
  127. DataBus.StoreInfo = data;
  128. var storeinfo = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json"));
  129. SyncStatic.WriteFile(Encoding.UTF8.GetBytes(data.ToJson()), storeinfo);
  130. }
  131. else
  132. {
  133. DataBus.StoreInfo = SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json")).ToModel<StoreInfoResponse>();
  134. }
  135. }
  136. /// <summary>
  137. /// 获取菜单
  138. /// </summary>
  139. public static void GetFoodMenus()
  140. {
  141. if (DataBus.NetWordState)
  142. {
  143. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  144. {
  145. t.NodePath = ApiRoute.FoodCtrl;
  146. }).Build().RunStringFirst();
  147. DataBus.Menu = data.ToModel<JObject>()["data"].ToJson().ToModel<FoodDto>();
  148. }
  149. }
  150. public static void GetRangeCtrl()
  151. {
  152. if (DataBus.NetWordState)
  153. {
  154. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  155. {
  156. t.NodePath = ApiRoute.RangCtrl;
  157. }).Build().RunStringFirst();
  158. DataBus.RangeCtrl = data.ToModel<JObject>()["data"].ToJson().ToModel<List<GateSetUp>>();
  159. }
  160. }
  161. }
  162. }