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.
 
 
 
 
 
 

298 lines
8.4 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. public RoleEntity GetEntityByRoleCode(string code)
  100. {
  101. try
  102. {
  103. return roleService.GetEntityByRoleCode(code);
  104. }
  105. catch (Exception ex)
  106. {
  107. if (ex is ExceptionEx)
  108. {
  109. throw;
  110. }
  111. else
  112. {
  113. throw ExceptionEx.ThrowBusinessException(ex);
  114. }
  115. }
  116. }
  117. /// <summary>
  118. /// 获取分页数据
  119. /// </summary>
  120. /// <param name="pagination">分页参数</param>
  121. /// <param name="keyword">查询关键词</param>
  122. /// <returns></returns>
  123. public List<RoleEntity> GetPageList(Pagination pagination, string keyword)
  124. {
  125. try
  126. {
  127. return (List<RoleEntity>)roleService.GetPageList(pagination, keyword);
  128. }
  129. catch (Exception ex)
  130. {
  131. if (ex is ExceptionEx)
  132. {
  133. throw;
  134. }
  135. else
  136. {
  137. throw ExceptionEx.ThrowBusinessException(ex);
  138. }
  139. }
  140. }
  141. /// <summary>
  142. /// 根据角色名获取角色
  143. /// </summary>
  144. /// <param name="roleName"></param>
  145. /// <returns></returns>
  146. public RoleEntity GetRoleByRoleName(string roleName)
  147. {
  148. try
  149. {
  150. return roleService.GetRoleByRoleName(roleName);
  151. }
  152. catch (Exception ex)
  153. {
  154. if (ex is ExceptionEx)
  155. {
  156. throw;
  157. }
  158. else
  159. {
  160. throw ExceptionEx.ThrowBusinessException(ex);
  161. }
  162. }
  163. }
  164. /// <summary>
  165. /// 获取角色数据列表
  166. /// </summary>
  167. /// <param name="roleIds">主键串</param>
  168. /// <returns></returns>
  169. public IEnumerable<RoleEntity> GetListByRoleIds(string roleIds)
  170. {
  171. try
  172. {
  173. List<RoleEntity> listout = new List<RoleEntity>();
  174. List<RoleEntity> list = GetList();
  175. foreach (var roleid in roleIds.Split(','))
  176. {
  177. if (list.Find(t => t.F_RoleId == roleid) != null)
  178. {
  179. listout.Add(list.Find(t => t.F_RoleId == roleid));
  180. }
  181. }
  182. return listout;
  183. }
  184. catch (Exception ex)
  185. {
  186. if (ex is ExceptionEx)
  187. {
  188. throw;
  189. }
  190. else
  191. {
  192. throw ExceptionEx.ThrowBusinessException(ex);
  193. }
  194. }
  195. }
  196. #endregion
  197. #region 提交数据
  198. /// <summary>
  199. /// 虚拟删除角色
  200. /// </summary>
  201. /// <param name="keyValue">主键</param>
  202. public void VirtualDelete(string keyValue)
  203. {
  204. try
  205. {
  206. cache.Remove(cacheKey, CacheId.role);
  207. roleService.VirtualDelete(keyValue);
  208. }
  209. catch (Exception ex)
  210. {
  211. if (ex is ExceptionEx)
  212. {
  213. throw;
  214. }
  215. else
  216. {
  217. throw ExceptionEx.ThrowBusinessException(ex);
  218. }
  219. }
  220. }
  221. /// <summary>
  222. /// 保存角色(新增、修改)
  223. /// </summary>
  224. /// <param name="keyValue">主键值</param>
  225. /// <param name="roleEntity">角色实体</param>
  226. /// <returns></returns>
  227. public void SaveEntity(string keyValue, RoleEntity roleEntity)
  228. {
  229. try
  230. {
  231. cache.Remove(cacheKey, CacheId.role);
  232. roleService.SaveEntity(keyValue, roleEntity);
  233. }
  234. catch (Exception ex)
  235. {
  236. if (ex is ExceptionEx)
  237. {
  238. throw;
  239. }
  240. else
  241. {
  242. throw ExceptionEx.ThrowBusinessException(ex);
  243. }
  244. }
  245. }
  246. #endregion
  247. #region 扩展数据
  248. /// <summary>
  249. /// 获取树形数据
  250. /// </summary>
  251. /// <param name="parentId">父级id</param>
  252. /// <returns></returns>
  253. public List<TreeModel> GetTree(string parentId)
  254. {
  255. try
  256. {
  257. List<RoleEntity> list = GetList();
  258. List<TreeModel> treeList = new List<TreeModel>();
  259. foreach (var item in list)
  260. {
  261. TreeModel node = new TreeModel
  262. {
  263. id = item.F_RoleId,
  264. text = item.F_FullName,
  265. value = item.F_RoleId,
  266. showcheck = false,
  267. checkstate = 0,
  268. isexpand = true,
  269. parentId = item.F_RoleId
  270. };
  271. treeList.Add(node);
  272. }
  273. return treeList;
  274. }
  275. catch (Exception ex)
  276. {
  277. if (ex is ExceptionEx)
  278. {
  279. throw;
  280. }
  281. else
  282. {
  283. throw ExceptionEx.ThrowBusinessException(ex);
  284. }
  285. }
  286. }
  287. #endregion
  288. }
  289. }