Commit 32808101 by chamberone

feat: 添加组织结构相关逻辑

1 parent 5c7d47dd
package com.dituhui.pea.order;
import java.util.List;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.dituhui.pea.common.Result;
/**
* 组织结构相关接口
*
*/
@FeignClient(value = "project-order", contextId = "org")
@RequestMapping("/pea-order")
public interface IOrganization {
/**
* 获取指定等级下的所有组织
*
* @param levelType 大区/分部/分站/小组
* @param organizationIds 组织编号
* @return
*/
@RequestMapping(value = "/organization/list", method = RequestMethod.GET)
public Result<?> getAllOrganizations(@RequestParam("levelType") String levelType,
@RequestParam("organizationIds") List<String> organizationIds);
}
package com.dituhui.pea.pojo;
import lombok.Data;
@Data
public class OrganizationDTO {
/**
* ID
*/
private String id;
/**
* 名称
*/
private String name;
/**
* 类型
*/
private String type;
public OrganizationDTO(String id, String name, String type) {
this.id = id;
this.name = name;
this.type = type;
}
}
......@@ -24,6 +24,7 @@ public class UserLoginDTO {
private String token;
private List<RoleInfo> roles;
private List<ResourceInfo> resources;
private List<ResourceInfo> menus;
private List<OrganizationDTO> auths;
}
package com.dituhui.pea.order.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.druid.util.StringUtils;
import com.alibaba.nacos.client.naming.utils.CollectionUtils;
import com.dituhui.pea.common.BusinessException;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.IOrganization;
import com.dituhui.pea.order.service.OrganizationService;
import com.dituhui.pea.pojo.OrganizationDTO;
/**
* 对外组织结构服务
*
*/
@RestController
public class PublicOrganizationController implements IOrganization {
@Autowired
private OrganizationService organizationService;
@Override
public Result<?> getAllOrganizations(String levelType, List<String> organizationIds) {
if (StringUtils.isEmpty(levelType)) {
return Result.failed("缺少参数levelType");
}
if (CollectionUtils.isEmpty(organizationIds)) {
return Result.failed("缺少参数organizationIds");
}
Result<?> res = null;
try {
List<OrganizationDTO> orgs = organizationService.getAllOrganizations(levelType, organizationIds);
res = Result.success(orgs);
} catch (BusinessException e) {
return Result.failed(e.getMessage());
}
return res;
}
}
......@@ -14,4 +14,6 @@ public interface OrgBranchDao extends JpaRepository<OrgBranchEntity, Integer> {
List<OrgBranchEntity> findAllByClusterId(String clusterId);
OrgBranchEntity getByBranchId(String branchId);
public List<OrgBranchEntity> findByBranchIdIn(List<String> ids);
}
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgClusterEntity;
import java.util.List;
import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
......@@ -10,4 +13,6 @@ import org.springframework.stereotype.Repository;
public interface OrgClusterDao extends JpaRepository <OrgClusterEntity, Integer> {
OrgClusterEntity getByClusterId(String clusterId);
public List<OrgClusterEntity> findByClusterIdIn(List<String> ids);
}
......@@ -16,4 +16,6 @@ public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> {
List<OrgGroupEntity> findAllByClusterId(String clusterId);
OrgGroupEntity getByGroupId(String groupId);
public List<OrgGroupEntity> findByGroupIdIn(List<String> ids);
}
package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgTeamEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
......@@ -36,4 +35,6 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer> {
@Modifying
@Query("UPDATE OrgTeamEntity tt SET tt.status = :status WHERE tt.teamId = :teamId")
void updateStatusByTeamId(String teamId, int status);
public List<OrgTeamEntity> findByTeamIdIn(List<String> ids);
}
package com.dituhui.pea.order.enums;
/**
* 组织等级类型
*
*/
public enum OrganizationType {
/**
* 大区
*/
cluster("cluster"),
/**
* 分部
*/
branch("branch"),
/**
* 分站
*/
group("group"),
/**
* 工作队
*/
team("team");
private String value;
private OrganizationType(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.pojo.OrganizationDTO;
import java.util.List;
......@@ -12,4 +13,6 @@ public interface OrganizationService {
Result<?> getTeamsByLevel(String levelType, String levelValue);
Result<?> getEngineersByLevel(String levelType, String levelValue);
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds);
}
package com.dituhui.pea.order.service.impl;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrganizationType;
import com.dituhui.pea.order.service.OrganizationService;
import com.dituhui.pea.pojo.OrganizationDTO;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
......@@ -19,159 +24,191 @@ import java.util.stream.Collectors;
@Slf4j
public class OrganizationServiceImpl implements OrganizationService {
@Autowired
private OrgClusterDao orgClusterDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgTeamDao orgTeamDao;
@Autowired
private EngineerUtils engineerUtils;
@Override
public Result<?> getOrganizationTree(String levelType, String levelValue) {
// 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容
if ("group".equals(levelType)) {
OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelValue);
if (orgGroupEntity == null) {
return Result.failed("groupId对应的信息不存在");
}
List<?> groups = new ArrayList<>(Collections.singletonList(groupEntity2Dto(orgGroupEntity)));
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(orgGroupEntity.getBranchId());
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId());
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("branch".equals(levelType)) {
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue);
if (orgBranchEntity == null) {
return Result.failed("分站信息不存在");
}
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId());
List<?> groups = getChildByBranch(levelValue);
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("cluster".equals(levelType)) {
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue);
if (orgClusterEntity == null) {
return Result.failed("大区信息不存在");
}
List<?> branchs = getChildByCluster(levelValue);
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else {
return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot()));
}
}
@Override
public Result<?> getEngineersByTeams(List<String> teamIds) {
List<OrganizationEngineersByTeamsDTO.Engineer> engineers = new ArrayList<>();
for (OrgTeamEngineerEntity e : orgTeamEngineerDao.findAllByTeamIdIn(teamIds)) {
EngineerInfoEntity engineerInfoEntity = engineerInfoDao.getByEngineerCode(e.getEngineerCode());
if (engineerInfoEntity == null) {
log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode());
continue;
}
engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(), engineerInfoEntity.getName()));
}
return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers));
}
@Override
public Result<?> getTeamsByLevel(String levelType, String levelValue) {
log.debug("getTeamsByLevel({}, {})", levelType, levelValue);
List<OrgTeamEntity> entities;
if ("cluster".equals(levelType)) {
entities = orgTeamDao.findAllByClusterId(levelValue);
} else if ("branch".equals(levelType)) {
entities = orgTeamDao.findAllByBranchId(levelValue);
} else if ("group".equals(levelType)) {
entities = orgTeamDao.findAllByGroupId(levelValue);
} else {
entities = orgTeamDao.findAll();
}
List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>();
for (OrgTeamEntity e : entities) {
teams.add(new OrganizationTeamsRespDTO.Team()
.setTeamType(e.getTeamType())
.setTeamId(e.getTeamId())
.setTeamName(e.getTeamName())
.setClusterId(e.getClusterId())
.setBranchId(e.getBranchId())
.setGroupId(e.getGroupId())
);
}
return Result.success(new OrganizationTeamsRespDTO().setTeams(teams));
}
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer()
.setEngineerCode(entity.getEngineerCode())
.setEngineerName(entity.getName())
.setPhone(entity.getPhone());
}).collect(Collectors.toList());
OrganizationEngineersDTO.Result rs = new OrganizationEngineersDTO.Result();
rs.setLevelType(levelType).setLevelValue(levelValue).setEngineers(engineers1);
return Result.success(rs);
}
private List<?> getTreeByRoot() {
List<OrganizationTreeRespDTO.Cluster> clusters = new ArrayList<>();
for (OrgClusterEntity c : orgClusterDao.findAll()) {
clusters.add(clusterEntity2Dto(c).setChildren(getChildByCluster(c.getClusterId())));
}
return clusters;
}
private List<?> getChildByCluster(String clusterId) {
List<OrganizationTreeRespDTO.Branch> branches = new ArrayList<>();
for (OrgBranchEntity b : orgBranchDao.findAllByClusterId(clusterId)) {
branches.add(branchEntityh2Dto(b).setChildren(getChildByBranch(b.getBranchId())));
}
return branches;
}
private List<?> getChildByBranch(String branchId) {
// 获取branch及下面的group
List<OrganizationTreeRespDTO.Group> groups = new ArrayList<>();
for (OrgGroupEntity g : orgGroupDao.findAllByBranchId(branchId)) {
groups.add(groupEntity2Dto(g));
}
return groups;
}
private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) {
return new OrganizationTreeRespDTO.Group()
.setType("group")
.setId(orgGroupEntity.getGroupId())
.setTitle(orgGroupEntity.getGroupName());
}
private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) {
return new OrganizationTreeRespDTO.Branch()
.setType("branch")
.setId(orgBranchEntity.getBranchId())
.setTitle(orgBranchEntity.getBranchName());
}
private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) {
return new OrganizationTreeRespDTO.Cluster()
.setType("cluster")
.setId(orgClusterEntity.getClusterId())
.setTitle(orgClusterEntity.getName());
}
@Autowired
private OrgClusterDao orgClusterDao;
@Autowired
private OrgBranchDao orgBranchDao;
@Autowired
private OrgGroupDao orgGroupDao;
@Autowired
private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired
private EngineerInfoDao engineerInfoDao;
@Autowired
private OrgTeamDao orgTeamDao;
@Autowired
private EngineerUtils engineerUtils;
@Override
public Result<?> getOrganizationTree(String levelType, String levelValue) {
// 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容
if ("group".equals(levelType)) {
OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelValue);
if (orgGroupEntity == null) {
return Result.failed("groupId对应的信息不存在");
}
List<?> groups = new ArrayList<>(Collections.singletonList(groupEntity2Dto(orgGroupEntity)));
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(orgGroupEntity.getBranchId());
List<?> branchs = new ArrayList<>(
Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId());
List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("branch".equals(levelType)) {
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue);
if (orgBranchEntity == null) {
return Result.failed("分站信息不存在");
}
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId());
List<?> groups = getChildByBranch(levelValue);
List<?> branchs = new ArrayList<>(
Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("cluster".equals(levelType)) {
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue);
if (orgClusterEntity == null) {
return Result.failed("大区信息不存在");
}
List<?> branchs = getChildByCluster(levelValue);
List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else {
return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot()));
}
}
@Override
public Result<?> getEngineersByTeams(List<String> teamIds) {
List<OrganizationEngineersByTeamsDTO.Engineer> engineers = new ArrayList<>();
for (OrgTeamEngineerEntity e : orgTeamEngineerDao.findAllByTeamIdIn(teamIds)) {
EngineerInfoEntity engineerInfoEntity = engineerInfoDao.getByEngineerCode(e.getEngineerCode());
if (engineerInfoEntity == null) {
log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode());
continue;
}
engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(),
engineerInfoEntity.getName()));
}
return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers));
}
@Override
public Result<?> getTeamsByLevel(String levelType, String levelValue) {
log.debug("getTeamsByLevel({}, {})", levelType, levelValue);
List<OrgTeamEntity> entities;
if ("cluster".equals(levelType)) {
entities = orgTeamDao.findAllByClusterId(levelValue);
} else if ("branch".equals(levelType)) {
entities = orgTeamDao.findAllByBranchId(levelValue);
} else if ("group".equals(levelType)) {
entities = orgTeamDao.findAllByGroupId(levelValue);
} else {
entities = orgTeamDao.findAll();
}
List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>();
for (OrgTeamEntity e : entities) {
teams.add(new OrganizationTeamsRespDTO.Team().setTeamType(e.getTeamType()).setTeamId(e.getTeamId())
.setTeamName(e.getTeamName()).setClusterId(e.getClusterId()).setBranchId(e.getBranchId())
.setGroupId(e.getGroupId()));
}
return Result.success(new OrganizationTeamsRespDTO().setTeams(teams));
}
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer().setEngineerCode(entity.getEngineerCode())
.setEngineerName(entity.getName()).setPhone(entity.getPhone());
}).collect(Collectors.toList());
OrganizationEngineersDTO.Result rs = new OrganizationEngineersDTO.Result();
rs.setLevelType(levelType).setLevelValue(levelValue).setEngineers(engineers1);
return Result.success(rs);
}
private List<?> getTreeByRoot() {
List<OrganizationTreeRespDTO.Cluster> clusters = new ArrayList<>();
for (OrgClusterEntity c : orgClusterDao.findAll()) {
clusters.add(clusterEntity2Dto(c).setChildren(getChildByCluster(c.getClusterId())));
}
return clusters;
}
private List<?> getChildByCluster(String clusterId) {
List<OrganizationTreeRespDTO.Branch> branches = new ArrayList<>();
for (OrgBranchEntity b : orgBranchDao.findAllByClusterId(clusterId)) {
branches.add(branchEntityh2Dto(b).setChildren(getChildByBranch(b.getBranchId())));
}
return branches;
}
private List<?> getChildByBranch(String branchId) {
// 获取branch及下面的group
List<OrganizationTreeRespDTO.Group> groups = new ArrayList<>();
for (OrgGroupEntity g : orgGroupDao.findAllByBranchId(branchId)) {
groups.add(groupEntity2Dto(g));
}
return groups;
}
private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) {
return new OrganizationTreeRespDTO.Group().setType("group").setId(orgGroupEntity.getGroupId())
.setTitle(orgGroupEntity.getGroupName());
}
private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) {
return new OrganizationTreeRespDTO.Branch().setType("branch").setId(orgBranchEntity.getBranchId())
.setTitle(orgBranchEntity.getBranchName());
}
private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) {
return new OrganizationTreeRespDTO.Cluster().setType("cluster").setId(orgClusterEntity.getClusterId())
.setTitle(orgClusterEntity.getName());
}
@Override
public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
switch (OrganizationType.valueOf(levelType)) {
case cluster:
List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(clusters)) {
return clusters.stream().map(
c -> new OrganizationDTO(c.getClusterId(), c.getName(), OrganizationType.cluster.getValue()))
.collect(Collectors.toList());
}
break;
case branch:
List<OrgBranchEntity> branchs = orgBranchDao.findByBranchIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(branchs)) {
return branchs.stream().map(c -> new OrganizationDTO(c.getBranchId(), c.getBranchName(),
OrganizationType.branch.getValue())).collect(Collectors.toList());
}
break;
case group:
List<OrgGroupEntity> groups = orgGroupDao.findByGroupIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(groups)) {
return groups.stream().map(
c -> new OrganizationDTO(c.getGroupId(), c.getGroupName(), OrganizationType.group.getValue()))
.collect(Collectors.toList());
}
break;
case team:
List<OrgTeamEntity> teams = orgTeamDao.findByTeamIdIn(organizationIds);
if (CollectionUtils.isNotEmpty(teams)) {
return teams.stream()
.map(c -> new OrganizationDTO(c.getTeamId(), c.getTeamName(), OrganizationType.team.getValue()))
.collect(Collectors.toList());
}
break;
default:
break;
}
return Lists.newArrayList();
}
}
package com.dituhui.pea.user.service;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
......@@ -16,10 +17,13 @@ import org.springframework.transaction.annotation.Transactional;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.enums.RedisKeyGroup;
import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.exception.BusinessException;
import com.dituhui.pea.order.IOrganization;
import com.dituhui.pea.pojo.OrganizationDTO;
import com.dituhui.pea.pojo.ResourceInfo;
import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.ThirdUserInfo;
......@@ -40,6 +44,7 @@ import com.dituhui.pea.user.entity.UserRoleEntity;
import com.dituhui.pea.user.factory.ThirdStrategy;
import com.dituhui.pea.user.factory.ThirdStrategyFactory;
import com.dituhui.pea.user.utils.TextHelper;
import com.google.common.collect.Lists;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
......@@ -82,6 +87,9 @@ public class UserService {
@Autowired
ResourceDao resourceDao;
@Autowired
IOrganization organizationService;
public Result<?> userLogin(String account, String password) {
UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password));
......@@ -118,30 +126,46 @@ public class UserService {
List<String> resourceIds = roleResources.stream().map(r -> r.getResourceId())
.collect(Collectors.toList());
List<ResourceEntity> resources = resourceDao.findAllById(resourceIds);
// 子菜单嵌套处理+菜单排序
// 菜单嵌套处理+菜单排序
List<ResourceInfo> levelOne = resources.stream()
.filter(r -> StringUtils.isEmpty(r.getParentId()) && r.getType() == 1)
.map(r -> BeanUtil.copyProperties(r, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo resourceInfo : levelOne) {
splitExtra(resourceInfo);
splitMenuExtra(resourceInfo);
List<ResourceEntity> levelTow = resourceDao.findByParentId(resourceInfo.getId());
List<ResourceInfo> levelTowResourceInfo = levelTow.stream().map(r -> {
ResourceInfo res = BeanUtil.copyProperties(r, ResourceInfo.class);
splitExtra(res);
splitMenuExtra(res);
return res;
}).sorted(Comparator.comparing(ResourceInfo::getOrder)).collect(Collectors.toList());
resourceInfo.setChildren(levelTowResourceInfo);
}
levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder))
.collect(Collectors.toList());
userDTO.setResources(levelOne);
userDTO.setMenus(levelOne);
// 获取组织架构资源
List<OrganizationDTO> allOrgs = resources.stream().filter(r -> r.getType() == 3)
// 暂时只允许一种角色
.limit(1).map(r -> {
List<OrganizationDTO> orgs = Lists.newArrayList();
String[] temp = r.getExtra().split("|");
Result<?> result = organizationService.getAllOrganizations(temp[0],
Arrays.asList(temp[1].split(",")));
if (StringUtils.equals(ResultEnum.SUCCESS.getCode(), result.getCode())) {
orgs = (List<OrganizationDTO>) result.getResult();
}
return orgs;
}).flatMap(a -> a.stream()).collect(Collectors.toList());
userDTO.setAuths(allOrgs);
}
}
}
return userDTO;
}
private void splitExtra(ResourceInfo resourceInfo) {
private void splitMenuExtra(ResourceInfo resourceInfo) {
String[] temp = resourceInfo.getExtra().split(",");
resourceInfo.setCode(temp[0]);
resourceInfo.setOrder(Integer.parseInt(temp[1]));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!