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.
 
 
 
 
 
 

251 lines
7.5 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. public AreaEntity GetEntityByCode(string code)
  114. {
  115. try
  116. {
  117. return areaService.GetEntityByCode(code);
  118. }
  119. catch (Exception ex)
  120. {
  121. if (ex is ExceptionEx)
  122. {
  123. throw;
  124. }
  125. else
  126. {
  127. throw ExceptionEx.ThrowBusinessException(ex);
  128. }
  129. throw;
  130. }
  131. }
  132. /// <summary>
  133. /// 获取区域数据树(某一级的)
  134. /// </summary>
  135. /// <param name="parentId">父级主键</param>
  136. /// <returns></returns>
  137. public List<TreeModel> GetTree(string parentId)
  138. {
  139. try
  140. {
  141. List<TreeModel> treeList = new List<TreeModel>();
  142. List<AreaEntity> list = GetList(parentId);
  143. foreach (var item in list)
  144. {
  145. TreeModel node = new TreeModel();
  146. node.id = item.F_AreaCode;
  147. node.text = item.F_AreaName;
  148. node.value = item.F_AreaCode;
  149. node.showcheck = false;
  150. node.checkstate = 0;
  151. node.hasChildren = GetList(item.F_AreaCode).Count > 0 ? true : false;
  152. node.isexpand = false;
  153. node.complete = false;
  154. treeList.Add(node);
  155. }
  156. return treeList;
  157. }
  158. catch (Exception ex)
  159. {
  160. if (ex is ExceptionEx)
  161. {
  162. throw;
  163. }
  164. else
  165. {
  166. throw ExceptionEx.ThrowBusinessException(ex);
  167. }
  168. throw;
  169. }
  170. }
  171. #endregion
  172. #region 提交数据
  173. /// <summary>
  174. /// 虚拟删除区域
  175. /// </summary>
  176. /// <param name="keyValue">主键</param>
  177. public void VirtualDelete(string keyValue)
  178. {
  179. try
  180. {
  181. AreaEntity entity = areaService.GetEntity(keyValue);
  182. cache.Remove(cacheKey + entity.F_ParentId,CacheId.area);
  183. areaService.VirtualDelete(keyValue);
  184. }
  185. catch (Exception ex)
  186. {
  187. if (ex is ExceptionEx)
  188. {
  189. throw;
  190. }
  191. else
  192. {
  193. throw ExceptionEx.ThrowBusinessException(ex);
  194. }
  195. }
  196. }
  197. /// <summary>
  198. /// 保存区域表单(新增、修改)
  199. /// </summary>
  200. /// <param name="keyValue">主键值</param>
  201. /// <param name="areaEntity">区域实体</param>
  202. /// <returns></returns>
  203. public void SaveEntity(string keyValue, AreaEntity areaEntity)
  204. {
  205. try
  206. {
  207. cache.Remove(cacheKey + areaEntity.F_ParentId, CacheId.area);
  208. if (!string.IsNullOrEmpty(keyValue))
  209. {
  210. AreaEntity entity = areaService.GetEntity(keyValue);
  211. cache.Remove(cacheKey + entity.F_ParentId, CacheId.area);
  212. }
  213. if (areaEntity.F_ParentId != "0")
  214. {
  215. AreaEntity entity = GetEntity(areaEntity.F_ParentId);
  216. if (entity != null)
  217. {
  218. areaEntity.F_Layer = entity.F_Layer + 1;
  219. }
  220. }
  221. else
  222. {
  223. areaEntity.F_Layer = 1;
  224. }
  225. areaService.SaveEntity(keyValue, areaEntity);
  226. }
  227. catch (Exception ex)
  228. {
  229. if (ex is ExceptionEx)
  230. {
  231. throw;
  232. }
  233. else
  234. {
  235. throw ExceptionEx.ThrowBusinessException(ex);
  236. }
  237. }
  238. }
  239. #endregion
  240. }
  241. }