SkillsBLL.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using CP.Cache;
  2. using CP.Model;
  3. using CP.Model.other;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. namespace CP.Business
  10. {
  11. public class SkillsBLL : DataConnect
  12. {
  13. /// 缓存
  14. /// </summary>
  15. static WMCache cache = WMCache.GetCacheService();
  16. /// <summary>
  17. /// 得到集合根据类型名称
  18. /// </summary>
  19. /// <param name="typeName"></param>
  20. /// <returns></returns>
  21. public List<Skills> GetList(string typeName)
  22. {
  23. DataConnect dc = new DataConnect();
  24. string key = "Skills_" + typeName;
  25. List<Skills> list = cache.GetObject<List<Skills>>(key);
  26. if (list == null)
  27. {
  28. //var listAll = cache.GetObject<List<Skills>>(CacheKeys.SkillsList);
  29. //if (listAll == null)
  30. //{
  31. // listAll = dc.db.Fetch<Skills>($" ORDER BY id asc");
  32. // cache.AddObject(CacheKeys.SkillsList, listAll, (int)CacheTime.System);
  33. //}
  34. list = dc.db.Fetch<Skills>($" WHERE typename='{typeName}'");
  35. cache.AddObject(key, list, (int)CacheTime.System);
  36. }
  37. return list;
  38. }
  39. /// <summary>
  40. /// 得到集合根据类型名称
  41. /// </summary>
  42. /// <param name="typeName"></param>
  43. /// <returns></returns>
  44. public Skills GetSkills(int id)
  45. {
  46. DataConnect dc = new DataConnect();
  47. string key = "Skills_" + id;
  48. var model = cache.GetObject<Skills>(key);
  49. if (model == null)
  50. {
  51. var list = dc.db.Fetch<Skills>($" WHERE id={id}");
  52. cache.AddObject(key, list.Count > 0 ? list[0] : new Skills(), (int)CacheTime.System);
  53. return list.Count > 0 ? list[0] : new Skills();
  54. }
  55. return model;
  56. }
  57. /// <summary>
  58. /// 获取类型名称集合
  59. /// </summary>
  60. /// <returns></returns>
  61. public List<string> GetTypeName()
  62. {
  63. string key = string.Format(CacheKeys.SkillsTypeNameList);
  64. var list = cache.GetObject<List<string>>(key);
  65. if (list == null)
  66. {
  67. DataConnect dc = new DataConnect();
  68. list = dc.db.Fetch<Skills>($" ORDER BY id asc").GroupBy(p => p.typename).Select(p => p.Key).ToList();
  69. cache.AddObject(key, list, (int)CacheTime.System);
  70. }
  71. return list;
  72. }
  73. /// <summary>
  74. /// 获取具体内容
  75. /// </summary>
  76. /// <param name="id"></param>
  77. /// <returns></returns>
  78. public SkillsContent GetSkillsContent(int id)
  79. {
  80. DataConnect dc = new DataConnect();
  81. string key = "SkillsContent_" + id;
  82. List<SkillsContent> list = cache.GetObject<List<SkillsContent>>(key);
  83. if (list == null)
  84. {
  85. //var listAll = cache.GetObject<List<SkillsContent>>(CacheKeys.SkillsContenteList);
  86. //if (listAll == null)
  87. //{
  88. // listAll = dc.db.Fetch<SkillsContent>($" ORDER BY skillsid asc");
  89. // cache.AddObject(CacheKeys.SkillsContenteList, listAll, (int)CacheTime.System);
  90. //}
  91. list = dc.db.Fetch<SkillsContent>($" where skillsid={id}");
  92. cache.AddObject(key, list, (int)CacheTime.System);
  93. }
  94. return list[0];
  95. }
  96. }
  97. }