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? orderStatusAction; public Action? editRecipeAction; public ConcurrentDictionary allViews = new ConcurrentDictionary(); public Action? showInfo; public string stateInfo { get; set; } = ""; public Action? StateInfo; public ObservableCollection doNoodles = new ObservableCollection(); 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; } /// /// 初始化 /// 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.Data.localOrder?.Keys?.ToList().ForEach(key => FoodMenuViewModel.FoodMenus.Add(new FoodMenuModel { GoodName = key, BowLoc = Json.Data.localOrder[key].Bowloc, NoodleLoc = Json.Data.localOrder[key].NoodleLoc, FrytimeMin = Json.Data.localOrder[key].FryTimeMin, FrytimeS = Json.Data.localOrder[key].FryTimeS })); Json.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.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); // } //} /// /// 开始制作 /// /// /// public void StartOrder(FoodMenuModel localOrder, int amount) { if (amount > 0 && !string.IsNullOrEmpty(localOrder.GoodName)) { MorksSimorderModel res = Json.Data.localOrder[localOrder.GoodName]; if (res != null) { ObservableCollection morks = new ObservableCollection(); 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.Data.localOrder[localOrder.GoodName].Publish(); } Show($"成功下发{localOrder.GoodName}!共{amount}单!"); ActionManage.GetInstance.Send("EnableForOrder", morks); } } else { Show($"请选择后下单"); } } /// /// 选择配方 /// /// public void EditOrder(object o) { if (o is string re) { if (Json.Data.localOrder.ContainsKey(re)) { var res = Json.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); } } } } /// /// 取消订单 /// /// 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.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($"订单异常"); } } } }); } /// /// 订单状态展示 /// /// /// 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 "异常"; } } /// /// 保存配方 /// /// public void SaveRecipe(FoodMenuModel order) { if (!string.IsNullOrEmpty(order.GoodName)) { if (Json.Data.localOrder.ContainsKey(order.GoodName)) { Json.Data.localOrder.ReMove(order.GoodName); Json.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 }); Json.Save(); Show("已更改!"); } else { Json.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 }); Json.Save(); Show("已添加!"); } } else { Show("请输入配方名称!!!"); } } //public void NewRecipe(LocalOrder order) //{ // if (!Json.Data.localOrder.ContainsKey(order.Name)) // { // Json.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.Data.localOrder.ContainsKey(re)) { Json.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.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); }); }); } } }