终端一体化运控平台
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

155 rindas
6.7 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. }
  89. private static void OrderStatusChangedHandle(IEvent @event, EventBus.EventBus.EventCallBackHandle callBack)
  90. {
  91. OrderStatusChangedEvent orderStatusChange = @event as OrderStatusChangedEvent;
  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 && index >= 0 && index < orderStatusLists.Count)
  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. }
  137. }