DataItemCache.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. using Lottomat.Application.Busines;
  2. using Lottomat.Application.Busines.SystemManage;
  3. using Lottomat.Application.Entity.SystemManage.ViewModel;
  4. using Lottomat.Cache.Factory;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using Lottomat.Application.Code;
  10. using Lottomat.Application.Entity.SystemManage;
  11. namespace Lottomat.Application.Cache
  12. {
  13. /// <summary>
  14. /// 版 本 1.0
  15. /// Copyright (c) 2016-2017
  16. /// 创建人:赵轶
  17. /// 日 期:2015.12.29 9:56
  18. /// 描 述:数据字典缓存
  19. /// </summary>
  20. public class DataItemCache
  21. {
  22. private DataItemDetailBLL busines = new DataItemDetailBLL();
  23. /// <summary>
  24. /// 字典分类bll
  25. /// </summary>
  26. public static DataItemBLL dataItemBll = new DataItemBLL();
  27. /// <summary>
  28. /// 数据字典列表
  29. /// </summary>
  30. /// <returns></returns>
  31. public IEnumerable<DataItemModel> GetDataItemList()
  32. {
  33. string key = "";
  34. IEnumerable<DataItemModel> cacheList = CacheFactory.Cache().GetCache<IEnumerable<DataItemModel>>(busines.cacheKey);
  35. if (cacheList == null)
  36. {
  37. cacheList = busines.GetDataItemList();
  38. CacheFactory.Cache().WriteCache(cacheList, busines.cacheKey);
  39. }
  40. return cacheList;
  41. }
  42. /// <summary>
  43. /// 根据编码获取项目
  44. /// </summary>
  45. /// <param name="code"></param>
  46. /// <returns></returns>
  47. public DataItemEntity GetDataItemEntityByCode(string code)
  48. {
  49. if (!string.IsNullOrEmpty(code))
  50. {
  51. DataItemEntity entity = CacheFactory.Cache().GetCache<DataItemEntity>("__" + code + "__");
  52. if (entity == null)
  53. {
  54. entity = dataItemBll.GetEntityByCode(code);
  55. CacheFactory.Cache().WriteCache(entity, "__" + code + "__");
  56. }
  57. return entity;
  58. }
  59. return default(DataItemEntity);
  60. }
  61. /// <summary>
  62. /// 根据字典详细信息ID获取字典实体
  63. /// </summary>
  64. /// <param name="id"></param>
  65. /// <returns></returns>
  66. public DataItemDetailEntity GetDataItemEntityById(string id)
  67. {
  68. if (!string.IsNullOrEmpty(id))
  69. {
  70. DataItemDetailEntity entity = CacheFactory.Cache().GetCache<DataItemDetailEntity>("__" + id + "__");
  71. if (entity == null)
  72. {
  73. entity = busines.GetEntityById(id);
  74. CacheFactory.Cache().WriteCache(entity, "__" + id + "__");
  75. }
  76. return entity;
  77. }
  78. return default(DataItemDetailEntity);
  79. }
  80. /// <summary>
  81. /// 根据字典详细信息ID获取字典实体集合
  82. /// </summary>
  83. /// <param name="id"></param>
  84. /// <returns></returns>
  85. public List<DataItemDetailEntity> GetDataItemListById(string id)
  86. {
  87. if (!string.IsNullOrEmpty(id))
  88. {
  89. List<DataItemDetailEntity> entity = CacheFactory.Cache().GetCache<List<DataItemDetailEntity>>("__" + id + "__DATA__ITEM__LIST__");
  90. if (entity == null)
  91. {
  92. entity = busines.GetDataItemListById(id);
  93. CacheFactory.Cache().WriteCache(entity, "__" + id + "__DATA__ITEM__LIST__");
  94. }
  95. return entity;
  96. }
  97. return default(List<DataItemDetailEntity>);
  98. }
  99. /// <summary>
  100. /// 数据字典列表
  101. /// </summary>
  102. /// <param name="EnCode">分类代码</param>
  103. /// <returns></returns>
  104. public List<DataItemModel> GetDataItemList(string EnCode)
  105. {
  106. string[] codeArr = EnCode.Split("|".ToArray());
  107. return this.GetDataItemList().Where(t => codeArr.Contains(t.EnCode) && t.EnabledMark == (int)EnabledMarkEnum.Enabled).ToList();
  108. }
  109. /// <summary>
  110. /// 数据字典列表
  111. /// </summary>
  112. /// <param name="EnCode">分类代码</param>
  113. /// <param name="ItemValue">项目值</param>
  114. /// <returns></returns>
  115. public IEnumerable<DataItemModel> GetSubDataItemList(string EnCode, string ItemValue)
  116. {
  117. IEnumerable<DataItemModel> data = this.GetDataItemList().Where(t => t.EnCode == EnCode);
  118. IEnumerable<DataItemModel> dataItemModels = data as DataItemModel[] ?? data.ToArray();
  119. string itemDetailId = dataItemModels.First(t => t.ItemValue == ItemValue).ItemDetailId;
  120. return dataItemModels.Where(t => t.ParentId == itemDetailId);
  121. }
  122. /// <summary>
  123. /// 根据itemvalue 获取实体
  124. /// </summary>
  125. /// <param name="ItemValue"></param>
  126. /// <returns></returns>
  127. public DataItemModel GetItemDetailByItemValue(string ItemValue)
  128. {
  129. DataItemModel data = this.GetDataItemList().First(t => t.ItemValue == ItemValue);
  130. return data;
  131. }
  132. /// <summary>
  133. /// 项目值转换名称
  134. /// </summary>
  135. /// <param name="EnCode">分类代码</param>
  136. /// <param name="ItemValue">项目值</param>
  137. /// <returns></returns>
  138. public string ToItemName(string EnCode, string ItemValue)
  139. {
  140. IEnumerable<DataItemModel> data = this.GetDataItemList().Where(t => t.EnCode == EnCode);
  141. return data.First(t => t.ItemValue == ItemValue).ItemName;
  142. }
  143. }
  144. }