FCQLCCache.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using CB.Cache;
  5. using CB.Entity;
  6. namespace CB.Data
  7. {
  8. public partial class Caches
  9. {
  10. /// <summary>
  11. /// 福彩七乐彩开奖信息缓存
  12. /// </summary>
  13. /// <returns></returns>
  14. public static IList<FCQLCInfo> GetFCQLCList()
  15. {
  16. var cache = CBCache.GetCacheService();
  17. IList<FCQLCInfo> list = cache.GetObject(CacheKeys.FCQLCList) as IList<FCQLCInfo>;
  18. if (null == list)
  19. {
  20. list = FCQLCService.ToList();
  21. cache.AddObject(CacheKeys.FCQLCList, list);
  22. }
  23. return list;
  24. }
  25. /// <summary>
  26. /// 福彩七乐彩开奖信息缓存
  27. /// </summary>
  28. /// <param name="topSize">top行(没有值默认传0)</param>
  29. /// <param name="term">期数(没有值默认传0)</param>
  30. /// <param name="year">年份(没有值默认传0)</param>
  31. /// <returns></returns>
  32. public static List<FCQLCInfo> GetFCQLCList(int topSize, int term, int year)
  33. {
  34. var list = GetFCQLCList();
  35. if (null == list || 0 >= list.Count)
  36. return null;
  37. List<FCQLCInfo> result = new List<FCQLCInfo>();
  38. if (topSize > 0)
  39. {
  40. int n = topSize > list.Count ? 0 : list.Count - topSize;
  41. for (int i = list.Count - 1; i >= n; i--)
  42. {
  43. if (0 <= list[i].OpenCode1) result.Add(list[i]);
  44. //如果没有正确开奖号的情况就忽略该行数据,并多循环一次到topSize行
  45. else if (n > 0) n--;
  46. }
  47. }
  48. else if (term > 0)
  49. {
  50. FCQLCInfo info = list.FirstOrDefault(x => x.Term == term && 0 <= x.OpenCode1);
  51. if (info != null) result.Add(info);
  52. }
  53. else if (year > 0)
  54. result = list.ToList().FindAll(x => x.Term >= year * 1000 + 1 && x.Term < (year + 1) * 1000 && 0 <= x.OpenCode1);
  55. return result;
  56. }
  57. /// <summary>
  58. /// 返回七乐彩近topSize条开机号、试机号、开奖号列表
  59. /// </summary>
  60. /// <param name="topSize">查询记录数</param>
  61. /// <param name="openCodeType">号码类型</param>
  62. /// <returns></returns>
  63. public static IList<FCQLCInfo> GetFCQLCList(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  64. {
  65. if (0 >= topSize)
  66. return null;
  67. var list = GetFCQLCList();
  68. if (null == list || 0 >= list.Count)
  69. return null;
  70. IList<FCQLCInfo> r = new List<FCQLCInfo>();
  71. int n = topSize > list.Count ? list.Count : topSize;
  72. for (int i = list.Count - 1; i >= 0; i--)
  73. {
  74. if (0 == n) { break; }
  75. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1"))
  76. { r.Add(list[i]); n--; continue; }
  77. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1"))
  78. { r.Add(list[i]); n--; continue; }
  79. if (openCodeType == OpenCodeType.KaiJiangHao && 1 <= list[i].OpenCode1)
  80. { r.Add(list[i]); n--; continue; }
  81. }
  82. return r;
  83. }
  84. /// <summary>
  85. /// 根据期数获取七乐彩开奖明细
  86. /// term=0时,读取最新一期开奖明细;
  87. /// term=0时并不一定包含开奖号数据,有可能只有开机号数据或试机号数据
  88. /// </summary>
  89. /// <param name="term">查询期数</param>
  90. /// <param name="openCodeType">开奖号码类型;仅term=0时,此参数有效</param>
  91. /// <returns>开奖数据</returns>
  92. public static FCQLCInfo GetFCQLCInfo(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
  93. {
  94. var list = GetFCQLCList();
  95. if (null == list || 0 >= list.Count)
  96. return null;
  97. FCQLCInfo entity = null;
  98. if (0 == term)
  99. {
  100. entity = list[list.Count - 1];
  101. if (openCodeType == OpenCodeType.Normal)
  102. return entity;
  103. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  104. return entity;
  105. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  106. return entity;
  107. if (openCodeType == OpenCodeType.KaiJiangHao && 1 <= entity.OpenCode1)
  108. return entity;
  109. for (int i = list.Count - 2; i >= 0; i--)
  110. {
  111. entity = list[i];
  112. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  113. return entity;
  114. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  115. return entity;
  116. if (openCodeType == OpenCodeType.KaiJiangHao && 1 <= entity.OpenCode1)
  117. return entity;
  118. }
  119. return null;
  120. }
  121. foreach (var item in list)
  122. {
  123. if (term == item.Term)
  124. { entity = item; break; }
  125. }
  126. return entity;
  127. }
  128. }
  129. }