修复登录校验用户系统权限问题,新增用户角色组获取当前用户机构权限,用户获取权限时获取角色及角色组

This commit is contained in:
lhc
2021-05-19 19:00:37 +08:00
parent fd867b1a39
commit 0bc1c6a56f
3 changed files with 104 additions and 27 deletions

View File

@@ -176,12 +176,12 @@ public class AuthDaoImpl implements AuthDao {
SelectCondition selectCondition = SelectCondition
.sqlJoinBuilder("OS_REL_USER_ROLE")
.field("count(OS_SYS_OS.OS_CODE)")
.join("OS_REL_ROLE_OS")
.on("ROLE_ID", "OS_REL_ROLE_OS", "ROLE_ID")
.join("OS_SYS_OS")
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
.join("OS_SYS_ROLE")
.on("ROLE_ID", "OS_REL_USER_ROLE", "ROLE_ID")
.join("OS_REL_ROLE_OS")
.on("ROLE_ID", "OS_SYS_ROLE", "ROLE_ID")
.join("OS_SYS_OS")
.on("OS_ID", "OS_REL_ROLE_OS", "OS_ID")
.build();
Condition condition = Condition.creatCriteria(selectCondition)
.andEqual("OS_SYS_ROLE.DELETED", 1)

View File

@@ -246,9 +246,17 @@ public class AuthServiceImpl implements AuthService {
Long count = 0L;
count += getRoleOs(userId);
count += getGroupOs(userId);
count += getOrgOs("guobo");
count += getOrgGroupOs("guobo");
if (!org.springframework.util.StringUtils.isEmpty(user.get("DEPT_CODE"))) {
count += getOrgOs(String.valueOf(user.get("DEPT_CODE")));
count += getOrgGroupOs(String.valueOf(user.get("DEPT_CODE")));
String deptCode = String.valueOf(user.get("DEPT_CODE"));
count += getOrgOs(deptCode);
count += getOrgGroupOs(deptCode);
if (!"guobo".equals(deptCode) && deptCode.length() > 4) {
String parentCode = deptCode.substring(0, 4);
count += getOrgOs(parentCode);
count += getOrgGroupOs(parentCode);
}
}
return count;
}

View File

@@ -36,6 +36,7 @@ public class RoleUserServiceImpl implements RoleUserService {
final TableService tableService;
public RoleUserServiceImpl(@Qualifier(BaseMapperImpl.BASE) BaseMapper baseMapper,
TableService tableService) {
this.baseMapper = baseMapper;
@@ -80,46 +81,114 @@ public class RoleUserServiceImpl implements RoleUserService {
@Override
public ResultVO<Object> getUserRole(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_ROLE, condition);
Map<String, Object> result = new HashMap<>(2);
result.put("user", list);
Map<String,Object> result = getUserAuth(userId, OS_REL_USER_ROLE);
result.put("org", getOrgRoleList(userId));
return ResultVO.getSuccess(result);
}
@Override
public ResultVO<Object> getUserGroup(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_GROUP, condition);
return ResultVO.getSuccess(list);
Map<String, Object> result = getUserAuth(userId, OS_REL_USER_GROUP);
result.put("org", getOrgRoleGroupList(userId));
return ResultVO.getSuccess(result);
}
private Set<Map<String, Object>> getOrgRoleList(String userId) {
Condition deptCondition = Condition.creatCriteria().andEqual("DEPT_ID",GUOBO_ID).andEqual("DELETED",1).build();
List<Map<String,Object>> guoboList= baseMapper.selectByCondition("OS_REL_DEPT_ROLE", deptCondition);
Set<Map<String, Object>> set = new HashSet<>(guoboList);
Condition condition = Condition.creatCriteria().andEqual("ID",userId).andEqual("DELETED",1).build();
Map<String,Object> user = baseMapper.selectOneByCondition("GB_CAS_MEMBER", condition);
String code = (String) user.get("DEPT_CODE");
private Map<String,Object> getUserAuth(String userId, String osRelUserGroup) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(osRelUserGroup, condition);
Map<String, Object> result = new HashMap<>(2);
result.put("user", list);
return result;
}
private Set<Map<String,Object>> getOrgRoleGroupList(String userId) {
Set<Map<String, Object>> set = getGuoboOrgRole("OS_REL_DEPT_GROUP");
String code = getUserOrgCode(userId);
if (code.length() == 4) {
getDepList(set, code);
getDepRoleList(set, code,"OS_REL_DEPT_GROUP");
} else {
getDepList(set, code);
getDepList(set,code.substring(0,4));
getDepRoleList(set, code,"OS_REL_DEPT_GROUP");
getDepRoleList(set,code.substring(0,4),"OS_REL_DEPT_GROUP");
}
return set;
}
private void getDepList(Set<Map<String, Object>> set, String code) {
/**
* @author lhc
* @description // 获取用户所属机构编码
* @date 2:53 下午 2021/5/19
* @params [userId]
* @return java.lang.String
**/
private String getUserOrgCode(String userId) {
Condition condition = Condition.creatCriteria().andEqual("ID",userId).andEqual("DELETED",1).build();
Map<String,Object> user = baseMapper.selectOneByCondition("GB_CAS_MEMBER", condition);
return (String) user.get("DEPT_CODE");
}
/**
* @author lhc
* @description // 获取国博机构角色
* @date 2:53 下午 2021/5/19
* @params []
* @return java.util.Set<java.util.Map<java.lang.String,java.lang.Object>>
**/
private Set<Map<String,Object>> getGuoboOrgRole(String tableName) {
Condition deptCondition = Condition.creatCriteria().andEqual("DEPT_ID",GUOBO_ID).andEqual("DELETED",1).build();
List<Map<String,Object>> guoboList= baseMapper.selectByCondition(tableName, deptCondition);
return new HashSet<>(guoboList);
}
/**
* @author lhc
* @description // 获取机构及父级机构所拥有的权限
* @date 2:55 下午 2021/5/19
* @params [userId]
* @return java.util.Set<java.util.Map<java.lang.String,java.lang.Object>>
**/
private Set<Map<String, Object>> getOrgRoleList(String userId) {
Set<Map<String, Object>> set = getGuoboOrgRole("OS_REL_DEPT_ROLE");
String code = getUserOrgCode(userId);
if (code.length() == 4) {
getDepRoleList(set, code,"OS_REL_DEPT_ROLE");
} else {
getDepRoleList(set, code,"OS_REL_DEPT_ROLE");
getDepRoleList(set,code.substring(0,4),"OS_REL_DEPT_ROLE");
}
List<Object> objectList = getRoleByGroup(userId);
if (objectList != null && objectList.size() > 0) {
Condition condition = Condition.creatCriteria().andIn("GROUP_ID",getRoleByGroup(userId)).build();
List<Map<String,Object>> list = baseMapper.selectByCondition("OS_REL_GROUP_ROLE", condition);
set.addAll(list);
}
return set;
}
private List<Object> getRoleByGroup(String userId) {
Condition condition = Condition.creatCriteria().andEqual("USER_ID",userId).andEqual("DELETED",1).build();
List<Map<String,Object>> list = baseMapper.selectByCondition(OS_REL_USER_GROUP, condition);
Set<Map<String, Object>> set = new HashSet<>(list);
set.addAll(getOrgRoleGroupList(userId));
List<Object> objectList = new ArrayList<>();
for (Map<String, Object> map : set) {
objectList.add(map.get("GROUP_ID"));
}
return objectList;
}
/**
* @author lhc
* @description // 获取机构所绑定的角色
* @date 2:54 下午 2021/5/19
* @params [set, code]
* @return void
**/
private void getDepRoleList(Set<Map<String, Object>> set, String code,String tableName) {
Condition deptCondition;
Map<String, Object> org = baseMapper.selectOneByCondition("GB_CAS_DEPT", Condition.creatCriteria().andEqual("CODE", code).andEqual("DELETED", 1).build());
if (org != null && !org.isEmpty()) {
deptCondition = Condition.creatCriteria().andEqual("DEPT_ID", org.get("ID")).andEqual("DELETED", 1).build();
List<Map<String, Object>> roleList = baseMapper.selectByCondition("OS_REL_DEPT_ROLE", deptCondition);
List<Map<String, Object>> roleList = baseMapper.selectByCondition(tableName, deptCondition);
set.addAll(roleList);
}
}
}