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

251 line
8.3 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. TaskManage.GetInstance.StartLong(new Action(() =>
  138. {
  139. System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
  140. {
  141. ViewData = Main.GetInstance.mqttDatasDic;
  142. //所有告警
  143. List<AlarmModel> alarms = new List<AlarmModel>();
  144. //所有统计
  145. List<StatsModel> Stats = new List<StatsModel>();
  146. foreach (var item in Main.GetInstance.mqttDatasDic)
  147. {
  148. if (item.Value != null)
  149. {
  150. if((item.Value as ScreenModelBase).Alarm!=null)
  151. alarms.AddRange((item.Value as ScreenModelBase).Alarm);
  152. if ((item.Value as ScreenModelBase).StatsCount != null)
  153. Stats.AddRange((item.Value as ScreenModelBase).StatsCount);
  154. }
  155. }
  156. AlarmAll.Clear();
  157. alarms?.OrderByDescending(k => DateTime.Parse(k.AlarmTime))?.ToList().ForEach(alarm => {
  158. AlarmAll.Add(alarm);
  159. });
  160. int gz = 0;
  161. if (ViewData.ContainsKey(ScreenDeviceType.小炒))
  162. {
  163. ScreenModelMinWok min = ViewData[ScreenDeviceType.小炒] as ScreenModelMinWok;
  164. MinCout = min.MinWok_OrderCount_1 + min.MinWok_OrderCount_2;
  165. gz += min.FailuresCount;
  166. }
  167. if (ViewData.ContainsKey(ScreenDeviceType.大炒))
  168. {
  169. ScreenModelMaxWok min = ViewData[ScreenDeviceType.大炒] as ScreenModelMaxWok;
  170. MaxCout = min.MaxWok_OrderCount_1 + min.MaxWok_OrderCount_2;
  171. gz += min.FailuresCount;
  172. }
  173. if (ViewData.ContainsKey(ScreenDeviceType.分餐机))
  174. {
  175. ScreenModelSplitMeals min = ViewData[ScreenDeviceType.分餐机] as ScreenModelSplitMeals;
  176. SplitMealsCout = min.SplitMeals_CreditCardCount_1 + min.SplitMeals_CreditCardCount_2
  177. + min.SplitMeals_CreditCardCount_3 + min.SplitMeals_CreditCardCount_4
  178. + min.SplitMeals_CreditCardCount_5 + min.SplitMeals_CreditCardCount_6;
  179. gz += min.FailuresCount;
  180. }
  181. int zmj_count = 0;
  182. if (ViewData.ContainsKey(ScreenDeviceType.煮面机))
  183. {
  184. ScreenModelMorkS morks = ViewData[ScreenDeviceType.煮面机] as ScreenModelMorkS;
  185. zmj_count = morks.MorkS_OrderCount;
  186. gz += morks.FailuresCount;
  187. }
  188. UserCout = SplitMealsCout + MaxCout + MinCout + zmj_count;
  189. GZallCout = gz;
  190. if (Stats != null && Stats.Count > 0)
  191. {
  192. Dictionary<string, int> _Stats = new Dictionary<string, int>();
  193. foreach (StatsModel item in Stats)
  194. {
  195. if (!string.IsNullOrEmpty(item.Name))
  196. {
  197. if (!_Stats.ContainsKey(item.Name))
  198. _Stats[item.Name] = item.Count;
  199. else
  200. _Stats[item.Name] += item.Count;
  201. }
  202. }
  203. List<StatsAllModel> _Statsall = new List<StatsAllModel>();
  204. _Stats?.ToList().ForEach(par => {
  205. _Statsall.Add(new StatsAllModel { Name = par.Key,Count = par.Value });
  206. });
  207. int maxcount = _Statsall.Max(k => k.Count);
  208. _Statsall?.ForEach(par =>
  209. {
  210. par.bfb = (int)(((double)par.Count / (double)maxcount) * 100.0);
  211. });
  212. string str = JsonConvert.SerializeObject(_Statsall?.OrderByDescending(k => k.Count)?.ToList());
  213. StatsCountAll= JsonConvert.DeserializeObject<ObservableCollection<StatsAllModel>>(str);
  214. }
  215. //假数据
  216. }));
  217. Thread.Sleep(1000);
  218. }), $"{DateTime.Now},线程服务");
  219. }
  220. }
  221. public class StatsAllModel: StatsModel
  222. {
  223. public int bfb { get; set; }
  224. }
  225. }