using CP.Cache;
using CP.Model;
using CP.Model.other;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CP.Business
{
public class SkillsBLL : DataConnect
{
/// 缓存
///
static WMCache cache = WMCache.GetCacheService();
///
/// 得到集合根据类型名称
///
///
///
public List GetList(string typeName)
{
DataConnect dc = new DataConnect();
string key = "Skills_" + typeName;
List list = cache.GetObject>(key);
if (list == null)
{
//var listAll = cache.GetObject>(CacheKeys.SkillsList);
//if (listAll == null)
//{
// listAll = dc.db.Fetch($" ORDER BY id asc");
// cache.AddObject(CacheKeys.SkillsList, listAll, (int)CacheTime.System);
//}
list = dc.db.Fetch($" WHERE typename='{typeName}'");
cache.AddObject(key, list, (int)CacheTime.System);
}
return list;
}
///
/// 得到集合根据类型名称
///
///
///
public Skills GetSkills(int id)
{
DataConnect dc = new DataConnect();
string key = "Skills_" + id;
var model = cache.GetObject(key);
if (model == null)
{
var list = dc.db.Fetch($" WHERE id={id}");
cache.AddObject(key, list.Count > 0 ? list[0] : new Skills(), (int)CacheTime.System);
return list.Count > 0 ? list[0] : new Skills();
}
return model;
}
///
/// 获取类型名称集合
///
///
public List GetTypeName()
{
string key = string.Format(CacheKeys.SkillsTypeNameList);
var list = cache.GetObject>(key);
if (list == null)
{
DataConnect dc = new DataConnect();
list = dc.db.Fetch($" ORDER BY id asc").GroupBy(p => p.typename).Select(p => p.Key).ToList();
cache.AddObject(key, list, (int)CacheTime.System);
}
return list;
}
///
/// 获取具体内容
///
///
///
public SkillsContent GetSkillsContent(int id)
{
DataConnect dc = new DataConnect();
string key = "SkillsContent_" + id;
List list = cache.GetObject>(key);
if (list == null)
{
//var listAll = cache.GetObject>(CacheKeys.SkillsContenteList);
//if (listAll == null)
//{
// listAll = dc.db.Fetch($" ORDER BY skillsid asc");
// cache.AddObject(CacheKeys.SkillsContenteList, listAll, (int)CacheTime.System);
//}
list = dc.db.Fetch($" where skillsid={id}");
cache.AddObject(key, list, (int)CacheTime.System);
}
return list[0];
}
}
}