TCP3Cache.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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<TCP3Info> GetTCP3List()
  15. {
  16. var cache = CBCache.GetCacheService();
  17. IList<TCP3Info> list = cache.GetObject(CacheKeys.TCP3List) as IList<TCP3Info>;
  18. if (null == list)
  19. {
  20. list = TCP3Service.ToList();
  21. cache.AddObject(CacheKeys.TCP3List, 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<TCP3Info> GetTCP3List(int topSize, int term, int year)
  33. {
  34. var list = GetTCP3List();
  35. if (null == list || 0 >= list.Count)
  36. return null;
  37. List<TCP3Info> result = new List<TCP3Info>();
  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. TCP3Info 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<TCP3Info> GetTCP3List(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  64. {
  65. if (0 >= topSize)
  66. return null;
  67. var list = GetTCP3List();
  68. if (null == list || 0 >= list.Count)
  69. return null;
  70. IList<TCP3Info> r = new List<TCP3Info>();
  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<TCP3Info> GetTCP3ListByYear(int year, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  91. {
  92. if (0 >= year)
  93. return null;
  94. var list = GetTCP3List();
  95. if (null == list || 0 >= list.Count)
  96. return null;
  97. IList<TCP3Info> r = new List<TCP3Info>();
  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<TCP3Info> GetTCP3ListByNumber(string number, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
  119. {
  120. if (string.IsNullOrEmpty(number))
  121. return null;
  122. var list = GetTCP3List();
  123. if (null == list || 0 >= list.Count)
  124. return null;
  125. IList<TCP3Info> r = new List<TCP3Info>();
  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. /// 福彩3D开奖信息缓存的按当期为基数的top n行
  140. /// </summary>
  141. /// <param name="topSize">top行(没有值默认传0)</param>
  142. /// <param name="term">期数(没有值默认传0)</param>
  143. /// <returns></returns>
  144. public static IList<TCP3Info> GetTCP3List(int topSize, long term)
  145. {
  146. IList<TCP3Info> result = new List<TCP3Info>();
  147. var list = GetTCP3List();
  148. if (null == list || 0 >= list.Count)
  149. return null;
  150. if (topSize > 0)
  151. {
  152. //int n = topSize;// > list.Count ? 0 : list.Count - topSize;
  153. //for (int i = list.Count - 1; i >= n; i--)
  154. //{
  155. // if (term > 0 && list[i].Term > term) continue;
  156. // result.Add(list[i]);
  157. // n--;
  158. // if (n <= 0) break;
  159. //}
  160. if (term > 0)
  161. return list.Where(p => p.Term <= term).OrderByDescending(p => p.Term).Take(topSize).ToList();
  162. return list.Take(topSize).OrderByDescending(p => p.Term).ToList();
  163. }
  164. return result;
  165. }
  166. /// <summary>
  167. /// 历史同期开奖数据(开机号、试机号、开奖号)
  168. /// </summary>
  169. /// <param name="term">当前期数</param>
  170. /// <param name="openCodeType">开奖号码类型</param>
  171. /// <returns></returns>
  172. public static IList<TCP3Info> GetTCP3HistorySameTerm(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
  173. {
  174. if (0 >= term)
  175. return null;
  176. var list = GetTCP3List();
  177. if (null == list || 0 >= list.Count)
  178. return null;
  179. IList<TCP3Info> r = new List<TCP3Info>();
  180. long number = term % 1000;
  181. for (int i = list.Count - 1; i >= 0; i--)
  182. {
  183. if (list[i].Term % 1000 == number)
  184. {
  185. if (openCodeType == OpenCodeType.Normal)
  186. { r.Add(list[i]); continue; }
  187. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1"))
  188. { r.Add(list[i]); continue; }
  189. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1"))
  190. { r.Add(list[i]); continue; }
  191. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1)
  192. { r.Add(list[i]); continue; }
  193. }
  194. }
  195. return r;
  196. }
  197. /// <summary>
  198. /// 根据期数获取排列三开奖明细
  199. /// term=0时,读取最新一期开奖明细;
  200. /// term=0时并不一定包含开奖号数据,有可能只有开机号数据或试机号数据
  201. /// </summary>
  202. /// <param name="term">查询期数</param>
  203. /// <param name="openCodeType">查询开奖数据类型;term=0时,此参数有效</param>
  204. /// <returns>开奖数据</returns>
  205. public static TCP3Info GetTCP3Info(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
  206. {
  207. var list = GetTCP3List();
  208. if (null == list || 0 >= list.Count)
  209. return null;
  210. TCP3Info entity = null;
  211. if (0 == term)
  212. {
  213. entity = list[list.Count - 1];
  214. if (openCodeType == OpenCodeType.Normal)
  215. return entity;
  216. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  217. return entity;
  218. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  219. return entity;
  220. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
  221. return entity;
  222. for (int i = list.Count - 2; i >= 0; i--)
  223. {
  224. entity = list[i];
  225. if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1"))
  226. return entity;
  227. if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1"))
  228. return entity;
  229. if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1)
  230. return entity;
  231. }
  232. return null;
  233. }
  234. foreach (var item in list)
  235. {
  236. if (term == item.Term)
  237. {
  238. entity = item; break;
  239. }
  240. }
  241. return entity;
  242. }
  243. }
  244. }