123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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
- {
- /// 缓存
- /// </summary>
- static WMCache cache = WMCache.GetCacheService();
- /// <summary>
- /// 得到集合根据类型名称
- /// </summary>
- /// <param name="typeName"></param>
- /// <returns></returns>
- public List<Skills> GetList(string typeName)
- {
- DataConnect dc = new DataConnect();
- string key = "Skills_" + typeName;
- List<Skills> list = cache.GetObject<List<Skills>>(key);
- if (list == null)
- {
- //var listAll = cache.GetObject<List<Skills>>(CacheKeys.SkillsList);
- //if (listAll == null)
- //{
- // listAll = dc.db.Fetch<Skills>($" ORDER BY id asc");
- // cache.AddObject(CacheKeys.SkillsList, listAll, (int)CacheTime.System);
- //}
- list = dc.db.Fetch<Skills>($" WHERE typename='{typeName}'");
- cache.AddObject(key, list, (int)CacheTime.System);
- }
- return list;
- }
- /// <summary>
- /// 得到集合根据类型名称
- /// </summary>
- /// <param name="typeName"></param>
- /// <returns></returns>
- public Skills GetSkills(int id)
- {
- DataConnect dc = new DataConnect();
- string key = "Skills_" + id;
- var model = cache.GetObject<Skills>(key);
- if (model == null)
- {
- var list = dc.db.Fetch<Skills>($" 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;
- }
- /// <summary>
- /// 获取类型名称集合
- /// </summary>
- /// <returns></returns>
- public List<string> GetTypeName()
- {
- string key = string.Format(CacheKeys.SkillsTypeNameList);
- var list = cache.GetObject<List<string>>(key);
- if (list == null)
- {
- DataConnect dc = new DataConnect();
- list = dc.db.Fetch<Skills>($" ORDER BY id asc").GroupBy(p => p.typename).Select(p => p.Key).ToList();
- cache.AddObject(key, list, (int)CacheTime.System);
- }
- return list;
- }
- /// <summary>
- /// 获取具体内容
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public SkillsContent GetSkillsContent(int id)
- {
- DataConnect dc = new DataConnect();
- string key = "SkillsContent_" + id;
- List<SkillsContent> list = cache.GetObject<List<SkillsContent>>(key);
- if (list == null)
- {
- //var listAll = cache.GetObject<List<SkillsContent>>(CacheKeys.SkillsContenteList);
- //if (listAll == null)
- //{
- // listAll = dc.db.Fetch<SkillsContent>($" ORDER BY skillsid asc");
- // cache.AddObject(CacheKeys.SkillsContenteList, listAll, (int)CacheTime.System);
- //}
- list = dc.db.Fetch<SkillsContent>($" where skillsid={id}");
- cache.AddObject(key, list, (int)CacheTime.System);
- }
- return list[0];
- }
- }
- }
|