终端一体化运控平台
Não pode escolher mais do que 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.
 
 
 

243 linhas
9.5 KiB

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