Commit 548cc0eb by shiwenbo

修改调整后的权限获取策略,优化查询速度

parent 01bb76fc
...@@ -14,6 +14,7 @@ public class RoleInfo { ...@@ -14,6 +14,7 @@ public class RoleInfo {
private String name; private String name;
private String title; private String title;
private String description; private String description;
private String orgId;
private Group group; private Group group;
private List<StaffInfo> staffs; private List<StaffInfo> staffs;
private List<PrivilegeInfo> privilegeInfos; private List<PrivilegeInfo> privilegeInfos;
...@@ -62,6 +63,14 @@ public class RoleInfo { ...@@ -62,6 +63,14 @@ public class RoleInfo {
public String getOrgId() {
return orgId;
}
public void setOrgId(String orgId) {
this.orgId = orgId;
}
public List<StaffInfo> getStaffs() { public List<StaffInfo> getStaffs() {
return staffs; return staffs;
} }
......
...@@ -22,7 +22,6 @@ import com.beecode.bap.staff.BapContext; ...@@ -22,7 +22,6 @@ import com.beecode.bap.staff.BapContext;
import com.beecode.bap.staff.service.StaffService; import com.beecode.bap.staff.service.StaffService;
import com.beecode.bap2.common.license.LicenseProperty; import com.beecode.bap2.common.license.LicenseProperty;
import com.beecode.bap2.common.license.service.LicensePropertyService; import com.beecode.bap2.common.license.service.LicensePropertyService;
import com.beecode.bcp.User;
import com.beecode.bcp.authz.Privilege; import com.beecode.bcp.authz.Privilege;
import com.beecode.bcp.authz.Role; import com.beecode.bcp.authz.Role;
import com.beecode.bcp.authz.service.IdentityService; import com.beecode.bcp.authz.service.IdentityService;
...@@ -34,7 +33,6 @@ import com.beecode.bcp.type.KClass; ...@@ -34,7 +33,6 @@ import com.beecode.bcp.type.KClass;
import com.beecode.bcp.type.KObject; import com.beecode.bcp.type.KObject;
import com.beecode.bcp.type.json.JSONObjectUtils; import com.beecode.bcp.type.json.JSONObjectUtils;
import com.beecode.inz.authmgr.domain.PrivilegeInfo; import com.beecode.inz.authmgr.domain.PrivilegeInfo;
import com.beecode.inz.authmgr.domain.RoleGroupInfo;
import com.beecode.inz.authmgr.exception.AuthDataMissingException; import com.beecode.inz.authmgr.exception.AuthDataMissingException;
import com.beecode.inz.authmgr.service.AuthManagerService; import com.beecode.inz.authmgr.service.AuthManagerService;
import com.beecode.inz.authmgr.service.FunctionTreeService; import com.beecode.inz.authmgr.service.FunctionTreeService;
...@@ -122,48 +120,30 @@ public class FunctionTreeServiceImpl implements FunctionTreeService { ...@@ -122,48 +120,30 @@ public class FunctionTreeServiceImpl implements FunctionTreeService {
List<Group> groups = groupService.getChildren(roleService.getRoleGroupCategoryId(), getRootGroup().getId()); List<Group> groups = groupService.getChildren(roleService.getRoleGroupCategoryId(), getRootGroup().getId());
if (groups != null) { if (groups != null) {
groups.forEach((children) -> { groups.forEach((children) -> {
RoleGroupInfo groupInfo = new RoleGroupInfo(children);
List<Role> roles = groupService.getItems(children.getId(), Role.class, null); List<Role> roles = groupService.getItems(children.getId(), Role.class, null);
UUID currentRegionalCompany = getCurrentLoginRegionalCompany().getUuid("id"); UUID currentRegionalCompany = getCurrentLoginRegionalCompany().getUuid("id");
for(int i = 0; i < roles.size(); i++) { for(int i = 0; i < roles.size(); i++) {
List<User> user = identityService.getUsers(roles.get(i).getCreateUser()); if(!roles.get(i).getOrgId().equals(currentRegionalCompany)){
KObject staff = staffService.getByUserId(user.get(0).getId());
List<String> ids = new ArrayList<String>();
ids.add(staff.getUuid("id").toString());
List<KObject> followingList = followerDao.loadByMemberIds("com.xyst.dinas.biz.follower.datamodel.OrganizationFollower", ids);
List<UUID> organizaitonList = new ArrayList<UUID>();
for(KObject following : followingList) {
organizaitonList.add(following.get("following").getUuid("id"));
}
if(!organizaitonList.contains(currentRegionalCompany)) {
roles.remove(i); roles.remove(i);
i--; i--;
} }
} }
groupInfo.setRoles(roles);
//获取当前登录用户拥有的角色列表 //获取当前登录用户拥有的角色列表
KObject currentStaff = getCurrentStaff(); KObject currentStaff = getCurrentStaff();
if(currentStaff != null) { if(currentStaff != null) {
List<Role> staffRoleList = roleService.getByUser(currentStaff.get("user").getUuid("id")); List<Role> staffRoleList = roleService.getByUser(currentStaff.get("user").getUuid("id"));
List<Role> commonRoleList = groupInfo.getRoles();
//以上两个List取交集,得到当前登录用户在该组织机构内所拥有的角色 //以上两个List取交集,得到当前登录用户在该组织机构内所拥有的角色
List<Role> resultRoleList = new ArrayList<Role>();
for(int i = 0; i < staffRoleList.size(); i++) { for(int i = 0; i < staffRoleList.size(); i++) {
for(int j = 0; j < commonRoleList.size(); j++) { for(int j = 0; j < roles.size(); j++) {
if(commonRoleList.get(j).getId().equals(staffRoleList.get(i).getId())) { if(roles.get(j).getId().equals(staffRoleList.get(i).getId())) {
resultRoleList.add(staffRoleList.get(i)); result.addAll(authManagerService.getPrivilegeInfoByRole(staffRoleList.get(i).getId()));
break; break;
} }
} }
} }
for(int i = 0; i < resultRoleList.size(); i++) {
result.addAll(authManagerService.getPrivilegeInfoByRole(resultRoleList.get(i).getId()));
}
} }
}); });
} }
......
...@@ -75,6 +75,7 @@ public class RoleManagerServiceImpl implements RoleManagerService { ...@@ -75,6 +75,7 @@ public class RoleManagerServiceImpl implements RoleManagerService {
role.setTitle(roleInfo.getTitle()); role.setTitle(roleInfo.getTitle());
role.setDescription(roleInfo.getDescription()); role.setDescription(roleInfo.getDescription());
role.setOrgId(UUID.fromString(roleInfo.getOrgId()));
UUID roleId = roleService.create(role); UUID roleId = roleService.create(role);
//保存角色的权限信息 //保存角色的权限信息
......
...@@ -23,6 +23,8 @@ public class RolePara { ...@@ -23,6 +23,8 @@ public class RolePara {
@Size(max = 200, message = "长度必须小于{max}") @Size(max = 200, message = "长度必须小于{max}")
private String description; private String description;
private String orgId;
private boolean needCopyPrivilege; private boolean needCopyPrivilege;
private UUID targetRoleId; private UUID targetRoleId;
...@@ -54,6 +56,12 @@ public class RolePara { ...@@ -54,6 +56,12 @@ public class RolePara {
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public String getOrgId() {
return orgId;
}
public void setOrgId(String orgId) {
this.orgId = orgId;
}
public boolean isNeedCopyPrivilege() { public boolean isNeedCopyPrivilege() {
return needCopyPrivilege; return needCopyPrivilege;
} }
......
...@@ -265,16 +265,7 @@ public class AuthMgrController { ...@@ -265,16 +265,7 @@ public class AuthMgrController {
} }
for(int i = 0; i < roles.size(); i++) { for(int i = 0; i < roles.size(); i++) {
List<User> user = identityService.getUsers(roles.get(i).getCreateUser()); if(!roles.get(i).getOrgId().equals(currentRegionalCompany)){
KObject staff = staffService.getByUserId(user.get(0).getId());
List<String> ids = new ArrayList<String>();
ids.add(staff.getUuid("id").toString());
List<KObject> followingList = followerDao.loadByMemberIds("com.xyst.dinas.biz.follower.datamodel.OrganizationFollower", ids);
List<UUID> organizaitonList = new ArrayList<UUID>();
for(KObject following : followingList) {
organizaitonList.add(following.get("following").getUuid("id"));
}
if(!organizaitonList.contains(currentRegionalCompany)) {
roles.remove(i); roles.remove(i);
i--; i--;
} }
......
...@@ -89,6 +89,7 @@ public class RoleController { ...@@ -89,6 +89,7 @@ public class RoleController {
roleInfo.setTitle(rolePara.getTitle()); roleInfo.setTitle(rolePara.getTitle());
roleInfo.setDescription(rolePara.getDescription()); roleInfo.setDescription(rolePara.getDescription());
roleInfo.setName(rolePara.getName()); roleInfo.setName(rolePara.getName());
roleInfo.setOrgId(rolePara.getOrgId());
roleInfo.setGroup(getRootGroup()); roleInfo.setGroup(getRootGroup());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment