25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

213 satır
9.6 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. /// <summary>
  49. /// 当天时间
  50. /// </summary>
  51. public static DateTime TodayTime { get; set; }
  52. public static List<string> Admin { get; set; }
  53. public static TimeSpilte Times { get; set; }
  54. public static StoreInfoResponse StoreInfo { get; set; }
  55. public static Dictionary<string, AdWindow> AdStatus { get; set; } = new Dictionary<string, AdWindow>();
  56. public static List<UserListDto> UserListDto { get; set; }
  57. public static ConcurrentQueue<SaleLogDto> saleLogDtos { get; set; }
  58. public static ConcurrentDictionary<string, ConcurrentQueue<SaleLogDto>> SaleLogDtoList { get; set; } = new ConcurrentDictionary<string, ConcurrentQueue<SaleLogDto>>();
  59. public static ConcurrentQueue<SaleLog> Entitys { get; set; }
  60. public static FoodDto Menu { get; set; }
  61. public static List<GateSetUp> RangeCtrl { get; set; }
  62. }
  63. public class ApiRoute
  64. {
  65. public static string GetTime = DataBus.SaasRoute + "api/one-card/eat-time-interval";
  66. /// <summary>
  67. /// 获取所有卡
  68. /// </summary>
  69. public static string CheckCardStatus = DataBus.SaasRoute + "api/one-card/card-list";
  70. /// <summary>
  71. /// 同步消费记录
  72. /// </summary>
  73. public static string SyncSaleLog = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrecharge";
  74. /// <summary>
  75. /// 批量消费记录
  76. /// </summary>
  77. public static string SyncSaleLogList = DataBus.SaasRoute + "api/member-helper/memberconsumptionorrechargelist";
  78. /// <summary>
  79. /// 获取店铺信息
  80. /// </summary>
  81. public static string PullShopInfo = DataBus.SaasRoute + $"api/StoreHelper/GeBasisGateList?StoreId={DataBus.StoreId}";
  82. /// <summary>
  83. /// 区域控制
  84. /// </summary>
  85. public static string RangCtrl = DataBus.SaasRoute + $"api/StoreHelper/GetBasisGateSetUp?StoreId={DataBus.StoreId}";
  86. /// <summary>
  87. /// 菜品数据
  88. /// </summary>
  89. public static string FoodCtrl = DataBus.SaasRoute + $"api/StoreHelper/GetBasisGateFoodList?StoreId={DataBus.StoreId}";
  90. }
  91. public class HKConverter : IValueConverter
  92. {
  93. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  94. {
  95. return (bool)value ? "启用" : "禁用";
  96. }
  97. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  98. {
  99. return value;
  100. }
  101. }
  102. public class MemoryBus
  103. {
  104. public static List<CardStutas> CardStatus { get; set; } = new List<CardStutas>();
  105. public static List<SaleLog> CardRecord { get; set; } = new List<SaleLog>();
  106. }
  107. public static class MQTTCon
  108. {
  109. static MqttHelper mqttHelper;
  110. static MQTTCon()
  111. {
  112. mqttHelper = new MqttHelper();
  113. }
  114. /// <summary>
  115. /// Mqtt是否运行
  116. /// </summary>
  117. static bool IsRunningMqtt = false;
  118. public static void Connection()
  119. {
  120. try
  121. {
  122. //2.Mqtt连接
  123. if (!string.IsNullOrEmpty(DataBus.MQTT) && DataBus.MQTT.Contains(','))
  124. {
  125. string[] mqttcom = DataBus.MQTT.Split(',');
  126. if (mqttcom != null && mqttcom.Count() == 4)
  127. {
  128. mqttHelper.Connect(mqttcom[2], mqttcom[3], mqttcom[0], int.Parse(mqttcom[1]), $"分餐机{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}");
  129. }
  130. }
  131. mqttHelper.Disconnect = new Action(() =>
  132. {
  133. IsRunningMqtt = false;
  134. MessageLog.GetInstance.ShowEx($"分餐机MQTT异常断开....");
  135. });
  136. mqttHelper.ConnectOk = new Action(() =>
  137. {
  138. IsRunningMqtt = true;//连接成功
  139. });
  140. }
  141. catch (Exception ex)
  142. {
  143. MessageLog.GetInstance.ShowEx($"分餐机初始化连接 MQTT,原因:{ex.Message}");
  144. }
  145. }
  146. public static void Send(ScreenModelSplitMeals screenModel)
  147. {
  148. if (!IsRunningMqtt) return;
  149. SendScreenDataModel sendScreenData = new SendScreenDataModel();
  150. sendScreenData.Name = ScreenDeviceType.分餐机;
  151. sendScreenData.Value = screenModel;
  152. //new ScreenModelSplitMeals
  153. //{
  154. // IsRun = k2 == 0 ? IsRun.运行 : IsRun.停止,
  155. // WorkStatus = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
  156. // RobotStatu = k2 == 0 ? WorkStatus.工作 : WorkStatus.待机,
  157. // Alarm = new List<AlarmModel> {
  158. // new AlarmModel { AlarmTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  159. // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  160. // new AlarmModel { AlarmTime = DateTime.Now.AddSeconds(2).ToString("yyyy-MM-dd HH:mm:ss"), AlarmMs = "XXXX机构出现故障!!!!" },
  161. // },
  162. // FailuresCount = 0,
  163. // StatsCount = new List<StatsModel> {
  164. // new StatsModel { Name = name_s[0], Count = new Random().Next(0, 100) },
  165. // new StatsModel { Name = name_s[1], Count = new Random().Next(0, 100) },
  166. // new StatsModel { Name = name_s[2], Count = new Random().Next(0, 100) },
  167. // new StatsModel { Name = name_s[3], Count = new Random().Next(0, 100) },
  168. // new StatsModel { Name = name_s[4], Count = new Random().Next(0, 100) },
  169. // },
  170. // SplitMeals_CreditCardCount_1 = new Random().Next(0, 100),
  171. // SplitMeals_CreditCardNameBefore_1 = name_XM[new Random().Next(0, 5)],
  172. // SplitMeals_CreditCardName_1 = name_XM[new Random().Next(0, 5)],
  173. // SplitMeals_CookType_1 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  174. // SplitMeals_CreditCardCount_2 = new Random().Next(0, 100),
  175. // SplitMeals_CreditCardNameBefore_2 = name_XM[new Random().Next(0, 5)],
  176. // SplitMeals_CreditCardName_2 = name_XM[new Random().Next(0, 5)],
  177. // SplitMeals_CookType_2 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  178. // SplitMeals_CreditCardCount_3 = new Random().Next(0, 100),
  179. // SplitMeals_CreditCardNameBefore_3 = name_XM[new Random().Next(0, 5)],
  180. // SplitMeals_CreditCardName_3 = name_XM[new Random().Next(0, 5)],
  181. // SplitMeals_CookType_3 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  182. // SplitMeals_CreditCardCount_4 = new Random().Next(0, 100),
  183. // SplitMeals_CreditCardNameBefore_4 = name_XM[new Random().Next(0, 5)],
  184. // SplitMeals_CreditCardName_4 = name_XM[new Random().Next(0, 5)],
  185. // SplitMeals_CookType_4 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  186. // SplitMeals_CreditCardCount_5 = new Random().Next(0, 100),
  187. // SplitMeals_CreditCardNameBefore_5 = name_XM[new Random().Next(0, 5)],
  188. // SplitMeals_CreditCardName_5 = name_XM[new Random().Next(0, 5)],
  189. // SplitMeals_CookType_5 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  190. // SplitMeals_CreditCardCount_6 = new Random().Next(0, 100),
  191. // SplitMeals_CreditCardNameBefore_6 = name_XM[new Random().Next(0, 5)],
  192. // SplitMeals_CreditCardName_6 = name_XM[new Random().Next(0, 5)],
  193. // SplitMeals_CookType_6 = new List<string>() { "回锅肉", "烂肉豇豆", "火爆腰花" },
  194. //};
  195. string message = JsonConvert.SerializeObject(sendScreenData);
  196. mqttHelper.Publish(ScreenTOPIC.GetInstance.GetTopic(ScreenDeviceType.分餐机), message);
  197. }
  198. }
  199. }