Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 
 
 

236 lignes
6.9 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  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 RoleService : RepositoryFactory
  16. {
  17. #region 构造函数和属性
  18. private string fieldSql;
  19. public RoleService()
  20. {
  21. fieldSql = @"
  22. t.F_RoleId,
  23. t.F_Category,
  24. t.F_EnCode,
  25. t.F_FullName,
  26. t.F_SortCode,
  27. t.F_DeleteMark,
  28. t.F_EnabledMark,
  29. t.F_Description,
  30. t.F_CreateDate,
  31. t.F_CreateUserId,
  32. t.F_CreateUserName,
  33. t.F_ModifyDate,
  34. t.F_ModifyUserId,
  35. t.F_ModifyUserName
  36. ";
  37. }
  38. #endregion
  39. #region 获取数据
  40. /// <summary>
  41. /// 获取角色数据列表
  42. /// </summary>
  43. /// <returns></returns>
  44. public IEnumerable<RoleEntity> GetList()
  45. {
  46. try
  47. {
  48. var strSql = new StringBuilder();
  49. strSql.Append("SELECT ");
  50. strSql.Append(fieldSql);
  51. strSql.Append(" FROM LR_Base_Role t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ORDER BY t.F_FullName ");
  52. return this.BaseRepository().FindList<RoleEntity>(strSql.ToString());
  53. }
  54. catch (Exception ex)
  55. {
  56. if (ex is ExceptionEx)
  57. {
  58. throw;
  59. }
  60. else
  61. {
  62. throw ExceptionEx.ThrowServiceException(ex);
  63. }
  64. }
  65. }
  66. public IEnumerable<RoleEntity> GetPageList(Pagination pagination, string keyword)
  67. {
  68. try
  69. {
  70. var strSql = new StringBuilder();
  71. strSql.Append("SELECT ");
  72. strSql.Append(fieldSql);
  73. strSql.Append(" FROM LR_Base_Role t WHERE t.F_EnabledMark = 1 AND t.F_DeleteMark = 0 ");
  74. if (!string.IsNullOrEmpty(keyword))
  75. {
  76. keyword = "%" + keyword + "%";
  77. strSql.Append(" AND( t.F_FullName like @keyword or t.F_EnCode like @keyword ) ");
  78. }
  79. return this.BaseRepository().FindList<RoleEntity>(strSql.ToString(), new { keyword }, pagination);
  80. }
  81. catch (Exception ex)
  82. {
  83. if (ex is ExceptionEx)
  84. {
  85. throw;
  86. }
  87. else
  88. {
  89. throw ExceptionEx.ThrowServiceException(ex);
  90. }
  91. }
  92. }
  93. /// <summary>
  94. /// 根据角色名获取角色
  95. /// </summary>
  96. /// <param name="roleName"></param>
  97. /// <returns></returns>
  98. public RoleEntity GetRoleByRoleName(string roleName)
  99. {
  100. try
  101. {
  102. return this.BaseRepository().FindEntity<RoleEntity>(a => a.F_FullName == roleName);
  103. }
  104. catch (Exception ex)
  105. {
  106. if (ex is ExceptionEx)
  107. {
  108. throw;
  109. }
  110. else
  111. {
  112. throw ExceptionEx.ThrowServiceException(ex);
  113. }
  114. }
  115. }
  116. internal string GetIdByRoleName(string v)
  117. {
  118. try
  119. {
  120. return this.BaseRepository().FindEntity<RoleEntity>(t => t.F_FullName == v).F_RoleId;
  121. }
  122. catch (Exception ex)
  123. {
  124. if (ex is ExceptionEx)
  125. {
  126. throw;
  127. }
  128. else
  129. {
  130. throw ExceptionEx.ThrowServiceException(ex);
  131. }
  132. }
  133. }
  134. /// <summary>
  135. /// 获取角色数据列表
  136. /// </summary>
  137. /// <param name="roleIds">主键串</param>
  138. /// <returns></returns>
  139. public IEnumerable<RoleEntity> GetListByRoleIds(string roleIds)
  140. {
  141. try
  142. {
  143. return this.BaseRepository().FindList<RoleEntity>(t => roleIds.Contains(t.F_RoleId));
  144. }
  145. catch (Exception ex)
  146. {
  147. if (ex is ExceptionEx)
  148. {
  149. throw;
  150. }
  151. else
  152. {
  153. throw ExceptionEx.ThrowServiceException(ex);
  154. }
  155. }
  156. }
  157. #endregion
  158. #region 提交数据
  159. /// <summary>
  160. /// 虚拟删除角色
  161. /// </summary>
  162. /// <param name="keyValue">主键</param>
  163. public void VirtualDelete(string keyValue)
  164. {
  165. var db = this.BaseRepository().BeginTrans();
  166. try
  167. {
  168. RoleEntity entity = new RoleEntity()
  169. {
  170. F_RoleId = keyValue,
  171. F_DeleteMark = 1
  172. };
  173. db.Update(entity);
  174. db.ExecuteBySql(" Delete From LR_BASE_USERRELATION where F_OBJECTID = @keyValue ", new { keyValue = keyValue });
  175. db.Commit();
  176. }
  177. catch (Exception ex)
  178. {
  179. db.Rollback();
  180. if (ex is ExceptionEx)
  181. {
  182. throw;
  183. }
  184. else
  185. {
  186. throw ExceptionEx.ThrowServiceException(ex);
  187. }
  188. }
  189. }
  190. /// <summary>
  191. /// 保存角色(新增、修改)
  192. /// </summary>
  193. /// <param name="keyValue">主键值</param>
  194. /// <param name="roleEntity">角色实体</param>
  195. /// <returns></returns>
  196. public void SaveEntity(string keyValue, RoleEntity roleEntity)
  197. {
  198. try
  199. {
  200. if (!string.IsNullOrEmpty(keyValue))
  201. {
  202. roleEntity.Modify(keyValue);
  203. this.BaseRepository().Update(roleEntity);
  204. }
  205. else
  206. {
  207. roleEntity.Create();
  208. this.BaseRepository().Insert(roleEntity);
  209. }
  210. }
  211. catch (Exception ex)
  212. {
  213. if (ex is ExceptionEx)
  214. {
  215. throw;
  216. }
  217. else
  218. {
  219. throw ExceptionEx.ThrowServiceException(ex);
  220. }
  221. }
  222. }
  223. #endregion
  224. }
  225. }