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
{
///
/// 获取工具配置信息
///
///
public static IList GetTrendToolList(TrendToolInfo entity)
{
var cache = CBCache.GetCacheService();
IList list = cache.GetObject(CacheKeys.TrendToolList) as IList;
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();
}
///
/// 获取工具配置信息及子项
///
///
public static List GetTrendToolChildList(TrendToolInfo entity)
{
var cache = CBCache.GetCacheService();
IList list = cache.GetObject(CacheKeys.TrendToolList) as IList;
if(list== null)
{
list = TrendToolService.ToList();
cache.AddObject(CacheKeys.TrendToolList, list);
}
var query = GetSonId(list, entity.Id);
List result = query.ToList();
////加入第一级
var item = list.FirstOrDefault(x => x.Id == entity.Id);
if (item!=null)
{
result.Add(item);
}
return result;
}
///
/// 递归实现
///
///
///
///
private static IEnumerable GetSonId(IList list, int id)
{
var query = from c in list
where c.ParentID == id
select c;
var trendToolInfos = query as IList ?? query.ToList();
return trendToolInfos.ToList().Concat(trendToolInfos.ToList().SelectMany(t => GetSonId(list, t.Id)));
}
///
/// 生成3D所有的号码
///
///
public static List GetBase3DAllNumber()
{
var cache = CBCache.GetCacheService();
List cachelist = cache.GetObject(CacheKeys.TrendTool3DNumbers) as List;
if (null == cachelist || cachelist.Count == 0)
{
if (null == cachelist) cachelist = new List();
for (int i = 0; i < 1000; i++)
{
cachelist.Add(string.Join(",", i.ToString("000").ToCharArray()));
}
cache.AddObject(CacheKeys.TrendTool3DNumbers, cachelist);
}
List list = new List(cachelist.ToArray());
return list;
}
}
}