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 变量
///
/// 广告地址
///
public Uri GgAdder { get { return _GgAdder; } set { _GgAdder = value; OnPropertyChanged(); } }
private Uri _GgAdder = new Uri(System.Configuration.ConfigurationManager.AppSettings["GgAdder"].ToString());
///
/// 界面数据绑定
///
public Dictionary ViewData
{
get { return _ViewData; }
set
{
_ViewData = value;
OnPropertyChanged();
}
}
private Dictionary _ViewData = new Dictionary();
///
/// 小炒总数
///
public int MinCout
{
get { return _MinCout; }
set
{
_MinCout = value;
OnPropertyChanged();
}
}
private int _MinCout = 0;
///
/// 大炒总数
///
public int MaxCout
{
get { return _MaxCout; }
set
{
_MaxCout = value;
OnPropertyChanged();
}
}
private int _MaxCout = 0;
///
/// 分餐区总数
///
public int SplitMealsCout
{
get { return _SplitMealsCout; }
set
{
_SplitMealsCout = value;
OnPropertyChanged();
}
}
private int _SplitMealsCout = 0;
///
/// 日总接待人数
///
public int UserCout
{
get { return _UserCout; }
set
{
_UserCout = value;
OnPropertyChanged();
}
}
private int _UserCout = 0;
///
/// 累计故障数
///
public int GZallCout
{
get { return _GZallCout; }
set
{
_GZallCout = value;
OnPropertyChanged();
}
}
private int _GZallCout = 0;
///
/// 总告警列表
///
public ObservableCollection AlarmAll
{
get { return _AlarmAll; }
set
{
_AlarmAll = value;
OnPropertyChanged();
}
}
private ObservableCollection _AlarmAll =new ObservableCollection();
///
/// 今日商品热销统计
///
public ObservableCollection StatsCountAll
{
get { return _StatsBFB; }
set
{
_StatsBFB = value;
OnPropertyChanged();
}
}
private ObservableCollection _StatsBFB = new ObservableCollection();
#endregion
public ScreenALLControlViewModel()
{
Init();
}
///
/// 初始化
///
public void Init()
{
ThreadManage.GetInstance().StartLong(new Action(() =>
{
System.Windows.Application.Current?.Dispatcher.Invoke((Action)(() =>
{
ViewData = Main.GetInstance.mqttDatasDic;
//所有告警
List alarms = new List();
//所有统计
List Stats = new List();
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 _Stats = new Dictionary();
foreach (StatsModel item in Stats)
{
if (!string.IsNullOrEmpty(item.Name))
{
if (!_Stats.ContainsKey(item.Name))
_Stats[item.Name] = item.Count;
else
_Stats[item.Name] += item.Count;
}
}
List _Statsall = new List();
_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>(str);
}
//假数据
}));
Thread.Sleep(1000);
}), $"{DateTime.Now},线程服务");
}
}
public class StatsAllModel: StatsModel
{
public int bfb { get; set; }
}
}