Commit cbeab74c by levphon

修复选中组织节点获取可见用户bug

1 parent e34590f2
......@@ -49,8 +49,12 @@ public interface OrganizationMapper extends CommonBaseMapper<Organization> {
*/
List<OrgSuperiorModel> selectSuperiorIdsByOrg(OrgTreeSearch search);
List<OrgSuperiorModel> selectSuperiorIdsByOrgId(@Param("orgId") Long orgId);
/**
* 获取多个组织上级
*
* @param orgId
* @return
*/
List<OrgSuperiorModel> selectSuperiorIdsByOrgIds(@Param("orgIds") Collection<Long> orgId);
/**
......@@ -70,6 +74,13 @@ public interface OrganizationMapper extends CommonBaseMapper<Organization> {
*/
Organization selectSuperiorOrgByDepth(@Param("superiorId") Long superiorId, @Param("depth") Integer depth);
/**
* 得到特定层级的下级
*
* @param superiorId
* @param depth
* @return
*/
List<Organization> selectSuperiorOrgsByDepths(@Param("superiorId") Long superiorId, @Param("depths") Collection<Integer> depth);
/**
......@@ -123,16 +134,6 @@ public interface OrganizationMapper extends CommonBaseMapper<Organization> {
List<Organization> selectRootSubAllPaths(@Param("tenantId") Long tenantId);
/**
* 获取租户特定层级组织
*
* @param tenantId
* @return
*/
List<Department> selectSpecialLevelPaths(@Param("tenantId") Long tenantId,
@Param("subIds") Collection<Long> subIds,
@Param("depths") Collection<Integer> depth);
/**
* 找到根路径
*
* @param subId
......
......@@ -446,11 +446,11 @@ public class DepartmentService {
if (user == null) {
return Lists.newArrayList();
}
List<OrgSuperiorModel> superiorModelList = organizationMapper.selectSuperiorIdsByOrgId(user.getDepartmentId());
List<Organization> superiorOrgList = organizationMapper.selectAllSuperiorBySubId(user.getDepartmentId());
Set<Long> departmentIdList = this.getSuperiorIds(superiorModelList);
List<Long> superiorOrgIds = superiorOrgList.stream().map(Organization::getSuperiorId).collect(Collectors.toList());
List<Department> list = departmentMapper.selectByIds(departmentIdList);
List<Department> list = departmentMapper.selectByIds(superiorOrgIds);
return list;
}
......
......@@ -64,11 +64,14 @@ public class AllStrategy extends PermissionStrategy {
@Override
public List<User> permissionUsersByDepartmentId(Long departmentId) {
//departmentId全部下级组织节点
//假设本人所在组织链:R-A-B-C-本人组织-X-Y-Z
//departmentId全部下级组织节点(本人组织-X-Y-Z)
List<Organization> subOrgList = organizationMapper.selectAllSubBySuperiorId(departmentId);
List<Long> subOrgIdList = subOrgList.stream().map(Organization::getSubId).collect(Collectors.toList());
//返回departmentId及其下级用户
List<User> userList = userMapper.selectByDepartmentIds(subOrgIdList);
return userList;
......
......@@ -66,11 +66,11 @@ public class AssignTenantStrategy extends PermissionStrategy {
@Override
public List<User> permissionUsersByDepartmentId(Long departmentId) {
//权限可见租户
List<Tenant> tenantList = departmentService.getRolePermissionTenants();
List<Long> tenantIdList = tenantList.stream().map(Tenant::getId).collect(Collectors.toList());
//departmentId全部下级组织节点
List<Organization> subOrgList = organizationMapper.selectTenantsSubBySuperiorId(tenantIdList, departmentId);
List<Long> subOrgIdList = subOrgList.stream().map(Organization::getSubId).collect(Collectors.toList());
......
......@@ -2,6 +2,7 @@ package cn.com.glsx.shield.modules.service.permissionStrategy;
import cn.com.glsx.auth.utils.ShieldContextHolder;
import cn.com.glsx.shield.modules.entity.Department;
import cn.com.glsx.shield.modules.entity.Organization;
import cn.com.glsx.shield.modules.entity.User;
import cn.com.glsx.shield.modules.model.param.OrgTreeSearch;
import cn.com.glsx.shield.modules.model.view.DepartmentDTO;
......@@ -56,7 +57,15 @@ public class OneselfStrategy extends PermissionStrategy {
@Override
public List<User> permissionUsersByDepartmentId(Long departmentId) {
if (ShieldContextHolder.getDepartmentId().equals(departmentId)) {
//假设本人所在组织链:R-A-B-C-本人组织-X-Y-Z
//departmentId全部上级组织节点(R-A-B-C-本人组织)
List<Organization> superiorOrgList = organizationMapper.selectAllSuperiorBySubId(ShieldContextHolder.getDepartmentId());
List<Long> superiorOrgIds = superiorOrgList.stream().map(Organization::getSuperiorId).collect(Collectors.toList());
//departmentId只要在所在上级组织链上(R-A-B-C-本人组织),返回本人即可
if (superiorOrgIds.contains(departmentId)) {
return permissionUsers();
}
return Lists.newArrayList();
......
......@@ -63,8 +63,16 @@ public class SelfDepartmentStrategy extends PermissionStrategy {
@Override
public List<User> permissionUsersByDepartmentId(Long departmentId) {
if (ShieldContextHolder.getDepartmentId().equals(departmentId)) {
return permissionUsers();
//假设本人所在组织链:R-A-B-C-本人组织-X-Y-Z
//departmentId全部上级组织节点(R-A-B-C-本人组织)
List<Organization> superiorOrgList = organizationMapper.selectAllSuperiorBySubId(ShieldContextHolder.getDepartmentId());
List<Long> superiorOrgIds = superiorOrgList.stream().map(Organization::getSuperiorId).collect(Collectors.toList());
//只要departmentId在上级组织链上(R-A-B-C-本人组织),返回本部门全部用户
if (superiorOrgIds.contains(departmentId)) {
return this.permissionUsers();
}
return Lists.newArrayList();
}
......
......@@ -81,21 +81,29 @@ public class SubDepartmentStrategy extends PermissionStrategy {
*/
@Override
public List<User> permissionUsersByDepartmentId(Long departmentId) {
Set<Long> departmentIdSet = this.permissionDepartmentIds();
//如果是非可见部门id
if (!departmentIdSet.contains(departmentId)) {
return Lists.newArrayList();
}
//假设本人所在组织链:R-A-B-C-本人组织-X-Y-Z
//departmentId全部上级组织节点(R-A-B-C-本人组织)
List<Organization> superiorOrgList = organizationMapper.selectAllSuperiorBySubId(ShieldContextHolder.getDepartmentId());
//否则返回departmentId下所有下级部门的用户
List<Long> superiorOrgIdList = superiorOrgList.stream().map(Organization::getSuperiorId).collect(Collectors.toList());
//departmentId全部下级组织节点(本人组织-X-Y-Z)
List<Organization> subOrgList = organizationMapper.selectAllSubBySuperiorId(departmentId);
List<Long> subOrgIdList = subOrgList.stream().map(Organization::getSubId).collect(Collectors.toList());
List<User> userList = userMapper.selectByDepartmentIds(subOrgIdList);
//如果departmentId在上级组织链上(R-A-B-C-本人组织),返回全部可见部门用户
if (superiorOrgIdList.contains(departmentId)) {
return this.permissionUsers();
}
return userList;
//如果departmentId在下级组织链上(本人组织-X-Y-Z),返回departmentId部门用户
if (subOrgIdList.contains(departmentId)) {
return userMapper.selectByDepartmentId(departmentId);
}
return Lists.newArrayList();
}
/**
......
......@@ -156,7 +156,7 @@
from t_organization
where del_flag = 0
and sub_id = #{subId}
order by depth desc
order by sub_id, depth desc
</select>
<select id="selectAllSubBySuperiorId" resultMap="BaseResultMap">
......@@ -165,7 +165,7 @@
from t_organization
where del_flag = 0
and superior_id = #{superiorId}
order by depth
order by superior_id, depth
</select>
<select id="selectTenantsSubBySuperiorId" resultMap="BaseResultMap">
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!