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.
 
 
 
 
 
 

259 lines
7.2 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. /// 获取分页数据
  124. /// <returns></returns>
  125. public List<RoleEntity> GetListForSelect()
  126. {
  127. try
  128. {
  129. return (List<RoleEntity>)roleService.GetListForSelect();
  130. }
  131. catch (Exception ex)
  132. {
  133. if (ex is ExceptionEx)
  134. {
  135. throw;
  136. }
  137. else
  138. {
  139. throw ExceptionEx.ThrowBusinessException(ex);
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 根据角色名获取角色
  145. /// </summary>
  146. /// <param name="roleName"></param>
  147. /// <returns></returns>
  148. public RoleEntity GetRoleByRoleName(string roleName)
  149. {
  150. try
  151. {
  152. return roleService.GetRoleByRoleName(roleName);
  153. }
  154. catch (Exception ex)
  155. {
  156. if (ex is ExceptionEx)
  157. {
  158. throw;
  159. }
  160. else
  161. {
  162. throw ExceptionEx.ThrowBusinessException(ex);
  163. }
  164. }
  165. }
  166. /// <summary>
  167. /// 获取角色数据列表
  168. /// </summary>
  169. /// <param name="roleIds">主键串</param>
  170. /// <returns></returns>
  171. public IEnumerable<RoleEntity> GetListByRoleIds(string roleIds)
  172. {
  173. try
  174. {
  175. List<RoleEntity> listout = new List<RoleEntity>();
  176. List<RoleEntity> list = GetList();
  177. foreach (var roleid in roleIds.Split(','))
  178. {
  179. if (list.Find(t => t.F_RoleId == roleid) != null)
  180. {
  181. listout.Add(list.Find(t => t.F_RoleId == roleid));
  182. }
  183. }
  184. return listout;
  185. }
  186. catch (Exception ex)
  187. {
  188. if (ex is ExceptionEx)
  189. {
  190. throw;
  191. }
  192. else
  193. {
  194. throw ExceptionEx.ThrowBusinessException(ex);
  195. }
  196. }
  197. }
  198. #endregion
  199. #region 提交数据
  200. /// <summary>
  201. /// 虚拟删除角色
  202. /// </summary>
  203. /// <param name="keyValue">主键</param>
  204. public void VirtualDelete(string keyValue)
  205. {
  206. try
  207. {
  208. cache.Remove(cacheKey, CacheId.role);
  209. roleService.VirtualDelete(keyValue);
  210. }
  211. catch (Exception ex)
  212. {
  213. if (ex is ExceptionEx)
  214. {
  215. throw;
  216. }
  217. else
  218. {
  219. throw ExceptionEx.ThrowBusinessException(ex);
  220. }
  221. }
  222. }
  223. /// <summary>
  224. /// 保存角色(新增、修改)
  225. /// </summary>
  226. /// <param name="keyValue">主键值</param>
  227. /// <param name="roleEntity">角色实体</param>
  228. /// <returns></returns>
  229. public void SaveEntity(string keyValue, RoleEntity roleEntity)
  230. {
  231. try
  232. {
  233. cache.Remove(cacheKey, CacheId.role);
  234. roleService.SaveEntity(keyValue, roleEntity);
  235. }
  236. catch (Exception ex)
  237. {
  238. if (ex is ExceptionEx)
  239. {
  240. throw;
  241. }
  242. else
  243. {
  244. throw ExceptionEx.ThrowBusinessException(ex);
  245. }
  246. }
  247. }
  248. #endregion
  249. }
  250. }