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

359 line
15 KiB

  1. using BPA.Helper;
  2. using BPA.Message.Enum;
  3. using BPA.Message;
  4. using BPASmartClient.Model;
  5. using BPASmartClient.Model.煮面机;
  6. using BPASmartClient.ViewModel;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Collections.ObjectModel;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Windows;
  13. using Org.BouncyCastle.Asn1.Crmf;
  14. using System.Collections.Concurrent;
  15. using System.Threading.Tasks;
  16. using System.Threading;
  17. using BPASmartClient.CustomResource.Converters;
  18. using System.Security.RightsManagement;
  19. using System.Net;
  20. namespace BPASmartClient
  21. {
  22. public class NoodOrderCtrl : NotifyBase
  23. {
  24. private static NoodOrderCtrl _instance;
  25. public static NoodOrderCtrl GetInstance { get; set; } = _instance ??= new NoodOrderCtrl();
  26. public Action<FoodMenuModel>? orderStatusAction;
  27. public Action<FoodMenuModel>? editRecipeAction;
  28. public ConcurrentDictionary<string, FrameworkElement> allViews = new ConcurrentDictionary<string, FrameworkElement>();
  29. public Action<string>? showInfo;
  30. public string stateInfo { get; set; } = "";
  31. public Action<string>? StateInfo;
  32. public ObservableCollection<DoNoodle> doNoodles = new ObservableCollection<DoNoodle>();
  33. public FoodMenuModel LocalOrder { get; set; } = new FoodMenuModel();
  34. public Action? FlushNood;
  35. public DoNoodle doNFlush { get;set; }
  36. public void Flush(DoNoodle doN)
  37. {
  38. doNFlush = doN;
  39. FlushNood?.Invoke();
  40. }
  41. //public void CheckOrder(object o)
  42. //{
  43. // if (o is string x)
  44. // {
  45. // var res = FoodMenuViewModel.FoodMenus.FirstOrDefault(o => o.GoodName == x);
  46. // if (res != null)
  47. // OrderStatusViewModel.orderMenus.Add(res);
  48. // }
  49. //}
  50. public void Show(string info)
  51. {
  52. showInfo?.Invoke(info);
  53. }
  54. public void StateShow(string info)
  55. {
  56. StateInfo?.Invoke(info);
  57. stateInfo = info;
  58. }
  59. /// <summary>
  60. /// 初始化
  61. /// </summary>
  62. public void Init()
  63. {
  64. for (int i = 0; i < 6; i++)
  65. {
  66. doNoodles.Add(new DoNoodle() { Reset = i + 1, Docook = false,BtnIsChecked = false});
  67. }
  68. for (int i = 0; i < 5; i++)
  69. {
  70. DeviceCtrlViewModel.CtrlTurns.Add(new CtrlTurn() { Set = $"{i + 1} 号位", UnderSet = false });
  71. }
  72. FoodMenuViewModel.FoodMenus.Clear();
  73. 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 }));
  74. Json<NoodOrder>.Data.localOrder.addItem = ((key, value) =>
  75. {
  76. FoodMenuViewModel.FoodMenus.Add(new FoodMenuModel { GoodName = key, BowLoc = value.Bowloc, NoodleLoc = value.NoodleLoc, FrytimeS = value.FryTimeS, FrytimeMin = value.FryTimeMin });
  77. });
  78. Json<NoodOrder>.Data.localOrder.removeItem = ((key, value) =>
  79. {
  80. var re = FoodMenuViewModel.FoodMenus.FirstOrDefault(o => o.GoodName == key);
  81. if (re != null)
  82. {
  83. FoodMenuViewModel.FoodMenus.Remove(re);
  84. }
  85. });
  86. if (FoodMenuViewModel.WaitTakeMeal.Count > 0)
  87. {
  88. FoodMenuViewModel.SortNum = FoodMenuViewModel.WaitTakeMeal.Count + 1;
  89. }
  90. }
  91. //public void RemoveOrder(object o)
  92. //{
  93. // if (o is string re)
  94. // {
  95. // var res = OrderStatusViewModel.orderMenus.FirstOrDefault(o => o.GoodName == re);
  96. // if (res != null)
  97. // OrderStatusViewModel.orderMenus.Remove(res);
  98. // }
  99. //}
  100. /// <summary>
  101. /// 开始制作
  102. /// </summary>
  103. /// <param name="localOrder"></param>
  104. /// <param name="amount"></param>
  105. public void StartOrder(FoodMenuModel localOrder, int amount)
  106. {
  107. if (amount > 0 && !string.IsNullOrEmpty(localOrder.GoodName))
  108. {
  109. MorksSimorderModel res = Json<NoodOrder>.Data.localOrder[localOrder.GoodName];
  110. if (res != null)
  111. {
  112. ObservableCollection<MorkOrder> morks = new ObservableCollection<MorkOrder>();
  113. for (int i = 0; i < amount; i++)
  114. {
  115. Application.Current.Dispatcher.Invoke(() =>
  116. {
  117. morks.Add(new MorkOrder()
  118. {
  119. OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum },
  120. OrderStatus = ORDER_STATUS.WAIT,
  121. StartDate = DateTime.Now.ToString("HH:mm:ss"),
  122. FoodMenuModel = localOrder
  123. });
  124. #region 展示使用
  125. //if (FoodMenuViewModel.orderStatusLists.Count == 0)
  126. //{
  127. // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
  128. // {
  129. // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
  130. // OrderStatus = ORDER_STATUS.COMPLETED_COOK,
  131. // StartDate = DateTime.Now.ToString("HH:mm:ss"),
  132. // FoodMenuModel = localOrder
  133. // });
  134. //}
  135. //else if (FoodMenuViewModel.orderStatusLists.Count == 1)
  136. //{
  137. // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
  138. // {
  139. // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
  140. // OrderStatus = ORDER_STATUS.COOKING,
  141. // StartDate = DateTime.Now.ToString("HH:mm:ss"),
  142. // FoodMenuModel = localOrder
  143. // });
  144. //}
  145. //else if (FoodMenuViewModel.orderStatusLists.Count == 2)
  146. //{
  147. // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
  148. // {
  149. // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
  150. // OrderStatus = ORDER_STATUS.COOKING,
  151. // StartDate = DateTime.Now.ToString("HH:mm:ss"),
  152. // FoodMenuModel = localOrder
  153. // });
  154. //}
  155. //else
  156. //{
  157. // FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
  158. // {
  159. // OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
  160. // OrderStatus = ORDER_STATUS.WAIT,
  161. // StartDate = DateTime.Now.ToString("HH:mm:ss"),
  162. // FoodMenuModel = localOrder
  163. // });
  164. //}
  165. #endregion
  166. FoodMenuViewModel.orderStatusLists.Insert(0, new MorkOrder()
  167. {
  168. OrderPush = new MorkOrderPush() { DeviceId = res.DeviceId, GoodsName = localOrder.GoodName, SortNum = FoodMenuViewModel.SortNum++ },
  169. OrderStatus = ORDER_STATUS.WAIT,
  170. StartDate = DateTime.Now.ToString("HH:mm:ss"),
  171. FoodMenuModel = localOrder
  172. });
  173. });
  174. Json<NoodOrder>.Data.localOrder[localOrder.GoodName].Publish();
  175. }
  176. Show($"成功下发{localOrder.GoodName}!共{amount}单!");
  177. ActionManage.GetInstance.Send("EnableForOrder", morks);
  178. }
  179. }
  180. else
  181. {
  182. Show($"请选择后下单");
  183. }
  184. }
  185. /// <summary>
  186. /// 选择配方
  187. /// </summary>
  188. /// <param name="o"></param>
  189. public void EditOrder(object o)
  190. {
  191. if (o is string re)
  192. {
  193. if (Json<NoodOrder>.Data.localOrder.ContainsKey(re))
  194. {
  195. var res = Json<NoodOrder>.Data.localOrder[re];
  196. if (res != null)
  197. {
  198. LocalOrder = new FoodMenuModel() { GoodName = re, NoodleLoc = res.NoodleLoc, BowLoc = res.Bowloc, FrytimeMin = res.FryTimeMin, FrytimeS = res.FryTimeS };
  199. orderStatusAction?.Invoke(LocalOrder);
  200. editRecipeAction?.Invoke(LocalOrder);
  201. }
  202. }
  203. }
  204. }
  205. /// <summary>
  206. /// 取消订单
  207. /// </summary>
  208. /// <param name="o"></param>
  209. public void ExitOrder(object o)
  210. {
  211. Task.Factory.StartNew(() =>
  212. {
  213. Thread.Sleep(500);
  214. if (o is string re)
  215. {
  216. var res = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SortNum == Convert.ToInt32(re) && o.OrderStatus == ORDER_STATUS.WAIT);
  217. if (res != null)
  218. {
  219. Application.Current.Dispatcher.Invoke(() =>
  220. {
  221. res.OrderStatus = ORDER_STATUS.UNABLE_COOK;
  222. Json<NoodOrder>.Data.historyOrderLists.Insert(0, res);
  223. FoodMenuViewModel.WaitTakeMeal.Insert(0, res);
  224. FoodMenuViewModel.orderStatusLists.Remove(res);
  225. Show("成功取消订单!!!");
  226. });
  227. }
  228. else
  229. {
  230. var res_1 = FoodMenuViewModel.orderStatusLists.FirstOrDefault(o => o.OrderPush.SortNum == Convert.ToInt32(re));
  231. if (res_1 != null)
  232. {
  233. Show($"当前订单处于{StatusConvert(res_1.OrderStatus)}状态");
  234. }
  235. else
  236. {
  237. Show($"订单异常");
  238. }
  239. }
  240. }
  241. });
  242. }
  243. /// <summary>
  244. /// 订单状态展示
  245. /// </summary>
  246. /// <param name="sTATUS"></param>
  247. /// <returns></returns>
  248. public string StatusConvert(ORDER_STATUS sTATUS)
  249. {
  250. switch (sTATUS)
  251. {
  252. case ORDER_STATUS.WAIT:
  253. return "等待制作";
  254. case ORDER_STATUS.COOKING:
  255. return "正在制作";
  256. case ORDER_STATUS.COMPLETED_COOK:
  257. return "制作完成";
  258. case ORDER_STATUS.ERR_NOT_REPLY_WHEN_COOKING:
  259. return "制作超时";
  260. default:
  261. return "异常";
  262. }
  263. }
  264. /// <summary>
  265. /// 保存配方
  266. /// </summary>
  267. /// <param name="order"></param>
  268. public void SaveRecipe(FoodMenuModel order)
  269. {
  270. if (!string.IsNullOrEmpty(order.GoodName))
  271. {
  272. if (Json<NoodOrder>.Data.localOrder.ContainsKey(order.GoodName))
  273. {
  274. Json<NoodOrder>.Data.localOrder.ReMove(order.GoodName);
  275. Json<NoodOrder>.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 });
  276. Json<NoodOrder>.Save();
  277. Show("已更改!");
  278. }
  279. else
  280. {
  281. Json<NoodOrder>.Data.localOrder.Add(order.GoodName, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.BowLoc, FryTimeMin = order.FrytimeMin, FryTimeS = order.FrytimeS, DeviceId = 42 });
  282. Json<NoodOrder>.Save();
  283. Show("已添加!");
  284. }
  285. }
  286. else
  287. {
  288. Show("请输入配方名称!!!");
  289. }
  290. }
  291. //public void NewRecipe(LocalOrder order)
  292. //{
  293. // if (!Json<NoodOrder>.Data.localOrder.ContainsKey(order.Name))
  294. // {
  295. // Json<NoodOrder>.Data.localOrder.Add(order.Name, new Model.MorksSimorderModel() { NoodleLoc = order.NoodleLoc, Bowloc = order.Bowloc, FryTime = order.FryTime });
  296. // }
  297. // else
  298. // {
  299. // MessageBox.Show("已存在该菜品,请注意菜品名称", "提示", MessageBoxButton.OK);
  300. // }
  301. //}
  302. public void DeleteRecipe(object o)
  303. {
  304. if (o is string re)
  305. {
  306. if (Json<NoodOrder>.Data.localOrder.ContainsKey(re))
  307. {
  308. Json<NoodOrder>.Data.localOrder.ReMove(re);
  309. Show("已删除!");
  310. }
  311. else
  312. {
  313. MessageBox.Show("未找到本地菜品", "提示", MessageBoxButton.OK);
  314. }
  315. }
  316. }
  317. public void statusList(MorkOrder res)
  318. {
  319. Application.Current.Dispatcher.Invoke(() => {
  320. FoodMenuViewModel.orderStatusLists.Remove(res);
  321. res.OrderStatus = ORDER_STATUS.COMPLETED_COOK;
  322. res.EndDate = DateTime.Now.ToString("HH:mm:ss");
  323. FoodMenuViewModel.WaitTakeMeal.Insert(0, res);
  324. Json<NoodOrder>.Data.historyOrderLists.Insert(0,res);
  325. });
  326. }
  327. public void WorkList(MorkOrder res)
  328. {
  329. Application.Current.Dispatcher.Invoke(() => {
  330. res.OrderPush.SuborderId = Guid.NewGuid().ToString();
  331. });
  332. }
  333. public Task FinishOrder(MorkOrder res)
  334. {
  335. return Task.Factory.StartNew(() =>
  336. {
  337. Thread.Sleep(2000);
  338. Application.Current.Dispatcher.Invoke(() =>
  339. {
  340. FoodMenuViewModel.WaitTakeMeal.Remove(res);
  341. });
  342. });
  343. }
  344. }
  345. }