|
- using BPA.CustomResource.UserControls;
- using BPA.Helper;
- using BPA.Message;
- using BPA.Message.Enum;
- using Newtonsoft.Json;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
-
- namespace BPASmartClient.ScreenLib
- {
- public class ScreenALLControlViewModel : NotifyBase
- {
- #region 变量
- /// <summary>
- /// 广告地址
- /// </summary>
- public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } }
- private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString());
-
- /// <summary>
- /// 界面数据绑定
- /// </summary>
- public Dictionary<ScreenDeviceType, object> ViewData
- {
- get { return _ViewData; }
- set
- {
- _ViewData = value;
- OnPropertyChanged();
- }
- }
- private Dictionary<ScreenDeviceType, object> _ViewData = new Dictionary<ScreenDeviceType, object>();
-
- /// <summary>
- /// 小炒总数
- /// </summary>
- public int MinCout
- {
- get { return _MinCout; }
- set
- {
- _MinCout = value;
- OnPropertyChanged();
- }
- }
- private int _MinCout = 0;
-
- /// <summary>
- /// 大炒总数
- /// </summary>
- public int MaxCout
- {
- get { return _MaxCout; }
- set
- {
- _MaxCout = value;
- OnPropertyChanged();
- }
- }
- private int _MaxCout = 0;
-
-
- /// <summary>
- /// 分餐区总数
- /// </summary>
- public int SplitMealsCout
- {
- get { return _SplitMealsCout; }
- set
- {
- _SplitMealsCout = value;
- OnPropertyChanged();
- }
- }
- private int _SplitMealsCout = 0;
-
-
- /// <summary>
- /// 日总接待人数
- /// </summary>
- public int UserCout
- {
- get { return _UserCout; }
- set
- {
- _UserCout = value;
- OnPropertyChanged();
- }
- }
- private int _UserCout = 0;
-
- /// <summary>
- /// 累计故障数
- /// </summary>
- public int GZallCout
- {
- get { return _GZallCout; }
- set
- {
- _GZallCout = value;
- OnPropertyChanged();
- }
- }
- private int _GZallCout = 0;
-
-
- /// <summary>
- /// 总告警列表
- /// </summary>
- public ObservableCollection<AlarmModel> AlarmAll
- {
- get { return _AlarmAll; }
- set
- {
- _AlarmAll = value;
- OnPropertyChanged();
- }
- }
- private ObservableCollection<AlarmModel> _AlarmAll =new ObservableCollection<AlarmModel>();
-
- /// <summary>
- /// 今日商品热销统计
- /// </summary>
- public ObservableCollection<StatsAllModel> StatsCountAll
- {
- get { return _StatsBFB; }
- set
- {
- _StatsBFB = value;
- OnPropertyChanged();
- }
- }
- private ObservableCollection<StatsAllModel> _StatsBFB = new ObservableCollection<StatsAllModel>();
- #endregion
- public ScreenALLControlViewModel()
- {
- Init();
- }
-
- /// <summary>
- /// 初始化
- /// </summary>
- public void Init()
- {
- ThreadManage.GetInstance().StartLong(new Action(() =>
- {
- System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
- {
- ViewData = Main.GetInstance.mqttDatasDic;
- List<AlarmModel> alarms = new List<AlarmModel>();
- List<StatsModel> Stats = new List<StatsModel>();
- foreach (var item in Main.GetInstance.mqttDatasDic)
- {
- if (item.Value != null)
- {
- if((item.Value as ScreenModelBase).Alarm!=null)
- alarms.AddRange((item.Value as ScreenModelBase).Alarm);
- if ((item.Value as ScreenModelBase).StatsCount != null)
- Stats.AddRange((item.Value as ScreenModelBase).StatsCount);
- }
- }
-
- AlarmAll.Clear();
- alarms?.OrderByDescending(k => DateTime.Parse(k.AlarmTime))?.ToList().ForEach(alarm => {
- AlarmAll.Add(alarm);
- });
-
-
- int gz = 0;
- if (ViewData.ContainsKey(ScreenDeviceType.小炒))
- {
- ScreenModelMinWok min = ViewData[ScreenDeviceType.小炒] as ScreenModelMinWok;
- MinCout = min.MinWok_OrderCount_1 + min.MinWok_OrderCount_2;
- gz += min.FailuresCount;
- }
-
- if (ViewData.ContainsKey(ScreenDeviceType.大炒))
- {
- ScreenModelMaxWok min = ViewData[ScreenDeviceType.大炒] as ScreenModelMaxWok;
- MaxCout = min.MaxWok_OrderCount_1 + min.MaxWok_OrderCount_2;
- gz += min.FailuresCount;
-
- }
-
- if (ViewData.ContainsKey(ScreenDeviceType.分餐机))
- {
- ScreenModelSplitMeals min = ViewData[ScreenDeviceType.分餐机] as ScreenModelSplitMeals;
- SplitMealsCout = min.SplitMeals_CreditCardCount_1 + min.SplitMeals_CreditCardCount_2
- + min.SplitMeals_CreditCardCount_3 + min.SplitMeals_CreditCardCount_4
- + min.SplitMeals_CreditCardCount_5 + min.SplitMeals_CreditCardCount_6;
- gz += min.FailuresCount;
-
- }
-
- int zmj_count = 0;
- if (ViewData.ContainsKey(ScreenDeviceType.煮面机))
- {
- ScreenModelMorkS morks = ViewData[ScreenDeviceType.煮面机] as ScreenModelMorkS;
- zmj_count = morks.MorkS_OrderCount;
- gz += morks.FailuresCount;
-
- }
- UserCout = SplitMealsCout + MaxCout + MinCout + zmj_count;
-
- GZallCout = gz;
-
-
-
- if (Stats != null && Stats.Count > 0)
- {
- Dictionary<string, int> _Stats = new Dictionary<string, int>();
- foreach (StatsModel item in Stats)
- {
- if(!_Stats.ContainsKey(item.Name))
- _Stats[item.Name]= item.Count;
- else
- _Stats[item.Name] += item.Count;
- }
- List<StatsAllModel> _Statsall = new List<StatsAllModel>();
- _Stats?.ToList().ForEach(par => {
- _Statsall.Add(new StatsAllModel { Name = par.Key,Count = par.Value });
- });
- int maxcount = _Statsall.Max(k => k.Count);
- _Statsall?.ForEach(par =>
- {
- par.bfb = (int)(((double)par.Count / (double)maxcount) * 100.0);
- });
- string str = JsonConvert.SerializeObject(_Statsall?.OrderByDescending(k => k.Count)?.ToList());
- StatsCountAll= JsonConvert.DeserializeObject<ObservableCollection<StatsAllModel>>(str);
- }
- }));
- Thread.Sleep(2000);
- }), $"{DateTime.Now},线程服务");
- }
- }
-
- public class StatsAllModel: StatsModel
- {
- public int bfb { get; set; }
- }
- }
|