Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

146 linhas
5.4 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. /*
  51. {"statusCode":200,"data":{"isSuccess":true,"msg":null,"data":{"amStartTime":"17:50","amEndTime":"17:50","pmStartTime":"17:50","pmEndTime":"17:50","atStartTime":"17:50","atEndTime":"17:50"}},"succeeded":true,"errors":null,"extras":null,"timestamp":1665654784093}
  52. */
  53. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  54. {
  55. t.NodePath = ApiRoute.GetTime;
  56. t.ReqType = MultiType.GET;
  57. }).Build().RunStringFirst();
  58. DataBus.Times = data.ToModel<JObject>()["data"]["data"].ToJson().ToModel<TimeSpilte>();
  59. }
  60. /// <summary>
  61. /// 同步消费记录
  62. /// </summary>
  63. /// <param name="CardNo"></param>
  64. /// <param name="Money"></param>
  65. public static bool SyncSaleLog(string CardNo, string StallId)
  66. {
  67. try
  68. {
  69. var GateId = DataBus.StoreInfo.Devices.FirstOrDefault(t => t.Address.AsInt() == StallId.AsInt())?.GateId;
  70. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  71. {
  72. t.ReqType = MultiType.POST;
  73. t.JsonParam = (new { GateId = GateId, Type = -1, CardNum = CardNo }).ToJson();
  74. t.NodePath = ApiRoute.SyncSaleLog;
  75. }).Build().RunStringFirst();
  76. HKLog.HKLogImport.WriteInfo($"同步消费时候调用:{data}");
  77. return bool.Parse(data.ToModel<JObject>()["data"].ToString());
  78. }
  79. catch (Exception ex)
  80. {
  81. HKLog.HKLogImport.WriteError(ex);
  82. return false;
  83. }
  84. }
  85. /// <summary>
  86. /// 批量同步同步消费记录
  87. /// </summary>
  88. /// <returns></returns>
  89. public static bool SyncSaleLogList(List<SaleDto> dto)
  90. {
  91. try
  92. {
  93. lock (locker)
  94. {
  95. var Ids = dto.Select(t => t.Id).ToList();
  96. var check = DbContext.Context.Queryable<SaleLog>().Where(t => Ids.Contains(t.Id)).Any(t => t.IsSync);
  97. if (check) return false;
  98. var data = IHttpMultiClient.HttpMulti.AddHeader(t =>
  99. {
  100. t.HeaderKey = "TenantId";
  101. t.HeaderValue = DataBus.TenantId;
  102. }).AddNode(t =>
  103. {
  104. t.ReqType = MultiType.POST;
  105. t.JsonParam = dto.ToJson();
  106. t.NodePath = ApiRoute.SyncSaleLogList;
  107. }).Build().RunStringFirst();
  108. HKLog.HKLogImport.WriteInfo($"批量同步同步消费记录调用:{data}");
  109. return bool.Parse(data.ToModel<JObject>()["data"].ToString());
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. HKLog.HKLogImport.WriteError(ex);
  115. return false;
  116. }
  117. }
  118. /// <summary>
  119. /// 获取店铺信息
  120. /// </summary>
  121. public static void PullShopInfo()
  122. {
  123. if (DataBus.NetWordState)
  124. {
  125. var data = IHttpMultiClient.HttpMulti.AddNode(t =>
  126. {
  127. t.NodePath = ApiRoute.PullShopInfo;
  128. }).Build().RunStringFirst()
  129. .ToModel<JObject>()["data"].ToJson().ToModel<StoreInfoResponse>();
  130. DataBus.StoreInfo = data;
  131. var storeinfo = SyncStatic.CreateFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json"));
  132. SyncStatic.WriteFile(Encoding.UTF8.GetBytes(data.ToJson()), storeinfo);
  133. }
  134. else
  135. {
  136. DataBus.StoreInfo = SyncStatic.ReadFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "StoreInfo.json")).ToModel<StoreInfoResponse>();
  137. }
  138. }
  139. }
  140. }