TrendToolsCache.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using CB.Cache;
  6. using CB.Entity;
  7. namespace CB.Data
  8. {
  9. public partial class Caches
  10. {
  11. /// <summary>
  12. /// 获取工具配置信息
  13. /// </summary>
  14. /// <returns></returns>
  15. public static IList<TrendToolInfo> GetTrendToolList(TrendToolInfo entity)
  16. {
  17. var cache = CBCache.GetCacheService();
  18. IList<TrendToolInfo> list = cache.GetObject(CacheKeys.TrendToolList) as IList<TrendToolInfo>;
  19. if (null == list)
  20. {
  21. list = TrendToolService.ToList();
  22. cache.AddObject(CacheKeys.TrendToolList, list);
  23. }
  24. #region
  25. //foreach (var item in list)
  26. //{
  27. // if ((entity.Id == item.Id || entity.Id == 0)
  28. // && (entity.PageID == item.PageID || entity.PageID == 0)
  29. // && (entity.ParentID == item.ParentID || entity.ParentID == 0)
  30. // && (entity.Status == item.Status || entity.Status == FilterStatus.None))
  31. // {
  32. // listResult.Add(item);
  33. // }
  34. //}
  35. #endregion
  36. return list.Where(item => (entity.Id == item.Id || entity.Id == 0)
  37. && (entity.PageID == item.PageID || entity.PageID == 0)
  38. && (entity.ParentID == item.ParentID || entity.ParentID == 0)
  39. && (entity.Status == item.Status || entity.Status == FilterStatus.None)).ToList();
  40. }
  41. /// <summary>
  42. /// 获取工具配置信息及子项
  43. /// </summary>
  44. /// <returns></returns>
  45. public static List<TrendToolInfo> GetTrendToolChildList(TrendToolInfo entity)
  46. {
  47. var cache = CBCache.GetCacheService();
  48. IList<TrendToolInfo> list = cache.GetObject(CacheKeys.TrendToolList) as IList<TrendToolInfo>;
  49. if(list== null)
  50. {
  51. list = TrendToolService.ToList();
  52. cache.AddObject(CacheKeys.TrendToolList, list);
  53. }
  54. var query = GetSonId(list, entity.Id);
  55. List<TrendToolInfo> result = query.ToList();
  56. ////加入第一级
  57. var item = list.FirstOrDefault(x => x.Id == entity.Id);
  58. if (item!=null)
  59. {
  60. result.Add(item);
  61. }
  62. return result;
  63. }
  64. /// <summary>
  65. /// 递归实现
  66. /// </summary>
  67. /// <param name="list"></param>
  68. /// <param name="id"></param>
  69. /// <returns></returns>
  70. private static IEnumerable<TrendToolInfo> GetSonId(IList<TrendToolInfo> list, int id)
  71. {
  72. var query = from c in list
  73. where c.ParentID == id
  74. select c;
  75. var trendToolInfos = query as IList<TrendToolInfo> ?? query.ToList();
  76. return trendToolInfos.ToList().Concat(trendToolInfos.ToList().SelectMany(t => GetSonId(list, t.Id)));
  77. }
  78. /// <summary>
  79. /// 生成3D所有的号码
  80. /// </summary>
  81. /// <returns></returns>
  82. public static List<string> GetBase3DAllNumber()
  83. {
  84. var cache = CBCache.GetCacheService();
  85. List<string> cachelist = cache.GetObject(CacheKeys.TrendTool3DNumbers) as List<string>;
  86. if (null == cachelist || cachelist.Count == 0)
  87. {
  88. if (null == cachelist) cachelist = new List<string>();
  89. for (int i = 0; i < 1000; i++)
  90. {
  91. cachelist.Add(string.Join(",", i.ToString("000").ToCharArray()));
  92. }
  93. cache.AddObject(CacheKeys.TrendTool3DNumbers, cachelist);
  94. }
  95. List<string> list = new List<string>(cachelist.ToArray());
  96. return list;
  97. }
  98. }
  99. }