DataItemCache.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using LeaRun.Application.Busines;
  2. using LeaRun.Application.Busines.SystemManage;
  3. using LeaRun.Application.Entity.SystemManage.ViewModel;
  4. using LeaRun.Cache.Factory;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. namespace LeaRun.Application.Cache
  10. {
  11. /// <summary>
  12. /// 版 本 6.1
  13. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  14. /// 创建人:佘赐雄
  15. /// 日 期:2015.12.29 9:56
  16. /// 描 述:数据字典缓存
  17. /// </summary>
  18. public class DataItemCache
  19. {
  20. private DataItemDetailBLL busines = new DataItemDetailBLL();
  21. /// <summary>
  22. /// 数据字典列表
  23. /// </summary>
  24. /// <returns></returns>
  25. public IEnumerable<DataItemModel> GetDataItemList()
  26. {
  27. var cacheList = CacheFactory.Cache().GetCache<IEnumerable<DataItemModel>>(busines.cacheKey);
  28. if (cacheList == null)
  29. {
  30. var data = busines.GetDataItemList();
  31. CacheFactory.Cache().WriteCache(data, busines.cacheKey);
  32. return data;
  33. }
  34. else
  35. {
  36. return cacheList;
  37. }
  38. }
  39. /// <summary>
  40. /// 数据字典列表
  41. /// </summary>
  42. /// <param name="EnCode">分类代码</param>
  43. /// <returns></returns>
  44. public IEnumerable<DataItemModel> GetDataItemList(string EnCode)
  45. {
  46. return this.GetDataItemList().Where(t => t.EnCode == EnCode);
  47. }
  48. /// <summary>
  49. /// 数据字典列表
  50. /// </summary>
  51. /// <param name="EnCode">分类代码</param>
  52. /// <param name="ItemValue">项目值</param>
  53. /// <returns></returns>
  54. public IEnumerable<DataItemModel> GetSubDataItemList(string EnCode, string ItemValue)
  55. {
  56. var data = this.GetDataItemList().Where(t => t.EnCode == EnCode);
  57. string ItemDetailId = data.First(t => t.ItemValue == ItemValue).ItemDetailId;
  58. return data.Where(t => t.ParentId == ItemDetailId);
  59. }
  60. /// <summary>
  61. /// 项目值转换名称
  62. /// </summary>
  63. /// <param name="EnCode">分类代码</param>
  64. /// <param name="ItemValue">项目值</param>
  65. /// <returns></returns>
  66. public string ToItemName(string EnCode, string ItemValue)
  67. {
  68. var data = this.GetDataItemList().Where(t => t.EnCode == EnCode);
  69. return data.First(t => t.ItemValue == ItemValue).ItemName;
  70. }
  71. }
  72. }