123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using CB.Cache;
- using CB.Entity;
- namespace CB.Data
- {
- public partial class Caches
- {
- /// <summary>
- /// 获取工具配置信息
- /// </summary>
- /// <returns></returns>
- public static IList<TrendToolInfo> GetTrendToolList(TrendToolInfo entity)
- {
- var cache = CBCache.GetCacheService();
- IList<TrendToolInfo> list = cache.GetObject(CacheKeys.TrendToolList) as IList<TrendToolInfo>;
- if (null == list)
- {
- list = TrendToolService.ToList();
- cache.AddObject(CacheKeys.TrendToolList, list);
- }
- #region
- //foreach (var item in list)
- //{
- // if ((entity.Id == item.Id || entity.Id == 0)
- // && (entity.PageID == item.PageID || entity.PageID == 0)
- // && (entity.ParentID == item.ParentID || entity.ParentID == 0)
- // && (entity.Status == item.Status || entity.Status == FilterStatus.None))
- // {
- // listResult.Add(item);
- // }
- //}
- #endregion
- return list.Where(item => (entity.Id == item.Id || entity.Id == 0)
- && (entity.PageID == item.PageID || entity.PageID == 0)
- && (entity.ParentID == item.ParentID || entity.ParentID == 0)
- && (entity.Status == item.Status || entity.Status == FilterStatus.None)).ToList();
- }
- /// <summary>
- /// 获取工具配置信息及子项
- /// </summary>
- /// <returns></returns>
- public static List<TrendToolInfo> GetTrendToolChildList(TrendToolInfo entity)
- {
- var cache = CBCache.GetCacheService();
- IList<TrendToolInfo> list = cache.GetObject(CacheKeys.TrendToolList) as IList<TrendToolInfo>;
- if(list== null)
- {
- list = TrendToolService.ToList();
- cache.AddObject(CacheKeys.TrendToolList, list);
- }
- var query = GetSonId(list, entity.Id);
- List<TrendToolInfo> result = query.ToList();
- ////加入第一级
- var item = list.FirstOrDefault(x => x.Id == entity.Id);
- if (item!=null)
- {
- result.Add(item);
- }
- return result;
- }
- /// <summary>
- /// 递归实现
- /// </summary>
- /// <param name="list"></param>
- /// <param name="id"></param>
- /// <returns></returns>
- private static IEnumerable<TrendToolInfo> GetSonId(IList<TrendToolInfo> list, int id)
- {
- var query = from c in list
- where c.ParentID == id
- select c;
- var trendToolInfos = query as IList<TrendToolInfo> ?? query.ToList();
- return trendToolInfos.ToList().Concat(trendToolInfos.ToList().SelectMany(t => GetSonId(list, t.Id)));
- }
- /// <summary>
- /// 生成3D所有的号码
- /// </summary>
- /// <returns></returns>
- public static List<string> GetBase3DAllNumber()
- {
- var cache = CBCache.GetCacheService();
- List<string> cachelist = cache.GetObject(CacheKeys.TrendTool3DNumbers) as List<string>;
- if (null == cachelist || cachelist.Count == 0)
- {
- if (null == cachelist) cachelist = new List<string>();
- for (int i = 0; i < 1000; i++)
- {
- cachelist.Add(string.Join(",", i.ToString("000").ToCharArray()));
-
- }
- cache.AddObject(CacheKeys.TrendTool3DNumbers, cachelist);
- }
- List<string> list = new List<string>(cachelist.ToArray());
- return list;
- }
- }
- }
|