Ctrl.cs 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. using Interface;
  2. using Services;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using Models.Entity.LotteryNumDB;
  9. using Cache.Entity;
  10. using Models;
  11. using Common;
  12. using Business.KJH;
  13. namespace Cache
  14. {
  15. public static class Ctrl
  16. {
  17. private static LotteryNumInterface services;
  18. private static Dictionary<string, LotteryData> MlotteryData;
  19. private static Object ZXView;
  20. private static int UpTK = 300;
  21. private static DateTime lotteryLastUpTime;
  22. private static DateTime ZXviewUpTime;
  23. static Ctrl()
  24. {
  25. services = new LotteryService();
  26. MlotteryData = new Dictionary<string, LotteryData>();
  27. lotteryLastUpTime = DateTime.Now;
  28. ZXviewUpTime = new DateTime();
  29. ZXView = new object();
  30. // GetList();
  31. }
  32. private static void Test()
  33. {
  34. }
  35. private static void lotteryDoUpdate()
  36. {
  37. if (MlotteryData.Count==0)
  38. {
  39. GetList();
  40. }
  41. if ((DateTime.Now- lotteryLastUpTime).TotalSeconds> UpTK)
  42. {
  43. GetList();
  44. lotteryLastUpTime = DateTime.Now;
  45. }
  46. }
  47. public static bool ZXViewNeedUpdate()
  48. {
  49. if (ZXView==null)
  50. {
  51. return false;
  52. }
  53. if ((DateTime.Now - ZXviewUpTime).TotalSeconds > UpTK)
  54. {
  55. // ZXView = data;
  56. // ZXviewUpTime = DateTime.Now;
  57. return false;
  58. }
  59. return true;
  60. }
  61. public static object GetZXView()
  62. {
  63. return ZXView;
  64. }
  65. public static void SETZXView(object data)
  66. {
  67. ZXView = data;
  68. ZXviewUpTime = DateTime.Now;
  69. }
  70. private static void GetList()
  71. {
  72. var list = KJBLL.GetLotteryList();
  73. for (int i = 0; i < list.Count; i++)
  74. {
  75. var lottery = Enum.Parse(typeof(SCCLottery), list[i].LotteryType);
  76. if (ZSlotterType.TypeOfNameDict.Keys.Contains(list[i].LotteryType))
  77. {
  78. list[i].HasLotteryZS = true;
  79. }
  80. list[i].LotteryText = EnumHelper.GetLotteryText((SCCLottery)lottery);
  81. MlotteryData[list[i].LotteryType] = list[i];
  82. }
  83. //var gpcresult = new { c11x5 = new { Name = "11选5", Data = c11x5 }, k3 = new { Name = "快3", Data = k3 }, klsf = new { Name = "快乐十分", Data = klsf }, kl12 = new { Name = "快乐12", Data = kl12 }, qt = new { Name = "其他彩种", Data = qt } };
  84. // var res = new { QGC = qgc, DFC = dfc, GPC = gpcresult };
  85. }
  86. /// <summary>
  87. /// 返回单个
  88. /// </summary>
  89. /// <param name="lottery"></param>
  90. /// <returns></returns>
  91. public static LotteryData GetLottery(string typename)
  92. {
  93. try
  94. {
  95. if (!MlotteryData.Keys.Contains(typename))
  96. {
  97. lotteryDoUpdate();
  98. return MlotteryData[typename];
  99. }
  100. else
  101. {
  102. return MlotteryData[typename];
  103. }
  104. }
  105. catch (Exception ee)
  106. {
  107. return null; ;
  108. }
  109. }
  110. /// <summary>
  111. /// 返回所有缓存对象
  112. /// </summary>
  113. /// <returns></returns>
  114. public static List<LotteryData> GetLottery()
  115. {
  116. try
  117. {
  118. if (MlotteryData.Keys.Count == 0)
  119. {
  120. lotteryDoUpdate();
  121. }
  122. return MlotteryData.Values.ToList();
  123. }
  124. catch (Exception ee)
  125. {
  126. return null;
  127. }
  128. }
  129. }
  130. }