Commit 2f732dea by huangjinxin

fix:超管返回所有组织权限

1 parent bb6a2582
......@@ -7,6 +7,11 @@ package com.dituhui.pea.order.enums;
public enum OrganizationType {
/**
* 超管
*/
admin("admin"),
/**
* 大区
*/
cluster("cluster"),
......
......@@ -181,64 +181,76 @@ public class OrganizationServiceImpl implements OrganizationService {
.setTitle(orgClusterEntity.getName());
}
@Override
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
log.info("{} {}", levelType, organizationIds);
switch (OrganizationType.valueOf(levelType)) {
case cluster:
List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(clusters)) {
return clusters.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case branch:
List<OrgBranchEntity> branchs = orgBranchDao.findByBranchIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(branchs)) {
return branchs.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getBranchId());
organizationDTO.setName(c.getBranchName());
organizationDTO.setType(OrganizationType.branch.getValue());
return organizationDTO;
}
).collect(Collectors.toList());
}
break;
case group:
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(groups)) {
return groups.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getGroupId());
organizationDTO.setName(c.getGroupName());
organizationDTO.setType(OrganizationType.group.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case team:
List<OrgTeamEntity> teams = orgTeamDao.findByTeamIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(teams)) {
return teams.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getTeamId());
organizationDTO.setName(c.getTeamName());
organizationDTO.setType(OrganizationType.team.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
default:
break;
}
return Lists.newArrayList();
}
@Override
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
log.info("{} {}", levelType, organizationIds);
switch (OrganizationType.valueOf(levelType)) {
case cluster:
List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(clusters)) {
return clusters.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case branch:
List<OrgBranchEntity> branchs = orgBranchDao.findByBranchIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(branchs)) {
return branchs.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getBranchId());
organizationDTO.setName(c.getBranchName());
organizationDTO.setType(OrganizationType.branch.getValue());
return organizationDTO;
}
).collect(Collectors.toList());
}
break;
case group:
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(groups)) {
return groups.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getGroupId());
organizationDTO.setName(c.getGroupName());
organizationDTO.setType(OrganizationType.group.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case team:
List<OrgTeamEntity> teams = orgTeamDao.findByTeamIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(teams)) {
return teams.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getTeamId());
organizationDTO.setName(c.getTeamName());
organizationDTO.setType(OrganizationType.team.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
case admin:
List<OrgClusterEntity> adminCluster = orgClusterDao.findAll();
if (CollectionUtils.isNotEmpty(adminCluster)) {
return adminCluster.stream().map(c -> {
OrganizationDTO organizationDTO = new OrganizationDTO();
organizationDTO.setId(c.getClusterId());
organizationDTO.setName(c.getName());
organizationDTO.setType(OrganizationType.cluster.getValue());
return organizationDTO;
}).collect(Collectors.toList());
}
break;
default:
break;
}
return Lists.newArrayList();
}
}
......@@ -183,13 +183,22 @@ public class UserService {
//用户组织机构从关联表获取
List<OrganizationDTO> allOrgs = new ArrayList<>();
List<UserOrgEntity> byUserId = userOrgDao.findByUserId(userDTO.getId());
if (CollectionUtils.isNotEmpty(byUserId)) {
List<String> collect = byUserId.stream().map(UserOrgEntity::getOrgId).collect(Collectors.toList());
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations(LevelUtils.convertOrgLevel(byUserId.get(0).getOrgLevel()), collect);
// 超管处理,不用配置资源自动拥有所有权限
if (ids.contains(Globals.SUPER_ADMIN_ID)) {
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations("admin", Arrays.asList("admin"));
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
allOrgs = result.getResult();
}
} else {
List<UserOrgEntity> byUserId = userOrgDao.findByUserId(userDTO.getId());
if (CollectionUtils.isNotEmpty(byUserId)) {
List<String> collect = byUserId.stream().map(UserOrgEntity::getOrgId).collect(Collectors.toList());
Result<List<OrganizationDTO>> result = organizationService.getAllOrganizations(LevelUtils.convertOrgLevel(byUserId.get(0).getOrgLevel()), collect);
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
allOrgs = result.getResult();
}
}
}
if (CollectionUtils.isNotEmpty(allOrgs)) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!