123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using CB.Cache;
- using CB.Entity;
- namespace CB.Data
- {
- public partial class Caches
- {
-
-
-
-
- public static IList<TCP3Info> GetTCP3List()
- {
- var cache = CBCache.GetCacheService();
- IList<TCP3Info> list = cache.GetObject(CacheKeys.TCP3List) as IList<TCP3Info>;
- if (null == list)
- {
- list = TCP3Service.ToList();
- cache.AddObject(CacheKeys.TCP3List, list);
- }
- return list;
- }
-
-
-
-
-
-
-
- public static List<TCP3Info> GetTCP3List(int topSize, int term, int year)
- {
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- List<TCP3Info> result = new List<TCP3Info>();
- 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]);
-
- else if (n > 0) n--;
- }
- }
- else if (term > 0)
- {
- TCP3Info 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 + 1 && x.Term < (year + 1) * 1000 && 0 <= x.OpenCode1);
- return result;
- }
-
-
-
-
-
-
- public static IList<TCP3Info> GetTCP3List(int topSize, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
- {
- if (0 >= topSize)
- return null;
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- IList<TCP3Info> r = new List<TCP3Info>();
- 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<TCP3Info> GetTCP3ListByYear(int year, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
- {
- if (0 >= year)
- return null;
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- IList<TCP3Info> r = new List<TCP3Info>();
- 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<TCP3Info> GetTCP3ListByNumber(string number, OpenCodeType openCodeType = OpenCodeType.KaiJiangHao)
- {
- if (string.IsNullOrEmpty(number))
- return null;
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- IList<TCP3Info> r = new List<TCP3Info>();
- 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<TCP3Info> GetTCP3List(int topSize, long term)
- {
- IList<TCP3Info> result = new List<TCP3Info>();
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- if (topSize > 0)
- {
-
-
-
-
-
-
-
-
- if (term > 0)
- return list.Where(p => p.Term <= term).OrderByDescending(p => p.Term).Take(topSize).ToList();
- return list.Take(topSize).OrderByDescending(p => p.Term).ToList();
- }
- return result;
- }
-
-
-
-
-
-
- public static IList<TCP3Info> GetTCP3HistorySameTerm(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
- {
- if (0 >= term)
- return null;
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- IList<TCP3Info> r = new List<TCP3Info>();
- 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;
- }
-
-
-
-
-
-
-
-
- public static TCP3Info GetTCP3Info(long term, OpenCodeType openCodeType = OpenCodeType.Normal)
- {
- var list = GetTCP3List();
- if (null == list || 0 >= list.Count)
- return null;
- TCP3Info 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;
- }
- }
- }
|