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.

208 lines
9.4 KiB

  1. using BPA.Communication;
  2. using BPA.Helper;
  3. using BPA.Message.Enum;
  4. using BPA.Message;
  5. using DTO;
  6. using HKCardOUT.Logic.Model;
  7. using HKCardOUT.Views;
  8. using HKLib.Dto;
  9. using Logic.RemoteModel;
  10. using Newtonsoft.Json;
  11. using System;
  12. using System.Collections.Concurrent;
  13. using System.Collections.Generic;
  14. using System.Globalization;
  15. using System.IO;
  16. using System.Linq;
  17. using System.Text;
  18. using System.Threading.Tasks;
  19. using System.Windows.Data;
  20. using System.Xml.Linq;
  21. using XExten.Advance.StaticFramework;
  22. using static System.Net.Mime.MediaTypeNames;
  23. namespace HKCardOUT.Helper
  24. {
  25. public class DataBus
  26. {
  27. private static string _ConnectionString;
  28. public static string ConnectionString
  29. {
  30. get => _ConnectionString;
  31. set
  32. {
  33. var Route = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "DATA");
  34. _ConnectionString = $"DataSource={SyncStatic.CreateFile(Path.Combine(SyncStatic.CreateDir(Route), value))}";
  35. }
  36. }
  37. public static bool NetWordState { get; set; } = false;
  38. public static string Cron { get; set; }
  39. public static bool StartDevice { get; set; }
  40. public static bool Cancel { get; set; }
  41. public static string StoreId { get; set; }
  42. public static string TenantId { get; set; }
  43. public static string COM { get; set; }
  44. public static string SaasRoute { get; set; }
  45. public static int Span { get; set; }
  46. public static int Count { get; set; }
  47. public static string MQTT { get; set; }
  48. public static List<string> Admin { get; set; }
  49. public static TimeSpilte Times { get; set; }
  50. public static StoreInfoResponse StoreInfo { get; set; }
  51. public static Dictionary<string, AdWindow> AdStatus { get; set; } = new Dictionary<string, AdWindow>();
  52. public static List<UserListDto> UserListDto { get; set; }
  53. public static ConcurrentQueue<SaleLogDto> saleLogDtos { get; set; }
  54. public static ConcurrentDictionary<string, ConcurrentQueue<SaleLogDto>> SaleLogDtoList { get; set; } = new ConcurrentDictionary<string, ConcurrentQueue<SaleLogDto>>();
  55. public static ConcurrentQueue<SaleLog> Entitys { get; set; }
  56. public static FoodDto Menu { get; set; }
  57. public static List<GateSetUp> RangeCtrl { get; set; }
  58. }
  59. public class ApiRoute
  60. {
  61. public static string GetTime = DataBus.SaasRoute + "api/one-card/eat-time-interval";
  62. /// <summary>
  63. /// 获取所有卡
  64. /// </summary>
  65. public static string CheckCardStatus = DataBus.SaasRoute + "api/one-card/card-list";
  66. /// <summary>
  67. /// 同步消费记录
  68. /// </summary>
  69. public static string SyncSaleLog = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrecharge";
  70. /// <summary>
  71. /// 批量消费记录
  72. /// </summary>
  73. public static string SyncSaleLogList = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrechargelist";
  74. /// <summary>
  75. /// 获取店铺信息
  76. /// </summary>
  77. public static string PullShopInfo = DataBus.SaasRoute + $"api/StoreHelper/GeBasisGateList?StoreId={DataBus.StoreId}";
  78. /// <summary>
  79. /// 区域控制
  80. /// </summary>
  81. public static string RangCtrl = DataBus.SaasRoute + $"api/StoreHelper/GetBasisGateSetUp?StoreId={DataBus.StoreId}";
  82. /// <summary>
  83. /// 菜品数据
  84. /// </summary>
  85. public static string FoodCtrl = DataBus.SaasRoute + $"api/StoreHelper/GetBasisGateFoodList?StoreId={DataBus.StoreId}";
  86. }
  87. public class HKConverter : IValueConverter
  88. {
  89. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  90. {
  91. return (bool)value ? "启用" : "禁用";
  92. }
  93. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  94. {
  95. return value;
  96. }
  97. }
  98. public class MemoryBus
  99. {
  100. public static List<CardStutas> CardStatus { get; set; } = new List<CardStutas>();
  101. public static List<SaleLog> CardRecord { get; set; } = new List<SaleLog>();
  102. }
  103. public static class MQTTCon
  104. {
  105. static MqttHelper mqttHelper;
  106. static MQTTCon()
  107. {
  108. mqttHelper = new MqttHelper();
  109. }
  110. /// <summary>
  111. /// Mqtt是否运行
  112. /// </summary>
  113. static bool IsRunningMqtt = false;
  114. public static void Connection()
  115. {
  116. try
  117. {
  118. //2.Mqtt连接
  119. if (!string.IsNullOrEmpty(DataBus.MQTT) && DataBus.MQTT.Contains(','))
  120. {
  121. string[] mqttcom = DataBus.MQTT.Split(',');
  122. if (mqttcom != null && mqttcom.Count() == 4)
  123. {
  124. mqttHelper.Connect(mqttcom[2], mqttcom[3], mqttcom[0], int.Parse(mqttcom[1]), $"分餐机{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
  125. }
  126. }
  127. mqttHelper.Disconnect = new Action(() =>
  128. {
  129. IsRunningMqtt = false;
  130. MessageLog.GetInstance.ShowEx($"分餐机MQTT异常断开....");
  131. });
  132. mqttHelper.ConnectOk = new Action(() =>
  133. {
  134. IsRunningMqtt = true;//连接成功
  135. });
  136. }
  137. catch (Exception ex)
  138. {
  139. MessageLog.GetInstance.ShowEx($"分餐机初始化连接 MQTT,原因:{ex.Message}");
  140. }
  141. }
  142. public static void Send(ScreenModelSplitMeals screenModel)
  143. {
  144. SendScreenDataModel sendScreenData = new SendScreenDataModel();
  145. sendScreenData.Name = ScreenDeviceType.分餐机;
  146. sendScreenData.Value = screenModel;
  147. //new ScreenModelSplitMeals
  148. //{
  149. // IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
  150. // WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
  151. // RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
  152. // Alarm = new List<AlarmModel> {
  153. // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  154. // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  155. // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  156. // },
  157. // FailuresCount = 0,
  158. // StatsCount = new List<StatsModel> {
  159. // new StatsModel { Name = name_s[0], Count = new Random().Next(0, 100) },
  160. // new StatsModel { Name = name_s[1], Count = new Random().Next(0, 100) },
  161. // new StatsModel { Name = name_s[2], Count = new Random().Next(0, 100) },
  162. // new StatsModel { Name = name_s[3], Count = new Random().Next(0, 100) },
  163. // new StatsModel { Name = name_s[4], Count = new Random().Next(0, 100) },
  164. // },
  165. // SplitMeals_CreditCardCount_1 = new Random().Next(0, 100),
  166. // SplitMeals_CreditCardNameBefore_1 = name_XM[new Random().Next(0, 5)],
  167. // SplitMeals_CreditCardName_1 = name_XM[new Random().Next(0, 5)],
  168. // SplitMeals_CookType_1 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  169. // SplitMeals_CreditCardCount_2 = new Random().Next(0, 100),
  170. // SplitMeals_CreditCardNameBefore_2 = name_XM[new Random().Next(0, 5)],
  171. // SplitMeals_CreditCardName_2 = name_XM[new Random().Next(0, 5)],
  172. // SplitMeals_CookType_2 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  173. // SplitMeals_CreditCardCount_3 = new Random().Next(0, 100),
  174. // SplitMeals_CreditCardNameBefore_3 = name_XM[new Random().Next(0, 5)],
  175. // SplitMeals_CreditCardName_3 = name_XM[new Random().Next(0, 5)],
  176. // SplitMeals_CookType_3 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  177. // SplitMeals_CreditCardCount_4 = new Random().Next(0, 100),
  178. // SplitMeals_CreditCardNameBefore_4 = name_XM[new Random().Next(0, 5)],
  179. // SplitMeals_CreditCardName_4 = name_XM[new Random().Next(0, 5)],
  180. // SplitMeals_CookType_4 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  181. // SplitMeals_CreditCardCount_5 = new Random().Next(0, 100),
  182. // SplitMeals_CreditCardNameBefore_5 = name_XM[new Random().Next(0, 5)],
  183. // SplitMeals_CreditCardName_5 = name_XM[new Random().Next(0, 5)],
  184. // SplitMeals_CookType_5 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  185. // SplitMeals_CreditCardCount_6 = new Random().Next(0, 100),
  186. // SplitMeals_CreditCardNameBefore_6 = name_XM[new Random().Next(0, 5)],
  187. // SplitMeals_CreditCardName_6 = name_XM[new Random().Next(0, 5)],
  188. // SplitMeals_CookType_6 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  189. //};
  190. string message = JsonConvert.SerializeObject(sendScreenData);
  191. mqttHelper.Publish(ScreenTOPIC.GetInstance.GetTopic(ScreenDeviceType.分餐机), message);
  192. }
  193. }
  194. }