终端一体化运控平台
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.
 
 
 

209 lignes
10 KiB

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