FCHB22X5Cache.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  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. /// 福彩3D开奖信息缓存
  12. /// </summary>
  13. /// <returns></returns>
  14. public static IList<FCHB22X5Info> GetFCHB22X5List()
  15. {
  16. var cache = CBCache.GetCacheService();
  17. IList<FCHB22X5Info> list = cache.GetObject(CacheKeys.FCHB22X5List) as IList<FCHB22X5Info>;
  18. if (null == list)
  19. {
  20. list = FCHB22X5Service.ToList();
  21. cache.AddObject(CacheKeys.FCHB22X5List, list);
  22. }
  23. return list;
  24. }
  25. /// <summary>
  26. /// 福彩3D开奖信息缓存top n行
  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<FCHB22X5Info> GetFCHB22X5List(int topSize, int term, int year)
  33. {
  34. List<FCHB22X5Info> result = new List<FCHB22X5Info>();
  35. var list = GetFCHB22X5List();
  36. if (null == list || 0 >= list.Count)
  37. return null;
  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. FCHB22X5Info 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 * 1000 + 1 && x.Term < (year + 1) % 1000 * 1000 && 0 <= x.OpenCode1);
  55. return result;
  56. }
  57. /// <summary>
  58. /// 返回福彩3D近topSize条开机号、试机号、开奖号列表
  59. /// </summary>
  60. /// <param name="topSize">查询记录数</param>
  61. /// <param name="openCodeType">号码类型</param>
  62. /// <returns></returns>
  63. public static IList<FCHB22X5Info> GetFCHB22X5List(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  64. {
  65. if (0 >= topSize)
  66. return null;
  67. var list = GetFCHB22X5List();
  68. if (null == list || 0 >= list.Count)
  69. return null;
  70. IList<FCHB22X5Info> r = new List<FCHB22X5Info>();
  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 && 0 <= list[i].OpenCode1)
  80. { r.Add(list[i]); n--; continue; }
  81. }
  82. return r;
  83. }
  84. /// <summary>
  85. /// 返回某年的所有开机号、试机号、开奖号列表
  86. /// </summary>
  87. /// <param name="year">年份</param>
  88. /// <param name="openCodeType">号码类型</param>
  89. /// <returns></returns>
  90. public static IList<FCHB22X5Info> GetFCHB22X5ListByYear(int year, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  91. {
  92. if (0 >= year)
  93. return null;
  94. var list = GetFCHB22X5List();
  95. if (null == list || 0 >= list.Count)
  96. return null;
  97. IList<FCHB22X5Info> r = new List<FCHB22X5Info>();
  98. for (int i = list.Count - 1; i >= 0; i--)
  99. {
  100. if (list[i].Term.ToString().StartsWith(year.ToString(), StringComparison.CurrentCultureIgnoreCase))
  101. {
  102. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1"))
  103. { r.Add(list[i]); continue; }
  104. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1"))
  105. { r.Add(list[i]); continue; }
  106. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1)
  107. { r.Add(list[i]); continue; }
  108. }
  109. }
  110. return r;
  111. }
  112. /// <summary>
  113. /// 查询相同号码的所有开机号、试机号、开奖号列表
  114. /// </summary>
  115. /// <param name="year">年份</param>
  116. /// <param name="openCodeType">号码类型</param>
  117. /// <returns></returns>
  118. public static IList<FCHB22X5Info> GetFCHB22X5ListByNumber(string number, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  119. {
  120. if (string.IsNullOrEmpty(number))
  121. return null;
  122. var list = GetFCHB22X5List();
  123. if (null == list || 0 >= list.Count)
  124. return null;
  125. IList<FCHB22X5Info> r = new List<FCHB22X5Info>();
  126. for (int i = list.Count - 1; i >= 0; i--)
  127. {
  128. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1") && -1 != list[i].KaiJiHao.Replace(",", "").IndexOf(number))
  129. { r.Add(list[i]); continue; }
  130. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1") && -1 != list[i].ShiJiHao.Replace(",", "").IndexOf(number))
  131. { r.Add(list[i]); continue; }
  132. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1 && -1 != number.IndexOf(list[i].OpenCode1.ToString()) && -1 != number.IndexOf(list[i].OpenCode2.ToString())
  133. && -1 != number.IndexOf(list[i].OpenCode1.ToString()))
  134. { r.Add(list[i]); continue; }
  135. }
  136. return r;
  137. }
  138. /// <summary>
  139. /// 历史同期开奖数据(开机号、试机号、开奖号)
  140. /// </summary>
  141. /// <param name="term">当前期数</param>
  142. /// <param name="openCodeType">开奖号码类型</param>
  143. /// <returns></returns>
  144. public static IList<FCHB22X5Info> GetFCHB22X5HistorySameTerm(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
  145. {
  146. if (0 >= term)
  147. return null;
  148. var list = GetFCHB22X5List();
  149. if (null == list || 0 >= list.Count)
  150. return null;
  151. IList<FCHB22X5Info> r = new List<FCHB22X5Info>();
  152. long number = term % 1000;
  153. for (int i = list.Count - 1; i >= 0; i--)
  154. {
  155. if (list[i].Term % 1000 == number)
  156. {
  157. if (openCodeType == OpenCodeType.Normal)
  158. { r.Add(list[i]); continue; }
  159. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1"))
  160. { r.Add(list[i]); continue; }
  161. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1"))
  162. { r.Add(list[i]); continue; }
  163. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1)
  164. { r.Add(list[i]); continue; }
  165. }
  166. }
  167. return r;
  168. }
  169. /// <summary>
  170. /// 根据期数获取福彩3D开奖明细
  171. /// term=0时,读取最新一期开奖明细;
  172. /// term=0时并不一定包含开奖号数据,有可能只有开机号数据或试机号数据
  173. /// </summary>
  174. /// <param name="term">查询期数</param>
  175. /// <param name="openCodeType">开奖号码类型;仅term=0时,此参数有效</param>
  176. /// <returns></returns>
  177. public static FCHB22X5Info GetFCHB22X5Info(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
  178. {
  179. var list = GetFCHB22X5List();
  180. if (null == list || 0 >= list.Count)
  181. return null;
  182. FCHB22X5Info entity = null;
  183. if (0 == term)
  184. {
  185. entity = list[list.Count - 1];
  186. if (openCodeType == OpenCodeType.Normal)
  187. return entity;
  188. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  189. return entity;
  190. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  191. return entity;
  192. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
  193. return entity;
  194. for (int i = list.Count - 2; i >= 0; i--)
  195. {
  196. entity = list[i];
  197. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  198. return entity;
  199. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  200. return entity;
  201. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
  202. return entity;
  203. }
  204. return null;
  205. }
  206. foreach (var item in list)
  207. {
  208. if (term == item.Term)
  209. { entity = item; break; }
  210. }
  211. return entity;
  212. }
  213. }
  214. }