RoleService.cs 6.5 KB

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