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.
 
 
 
 
 
 

238 lines
6.6 KiB

  1. using Learun.Cache.Base;
  2. using Learun.Cache.Factory;
  3. using Learun.Util;
  4. using System;
  5. using System.Collections.Generic;
  6. namespace Learun.Application.Organization
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.04
  13. /// 描 述:角色管理
  14. /// </summary>
  15. public class RoleBLL : RoleIBLL
  16. {
  17. #region 属性
  18. private RoleService roleService = new RoleService();
  19. #endregion
  20. #region 缓存定义
  21. private ICache cache = CacheFactory.CaChe();
  22. private string cacheKey = "learun_adms_role";
  23. #endregion
  24. #region 获取数据
  25. /// <summary>
  26. /// 获取角色数据列表
  27. /// </summary>
  28. /// <returns></returns>
  29. public List<RoleEntity> GetList()
  30. {
  31. try
  32. {
  33. List<RoleEntity> list = cache.Read<List<RoleEntity>>(cacheKey, CacheId.role);
  34. if (list == null)
  35. {
  36. list = (List<RoleEntity>)roleService.GetList();
  37. cache.Write<List<RoleEntity>>(cacheKey, list, CacheId.role);
  38. }
  39. return list;
  40. }
  41. catch (Exception ex)
  42. {
  43. if (ex is ExceptionEx)
  44. {
  45. throw;
  46. }
  47. else
  48. {
  49. throw ExceptionEx.ThrowBusinessException(ex);
  50. }
  51. }
  52. }
  53. /// <summary>
  54. /// 获取角色数据列表
  55. /// </summary>
  56. /// <param name="keyword">关键字</param>
  57. /// <returns></returns>
  58. public List<RoleEntity> GetList(string keyword)
  59. {
  60. try
  61. {
  62. List<RoleEntity> list = GetList();
  63. if (!string.IsNullOrEmpty(keyword))
  64. {
  65. list = list.FindAll(t => t.F_FullName.Contains(keyword) || t.F_EnCode.Contains(keyword));
  66. }
  67. return list;
  68. }
  69. catch (Exception ex)
  70. {
  71. if (ex is ExceptionEx)
  72. {
  73. throw;
  74. }
  75. else
  76. {
  77. throw ExceptionEx.ThrowBusinessException(ex);
  78. }
  79. }
  80. }
  81. public string GetIdByRoleName(string v)
  82. {
  83. try
  84. {
  85. return roleService.GetIdByRoleName(v);
  86. }
  87. catch (Exception ex)
  88. {
  89. if (ex is ExceptionEx)
  90. {
  91. throw;
  92. }
  93. else
  94. {
  95. throw ExceptionEx.ThrowBusinessException(ex);
  96. }
  97. }
  98. }
  99. /// <summary>
  100. /// 获取分页数据
  101. /// </summary>
  102. /// <param name="pagination">分页参数</param>
  103. /// <param name="keyword">查询关键词</param>
  104. /// <returns></returns>
  105. public List<RoleEntity> GetPageList(Pagination pagination, string keyword)
  106. {
  107. try
  108. {
  109. return (List<RoleEntity>)roleService.GetPageList(pagination, keyword);
  110. }
  111. catch (Exception ex)
  112. {
  113. if (ex is ExceptionEx)
  114. {
  115. throw;
  116. }
  117. else
  118. {
  119. throw ExceptionEx.ThrowBusinessException(ex);
  120. }
  121. }
  122. }
  123. /// <summary>
  124. /// 根据角色名获取角色
  125. /// </summary>
  126. /// <param name="roleName"></param>
  127. /// <returns></returns>
  128. public RoleEntity GetRoleByRoleName(string roleName)
  129. {
  130. try
  131. {
  132. return roleService.GetRoleByRoleName(roleName);
  133. }
  134. catch (Exception ex)
  135. {
  136. if (ex is ExceptionEx)
  137. {
  138. throw;
  139. }
  140. else
  141. {
  142. throw ExceptionEx.ThrowBusinessException(ex);
  143. }
  144. }
  145. }
  146. /// <summary>
  147. /// 获取角色数据列表
  148. /// </summary>
  149. /// <param name="roleIds">主键串</param>
  150. /// <returns></returns>
  151. public IEnumerable<RoleEntity> GetListByRoleIds(string roleIds)
  152. {
  153. try
  154. {
  155. List<RoleEntity> listout = new List<RoleEntity>();
  156. List<RoleEntity> list = GetList();
  157. foreach (var roleid in roleIds.Split(','))
  158. {
  159. if (list.Find(t => t.F_RoleId == roleid) != null)
  160. {
  161. listout.Add(list.Find(t => t.F_RoleId == roleid));
  162. }
  163. }
  164. return listout;
  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. #endregion
  179. #region 提交数据
  180. /// <summary>
  181. /// 虚拟删除角色
  182. /// </summary>
  183. /// <param name="keyValue">主键</param>
  184. public void VirtualDelete(string keyValue)
  185. {
  186. try
  187. {
  188. cache.Remove(cacheKey, CacheId.role);
  189. roleService.VirtualDelete(keyValue);
  190. }
  191. catch (Exception ex)
  192. {
  193. if (ex is ExceptionEx)
  194. {
  195. throw;
  196. }
  197. else
  198. {
  199. throw ExceptionEx.ThrowBusinessException(ex);
  200. }
  201. }
  202. }
  203. /// <summary>
  204. /// 保存角色(新增、修改)
  205. /// </summary>
  206. /// <param name="keyValue">主键值</param>
  207. /// <param name="roleEntity">角色实体</param>
  208. /// <returns></returns>
  209. public void SaveEntity(string keyValue, RoleEntity roleEntity)
  210. {
  211. try
  212. {
  213. cache.Remove(cacheKey, CacheId.role);
  214. roleService.SaveEntity(keyValue, roleEntity);
  215. }
  216. catch (Exception ex)
  217. {
  218. if (ex is ExceptionEx)
  219. {
  220. throw;
  221. }
  222. else
  223. {
  224. throw ExceptionEx.ThrowBusinessException(ex);
  225. }
  226. }
  227. }
  228. #endregion
  229. }
  230. }