Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

142 linhas
5.8 KiB

  1. using BPA.Helper;
  2. using DTO;
  3. using HKCardOUT.Helper;
  4. using HKCardOUT.Logic.Service;
  5. using Stylet;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Collections.ObjectModel;
  9. using System.Linq;
  10. using System.Threading;
  11. using System.Windows.Media;
  12. using HKControl;
  13. using System.Collections.Concurrent;
  14. namespace HKCardOUT.ViewModels
  15. {
  16. public class AdWindowViewModel : NotifyBase
  17. {
  18. public AdWindowViewModel()
  19. {
  20. for (int i = 0; i < 6; i++)
  21. {
  22. Foods.Add("");
  23. }
  24. }
  25. #region 属性
  26. public AdInfoModel LAdInfo { get { return _mLAdInfo; } set { _mLAdInfo = value; OnPropertyChanged(); } }
  27. private AdInfoModel _mLAdInfo = new AdInfoModel();
  28. public AdInfoModel RAdinfo { get { return _mRAdinfo; } set { _mRAdinfo = value; OnPropertyChanged(); } }
  29. private AdInfoModel _mRAdinfo = new AdInfoModel();
  30. public ObservableCollection<string> Foods { get; set; } = new ObservableCollection<string>();
  31. #endregion
  32. void FoodsInit(int[] ScreenLoc)
  33. {
  34. string GateId = string.Empty;
  35. GateId = DataBus.StoreInfo.Devices.Where(t => t.Address == $"0{ScreenLoc[0]}" || t.Address == $"0{ScreenLoc[1]}").Select(t => t.GateId).FirstOrDefault();
  36. var res = DataBus.Menu.GateFood.Where(t => t.GateId == GateId)?.Select(t => t.Foods)?.FirstOrDefault();
  37. if (res != null)
  38. {
  39. App.Current.Dispatcher.Invoke(() =>
  40. {
  41. for (int i = 0; i < Foods.Count; i++)
  42. {
  43. if (i >= 0 && i < res.Count)
  44. Foods[i] = res.ElementAt(i);
  45. }
  46. });
  47. }
  48. }
  49. public void InitData(int[] BindScreen)
  50. {
  51. FoodsInit(BindScreen);
  52. ThreadManage.GetInstance().StartLong(() =>
  53. {
  54. if (DateTime.Now.Hour == 16)
  55. {
  56. LAdInfo.AInfo = new ObservableCollection<ScreenInfoDto>();
  57. RAdinfo.AInfo = new ObservableCollection<ScreenInfoDto>();
  58. }
  59. Thread.Sleep(5000);
  60. }, "清理屏幕数据", true);
  61. ThreadManage.GetInstance().StartLong(() =>
  62. {
  63. var model = (new HKCore()).PullDaySaleLog(BindScreen);
  64. if (BindScreen[1] == 6)
  65. LAdInfo.Gate = $"1号档口";
  66. if (BindScreen[1] == 4)
  67. LAdInfo.Gate = $"3号档口";
  68. if (BindScreen[1] == 2)
  69. LAdInfo.Gate = $"5号档口";
  70. if (BindScreen[0] == 5)
  71. RAdinfo.Gate = $"2号档口";
  72. if (BindScreen[0] == 3)
  73. RAdinfo.Gate = $"4号档口";
  74. if (BindScreen[0] == 1)
  75. RAdinfo.Gate = $"6号档口";
  76. LAdInfo.Count = model.Where(t => t.Key == $"{BindScreen[1]}").FirstOrDefault().Value;
  77. RAdinfo.Count = model.Where(t => t.Key == $"{BindScreen[0]}").FirstOrDefault().Value;
  78. if (Main.GetInstance.GetIsConnect(BindScreen[1]))
  79. LAdInfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[1]) ? "正常" : "异常";
  80. else
  81. LAdInfo.Msg = "未连接";
  82. if (Main.GetInstance.GetIsConnect(BindScreen[0]))
  83. RAdinfo.Msg = Main.GetInstance.GetIsSwipe(BindScreen[0]) ? "正常" : "异常";
  84. else
  85. RAdinfo.Msg = "未连接";
  86. for (int i = 0; i < BindScreen.Length; i++)
  87. {
  88. if (DataBus.SaleLogDtoList.ContainsKey(BindScreen[i].ToString()))
  89. {
  90. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].Count > 0)
  91. {
  92. if (DataBus.SaleLogDtoList[BindScreen[i].ToString()].TryDequeue(out SaleLogDto info))
  93. {
  94. ScreenInfoDto data = new ScreenInfoDto
  95. {
  96. CardNo = info.CardNo,
  97. UserName = "",
  98. Location = info.Location,
  99. };
  100. data.UserName = DataBus.UserListDto
  101. .Where(t => t.Cards.Select(x => x.CardNum).Contains(data.CardNo))
  102. .Select(x => x.Name).FirstOrDefault();
  103. HKLog.HKLogImport.WriteInfo("取出刷卡信息" + data.ToJson());
  104. App.Current.Dispatcher.Invoke(() =>
  105. {
  106. if (LAdInfo.Info != null && !string.IsNullOrEmpty(LAdInfo.Info.UserName))
  107. LAdInfo.AInfo.Insert(0, LAdInfo.Info); LAdInfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  108. if (RAdinfo.Info != null && !string.IsNullOrEmpty(RAdinfo.Info.UserName))
  109. RAdinfo.AInfo.Insert(0, RAdinfo.Info); RAdinfo.Info.Time = DateTime.Now.ToString("HH:mm:ss");
  110. });
  111. LAdInfo.Info = data.Location == $"{BindScreen[1]}" ? data : new ScreenInfoDto();
  112. RAdinfo.Info = data.Location == $"{BindScreen[0]}" ? data : new ScreenInfoDto();
  113. }
  114. }
  115. }
  116. else
  117. {
  118. //HKLog.HKLogImport.WriteInfo("未包含屏幕" + BindScreen[i]);
  119. }
  120. }
  121. Thread.Sleep(10);
  122. }, $"屏幕刷卡信息{BindScreen[0]}-{BindScreen[1]}", true);
  123. }
  124. }
  125. }