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 { ...@@ -24,6 +24,7 @@ public class UserLoginDTO {
private String token; private String token;
private List<RoleInfo> roles; 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> { ...@@ -14,4 +14,6 @@ public interface OrgBranchDao extends JpaRepository<OrgBranchEntity, Integer> {
List<OrgBranchEntity> findAllByClusterId(String clusterId); List<OrgBranchEntity> findAllByClusterId(String clusterId);
OrgBranchEntity getByBranchId(String branchId); OrgBranchEntity getByBranchId(String branchId);
public List<OrgBranchEntity> findByBranchIdIn(List<String> ids);
} }
package com.dituhui.pea.order.dao; package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgClusterEntity; import com.dituhui.pea.order.entity.OrgClusterEntity;
import java.util.List;
import org.hibernate.annotations.Where; import org.hibernate.annotations.Where;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -10,4 +13,6 @@ import org.springframework.stereotype.Repository; ...@@ -10,4 +13,6 @@ import org.springframework.stereotype.Repository;
public interface OrgClusterDao extends JpaRepository <OrgClusterEntity, Integer> { public interface OrgClusterDao extends JpaRepository <OrgClusterEntity, Integer> {
OrgClusterEntity getByClusterId(String clusterId); OrgClusterEntity getByClusterId(String clusterId);
public List<OrgClusterEntity> findByClusterIdIn(List<String> ids);
} }
...@@ -16,4 +16,6 @@ public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> { ...@@ -16,4 +16,6 @@ public interface OrgGroupDao extends JpaRepository<OrgGroupEntity, Integer> {
List<OrgGroupEntity> findAllByClusterId(String clusterId); List<OrgGroupEntity> findAllByClusterId(String clusterId);
OrgGroupEntity getByGroupId(String groupId); OrgGroupEntity getByGroupId(String groupId);
public List<OrgGroupEntity> findByGroupIdIn(List<String> ids);
} }
package com.dituhui.pea.order.dao; package com.dituhui.pea.order.dao;
import com.dituhui.pea.order.entity.OrgTeamEntity; import com.dituhui.pea.order.entity.OrgTeamEntity;
import org.hibernate.annotations.Where;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
...@@ -36,4 +35,6 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer> { ...@@ -36,4 +35,6 @@ public interface OrgTeamDao extends JpaRepository<OrgTeamEntity, Integer> {
@Modifying @Modifying
@Query("UPDATE OrgTeamEntity tt SET tt.status = :status WHERE tt.teamId = :teamId") @Query("UPDATE OrgTeamEntity tt SET tt.status = :status WHERE tt.teamId = :teamId")
void updateStatusByTeamId(String teamId, int status); 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; package com.dituhui.pea.order.service;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.pojo.OrganizationDTO;
import java.util.List; import java.util.List;
...@@ -12,4 +13,6 @@ public interface OrganizationService { ...@@ -12,4 +13,6 @@ public interface OrganizationService {
Result<?> getTeamsByLevel(String levelType, String levelValue); Result<?> getTeamsByLevel(String levelType, String levelValue);
Result<?> getEngineersByLevel(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; package com.dituhui.pea.order.service.impl;
import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.order.common.EngineerUtils; import com.dituhui.pea.order.common.EngineerUtils;
import com.dituhui.pea.order.dao.*; import com.dituhui.pea.order.dao.*;
import com.dituhui.pea.order.dto.*; import com.dituhui.pea.order.dto.*;
import com.dituhui.pea.order.entity.*; import com.dituhui.pea.order.entity.*;
import com.dituhui.pea.order.enums.OrganizationType;
import com.dituhui.pea.order.service.OrganizationService; 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 lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -45,9 +50,11 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -45,9 +50,11 @@ public class OrganizationServiceImpl implements OrganizationService {
} }
List<?> groups = new ArrayList<>(Collections.singletonList(groupEntity2Dto(orgGroupEntity))); List<?> groups = new ArrayList<>(Collections.singletonList(groupEntity2Dto(orgGroupEntity)));
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(orgGroupEntity.getBranchId()); OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(orgGroupEntity.getBranchId());
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups))); List<?> branchs = new ArrayList<>(
Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId()); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId());
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("branch".equals(levelType)) { } else if ("branch".equals(levelType)) {
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue); OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue);
...@@ -56,8 +63,10 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -56,8 +63,10 @@ public class OrganizationServiceImpl implements OrganizationService {
} }
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId()); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId());
List<?> groups = getChildByBranch(levelValue); List<?> groups = getChildByBranch(levelValue);
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups))); List<?> branchs = new ArrayList<>(
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else if ("cluster".equals(levelType)) { } else if ("cluster".equals(levelType)) {
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue);
...@@ -65,7 +74,8 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -65,7 +74,8 @@ public class OrganizationServiceImpl implements OrganizationService {
return Result.failed("大区信息不存在"); return Result.failed("大区信息不存在");
} }
List<?> branchs = getChildByCluster(levelValue); List<?> branchs = getChildByCluster(levelValue);
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> clusters = new ArrayList<>(
Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} else { } else {
return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot())); return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot()));
...@@ -81,7 +91,8 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -81,7 +91,8 @@ public class OrganizationServiceImpl implements OrganizationService {
log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode()); log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode());
continue; continue;
} }
engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(), engineerInfoEntity.getName())); engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(),
engineerInfoEntity.getName()));
} }
return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers)); return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers));
} }
...@@ -101,14 +112,9 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -101,14 +112,9 @@ public class OrganizationServiceImpl implements OrganizationService {
} }
List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>(); List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>();
for (OrgTeamEntity e : entities) { for (OrgTeamEntity e : entities) {
teams.add(new OrganizationTeamsRespDTO.Team() teams.add(new OrganizationTeamsRespDTO.Team().setTeamType(e.getTeamType()).setTeamId(e.getTeamId())
.setTeamType(e.getTeamType()) .setTeamName(e.getTeamName()).setClusterId(e.getClusterId()).setBranchId(e.getBranchId())
.setTeamId(e.getTeamId()) .setGroupId(e.getGroupId()));
.setTeamName(e.getTeamName())
.setClusterId(e.getClusterId())
.setBranchId(e.getBranchId())
.setGroupId(e.getGroupId())
);
} }
return Result.success(new OrganizationTeamsRespDTO().setTeams(teams)); return Result.success(new OrganizationTeamsRespDTO().setTeams(teams));
} }
...@@ -117,10 +123,8 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -117,10 +123,8 @@ public class OrganizationServiceImpl implements OrganizationService {
public Result<?> getEngineersByLevel(String levelType, String levelValue) { public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue); List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> { List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
return new OrganizationEngineersDTO.Engineer() return new OrganizationEngineersDTO.Engineer().setEngineerCode(entity.getEngineerCode())
.setEngineerCode(entity.getEngineerCode()) .setEngineerName(entity.getName()).setPhone(entity.getPhone());
.setEngineerName(entity.getName())
.setPhone(entity.getPhone());
}).collect(Collectors.toList()); }).collect(Collectors.toList());
OrganizationEngineersDTO.Result rs = new OrganizationEngineersDTO.Result(); OrganizationEngineersDTO.Result rs = new OrganizationEngineersDTO.Result();
rs.setLevelType(levelType).setLevelValue(levelValue).setEngineers(engineers1); rs.setLevelType(levelType).setLevelValue(levelValue).setEngineers(engineers1);
...@@ -152,26 +156,59 @@ public class OrganizationServiceImpl implements OrganizationService { ...@@ -152,26 +156,59 @@ public class OrganizationServiceImpl implements OrganizationService {
return groups; return groups;
} }
private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) { private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) {
return new OrganizationTreeRespDTO.Group() return new OrganizationTreeRespDTO.Group().setType("group").setId(orgGroupEntity.getGroupId())
.setType("group")
.setId(orgGroupEntity.getGroupId())
.setTitle(orgGroupEntity.getGroupName()); .setTitle(orgGroupEntity.getGroupName());
} }
private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) { private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) {
return new OrganizationTreeRespDTO.Branch() return new OrganizationTreeRespDTO.Branch().setType("branch").setId(orgBranchEntity.getBranchId())
.setType("branch")
.setId(orgBranchEntity.getBranchId())
.setTitle(orgBranchEntity.getBranchName()); .setTitle(orgBranchEntity.getBranchName());
} }
private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) { private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) {
return new OrganizationTreeRespDTO.Cluster() return new OrganizationTreeRespDTO.Cluster().setType("cluster").setId(orgClusterEntity.getClusterId())
.setType("cluster")
.setId(orgClusterEntity.getClusterId())
.setTitle(orgClusterEntity.getName()); .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; package com.dituhui.pea.user.service;
import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
...@@ -16,10 +17,13 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -16,10 +17,13 @@ import org.springframework.transaction.annotation.Transactional;
import com.alibaba.nacos.common.utils.CollectionUtils; import com.alibaba.nacos.common.utils.CollectionUtils;
import com.dituhui.pea.common.Result; import com.dituhui.pea.common.Result;
import com.dituhui.pea.common.ResultEnum;
import com.dituhui.pea.enums.RedisKeyGroup; import com.dituhui.pea.enums.RedisKeyGroup;
import com.dituhui.pea.enums.StatusCodeEnum; import com.dituhui.pea.enums.StatusCodeEnum;
import com.dituhui.pea.enums.ThirdPartyEnum; import com.dituhui.pea.enums.ThirdPartyEnum;
import com.dituhui.pea.exception.BusinessException; 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.ResourceInfo;
import com.dituhui.pea.pojo.RoleInfo; import com.dituhui.pea.pojo.RoleInfo;
import com.dituhui.pea.pojo.ThirdUserInfo; import com.dituhui.pea.pojo.ThirdUserInfo;
...@@ -40,6 +44,7 @@ import com.dituhui.pea.user.entity.UserRoleEntity; ...@@ -40,6 +44,7 @@ import com.dituhui.pea.user.entity.UserRoleEntity;
import com.dituhui.pea.user.factory.ThirdStrategy; import com.dituhui.pea.user.factory.ThirdStrategy;
import com.dituhui.pea.user.factory.ThirdStrategyFactory; import com.dituhui.pea.user.factory.ThirdStrategyFactory;
import com.dituhui.pea.user.utils.TextHelper; import com.dituhui.pea.user.utils.TextHelper;
import com.google.common.collect.Lists;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
...@@ -83,6 +88,9 @@ public class UserService { ...@@ -83,6 +88,9 @@ public class UserService {
@Autowired @Autowired
ResourceDao resourceDao; ResourceDao resourceDao;
@Autowired
IOrganization organizationService;
public Result<?> userLogin(String account, String password) { public Result<?> userLogin(String account, String password) {
UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password)); UserEntity user = userDao.findByAccountAndPassword(account, SecureUtil.md5(password));
log.info("{}/{} login", account, password); log.info("{}/{} login", account, password);
...@@ -118,30 +126,46 @@ public class UserService { ...@@ -118,30 +126,46 @@ public class UserService {
List<String> resourceIds = roleResources.stream().map(r -> r.getResourceId()) List<String> resourceIds = roleResources.stream().map(r -> r.getResourceId())
.collect(Collectors.toList()); .collect(Collectors.toList());
List<ResourceEntity> resources = resourceDao.findAllById(resourceIds); List<ResourceEntity> resources = resourceDao.findAllById(resourceIds);
// 子菜单嵌套处理+菜单排序
// 菜单嵌套处理+菜单排序
List<ResourceInfo> levelOne = resources.stream() List<ResourceInfo> levelOne = resources.stream()
.filter(r -> StringUtils.isEmpty(r.getParentId()) && r.getType() == 1) .filter(r -> StringUtils.isEmpty(r.getParentId()) && r.getType() == 1)
.map(r -> BeanUtil.copyProperties(r, ResourceInfo.class)).collect(Collectors.toList()); .map(r -> BeanUtil.copyProperties(r, ResourceInfo.class)).collect(Collectors.toList());
for (ResourceInfo resourceInfo : levelOne) { for (ResourceInfo resourceInfo : levelOne) {
splitExtra(resourceInfo); splitMenuExtra(resourceInfo);
List<ResourceEntity> levelTow = resourceDao.findByParentId(resourceInfo.getId()); List<ResourceEntity> levelTow = resourceDao.findByParentId(resourceInfo.getId());
List<ResourceInfo> levelTowResourceInfo = levelTow.stream().map(r -> { List<ResourceInfo> levelTowResourceInfo = levelTow.stream().map(r -> {
ResourceInfo res = BeanUtil.copyProperties(r, ResourceInfo.class); ResourceInfo res = BeanUtil.copyProperties(r, ResourceInfo.class);
splitExtra(res); splitMenuExtra(res);
return res; return res;
}).sorted(Comparator.comparing(ResourceInfo::getOrder)).collect(Collectors.toList()); }).sorted(Comparator.comparing(ResourceInfo::getOrder)).collect(Collectors.toList());
resourceInfo.setChildren(levelTowResourceInfo); resourceInfo.setChildren(levelTowResourceInfo);
} }
levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder)) levelOne = levelOne.stream().sorted(Comparator.comparing(ResourceInfo::getOrder))
.collect(Collectors.toList()); .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; return userDTO;
} }
private void splitExtra(ResourceInfo resourceInfo) { private void splitMenuExtra(ResourceInfo resourceInfo) {
String[] temp = resourceInfo.getExtra().split(","); String[] temp = resourceInfo.getExtra().split(",");
resourceInfo.setCode(temp[0]); resourceInfo.setCode(temp[0]);
resourceInfo.setOrder(Integer.parseInt(temp[1])); 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!