RoleService.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. using LeaRun.Data.Repository;
  2. using LeaRun.Util;
  3. using LeaRun.Util.WebControl;
  4. using LeaRun.Util.Extension;
  5. using System.Collections.Generic;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Data.Common;
  9. using LeaRun.Data;
  10. using LeaRun.Application.Entity.BaseManage;
  11. using LeaRun.Application.IService.BaseManage;
  12. using LeaRun.Application.Service.AuthorizeManage;
  13. using LeaRun.Application.IService.AuthorizeManage;
  14. namespace LeaRun.Application.Service.BaseManage
  15. {
  16. /// <summary>
  17. /// 版 本
  18. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  19. /// 创建人:佘赐雄
  20. /// 日 期:2015.11.4 14:31
  21. /// 描 述:角色管理
  22. /// </summary>
  23. public class RoleService : RepositoryFactory<RoleEntity>, IRoleService
  24. {
  25. private IAuthorizeService<RoleEntity> iauthorizeservice = new AuthorizeService<RoleEntity>();
  26. #region 获取数据
  27. /// <summary>
  28. /// 角色列表
  29. /// </summary>
  30. /// <returns></returns>
  31. public IEnumerable<RoleEntity> GetList()
  32. {
  33. var expression = LinqExtensions.True<RoleEntity>();
  34. expression = expression.And(t => t.Category == 1).And(t => t.EnabledMark == 1).And(t => t.DeleteMark == 0);
  35. return this.BaseRepository().IQueryable(expression).OrderByDescending(t => t.CreateDate).ToList();
  36. }
  37. /// <summary>
  38. /// 角色列表
  39. /// </summary>
  40. /// <param name="pagination">分页</param>
  41. /// <param name="queryJson">查询参数</param>
  42. /// <returns></returns>
  43. public IEnumerable<RoleEntity> GetPageList(Pagination pagination, string queryJson)
  44. {
  45. var expression = LinqExtensions.True<RoleEntity>();
  46. var queryParam = queryJson.ToJObject();
  47. //查询条件
  48. if (!queryParam["condition"].IsEmpty() && !queryParam["keyword"].IsEmpty())
  49. {
  50. string condition = queryParam["condition"].ToString();
  51. string keyword = queryParam["keyword"].ToString();
  52. switch (condition)
  53. {
  54. case "EnCode": //角色编号
  55. expression = expression.And(t => t.EnCode.Contains(keyword));
  56. break;
  57. case "FullName": //角色名称
  58. expression = expression.And(t => t.FullName.Contains(keyword));
  59. break;
  60. default:
  61. break;
  62. }
  63. }
  64. expression = expression.And(t => t.Category == 1);
  65. return this.BaseRepository().FindList(expression, pagination);
  66. }
  67. /// <summary>
  68. /// 角色列表all
  69. /// </summary>
  70. /// <returns></returns>
  71. public IEnumerable<RoleEntity> GetAllList()
  72. {
  73. var strSql = new StringBuilder();
  74. strSql.Append(@"SELECT r.RoleId ,
  75. o.FullName AS OrganizeId ,
  76. r.Category ,
  77. r.EnCode ,
  78. r.FullName ,
  79. r.SortCode ,
  80. r.EnabledMark ,
  81. r.Description ,
  82. r.CreateDate
  83. FROM Base_Role r
  84. LEFT JOIN Base_Organize o ON o.OrganizeId = r.OrganizeId
  85. WHERE o.FullName is not null and r.Category = 1 and r.EnabledMark =1
  86. ORDER BY o.FullName, r.SortCode");
  87. return this.BaseRepository().FindList(strSql.ToString());
  88. }
  89. /// <summary>
  90. /// 角色实体
  91. /// </summary>
  92. /// <param name="keyValue">主键值</param>
  93. /// <returns></returns>
  94. public RoleEntity GetEntity(string keyValue)
  95. {
  96. return this.BaseRepository().FindEntity(keyValue);
  97. }
  98. #endregion
  99. #region 验证数据
  100. /// <summary>
  101. /// 角色编号不能重复
  102. /// </summary>
  103. /// <param name="enCode">编号</param>
  104. /// <param name="keyValue">主键</param>
  105. /// <returns></returns>
  106. public bool ExistEnCode(string enCode, string keyValue)
  107. {
  108. var expression = LinqExtensions.True<RoleEntity>();
  109. expression = expression.And(t => t.EnCode == enCode).And(t => t.Category == 1);
  110. if (!string.IsNullOrEmpty(keyValue))
  111. {
  112. expression = expression.And(t => t.RoleId != keyValue);
  113. }
  114. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  115. }
  116. /// <summary>
  117. /// 角色名称不能重复
  118. /// </summary>
  119. /// <param name="fullName">名称</param>
  120. /// <param name="keyValue">主键</param>
  121. /// <returns></returns>
  122. public bool ExistFullName(string fullName, string keyValue)
  123. {
  124. var expression = LinqExtensions.True<RoleEntity>();
  125. expression = expression.And(t => t.FullName == fullName).And(t => t.Category == 1);
  126. if (!string.IsNullOrEmpty(keyValue))
  127. {
  128. expression = expression.And(t => t.RoleId != keyValue);
  129. }
  130. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  131. }
  132. #endregion
  133. #region 提交数据
  134. /// <summary>
  135. /// 删除角色
  136. /// </summary>
  137. /// <param name="keyValue">主键</param>
  138. public void RemoveForm(string keyValue)
  139. {
  140. this.BaseRepository().Delete(keyValue);
  141. }
  142. /// <summary>
  143. /// 保存角色表单(新增、修改)
  144. /// </summary>
  145. /// <param name="keyValue">主键值</param>
  146. /// <param name="roleEntity">角色实体</param>
  147. /// <returns></returns>
  148. public void SaveForm(string keyValue, RoleEntity roleEntity)
  149. {
  150. if (!string.IsNullOrEmpty(keyValue))
  151. {
  152. roleEntity.Modify(keyValue);
  153. this.BaseRepository().Update(roleEntity);
  154. }
  155. else
  156. {
  157. roleEntity.Create();
  158. roleEntity.Category = 1;
  159. this.BaseRepository().Insert(roleEntity);
  160. }
  161. }
  162. #endregion
  163. }
  164. }