You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

229 lines
7.0 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Util;
  3. using Learun.Cache.Factory;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.Base.SystemModule
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.04.01
  13. /// 描 述:行政区域 redis 3号库
  14. /// </summary>
  15. public class AreaBLL : AreaIBLL
  16. {
  17. #region 属性
  18. private AreaService areaService = new AreaService();
  19. #endregion
  20. #region 缓存定义
  21. private ICache cache = CacheFactory.CaChe();
  22. private string cacheKey = "Learun_adms_area_"; // +父级Id
  23. #endregion
  24. #region 获取数据
  25. /// <summary>
  26. /// 获取区域列表数据
  27. /// </summary>
  28. /// <param name="parentId">父节点主键(0表示顶层)</param>
  29. /// <returns></returns>
  30. public List<AreaEntity> GetList(string parentId)
  31. {
  32. try
  33. {
  34. if (string.IsNullOrEmpty(parentId))
  35. {
  36. parentId = "0";
  37. }
  38. List<AreaEntity> list = cache.Read<List<AreaEntity>>(cacheKey + parentId, CacheId.area);
  39. if (list == null|| list.Count==0)
  40. {
  41. list = (List<AreaEntity>)areaService.GetList(parentId);
  42. cache.Write<List<AreaEntity>>(cacheKey + parentId, list, CacheId.area);
  43. }
  44. return list;
  45. }
  46. catch (Exception ex)
  47. {
  48. if (ex is ExceptionEx)
  49. {
  50. throw;
  51. }
  52. else
  53. {
  54. throw ExceptionEx.ThrowBusinessException(ex);
  55. }
  56. throw;
  57. }
  58. }
  59. /// <summary>
  60. /// 获取区域列表数据
  61. /// </summary>
  62. /// <param name="parentId">父节点主键(0表示顶层)</param>
  63. /// <param name="keyword">关键字查询(名称/编号)</param>
  64. /// <returns></returns>
  65. public List<AreaEntity> GetList(string parentId, string keyword)
  66. {
  67. try
  68. {
  69. List<AreaEntity> list = GetList(parentId);
  70. if (!string.IsNullOrEmpty(keyword))
  71. {
  72. list = list.FindAll(t => t.F_AreaName.Contains(keyword) || t.F_AreaCode.Contains(keyword));
  73. }
  74. return list;
  75. }
  76. catch (Exception ex)
  77. {
  78. if (ex is ExceptionEx)
  79. {
  80. throw;
  81. }
  82. else
  83. {
  84. throw ExceptionEx.ThrowBusinessException(ex);
  85. }
  86. throw;
  87. }
  88. }
  89. /// <summary>
  90. /// 区域实体
  91. /// </summary>
  92. /// <param name="keyValue">主键值</param>
  93. /// <returns></returns>
  94. public AreaEntity GetEntity(string keyValue)
  95. {
  96. try
  97. {
  98. return areaService.GetEntity(keyValue);
  99. }
  100. catch (Exception ex)
  101. {
  102. if (ex is ExceptionEx)
  103. {
  104. throw;
  105. }
  106. else
  107. {
  108. throw ExceptionEx.ThrowBusinessException(ex);
  109. }
  110. throw;
  111. }
  112. }
  113. /// <summary>
  114. /// 获取区域数据树(某一级的)
  115. /// </summary>
  116. /// <param name="parentId">父级主键</param>
  117. /// <returns></returns>
  118. public List<TreeModel> GetTree(string parentId)
  119. {
  120. try
  121. {
  122. List<TreeModel> treeList = new List<TreeModel>();
  123. List<AreaEntity> list = GetList(parentId);
  124. foreach (var item in list)
  125. {
  126. TreeModel node = new TreeModel();
  127. node.id = item.F_AreaId;
  128. node.text = item.F_AreaName;
  129. node.value = item.F_AreaCode;
  130. node.showcheck = false;
  131. node.checkstate = 0;
  132. node.hasChildren = GetList(item.F_AreaId).Count > 0 ? true : false;
  133. node.isexpand = false;
  134. node.complete = false;
  135. treeList.Add(node);
  136. }
  137. return treeList;
  138. }
  139. catch (Exception ex)
  140. {
  141. if (ex is ExceptionEx)
  142. {
  143. throw;
  144. }
  145. else
  146. {
  147. throw ExceptionEx.ThrowBusinessException(ex);
  148. }
  149. throw;
  150. }
  151. }
  152. #endregion
  153. #region 提交数据
  154. /// <summary>
  155. /// 虚拟删除区域
  156. /// </summary>
  157. /// <param name="keyValue">主键</param>
  158. public void VirtualDelete(string keyValue)
  159. {
  160. try
  161. {
  162. AreaEntity entity = areaService.GetEntity(keyValue);
  163. cache.Remove(cacheKey + entity.F_ParentId,CacheId.area);
  164. areaService.VirtualDelete(keyValue);
  165. }
  166. catch (Exception ex)
  167. {
  168. if (ex is ExceptionEx)
  169. {
  170. throw;
  171. }
  172. else
  173. {
  174. throw ExceptionEx.ThrowBusinessException(ex);
  175. }
  176. }
  177. }
  178. /// <summary>
  179. /// 保存区域表单(新增、修改)
  180. /// </summary>
  181. /// <param name="keyValue">主键值</param>
  182. /// <param name="areaEntity">区域实体</param>
  183. /// <returns></returns>
  184. public void SaveEntity(string keyValue, AreaEntity areaEntity)
  185. {
  186. try
  187. {
  188. cache.Remove(cacheKey + areaEntity.F_ParentId, CacheId.area);
  189. if (!string.IsNullOrEmpty(keyValue))
  190. {
  191. AreaEntity entity = areaService.GetEntity(keyValue);
  192. cache.Remove(cacheKey + entity.F_ParentId, CacheId.area);
  193. }
  194. if (areaEntity.F_ParentId != "0")
  195. {
  196. AreaEntity entity = GetEntity(areaEntity.F_ParentId);
  197. if (entity != null)
  198. {
  199. areaEntity.F_Layer = entity.F_Layer + 1;
  200. }
  201. }
  202. else
  203. {
  204. areaEntity.F_Layer = 1;
  205. }
  206. areaService.SaveEntity(keyValue, areaEntity);
  207. }
  208. catch (Exception ex)
  209. {
  210. if (ex is ExceptionEx)
  211. {
  212. throw;
  213. }
  214. else
  215. {
  216. throw ExceptionEx.ThrowBusinessException(ex);
  217. }
  218. }
  219. }
  220. #endregion
  221. }
  222. }