终端一体化运控平台
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

154 行
6.6 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 BPA.Helper;
  12. using BPASmartClient.Model;
  13. using BPA.Helper;
  14. namespace BPASmartClient.ViewModel
  15. {
  16. public class OrderStatusViewModel : NotifyBase
  17. {
  18. public OrderStatusViewModel()
  19. {
  20. }
  21. /// <summary>
  22. /// 订单状态列表
  23. /// </summary>
  24. public static ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();
  25. /// <summary>
  26. /// 等待取餐列表
  27. /// </summary>
  28. public static ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>();
  29. /// <summary>
  30. /// MQTT 大屏取餐通知委托
  31. /// </summary>
  32. public static void Init()
  33. {
  34. //清除订单数据
  35. ActionManage.GetInstance.Register(new Action(() =>
  36. {
  37. Application.Current.Dispatcher.Invoke(() =>
  38. {
  39. orderStatusLists.Clear();
  40. WaitTakeMeal.Clear();
  41. });
  42. }), "ClearOrders");
  43. ActionManage.GetInstance.Register(new Action<object[]>((o) =>
  44. {
  45. if (o is object[] obj)
  46. {
  47. if (o.Length == 2)
  48. {
  49. if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
  50. {
  51. ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
  52. MorkOrder morkOrder = new MorkOrder()
  53. {
  54. OrderPush = morkOrderpush,
  55. OrderStatus = ORDER_STATUS.WAIT,
  56. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  57. };
  58. observableCollection.Add(morkOrder);
  59. Application.Current?.Dispatcher.BeginInvoke((Action)delegate
  60. {
  61. int index = Array.FindIndex(Json<KeepDataBase>.Data.orderLists.ToArray(), p => p.DeviceId == device.DeviceId.ToString());
  62. if (index < 0)
  63. {
  64. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  65. {
  66. DeviceId = device.DeviceId.ToString(),
  67. IsAllSelect = true,
  68. morkOrderPushes = observableCollection,
  69. });
  70. }
  71. else
  72. {
  73. Json<KeepDataBase>.Data.orderLists.ElementAt(index).morkOrderPushes.Add(morkOrder);
  74. }
  75. orderStatusLists.Add(new MorkOrder()
  76. {
  77. OrderPush = morkOrderpush,
  78. OrderStatus = ORDER_STATUS.WAIT,
  79. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  80. });
  81. });
  82. }
  83. }
  84. }
  85. }), "AddOrder");
  86. EventBus.GetInstance.Subscribe<OrderStatusChangedEvent>(0, OrderStatusChangedHandle);
  87. }
  88. private static void OrderStatusChangedHandle(IEvent @event, EventBus.EventCallBackHandle callBack)
  89. {
  90. OrderStatusChangedEvent orderStatusChange = @event as OrderStatusChangedEvent;
  91. int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  92. switch (orderStatusChange.Status)
  93. {
  94. case ORDER_STATUS.COOKING:
  95. if (index >= 0 && index < orderStatusLists.Count)
  96. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  97. break;
  98. case ORDER_STATUS.COMPLETED_COOK:
  99. if (index >= 0 && index < orderStatusLists.Count)
  100. {
  101. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  102. {
  103. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  104. orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
  105. TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
  106. orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
  107. //压力测试时注释,正常使用需要取消注释
  108. if (!BPASmartClient.Business.InternetInfo.IsEnableTest)
  109. {
  110. WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
  111. orderStatusLists.RemoveAt(index);
  112. }
  113. });
  114. }
  115. break;
  116. case ORDER_STATUS.COMPLETED_TAKE:
  117. if (BPASmartClient.Business.InternetInfo.IsEnableTest && index >= 0 && index < orderStatusLists.Count)
  118. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  119. //压力测试时注释,正常使用需要取消注释
  120. var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  121. if (re != null)
  122. {
  123. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  124. {
  125. WaitTakeMeal.Remove(re);
  126. var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
  127. if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
  128. });
  129. }
  130. break;
  131. default:
  132. break;
  133. }
  134. }
  135. }
  136. }