终端一体化运控平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 

247 рядки
8.1 KiB

  1. using BPA.CustomResource.UserControls;
  2. using BPA.Helper;
  3. using BPA.Message;
  4. using BPA.Message.Enum;
  5. using Newtonsoft.Json;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Text;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. namespace BPASmartClient.ScreenLib
  14. {
  15. public class ScreenALLControlViewModel : NotifyBase
  16. {
  17. #region 变量
  18. /// <summary>
  19. /// 广告地址
  20. /// </summary>
  21. public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } }
  22. private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString());
  23. /// <summary>
  24. /// 界面数据绑定
  25. /// </summary>
  26. public Dictionary<ScreenDeviceType, object> ViewData
  27. {
  28. get { return _ViewData; }
  29. set
  30. {
  31. _ViewData = value;
  32. OnPropertyChanged();
  33. }
  34. }
  35. private Dictionary<ScreenDeviceType, object> _ViewData = new Dictionary<ScreenDeviceType, object>();
  36. /// <summary>
  37. /// 小炒总数
  38. /// </summary>
  39. public int MinCout
  40. {
  41. get { return _MinCout; }
  42. set
  43. {
  44. _MinCout = value;
  45. OnPropertyChanged();
  46. }
  47. }
  48. private int _MinCout = 0;
  49. /// <summary>
  50. /// 大炒总数
  51. /// </summary>
  52. public int MaxCout
  53. {
  54. get { return _MaxCout; }
  55. set
  56. {
  57. _MaxCout = value;
  58. OnPropertyChanged();
  59. }
  60. }
  61. private int _MaxCout = 0;
  62. /// <summary>
  63. /// 分餐区总数
  64. /// </summary>
  65. public int SplitMealsCout
  66. {
  67. get { return _SplitMealsCout; }
  68. set
  69. {
  70. _SplitMealsCout = value;
  71. OnPropertyChanged();
  72. }
  73. }
  74. private int _SplitMealsCout = 0;
  75. /// <summary>
  76. /// 日总接待人数
  77. /// </summary>
  78. public int UserCout
  79. {
  80. get { return _UserCout; }
  81. set
  82. {
  83. _UserCout = value;
  84. OnPropertyChanged();
  85. }
  86. }
  87. private int _UserCout = 0;
  88. /// <summary>
  89. /// 累计故障数
  90. /// </summary>
  91. public int GZallCout
  92. {
  93. get { return _GZallCout; }
  94. set
  95. {
  96. _GZallCout = value;
  97. OnPropertyChanged();
  98. }
  99. }
  100. private int _GZallCout = 0;
  101. /// <summary>
  102. /// 总告警列表
  103. /// </summary>
  104. public ObservableCollection<AlarmModel> AlarmAll
  105. {
  106. get { return _AlarmAll; }
  107. set
  108. {
  109. _AlarmAll = value;
  110. OnPropertyChanged();
  111. }
  112. }
  113. private ObservableCollection<AlarmModel> _AlarmAll =new ObservableCollection<AlarmModel>();
  114. /// <summary>
  115. /// 今日商品热销统计
  116. /// </summary>
  117. public ObservableCollection<StatsAllModel> StatsCountAll
  118. {
  119. get { return _StatsBFB; }
  120. set
  121. {
  122. _StatsBFB = value;
  123. OnPropertyChanged();
  124. }
  125. }
  126. private ObservableCollection<StatsAllModel> _StatsBFB = new ObservableCollection<StatsAllModel>();
  127. #endregion
  128. public ScreenALLControlViewModel()
  129. {
  130. Init();
  131. }
  132. /// <summary>
  133. /// 初始化
  134. /// </summary>
  135. public void Init()
  136. {
  137. ThreadManage.GetInstance().StartLong(new Action(() =>
  138. {
  139. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  140. {
  141. ViewData = Main.GetInstance.mqttDatasDic;
  142. List<AlarmModel> alarms = new List<AlarmModel>();
  143. List<StatsModel> Stats = new List<StatsModel>();
  144. foreach (var item in Main.GetInstance.mqttDatasDic)
  145. {
  146. if (item.Value != null)
  147. {
  148. if((item.Value as ScreenModelBase).Alarm!=null)
  149. alarms.AddRange((item.Value as ScreenModelBase).Alarm);
  150. if ((item.Value as ScreenModelBase).StatsCount != null)
  151. Stats.AddRange((item.Value as ScreenModelBase).StatsCount);
  152. }
  153. }
  154. AlarmAll.Clear();
  155. alarms?.OrderByDescending(k => DateTime.Parse(k.AlarmTime))?.ToList().ForEach(alarm => {
  156. AlarmAll.Add(alarm);
  157. });
  158. int gz = 0;
  159. if (ViewData.ContainsKey(ScreenDeviceType.小炒))
  160. {
  161. ScreenModelMinWok min = ViewData[ScreenDeviceType.小炒] as ScreenModelMinWok;
  162. MinCout = min.MinWok_OrderCount_1 + min.MinWok_OrderCount_2;
  163. gz += min.FailuresCount;
  164. }
  165. if (ViewData.ContainsKey(ScreenDeviceType.大炒))
  166. {
  167. ScreenModelMaxWok min = ViewData[ScreenDeviceType.大炒] as ScreenModelMaxWok;
  168. MaxCout = min.MaxWok_OrderCount_1 + min.MaxWok_OrderCount_2;
  169. gz += min.FailuresCount;
  170. }
  171. if (ViewData.ContainsKey(ScreenDeviceType.分餐机))
  172. {
  173. ScreenModelSplitMeals min = ViewData[ScreenDeviceType.分餐机] as ScreenModelSplitMeals;
  174. SplitMealsCout = min.SplitMeals_CreditCardCount_1 + min.SplitMeals_CreditCardCount_2
  175. + min.SplitMeals_CreditCardCount_3 + min.SplitMeals_CreditCardCount_4
  176. + min.SplitMeals_CreditCardCount_5 + min.SplitMeals_CreditCardCount_6;
  177. gz += min.FailuresCount;
  178. }
  179. int zmj_count = 0;
  180. if (ViewData.ContainsKey(ScreenDeviceType.煮面机))
  181. {
  182. ScreenModelMorkS morks = ViewData[ScreenDeviceType.煮面机] as ScreenModelMorkS;
  183. zmj_count = morks.MorkS_OrderCount;
  184. gz += morks.FailuresCount;
  185. }
  186. UserCout = SplitMealsCout + MaxCout + MinCout + zmj_count;
  187. GZallCout = gz;
  188. if (Stats != null && Stats.Count > 0)
  189. {
  190. Dictionary<string, int> _Stats = new Dictionary<string, int>();
  191. foreach (StatsModel item in Stats)
  192. {
  193. if(!_Stats.ContainsKey(item.Name))
  194. _Stats[item.Name]= item.Count;
  195. else
  196. _Stats[item.Name] += item.Count;
  197. }
  198. List<StatsAllModel> _Statsall = new List<StatsAllModel>();
  199. _Stats?.ToList().ForEach(par => {
  200. _Statsall.Add(new StatsAllModel { Name = par.Key,Count = par.Value });
  201. });
  202. int maxcount = _Statsall.Max(k => k.Count);
  203. _Statsall?.ForEach(par =>
  204. {
  205. par.bfb = (int)(((double)par.Count / (double)maxcount) * 100.0);
  206. });
  207. string str = JsonConvert.SerializeObject(_Statsall?.OrderByDescending(k => k.Count)?.ToList());
  208. StatsCountAll= JsonConvert.DeserializeObject<ObservableCollection<StatsAllModel>>(str);
  209. }
  210. }));
  211. Thread.Sleep(2000);
  212. }), $"{DateTime.Now},线程服务");
  213. }
  214. }
  215. public class StatsAllModel: StatsModel
  216. {
  217. public int bfb { get; set; }
  218. }
  219. }