|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using BPA.Message;
- using BPA.Message.Enum;
- using BPASmartClient.Device;
- using BPASmartClient.EventBus;
- using BPASmartClient.Helper;
- using BPASmartClient.Model;
- using Microsoft.Toolkit.Mvvm.ComponentModel;
-
- namespace BPASmartClient.ViewModel
- {
- public class OrderStatusViewModel : ObservableObject
- {
- public OrderStatusViewModel()
- {
-
- }
-
- /// <summary>
- /// 订单状态列表
- /// </summary>
- public static ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();
-
- /// <summary>
- /// 等待取餐列表
- /// </summary>
- public static ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>();
-
- /// <summary>
- /// MQTT 大屏取餐通知委托
- /// </summary>
- public static void Init()
- {
- //清除订单数据
- //ActionManage.GetInstance.Register(new Action(() =>
- //{
- // Application.Current.Dispatcher.Invoke(() =>
- // {
- // orderStatusLists.Clear();
- // WaitTakeMeal.Clear();
- // });
- //}), "ClearOrders");
-
- ActionManage.GetInstance.Register(new Action<object[]>((o) =>
- {
- if (o is object[] obj)
- {
- if (o.Length == 2)
- {
- if (o[0] is MorkOrderPush morkOrderpush && o[1] is IDevice device)
- {
- ObservableCollection<MorkOrder> observableCollection = new ObservableCollection<MorkOrder>();
- observableCollection.Add(new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- });
- //var res = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.DeviceId == device.ToString());
- //if (res == null)
- //{
- Application.Current?.Dispatcher.BeginInvoke((Action)delegate
- {
- Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
- {
- DeviceId = device.ToString(),
- IsAllSelect = true,
- morkOrderPushes = observableCollection,
-
- });
- orderStatusLists.Add(new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
- });
- });
- //}
- //else
- //{
- // res.morkOrderPushes.Add(new MorkOrder() { OrderPush = morkOrderpush });
- //}
-
- }
- }
- }
-
- }), "AddOrder");
-
- ActionManage.GetInstance.Register(new Action<object>((o) =>
- {
- if (o is OrderStatusChangedEvent orderStatusChange)
- {
- int index = Array.FindIndex(orderStatusLists.ToArray(), p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
- switch (orderStatusChange.Status)
- {
- case ORDER_STATUS.COOKING:
- if (index >= 0 && index < orderStatusLists.Count)
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
- break;
- case ORDER_STATUS.COMPLETED_COOK:
- if (index >= 0 && index < orderStatusLists.Count)
- {
- Application.Current.Dispatcher.BeginInvoke((Action)delegate
- {
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
- orderStatusLists.ElementAt(index).EndDate = DateTime.Now.ToString("HH:mm:ss");
- TimeSpan timeSpan = DateTime.Now.Subtract(Convert.ToDateTime(orderStatusLists.ElementAt(index).StartDate));
- orderStatusLists.ElementAt(index).CompleteDate = $"{timeSpan.TotalSeconds.ToString("0.00")} S";
- WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
- orderStatusLists.RemoveAt(index);
- });
- }
-
- break;
- case ORDER_STATUS.COMPLETED_TAKE:
- var re = WaitTakeMeal.FirstOrDefault(p => p.OrderPush.SuborderId == orderStatusChange.SubOrderId);
- if (re != null)
- {
- Application.Current.Dispatcher.BeginInvoke((Action)delegate
- {
- WaitTakeMeal.Remove(re);
- var removeObj = Json<KeepDataBase>.Data.orderLists.FirstOrDefault(p => p.morkOrderPushes.FirstOrDefault(s => s.OrderPush.SuborderId == re.OrderPush.SuborderId) != null);
- if (removeObj != null) Json<KeepDataBase>.Data.orderLists.Remove(removeObj);
- });
- }
- break;
- default:
- break;
- }
- }
- }), "OrderStatusChange");
- }
-
-
- }
- }
|