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

MainControlViewModel.cs 9.8 KiB

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