TCQXCCache.cs 5.7 KB

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