|
- using BPA.Helper;
- using BPASmartClient.Model;
- using BPASmartClient.Model.小炒机;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using BPASmartClient.CustomResource.UserControls.MessageShow;
- using BPASmartClient.CustomResource.UserControls;
- using BPA.Message.Enum;
- using BPA.Message;
- using BPASmartClient.Device;
- using System.Threading;
- using BPASmartClient.CustomResource.Pages.Model;
- using BPASmartClient.Business;
- using BPASmartClient.Model.煮面机;
- using System.Windows.Controls;
- using static Opc.Ua.RelativePathFormatter;
- using SqlSugar;
- using Microsoft.Windows.Themes;
-
- namespace BPASmartClient.ViewModel
- {
- public class FoodMenuViewModel: NotifyBase
- {
- /// <summary>
- /// 菜单
- ///
- ///
- /// </summary>
- public static ObservableCollection<FoodMenuModel> FoodMenus { get; set; } = new ObservableCollection<FoodMenuModel>();
- public static int SortNum { get; set; } = 1;
- public static ObservableCollection<MorkOrder> orderStatusLists { get; set; } = new ObservableCollection<MorkOrder>();
- public ObservableCollection<MorkOrder> history { get; set; } = new ObservableCollection<MorkOrder>();
- /// <summary>
- /// 当天显示
- /// </summary>
- public static ObservableCollection<MorkOrder> WaitTakeMeal { get; set; } = new ObservableCollection<MorkOrder>(Json<NoodOrder>.Data.historyOrderLists.Where(o => o.Date.Day == DateTime.Now.Day));
- public FoodMenuViewModel()
- {
- SearCh = new BPARelayCommand(() =>
- {
- int re = SearchDate.Day;
- history.Clear();
- if (re<=DateTime.Now.Day)
- {
- var res = Json<NoodOrder>.Data.historyOrderLists.Where(o => o.Date.Day == SearchDate.Day);
- if (res != null && res.ToList().Count > 0)
- {
- res.ToList().ForEach(o => { history.Add(o); });
- }
- else
- {
- NoodOrderCtrl.GetInstance.Show("未查询到当日订单!");
- }
- }
- else
- {
- NoodOrderCtrl.GetInstance.Show("超出当前日期,请重新选择时间!");
- }
- });
- }
- public BPARelayCommand SearCh { get; set; }
-
-
- public DateTime SearchDate{get { return _searchDate; }set { _searchDate = value; OnPropertyChanged(); }}
- private DateTime _searchDate = DateTime.Now;
-
-
- /// <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>();
- MorkOrder morkOrder = new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("HH:mm:ss"),
- };
- observableCollection.Add(morkOrder);
- Application.Current?.Dispatcher.BeginInvoke((Action)delegate
- {
- int index = Array.FindIndex(Json<KeepDataBase>.Data.orderLists.ToArray(), p => p.DeviceId == device.DeviceId.ToString());
- if (index < 0)
- {
- Json<KeepDataBase>.Data.orderLists.Add(new OrderData()
- {
- DeviceId = device.DeviceId.ToString(),
- IsAllSelect = true,
- morkOrderPushes = observableCollection,
-
- });
- }
- else
- {
- Json<KeepDataBase>.Data.orderLists.ElementAt(index).morkOrderPushes.Add(morkOrder);
- }
-
- orderStatusLists.Insert(0,new MorkOrder()
- {
- OrderPush = morkOrderpush,
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("HH:mm:ss"),
- });
- });
- //if (orderStatusLists.Count > 0)
- //{
- // orderStatusLists[0].OrderStatus = ORDER_STATUS.COOKING;
- //}
-
- }
- }
- }
-
- }), "AddOrder");
-
- EventBus.GetInstance().Subscribe<OrderStatusChangedEvent>(0, OrderStatusChangedHandle);
-
- }
-
- private static void OrderStatusChangedHandle(IEvent @event, EventBus.EventCallBackHandle callBack)
- {
- OrderStatusChangedEvent orderStatusChange = @event as OrderStatusChangedEvent;
- 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";
-
- //压力测试时注释,正常使用需要取消注释
- if (!BPASmartClient.Business.InternetInfo.IsEnableTest)
- {
- WaitTakeMeal.Insert(0, orderStatusLists.ElementAt(index));
- orderStatusLists.RemoveAt(index);
- }
- });
- }
-
- break;
- case ORDER_STATUS.COMPLETED_TAKE:
- if (BPASmartClient.Business.InternetInfo.IsEnableTest && index >= 0 && index < orderStatusLists.Count)
- orderStatusLists.ElementAt(index).OrderStatus = orderStatusChange.Status;
-
- //压力测试时注释,正常使用需要取消注释
- 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;
-
- }
- }
-
- }
- }
|