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;
...@@ -19,159 +24,191 @@ import java.util.stream.Collectors; ...@@ -19,159 +24,191 @@ import java.util.stream.Collectors;
@Slf4j @Slf4j
public class OrganizationServiceImpl implements OrganizationService { public class OrganizationServiceImpl implements OrganizationService {
@Autowired @Autowired
private OrgClusterDao orgClusterDao; private OrgClusterDao orgClusterDao;
@Autowired @Autowired
private OrgBranchDao orgBranchDao; private OrgBranchDao orgBranchDao;
@Autowired @Autowired
private OrgGroupDao orgGroupDao; private OrgGroupDao orgGroupDao;
@Autowired @Autowired
private OrgTeamEngineerDao orgTeamEngineerDao; private OrgTeamEngineerDao orgTeamEngineerDao;
@Autowired @Autowired
private EngineerInfoDao engineerInfoDao; private EngineerInfoDao engineerInfoDao;
@Autowired @Autowired
private OrgTeamDao orgTeamDao; private OrgTeamDao orgTeamDao;
@Autowired @Autowired
private EngineerUtils engineerUtils; private EngineerUtils engineerUtils;
@Override @Override
public Result<?> getOrganizationTree(String levelType, String levelValue) { public Result<?> getOrganizationTree(String levelType, String levelValue) {
// 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容 // 如果传递了精确的id,只返回对应的tree内容;如果没有传递,返回所有tree内容
if ("group".equals(levelType)) { if ("group".equals(levelType)) {
OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelValue); OrgGroupEntity orgGroupEntity = orgGroupDao.getByGroupId(levelValue);
if (orgGroupEntity == null) { if (orgGroupEntity == null) {
return Result.failed("groupId对应的信息不存在"); return Result.failed("groupId对应的信息不存在");
} }
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<>(
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId()); Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgGroupEntity.getClusterId());
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); List<?> clusters = new ArrayList<>(
} else if ("branch".equals(levelType)) { Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
if (orgBranchEntity == null) { } else if ("branch".equals(levelType)) {
return Result.failed("分站信息不存在"); OrgBranchEntity orgBranchEntity = orgBranchDao.getByBranchId(levelValue);
} if (orgBranchEntity == null) {
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId()); return Result.failed("分站信息不存在");
List<?> groups = getChildByBranch(levelValue); }
List<?> branchs = new ArrayList<>(Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups))); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(orgBranchEntity.getClusterId());
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); List<?> groups = getChildByBranch(levelValue);
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); List<?> branchs = new ArrayList<>(
} else if ("cluster".equals(levelType)) { Collections.singletonList(branchEntityh2Dto(orgBranchEntity).setChildren(groups)));
OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue); List<?> clusters = new ArrayList<>(
if (orgClusterEntity == null) { Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.failed("大区信息不存在"); return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
} } else if ("cluster".equals(levelType)) {
List<?> branchs = getChildByCluster(levelValue); OrgClusterEntity orgClusterEntity = orgClusterDao.getByClusterId(levelValue);
List<?> clusters = new ArrayList<>(Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs))); if (orgClusterEntity == null) {
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters)); return Result.failed("大区信息不存在");
} else { }
return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot())); List<?> branchs = getChildByCluster(levelValue);
} List<?> clusters = new ArrayList<>(
} Collections.singletonList(clusterEntity2Dto(orgClusterEntity).setChildren(branchs)));
return Result.success(new OrganizationTreeRespDTO().setClusters(clusters));
@Override } else {
public Result<?> getEngineersByTeams(List<String> teamIds) { return Result.success(new OrganizationTreeRespDTO().setClusters(getTreeByRoot()));
List<OrganizationEngineersByTeamsDTO.Engineer> engineers = new ArrayList<>(); }
for (OrgTeamEngineerEntity e : orgTeamEngineerDao.findAllByTeamIdIn(teamIds)) { }
EngineerInfoEntity engineerInfoEntity = engineerInfoDao.getByEngineerCode(e.getEngineerCode());
if (engineerInfoEntity == null) { @Override
log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode()); public Result<?> getEngineersByTeams(List<String> teamIds) {
continue; List<OrganizationEngineersByTeamsDTO.Engineer> engineers = new ArrayList<>();
} for (OrgTeamEngineerEntity e : orgTeamEngineerDao.findAllByTeamIdIn(teamIds)) {
engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(), engineerInfoEntity.getName())); EngineerInfoEntity engineerInfoEntity = engineerInfoDao.getByEngineerCode(e.getEngineerCode());
} if (engineerInfoEntity == null) {
return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers)); log.error("技术员信息不存在!engineer_code: {}", e.getEngineerCode());
} continue;
}
@Override engineers.add(new OrganizationEngineersByTeamsDTO.Engineer(e.getTeamId(), e.getEngineerCode(),
public Result<?> getTeamsByLevel(String levelType, String levelValue) { engineerInfoEntity.getName()));
log.debug("getTeamsByLevel({}, {})", levelType, levelValue); }
List<OrgTeamEntity> entities; return Result.success(new OrganizationEngineersByTeamsDTO.Result().setEngineers(engineers));
if ("cluster".equals(levelType)) { }
entities = orgTeamDao.findAllByClusterId(levelValue);
} else if ("branch".equals(levelType)) { @Override
entities = orgTeamDao.findAllByBranchId(levelValue); public Result<?> getTeamsByLevel(String levelType, String levelValue) {
} else if ("group".equals(levelType)) { log.debug("getTeamsByLevel({}, {})", levelType, levelValue);
entities = orgTeamDao.findAllByGroupId(levelValue); List<OrgTeamEntity> entities;
} else { if ("cluster".equals(levelType)) {
entities = orgTeamDao.findAll(); entities = orgTeamDao.findAllByClusterId(levelValue);
} } else if ("branch".equals(levelType)) {
List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>(); entities = orgTeamDao.findAllByBranchId(levelValue);
for (OrgTeamEntity e : entities) { } else if ("group".equals(levelType)) {
teams.add(new OrganizationTeamsRespDTO.Team() entities = orgTeamDao.findAllByGroupId(levelValue);
.setTeamType(e.getTeamType()) } else {
.setTeamId(e.getTeamId()) entities = orgTeamDao.findAll();
.setTeamName(e.getTeamName()) }
.setClusterId(e.getClusterId()) List<OrganizationTeamsRespDTO.Team> teams = new ArrayList<>();
.setBranchId(e.getBranchId()) for (OrgTeamEntity e : entities) {
.setGroupId(e.getGroupId()) 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)); }
} return Result.success(new OrganizationTeamsRespDTO().setTeams(teams));
}
@Override
public Result<?> getEngineersByLevel(String levelType, String levelValue) { @Override
List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue); public Result<?> getEngineersByLevel(String levelType, String levelValue) {
List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> { List<EngineerInfoEntity> engineers = engineerUtils.getEngineersByLevel(levelType, levelValue);
return new OrganizationEngineersDTO.Engineer() List<OrganizationEngineersDTO.Engineer> engineers1 = engineers.stream().map(entity -> {
.setEngineerCode(entity.getEngineerCode()) return new OrganizationEngineersDTO.Engineer().setEngineerCode(entity.getEngineerCode())
.setEngineerName(entity.getName()) .setEngineerName(entity.getName()).setPhone(entity.getPhone());
.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); return Result.success(rs);
return Result.success(rs); }
}
private List<?> getTreeByRoot() {
private List<?> getTreeByRoot() { List<OrganizationTreeRespDTO.Cluster> clusters = new ArrayList<>();
List<OrganizationTreeRespDTO.Cluster> clusters = new ArrayList<>(); for (OrgClusterEntity c : orgClusterDao.findAll()) {
for (OrgClusterEntity c : orgClusterDao.findAll()) { clusters.add(clusterEntity2Dto(c).setChildren(getChildByCluster(c.getClusterId())));
clusters.add(clusterEntity2Dto(c).setChildren(getChildByCluster(c.getClusterId()))); }
} return clusters;
return clusters; }
}
private List<?> getChildByCluster(String clusterId) {
private List<?> getChildByCluster(String clusterId) { List<OrganizationTreeRespDTO.Branch> branches = new ArrayList<>();
List<OrganizationTreeRespDTO.Branch> branches = new ArrayList<>(); for (OrgBranchEntity b : orgBranchDao.findAllByClusterId(clusterId)) {
for (OrgBranchEntity b : orgBranchDao.findAllByClusterId(clusterId)) { branches.add(branchEntityh2Dto(b).setChildren(getChildByBranch(b.getBranchId())));
branches.add(branchEntityh2Dto(b).setChildren(getChildByBranch(b.getBranchId()))); }
} return branches;
return branches; }
}
private List<?> getChildByBranch(String branchId) {
private List<?> getChildByBranch(String branchId) { // 获取branch及下面的group
// 获取branch及下面的group List<OrganizationTreeRespDTO.Group> groups = new ArrayList<>();
List<OrganizationTreeRespDTO.Group> groups = new ArrayList<>(); for (OrgGroupEntity g : orgGroupDao.findAllByBranchId(branchId)) {
for (OrgGroupEntity g : orgGroupDao.findAllByBranchId(branchId)) { groups.add(groupEntity2Dto(g));
groups.add(groupEntity2Dto(g)); }
} return groups;
return groups; }
}
private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) {
return new OrganizationTreeRespDTO.Group().setType("group").setId(orgGroupEntity.getGroupId())
private OrganizationTreeRespDTO.Group groupEntity2Dto(OrgGroupEntity orgGroupEntity) { .setTitle(orgGroupEntity.getGroupName());
return new OrganizationTreeRespDTO.Group() }
.setType("group")
.setId(orgGroupEntity.getGroupId()) private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) {
.setTitle(orgGroupEntity.getGroupName()); return new OrganizationTreeRespDTO.Branch().setType("branch").setId(orgBranchEntity.getBranchId())
} .setTitle(orgBranchEntity.getBranchName());
}
private OrganizationTreeRespDTO.Branch branchEntityh2Dto(OrgBranchEntity orgBranchEntity) {
return new OrganizationTreeRespDTO.Branch() private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) {
.setType("branch") return new OrganizationTreeRespDTO.Cluster().setType("cluster").setId(orgClusterEntity.getClusterId())
.setId(orgBranchEntity.getBranchId()) .setTitle(orgClusterEntity.getName());
.setTitle(orgBranchEntity.getBranchName()); }
}
@Override
private OrganizationTreeRespDTO.Cluster clusterEntity2Dto(OrgClusterEntity orgClusterEntity) { public List<OrganizationDTO> getAllOrganizations(String levelType, List<String> organizationIds) {
return new OrganizationTreeRespDTO.Cluster() switch (OrganizationType.valueOf(levelType)) {
.setType("cluster") case cluster:
.setId(orgClusterEntity.getClusterId()) List<OrgClusterEntity> clusters = orgClusterDao.findByClusterIdIn(organizationIds);
.setTitle(orgClusterEntity.getName()); 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;
...@@ -82,6 +87,9 @@ public class UserService { ...@@ -82,6 +87,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));
...@@ -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!