终端一体化运控平台
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 

252 Zeilen
9.8 KiB

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