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

237 lines
9.3 KiB

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