using System; using System.Collections.Generic; using System.Linq; using CB.Cache; using CB.Entity; namespace CB.Data { public partial class Caches { /// /// 福彩3D开奖信息缓存 /// /// public static IList GetTCJS7WSList() { var cache = CBCache.GetCacheService(); IList list = cache.GetObject(CacheKeys.TCJS7WSList) as IList; if (null == list) { list = TCJS7WSService.ToList(); cache.AddObject(CacheKeys.TCJS7WSList, list); } return list; } /// /// 福彩3D开奖信息缓存top n行 /// /// top行(没有值默认传0) /// 期数(没有值默认传0) /// 年份(没有值默认传0) /// public static List GetTCJS7WSList(int topSize, int term, int year) { List result = new List(); var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; if (topSize > 0) { int n = topSize > list.Count ? 0 : list.Count - topSize; for (int i = list.Count - 1; i >= n; i--) { if (0 <= list[i].OpenCode1) result.Add(list[i]); //如果没有正确开奖号的情况就忽略该行数据,并多循环一次到topSize行 else if (n > 0) n--; } } else if (term > 0) { TCJS7WSInfo info = list.FirstOrDefault(x => x.Term == term && 0 <= x.OpenCode1); if (info != null) result.Add(info); } else if (year > 0) result = list.ToList().FindAll(x => x.Term >= year % 1000 * 1000 + 1 && x.Term < (year + 1) % 1000 * 1000 && 0 <= x.OpenCode1); return result; } /// /// 返回福彩3D近topSize条开机号、试机号、开奖号列表 /// /// 查询记录数 /// 号码类型 /// public static IList GetTCJS7WSList(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao) { if (0 >= topSize) return null; var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; IList r = new List(); int n = topSize > list.Count ? list.Count : topSize; for (int i = list.Count - 1; i >= 0; i--) { if (0 == n) { break; } if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1")) { r.Add(list[i]); n--; continue; } if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1")) { r.Add(list[i]); n--; continue; } if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1) { r.Add(list[i]); n--; continue; } } return r; } /// /// 返回某年的所有开机号、试机号、开奖号列表 /// /// 年份 /// 号码类型 /// public static IList GetTCJS7WSListByYear(int year, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao) { if (0 >= year) return null; var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; IList r = new List(); for (int i = list.Count - 1; i >= 0; i--) { if (list[i].Term.ToString().StartsWith(year.ToString(), StringComparison.CurrentCultureIgnoreCase)) { if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1")) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1")) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1) { r.Add(list[i]); continue; } } } return r; } /// /// 查询相同号码的所有开机号、试机号、开奖号列表 /// /// 年份 /// 号码类型 /// public static IList GetTCJS7WSListByNumber(string number, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao) { if (string.IsNullOrEmpty(number)) return null; var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; IList r = new List(); for (int i = list.Count - 1; i >= 0; i--) { if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1") && -1 != list[i].KaiJiHao.Replace(",", "").IndexOf(number)) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1") && -1 != list[i].ShiJiHao.Replace(",", "").IndexOf(number)) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1 && -1 != number.IndexOf(list[i].OpenCode1.ToString()) && -1 != number.IndexOf(list[i].OpenCode2.ToString()) && -1 != number.IndexOf(list[i].OpenCode1.ToString())) { r.Add(list[i]); continue; } } return r; } /// /// 历史同期开奖数据(开机号、试机号、开奖号) /// /// 当前期数 /// 开奖号码类型 /// public static IList GetTCJS7WSHistorySameTerm(long term, OpenCodeType openCodeType = OpenCodeType.Normal) { if (0 >= term) return null; var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; IList r = new List(); long number = term % 1000; for (int i = list.Count - 1; i >= 0; i--) { if (list[i].Term % 1000 == number) { if (openCodeType == OpenCodeType.Normal) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(list[i].KaiJiHao) && -1 == list[i].KaiJiHao.IndexOf("-1")) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(list[i].ShiJiHao) && -1 == list[i].ShiJiHao.IndexOf("-1")) { r.Add(list[i]); continue; } if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= list[i].OpenCode1) { r.Add(list[i]); continue; } } } return r; } /// /// 根据期数获取福彩3D开奖明细 /// term=0时,读取最新一期开奖明细; /// term=0时并不一定包含开奖号数据,有可能只有开机号数据或试机号数据 /// /// 查询期数 /// 开奖号码类型;仅term=0时,此参数有效 /// public static TCJS7WSInfo GetTCJS7WSInfo(long term, OpenCodeType openCodeType = OpenCodeType.Normal) { var list = GetTCJS7WSList(); if (null == list || 0 >= list.Count) return null; TCJS7WSInfo entity = null; if (0 == term) { entity = list[list.Count - 1]; if (openCodeType == OpenCodeType.Normal) return entity; if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1")) return entity; if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1")) return entity; if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1) return entity; for (int i = list.Count - 2; i >= 0; i--) { entity = list[i]; if (openCodeType == OpenCodeType.KaiJiHao && !string.IsNullOrEmpty(entity.KaiJiHao) && -1 == entity.KaiJiHao.IndexOf("-1")) return entity; if (openCodeType == OpenCodeType.ShiJiHao && !string.IsNullOrEmpty(entity.ShiJiHao) && -1 == entity.ShiJiHao.IndexOf("-1")) return entity; if (openCodeType == OpenCodeType.KaiJiangHao && 0 <= entity.OpenCode1) return entity; } return null; } foreach (var item in list) { if (term == item.Term) { entity = item; break; } } return entity; } } }