Commit cbeab74c by levphon

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

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