终端一体化运控平台
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

144 satır
6.2 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. observableCollection.Add(new MorkOrder()
  54. {
  55. OrderPush = morkOrderpush,
  56. OrderStatus = ORDER_STATUS.WAIT,
  57. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  58. });
  59. //var res = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.DeviceId == device.ToString());
  60. //if (res == null)
  61. //{
  62. Application.Current?.Dispatcher.BeginInvoke((Action)delegate
  63. {
  64. Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
  65. {
  66. DeviceId = device.ToString(),
  67. IsAllSelect = true,
  68. morkOrderPushes = observableCollection,
  69. });
  70. orderStatusLists.Add(new MorkOrder()
  71. {
  72. OrderPush = morkOrderpush,
  73. OrderStatus = ORDER_STATUS.WAIT,
  74. StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
  75. });
  76. });
  77. //}
  78. //else
  79. //{
  80. // res.morkOrderPushes.Add(new MorkOrder() { OrderPush = morkOrderpush });
  81. //}
  82. }
  83. }
  84. }
  85. }), "AddOrder");
  86. ActionManage.GetInstance.Register(new Action<object>((o) =>
  87. {
  88. if (o is OrderStatusChangedEvent orderStatusChange)
  89. {
  90. int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  91. switch (orderStatusChange.Status)
  92. {
  93. case ORDER_STATUS.COOKING:
  94. if (index >= 0 && index < orderStatusLists.Count)
  95. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  96. break;
  97. case ORDER_STATUS.COMPLETED_COOK:
  98. if (index >= 0 && index < orderStatusLists.Count)
  99. {
  100. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  101. {
  102. orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
  103. orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
  104. TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
  105. orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
  106. WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
  107. orderStatusLists.RemoveAt(index);
  108. });
  109. }
  110. break;
  111. case ORDER_STATUS.COMPLETED_TAKE:
  112. var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
  113. if (re != null)
  114. {
  115. Application.Current.Dispatcher.BeginInvoke((Action)delegate
  116. {
  117. WaitTakeMeal.Remove(re);
  118. var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
  119. if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
  120. });
  121. }
  122. break;
  123. default:
  124. break;
  125. }
  126. }
  127. }), "OrderStatusChange");
  128. }
  129. }
  130. }