|
- using BPA.Helper;
- using DTO;
- using HKCardOUT.Helper;
- using HKCardOUT.Logic.Service;
- using Stylet;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Threading;
- using System.Windows.Media;
- using HKControl;
- using System.Collections.Concurrent;
-
- namespace HKCardOUT.ViewModels
- {
- public class AdWindowViewModel : NotifyBase
- {
-
- public AdWindowViewModel()
- {
- for (int i = 0; i < 6; i++)
- {
- Foods.Add("");
- }
-
- }
-
- #region 属性
-
- public AdInfoModel LAdInfo { get { return _mLAdInfo; } set { _mLAdInfo = value; OnPropertyChanged(); } }
- private AdInfoModel _mLAdInfo = new AdInfoModel();
-
- public AdInfoModel RAdinfo { get { return _mRAdinfo; } set { _mRAdinfo = value; OnPropertyChanged(); } }
- private AdInfoModel _mRAdinfo = new AdInfoModel();
-
- public ObservableCollection<string> Foods { get; set; } = new ObservableCollection<string>();
- #endregion
-
-
-
- void FoodsInit(int[] ScreenLoc)
- {
- string GateId = string.Empty;
- GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == $"0{ScreenLoc[0]}" || t.Address == $"0{ScreenLoc[1]}").Select(t => t.GateId).FirstOrDefault();
- var res = DataBus.Menu.GateFood.Where(t => t.GateId == GateId)?.Select(t => t.Foods)?.FirstOrDefault();
- if (res != null)
- {
- App.Current.Dispatcher.Invoke(() =>
- {
- for (int i = 0; i < Foods.Count; i++)
- {
- if (i >= 0 && i < res.Count)
- Foods[i] = res.ElementAt(i);
- }
- });
- }
- }
-
- public void InitData(int[] BindScreen)
- {
- FoodsInit(BindScreen);
-
- ThreadManage.GetInstance().StartLong(() =>
- {
- if (DateTime.Now.Hour == 16)
- {
- LAdInfo.AInfo = new ObservableCollection<ScreenInfoDto>();
- RAdinfo.AInfo = new ObservableCollection<ScreenInfoDto>();
- }
- Thread.Sleep(5000);
- }, "清理屏幕数据", true);
-
- ThreadManage.GetInstance().StartLong(() =>
- {
- var model = (new HKCore()).PullDaySaleLog(BindScreen);
- if (BindScreen[1] == 6)
- LAdInfo.Gate = $"1号档口";
- if (BindScreen[1] == 4)
- LAdInfo.Gate = $"3号档口";
- if (BindScreen[1] == 2)
- LAdInfo.Gate = $"5号档口";
-
- if (BindScreen[0] == 5)
- RAdinfo.Gate = $"2号档口";
- if (BindScreen[0] == 3)
- RAdinfo.Gate = $"4号档口";
- if (BindScreen[0] == 1)
- RAdinfo.Gate = $"6号档口";
-
- LAdInfo.Count = model.Where(t => t.Key == $"{BindScreen[1]}").FirstOrDefault().Value;
- RAdinfo.Count = model.Where(t => t.Key == $"{BindScreen[0]}").FirstOrDefault().Value;
- if (Main.GetInstance.GetIsConnect(BindScreen[1]))
- LAdInfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[1]) ? "正常" : "异常";
- else
- LAdInfo.Msg = "未连接";
-
- if (Main.GetInstance.GetIsConnect(BindScreen[0]))
- RAdinfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[0]) ? "正常" : "异常";
- else
- RAdinfo.Msg = "未连接";
- for (int i = 0; i < BindScreen.Length; i++)
- {
- if (DataBus.SaleLogDtoList.ContainsKey(BindScreen[i].ToString()))
- {
- if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].Count > 0)
- {
- if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].TryDequeue(out SaleLogDto info))
- {
- ScreenInfoDto data = new ScreenInfoDto
- {
- CardNo = info.CardNo,
- UserName = "",
- Location = info.Location,
- };
- data.UserName = DataBus.UserListDto
- .Where(t => t.Cards.Select(x => x.CardNum).Contains(data.CardNo))
- .Select(x => x.Name).FirstOrDefault();
- HKLog.HKLogImport.WriteInfo("取出刷卡信息" + data.ToJson());
- App.Current.Dispatcher.Invoke(() =>
- {
- if (LAdInfo.Info != null && !string.IsNullOrEmpty(LAdInfo.Info.UserName))
- LAdInfo.AInfo.Insert(0, LAdInfo.Info); LAdInfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
- if (RAdinfo.Info != null && !string.IsNullOrEmpty(RAdinfo.Info.UserName))
- RAdinfo.AInfo.Insert(0, RAdinfo.Info); RAdinfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
- });
- LAdInfo.Info = data.Location == $"{BindScreen[1]}" ? data : new ScreenInfoDto();
- RAdinfo.Info = data.Location == $"{BindScreen[0]}" ? data : new ScreenInfoDto();
- }
- }
- }
- else
- {
- //HKLog.HKLogImport.WriteInfo("未包含屏幕" + BindScreen[i]);
- }
- }
- Thread.Sleep(10);
- }, $"屏幕刷卡信息{BindScreen[0]}-{BindScreen[1]}", true);
- }
- }
- }
|