终端一体化运控平台
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

276 lignes
10 KiB

  1. //global using CommunityToolkit.Mvvm.Input;
  2. using BPA.Helper;
  3. namespace BPASmartClient.MilkWithTea.ViewModel
  4. {
  5. partial class MainControlViewModel : NotifyBase
  6. {
  7. /// <summary>
  8. /// 本地奶茶列表
  9. /// </summary>
  10. public ObservableCollection<LocalRecipe> localTeaWithMilks { get; set; } = Json<JsonLocalRecipes>.Data.localRecipes;
  11. /// <summary>
  12. /// 奶茶对应的原料列表
  13. /// </summary>
  14. public ObservableCollection<LocalMaterail> materialRecipes { get; set; } = new ObservableCollection<LocalMaterail>();
  15. /// <summary>
  16. /// 订单状态列表
  17. /// </summary>
  18. public ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();
  19. /// <summary>
  20. /// 等待取餐列表
  21. /// </summary>
  22. public ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>();
  23. /// <summary>
  24. /// 当前正在制作的奶茶
  25. /// </summary>
  26. public string CurrentGood { get { return _currentGood; } set { _currentGood = value; OnPropertyChanged(); } }
  27. private string _currentGood = "茉莉花茶";
  28. /// <summary>
  29. /// 奶茶制作百分比
  30. /// </summary>
  31. public string MakePercent { get { return _makePercent; } set { _makePercent = value; OnPropertyChanged(); } }
  32. private string _makePercent = "0";
  33. /// <summary>
  34. /// 奶茶制作百分比
  35. /// </summary>
  36. public LocalRecipe SelectedRecipe { get { return _selectedRecipe; } set { _selectedRecipe = value; OnPropertyChanged(); } }
  37. private LocalRecipe _selectedRecipe;
  38. ///// <summary>
  39. ///// 当前正在制作的奶茶
  40. ///// </summary>
  41. //[ObservableProperty]
  42. //private string _currentGood = "茉莉花茶";
  43. ///// <summary>
  44. ///// 奶茶制作百分比
  45. ///// </summary>
  46. //[ObservableProperty]
  47. //private string _makePercent = "0";
  48. //[ObservableProperty]
  49. //private LocalRecipe _selectedRecipe;
  50. /// <summary>
  51. /// 当前正在制作的奶茶
  52. /// </summary>
  53. public bool MakeEnable { get { return GLobal.makeEnable; } set { GLobal.makeEnable = value; OnPropertyChanged(); } }
  54. /// <summary>
  55. /// 本地奶茶制作
  56. /// </summary>
  57. //[BPARelayCommand]
  58. private void MakeGood()
  59. {
  60. if (SelectedRecipe == null) return;
  61. foreach (var item in SelectedRecipe.localMaterails)
  62. {
  63. var res = Json<JsonLocalRecipes>.Data.localMaterails.FirstOrDefault(p => p.MaterialID == item.MaterialID);
  64. if (res != null)
  65. {
  66. item.MaterialPosition = res.MaterialPosition;
  67. }
  68. else
  69. {
  70. MessageLog.GetInstance.ShowEx($"配料:{item.MaterialName}不存在,下单失败");
  71. return;
  72. }
  73. }
  74. ActionManage.GetInstance.Send("MakeGoods", SelectedRecipe);
  75. }
  76. public MainControlViewModel()
  77. {
  78. Init();
  79. MorkOrderPush morkOrderPush = new MorkOrderPush() { GoodsName = "珍珠奶茶", SortNum = 1 };
  80. MorkOrderPush morkOrderPush1 = new MorkOrderPush() { GoodsName = "茉莉花茶", SortNum = 2 };
  81. MorkOrderPush morkOrderPush2 = new MorkOrderPush() { GoodsName = "芝芝梅梅", SortNum = 3 };
  82. orderStatusLists.Add(new MorkOrder()
  83. {
  84. StartDate = "11:20",
  85. EndDate = "11:24",
  86. CompleteDate = "4",
  87. OrderStatus = ORDER_STATUS.COMPLETED_COOK,
  88. OrderPush = morkOrderPush
  89. });
  90. orderStatusLists.Add(new MorkOrder()
  91. {
  92. StartDate = "11:36",
  93. EndDate = "11:40",
  94. CompleteDate = "4",
  95. OrderStatus = ORDER_STATUS.COOKING,
  96. OrderPush = morkOrderPush1
  97. });
  98. orderStatusLists.Add(new MorkOrder()
  99. {
  100. StartDate = "10:33",
  101. EndDate = "10:28",
  102. CompleteDate = "5",
  103. OrderStatus = ORDER_STATUS.COMPLETED_TAKE,
  104. OrderPush = morkOrderPush2
  105. });
  106. }
  107. /// <summary>
  108. /// MQTT 大屏取餐通知委托
  109. /// </summary>
  110. public void Init()
  111. {
  112. //清除订单数据
  113. //ActionManage.GetInstance.Register(new Action(() =>
  114. //{
  115. // Application.Current.Dispatcher.Invoke(() =>
  116. // {
  117. // orderStatusLists.Clear();
  118. // WaitTakeMeal.Clear();
  119. // });
  120. //}), "ClearOrders");
  121. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  122. {
  123. if (o is object[] obj)
  124. {
  125. if (o.Length == 2)
  126. {
  127. if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
  128. {
  129. ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
  130. MorkOrder morkOrder = new MorkOrder()
  131. {
  132. OrderPush = morkOrderpush,
  133. OrderStatus = ORDER_STATUS.WAIT,
  134. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  135. };
  136. observableCollection.Add(morkOrder);
  137. Application.Current?.Dispatcher.BeginInvoke((Action)delegate
  138. {
  139. int index = Array.FindIndex(Json<KeepDataBase>.Data.orderLists.ToArray(), p => p.DeviceId == device.DeviceId.ToString());
  140. if (index < 0)
  141. {
  142. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  143. {
  144. DeviceId = device.DeviceId.ToString(),
  145. IsAllSelect = true,
  146. morkOrderPushes = observableCollection,
  147. });
  148. }
  149. else
  150. {
  151. Json<KeepDataBase>.Data.orderLists.ElementAt(index).morkOrderPushes.Add(morkOrder);
  152. }
  153. orderStatusLists.Add(new MorkOrder()
  154. {
  155. OrderPush = morkOrderpush,
  156. OrderStatus = ORDER_STATUS.WAIT,
  157. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  158. });
  159. });
  160. }
  161. }
  162. }
  163. }), "AddOrder");
  164. EventBus.GetInstance().Subscribe<OrderStatusChangedEvent>(0, OrderStatusChangedHandle);
  165. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  166. {
  167. if (o is object[] obj)
  168. {
  169. if (o.Length == 2)
  170. {
  171. CurrentGood = o[0].ToString();
  172. MakePercent = o[1].ToString();
  173. }
  174. }
  175. }), "奶茶制作进度");
  176. }
  177. private void OrderStatusChangedHandle(IEvent @event, EventBus.EventCallBackHandle callBack)
  178. {
  179. OrderStatusChangedEvent orderStatusChange = @event as OrderStatusChangedEvent;
  180. int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  181. switch (orderStatusChange.Status)
  182. {
  183. case ORDER_STATUS.COOKING:
  184. if (index >= 0 && index < orderStatusLists.Count)
  185. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  186. break;
  187. case ORDER_STATUS.COMPLETED_COOK:
  188. if (index >= 0 && index < orderStatusLists.Count)
  189. {
  190. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  191. {
  192. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  193. orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
  194. TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
  195. orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
  196. //压力测试时注释,正常使用需要取消注释
  197. if (!BPASmartClient.Business.InternetInfo.IsEnableTest)
  198. {
  199. WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
  200. orderStatusLists.RemoveAt(index);
  201. }
  202. });
  203. }
  204. break;
  205. case ORDER_STATUS.COMPLETED_TAKE:
  206. if (BPASmartClient.Business.InternetInfo.IsEnableTest && index >= 0 && index < orderStatusLists.Count)
  207. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  208. //压力测试时注释,正常使用需要取消注释
  209. var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  210. if (re != null)
  211. {
  212. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  213. {
  214. WaitTakeMeal.Remove(re);
  215. var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
  216. if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
  217. });
  218. }
  219. break;
  220. default:
  221. break;
  222. }
  223. }
  224. }
  225. }