|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- 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; }
- }
- }
|