终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

201 lines
8.6 KiB

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