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.

125 lines
5.2 KiB

4 days 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.SystemManage;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. namespace NFine.Application.SystemManage
  11. {
  12. public class RoleApp
  13. {
  14. private IRoleRepository service = new RoleRepository();
  15. private ModuleApp moduleApp = new ModuleApp();
  16. private ModuleButtonApp moduleButtonApp = new ModuleButtonApp();
  17. public List<RoleEntity> GetList(string keyword = "")
  18. {
  19. var expression = ExtLinq.True<RoleEntity>();
  20. if (!string.IsNullOrEmpty(keyword))
  21. {
  22. expression = expression.And(t => t.F_FullName.Contains(keyword));
  23. expression = expression.Or(t => t.F_EnCode.Contains(keyword));
  24. }
  25. expression = expression.And(t => t.F_Category == 1);
  26. return service.IQueryable(expression).OrderBy(t => t.F_SortCode).ToList();
  27. }
  28. public RoleEntity GetForm(string keyValue)
  29. {
  30. return service.FindEntity(keyValue);
  31. }
  32. public void DeleteForm(string keyValue)
  33. {
  34. service.DeleteForm(keyValue);
  35. }
  36. public void SubmitForm(RoleEntity roleEntity, string[] permissionIds, string keyValue)
  37. {
  38. if (!string.IsNullOrEmpty(keyValue))
  39. {
  40. roleEntity.F_Id = keyValue;
  41. }
  42. else
  43. {
  44. roleEntity.F_Id = Common.GuId();
  45. }
  46. var moduledata = moduleApp.GetListAll();
  47. var buttondata = moduleButtonApp.GetList();
  48. List<RoleAuthorizeEntity> roleAuthorizeEntitys = new List<RoleAuthorizeEntity>();
  49. foreach (var itemId in permissionIds)
  50. {
  51. RoleAuthorizeEntity roleAuthorizeEntity = new RoleAuthorizeEntity();
  52. roleAuthorizeEntity.F_Id = Common.GuId();
  53. roleAuthorizeEntity.F_ObjectType = 1;
  54. roleAuthorizeEntity.F_ObjectId = roleEntity.F_Id;
  55. roleAuthorizeEntity.F_ItemId = itemId;
  56. if (moduledata.Find(t => t.F_Id == itemId) != null)
  57. {
  58. roleAuthorizeEntity.F_ItemType = 1;
  59. }
  60. if (buttondata.Find(t => t.F_Id == itemId) != null)
  61. {
  62. roleAuthorizeEntity.F_ItemType = 2;
  63. }
  64. roleAuthorizeEntitys.Add(roleAuthorizeEntity);
  65. }
  66. service.SubmitForm(roleEntity, roleAuthorizeEntitys, keyValue);
  67. }
  68. public DataTable GetRole()
  69. {
  70. string WorkPoint = NFine.Code.OperatorProvider.Provider.GetCurrent().Location;
  71. string sql = @"
  72. select '' as ID,'' as F_FullName
  73. union all
  74. SELECT F_Id as ID ,F_FullName as F_FullName FROM dbo.Sys_SRM_Role ";
  75. DataTable dt = SqlHelper.GetDataTableBySql(sql);
  76. return dt;
  77. }
  78. public int SubmitFormCloneRole(string keyValue)
  79. {
  80. string sql = string.Empty;
  81. var queryParam = keyValue.ToJObject();
  82. string RoleID = queryParam["RoleID"].ToString();
  83. string F_FullName = queryParam["F_FullName"].ToString();
  84. string F_EnCode = queryParam["F_EnCode"].ToString();
  85. string F_SortCode = queryParam["F_SortCode"].ToString();
  86. string F_Description = queryParam["F_Description"].ToString();
  87. var NewRoleID = Guid.NewGuid();
  88. sql += @"INSERT INTO dbo.Sys_SRM_Role
  89. (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 )
  90. 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
  91. from Sys_SRM_Role where F_Id='{5}'";
  92. sql += "\r\n";
  93. sql += @" INSERT INTO dbo.Sys_SRM_RoleAuthorize
  94. (F_Id,F_ItemType,F_ItemId,F_ObjectType,F_ObjectId,F_SortCode,F_CreatorTime,F_CreatorUserId)
  95. select newid(),F_ItemType,F_ItemId,F_ObjectType,'{0}',F_SortCode,F_CreatorTime,F_CreatorUserId
  96. from Sys_SRM_RoleAuthorize where F_ObjectId='{5}'";
  97. sql += "\r\n";
  98. sql += @" INSERT INTO dbo.Sys_RoleDataPower
  99. (ID,RoleId,DataActionId)
  100. select newid(),'{0}',DataActionId
  101. from Sys_RoleDataPower where RoleId='{5}'";
  102. sql += "\r\n";
  103. sql += @" INSERT INTO dbo.Sys_FormColsVisible
  104. (ID,MenuId,RoleId,FieldName,VisibleFlag,WorkPoint)
  105. select newid(),MenuId,'{0}',FieldName,VisibleFlag,WorkPoint
  106. from Sys_FormColsVisible where RoleId='{5}'";
  107. sql = string.Format(sql, NewRoleID, F_EnCode, F_FullName, F_SortCode, F_Description, RoleID);
  108. int count = SqlHelper.CmdExecuteNonQueryLi(sql);
  109. return count;
  110. }
  111. }
  112. }