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.

224 lines
8.9 KiB

3 weeks ago
  1. using NFine.Code;
  2. using NFine.Data.Extensions;
  3. using NFine.Domain.Entity.SystemManage;
  4. using NFine.Domain.IRepository.SystemManage;
  5. using NFine.Repository;
  6. using NFine.Repository.SystemManage;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Data;
  10. using System.Linq;
  11. using System.Text;
  12. namespace NFine.Application.SystemManage
  13. {
  14. public class RoleApp : RepositoryFactory<RoleEntity>
  15. {
  16. private IRoleRepository service = new RoleRepository();
  17. private ModuleApp moduleApp = new ModuleApp();
  18. private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
  19. public List<RoleEntity> GetList(Pagination pagination, string keyword = "")
  20. {
  21. var expression = ExtLinq.True<RoleEntity>();
  22. if (!string.IsNullOrEmpty(keyword))
  23. {
  24. expression = expression.And(t => t.F_FullName.Contains(keyword));
  25. expression = expression.Or(t => t.F_EnCode.Contains(keyword));
  26. }
  27. expression = expression.And(t => t.F_Category == 1);
  28. //return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
  29. if (pagination == null)
  30. {
  31. return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
  32. }
  33. else
  34. {
  35. return service.FindList(expression, pagination);
  36. }
  37. }
  38. public List<RoleEntity> GetList(string keyword = "")
  39. {
  40. var expression = ExtLinq.True<RoleEntity>();
  41. if (!string.IsNullOrEmpty(keyword))
  42. {
  43. expression = expression.And(t => t.F_FullName.Contains(keyword));
  44. expression = expression.Or(t => t.F_EnCode.Contains(keyword));
  45. }
  46. expression = expression.And(t => t.F_Category == 1);
  47. return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
  48. }
  49. public RoleEntity GetForm(string keyValue)
  50. {
  51. return service.FindEntity(keyValue);
  52. }
  53. public void DeleteForm(string keyValue)
  54. {
  55. service.DeleteForm(keyValue);
  56. }
  57. public void SubmitForm(RoleEntity roleEntity, string[] permissionIds, string keyValue)
  58. {
  59. try
  60. {
  61. string sql = "";
  62. if (!string.IsNullOrEmpty(keyValue))
  63. {
  64. roleEntity.F_Id = keyValue;
  65. }
  66. else
  67. {
  68. roleEntity.F_Id = Common.GuId();
  69. }
  70. var moduledata = moduleApp.GetListALL();
  71. var buttondata = moduleButtonApp.GetList();
  72. List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
  73. foreach (var itemId in permissionIds)
  74. {
  75. RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
  76. roleAuthorizeEntity.F_Id = Common.GuId();
  77. roleAuthorizeEntity.F_ObjectType = 1;
  78. roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
  79. roleAuthorizeEntity.F_ItemId = itemId;
  80. if (moduledata.Find(t => t.F_Id == itemId) != null)
  81. {
  82. roleAuthorizeEntity.F_ItemType = 1;
  83. }
  84. if (buttondata.Find(t => t.F_Id == itemId) != null)
  85. {
  86. roleAuthorizeEntity.F_ItemType = 2;
  87. }
  88. roleAuthorizeEntitys.Add(roleAuthorizeEntity);
  89. }
  90. sql += @"DELETE FROM Sys_RoleDataPower
  91. where RoleId='{0}'";
  92. sql = string.Format(sql, roleEntity.F_Id);
  93. StringBuilder sqlb = new StringBuilder(sql);
  94. Repository().ExecuteBySql(sqlb);
  95. service.SubmitForm(roleEntity, roleAuthorizeEntitys, keyValue);
  96. }
  97. catch (Exception ex)
  98. {
  99. throw new Exception(ex.Message);
  100. }
  101. }
  102. public void SubmitForm(RoleEntity roleEntity, string[] permissionIds, string[] dataActionIds, string keyValue)
  103. {
  104. try
  105. {
  106. string sql = "";
  107. if (!string.IsNullOrEmpty(keyValue))
  108. {
  109. roleEntity.F_Id = keyValue;
  110. }
  111. else
  112. {
  113. roleEntity.F_Id = Common.GuId();
  114. }
  115. var moduledata = moduleApp.GetListALL();
  116. var buttondata = moduleButtonApp.GetList();
  117. List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
  118. foreach (var itemId in permissionIds)
  119. {
  120. RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
  121. roleAuthorizeEntity.F_Id = Common.GuId();
  122. roleAuthorizeEntity.F_ObjectType = 1;
  123. roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
  124. roleAuthorizeEntity.F_ItemId = itemId;
  125. if (moduledata.Find(t => t.F_Id == itemId) != null)
  126. {
  127. roleAuthorizeEntity.F_ItemType = 1;
  128. }
  129. if (buttondata.Find(t => t.F_Id == itemId) != null)
  130. {
  131. roleAuthorizeEntity.F_ItemType = 2;
  132. }
  133. roleAuthorizeEntitys.Add(roleAuthorizeEntity);
  134. }
  135. if (dataActionIds.Count() != 0)
  136. {
  137. sql += @"DELETE FROM Sys_RoleDataPower
  138. where RoleId='{0}'";
  139. }
  140. foreach (var dataActionId in dataActionIds)
  141. {
  142. sql += @"insert into Sys_RoleDataPower
  143. values
  144. (NEWID(),'{0}','{1}')";
  145. sql = string.Format(sql, roleEntity.F_Id, dataActionId);
  146. }
  147. StringBuilder sqlb = new StringBuilder(sql);
  148. Repository().ExecuteBySql(sqlb);
  149. service.SubmitForm(roleEntity, roleAuthorizeEntitys, keyValue);
  150. }
  151. catch (Exception ex)
  152. {
  153. throw new Exception(ex.Message);
  154. }
  155. }
  156. public DataTable GetRole()
  157. {
  158. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  159. string sql = @"
  160. select '' as ID,'' as F_FullName
  161. union all
  162. SELECT F_Id as ID ,F_FullName as F_FullName FROM dbo.Sys_SRM_Role ";
  163. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  164. return dt;
  165. }
  166. public int SubmitFormCloneRole(string keyValue)
  167. {
  168. string sql = string.Empty;
  169. var queryParam = keyValue.ToJObject();
  170. string RoleID = queryParam["RoleID"].ToString();
  171. string F_FullName = queryParam["F_FullName"].ToString();
  172. string F_EnCode = queryParam["F_EnCode"].ToString();
  173. string F_SortCode = queryParam["F_SortCode"].ToString();
  174. string F_Description = queryParam["F_Description"].ToString();
  175. var NewRoleID = Guid.NewGuid();
  176. sql += @"INSERT INTO dbo.Sys_SRM_Role
  177. (F_Id,F_OrganizeId,F_Category,F_EnCode,F_FullName,F_Type,F_AllowEdit,F_AllowDelete,F_SortCode,F_DeleteMark,F_EnabledMark,F_Description,F_CreatorTime,F_CreatorUserId,F_LastModifyTime,F_LastModifyUserId,F_DeleteTime,F_DeleteUserId )
  178. select '{0}',F_OrganizeId,F_Category,'{1}','{2}',F_Type,F_AllowEdit,F_AllowDelete,'{3}',F_DeleteMark,F_EnabledMark,'{4}',getdate(),F_CreatorUserId,F_LastModifyTime,F_LastModifyUserId,F_DeleteTime,F_DeleteUserId
  179. from Sys_SRM_Role where F_Id='{5}'";
  180. sql += "\r\n";
  181. sql += @" INSERT INTO dbo.Sys_SRM_RoleAuthorize
  182. (F_Id,F_ItemType,F_ItemId,F_ObjectType,F_ObjectId,F_SortCode,F_CreatorTime,F_CreatorUserId)
  183. select newid(),F_ItemType,F_ItemId,F_ObjectType,'{0}',F_SortCode,F_CreatorTime,F_CreatorUserId
  184. from Sys_SRM_RoleAuthorize where F_ObjectId='{5}'";
  185. sql += "\r\n";
  186. sql += @" INSERT INTO dbo.Sys_RoleDataPower
  187. (ID,RoleId,DataActionId)
  188. select newid(),'{0}',DataActionId
  189. from Sys_RoleDataPower where RoleId='{5}'";
  190. sql += "\r\n";
  191. sql += @" INSERT INTO dbo.Sys_FormColsVisible
  192. (ID,MenuId,RoleId,FieldName,VisibleFlag,WorkPoint)
  193. select newid(),MenuId,'{0}',FieldName,VisibleFlag,WorkPoint
  194. from Sys_FormColsVisible where RoleId='{5}'";
  195. sql = string.Format(sql, NewRoleID, F_EnCode, F_FullName, F_SortCode, F_Description, RoleID);
  196. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  197. return count;
  198. }
  199. }
  200. }