|
- using BPA.Helper;
- using BPA.Message.Enum;
- using BPA.Message;
- using BPASmartClient.Model;
- using BPASmartClient.Model.煮面机;
- using BPASmartClient.ViewModel;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Windows;
- using Org.BouncyCastle.Asn1.Crmf;
- using System.Collections.Concurrent;
- using System.Threading.Tasks;
- using System.Threading;
- using BPASmartClient.CustomResource.Converters;
- using System.Security.RightsManagement;
- using System.Net;
-
- namespace BPASmartClient
- {
- public class NoodOrderCtrl : NotifyBase
- {
- private static NoodOrderCtrl _instance;
- public static NoodOrderCtrl GetInstance { get; set; } = _instance ??= new NoodOrderCtrl();
- public Action<FoodMenuModel>? orderStatusAction;
- public Action<FoodMenuModel>? editRecipeAction;
- public ConcurrentDictionary<string, FrameworkElement> allViews = new ConcurrentDictionary<string, FrameworkElement>();
- public Action<string>? showInfo;
- public string stateInfo { get; set; } = "";
- public Action<string>? StateInfo;
- public ObservableCollection<DoNoodle> doNoodles = new ObservableCollection<DoNoodle>();
- public FoodMenuModel LocalOrder { get; set; } = new FoodMenuModel();
- public Action? FlushNood;
- public DoNoodle doNFlush { get;set; }
- public void Flush(DoNoodle doN)
- {
- doNFlush = doN;
- FlushNood?.Invoke();
- }
- //public void CheckOrder(object o)
- //{
- // if (o is string x)
- // {
- // var res = FoodMenuViewModel.FoodMenus.FirstOrDefault(o => o.GoodName == x);
- // if (res != null)
- // OrderStatusViewModel.orderMenus.Add(res);
- // }
- //}
- public void Show(string info)
- {
- showInfo?.Invoke(info);
- }
- public void StateShow(string info)
- {
- StateInfo?.Invoke(info);
- stateInfo = info;
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Init()
- {
- for (int i = 0; i < 6; i++)
- {
- doNoodles.Add(new DoNoodle() { Reset = i + 1, Docook = false,BtnIsChecked = false});
- }
- for (int i = 0; i < 5; i++)
- {
- DeviceCtrlViewModel.CtrlTurns.Add(new CtrlTurn() { Set = $"{i + 1} 号位", UnderSet = false });
- }
- FoodMenuViewModel.FoodMenus.Clear();
- Json<NoodOrder>.Data.localOrder?.Keys?.ToList().ForEach(key => FoodMenuViewModel.FoodMenus.Add(new FoodMenuModel { GoodName = key, BowLoc = Json<NoodOrder>.Data.localOrder[key].Bowloc, NoodleLoc = Json<NoodOrder>.Data.localOrder[key].NoodleLoc, FrytimeMin = Json<NoodOrder>.Data.localOrder[key].FryTimeMin, FrytimeS = Json<NoodOrder>.Data.localOrder[key].FryTimeS }));
- Json<NoodOrder>.Data.localOrder.addItem = ((key, value) =>
- {
- FoodMenuViewModel.FoodMenus.Add(new FoodMenuModel { GoodName = key, BowLoc = value.Bowloc, NoodleLoc = value.NoodleLoc, FrytimeS = value.FryTimeS, FrytimeMin = value.FryTimeMin });
- });
- Json<NoodOrder>.Data.localOrder.removeItem = ((key, value) =>
- {
- var re = FoodMenuViewModel.FoodMenus.FirstOrDefault(o => o.GoodName == key);
- if (re != null)
- {
- FoodMenuViewModel.FoodMenus.Remove(re);
- }
- });
-
- if (FoodMenuViewModel.WaitTakeMeal.Count > 0)
- {
- FoodMenuViewModel.SortNum = FoodMenuViewModel.WaitTakeMeal.Count + 1;
- }
- }
- //public void RemoveOrder(object o)
- //{
- // if (o is string re)
- // {
- // var res = OrderStatusViewModel.orderMenus.FirstOrDefault(o => o.GoodName == re);
- // if (res != null)
- // OrderStatusViewModel.orderMenus.Remove(res);
- // }
- //}
- /// <summary>
- /// 开始制作
- /// </summary>
- /// <param name="localOrder"></param>
- /// <param name="amount"></param>
- public void StartOrder(FoodMenuModel localOrder, int amount)
- {
- if (amount > 0 && !string.IsNullOrEmpty(localOrder.GoodName))
- {
- MorksSimorderModel res = Json<NoodOrder>.Data.localOrder[localOrder.GoodName];
- if (res != null)
- {
- ObservableCollection<MorkOrder> morks = new ObservableCollection<MorkOrder>();
- for (int i = 0; i < amount; i++)
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- morks.Add(new MorkOrder()
- {
- OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum },
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("HH:mm:ss"),
- FoodMenuModel = localOrder
- });
- #region 展示使用
- //if (FoodMenuViewModel.orderStatusLists.Count == 0)
- //{
- // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
- // {
- // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
- // OrderStatus = ORDER_STATUS.COMPLETED_COOK,
- // StartDate = DateTime.Now.ToString("HH:mm:ss"),
- // FoodMenuModel = localOrder
- // });
- //}
- //else if (FoodMenuViewModel.orderStatusLists.Count == 1)
- //{
- // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
- // {
- // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
- // OrderStatus = ORDER_STATUS.COOKING,
- // StartDate = DateTime.Now.ToString("HH:mm:ss"),
- // FoodMenuModel = localOrder
- // });
- //}
- //else if (FoodMenuViewModel.orderStatusLists.Count == 2)
- //{
- // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
- // {
- // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
- // OrderStatus = ORDER_STATUS.COOKING,
- // StartDate = DateTime.Now.ToString("HH:mm:ss"),
- // FoodMenuModel = localOrder
- // });
- //}
- //else
- //{
- // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
- // {
- // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
- // OrderStatus = ORDER_STATUS.WAIT,
- // StartDate = DateTime.Now.ToString("HH:mm:ss"),
- // FoodMenuModel = localOrder
- // });
- //}
- #endregion
- FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
- {
- OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
- OrderStatus = ORDER_STATUS.WAIT,
- StartDate = DateTime.Now.ToString("HH:mm:ss"),
- FoodMenuModel = localOrder
- });
-
- });
- Json<NoodOrder>.Data.localOrder[localOrder.GoodName].Publish();
- }
- Show($"成功下发{localOrder.GoodName}!共{amount}单!");
- ActionManage.GetInstance.Send("EnableForOrder", morks);
-
- }
-
- }
- else
- {
- Show($"请选择后下单");
- }
- }
- /// <summary>
- /// 选择配方
- /// </summary>
- /// <param name="o"></param>
- public void EditOrder(object o)
- {
- if (o is string re)
- {
- if (Json<NoodOrder>.Data.localOrder.ContainsKey(re))
- {
- var res = Json<NoodOrder>.Data.localOrder[re];
- if (res != null)
- {
- LocalOrder = new FoodMenuModel() { GoodName = re, NoodleLoc = res.NoodleLoc, BowLoc = res.Bowloc, FrytimeMin = res.FryTimeMin, FrytimeS = res.FryTimeS };
- orderStatusAction?.Invoke(LocalOrder);
- editRecipeAction?.Invoke(LocalOrder);
- }
- }
-
- }
- }
- /// <summary>
- /// 取消订单
- /// </summary>
- /// <param name="o"></param>
- public void ExitOrder(object o)
- {
- Task.Factory.StartNew(() =>
- {
- Thread.Sleep(500);
- if (o is string re)
- {
- var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SortNum == Convert.ToInt32(re) && o.OrderStatus == ORDER_STATUS.WAIT);
- if (res != null)
- {
- Application.Current.Dispatcher.Invoke(() =>
- {
- res.OrderStatus = ORDER_STATUS.UNABLE_COOK;
- Json<NoodOrder>.Data.historyOrderLists.Insert(0, res);
- FoodMenuViewModel.WaitTakeMeal.Insert(0, res);
- FoodMenuViewModel.orderStatusLists.Remove(res);
- Show("成功取消订单!!!");
- });
- }
- else
- {
- var res_1 = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SortNum == Convert.ToInt32(re));
- if (res_1 != null)
- {
- Show($"当前订单处于{StatusConvert(res_1.OrderStatus)}状态");
- }
- else
- {
- Show($"订单异常");
- }
- }
- }
- });
-
- }
- /// <summary>
- /// 订单状态展示
- /// </summary>
- /// <param name="sTATUS"></param>
- /// <returns></returns>
- public string StatusConvert(ORDER_STATUS sTATUS)
- {
- switch (sTATUS)
- {
- case ORDER_STATUS.WAIT:
- return "等待制作";
- case ORDER_STATUS.COOKING:
- return "正在制作";
- case ORDER_STATUS.COMPLETED_COOK:
- return "制作完成";
- case ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING:
- return "制作超时";
- default:
- return "异常";
- }
- }
- /// <summary>
- /// 保存配方
- /// </summary>
- /// <param name="order"></param>
- public void SaveRecipe(FoodMenuModel order)
- {
- if (!string.IsNullOrEmpty(order.GoodName))
- {
- if (Json<NoodOrder>.Data.localOrder.ContainsKey(order.GoodName))
- {
- Json<NoodOrder>.Data.localOrder.ReMove(order.GoodName);
- Json<NoodOrder>.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 });
- Json<NoodOrder>.Save();
- Show("已更改!");
- }
- else
- {
- Json<NoodOrder>.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 });
- Json<NoodOrder>.Save();
- Show("已添加!");
- }
- }
- else
- {
- Show("请输入配方名称!!!");
- }
-
- }
- //public void NewRecipe(LocalOrder order)
- //{
- // if (!Json<NoodOrder>.Data.localOrder.ContainsKey(order.Name))
- // {
- // Json<NoodOrder>.Data.localOrder.Add(order.Name, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.Bowloc, FryTime = order.FryTime });
- // }
- // else
- // {
- // MessageBox.Show("已存在该菜品,请注意菜品名称", "提示", MessageBoxButton.OK);
- // }
- //}
- public void DeleteRecipe(object o)
- {
- if (o is string re)
- {
- if (Json<NoodOrder>.Data.localOrder.ContainsKey(re))
- {
- Json<NoodOrder>.Data.localOrder.ReMove(re);
- Show("已删除!");
- }
- else
- {
- MessageBox.Show("未找到本地菜品", "提示", MessageBoxButton.OK);
- }
-
- }
-
- }
-
-
- public void statusList(MorkOrder res)
- {
- Application.Current.Dispatcher.Invoke(() => {
- FoodMenuViewModel.orderStatusLists.Remove(res);
- res.OrderStatus = ORDER_STATUS.COMPLETED_COOK;
- res.EndDate = DateTime.Now.ToString("HH:mm:ss");
- FoodMenuViewModel.WaitTakeMeal.Insert(0, res);
- Json<NoodOrder>.Data.historyOrderLists.Insert(0,res);
- });
- }
- public void WorkList(MorkOrder res)
- {
- Application.Current.Dispatcher.Invoke(() => {
- res.OrderPush.SuborderId = Guid.NewGuid().ToString();
- });
- }
- public Task FinishOrder(MorkOrder res)
- {
- return Task.Factory.StartNew(() =>
- {
- Thread.Sleep(2000);
- Application.Current.Dispatcher.Invoke(() =>
- {
- FoodMenuViewModel.WaitTakeMeal.Remove(res);
- });
- });
- }
- }
- }
|