|
|
@@ -5,20 +5,17 @@ import cn.hutool.core.util.ObjectUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.tr.core.exception.ServiceException;
|
|
|
import cn.tr.core.exception.TRExcCode;
|
|
|
-import cn.tr.module.sys.mapper.user.SysMenuMapper;
|
|
|
import cn.tr.module.sys.mapper.user.SysRoleMapper;
|
|
|
-import cn.tr.module.sys.user.constant.MenuConstants;
|
|
|
+import cn.tr.module.sys.tenant.service.ISysTenantService;
|
|
|
import cn.tr.module.sys.user.dto.SysMenuDTO;
|
|
|
import cn.tr.module.sys.user.dto.SysRoleDTO;
|
|
|
import cn.tr.module.sys.user.dto.SysRoleQueryDTO;
|
|
|
-import cn.tr.module.sys.user.enums.MenuEnum;
|
|
|
+import cn.tr.module.sys.user.enums.RoleEnum;
|
|
|
import cn.tr.module.sys.user.po.SysRolePO;
|
|
|
import cn.tr.module.sys.user.repository.SysRoleRepository;
|
|
|
import cn.tr.module.sys.user.service.ISysMenuService;
|
|
|
import cn.tr.module.sys.user.service.ISysRoleService;
|
|
|
import cn.tr.module.sys.user.service.ISysUserRoleService;
|
|
|
-import cn.tr.module.sys.user.vo.RouteItemVO;
|
|
|
-import cn.tr.module.sys.user.vo.RouteMetoVO;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
@@ -46,21 +43,31 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|
|
@Lazy
|
|
|
private ISysUserRoleService userRoleService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private ISysTenantService tenantService;
|
|
|
+
|
|
|
@Autowired
|
|
|
@Lazy
|
|
|
private ISysRoleService self;
|
|
|
@Override
|
|
|
public List<SysRoleDTO> selectSysRoleList(SysRoleQueryDTO query) {
|
|
|
return SysRoleMapper.INSTANCE.toSysRoleDTOList(roleRepository.selectList(new LambdaQueryWrapper<SysRolePO>()
|
|
|
- .like(StrUtil.isNotEmpty(query.getRoleCode()),SysRolePO::getRoleCode,query.getRoleCode())
|
|
|
- .like(StrUtil.isNotEmpty(query.getRoleName()),SysRolePO::getRoleName,query.getRoleName()).eq(SysRolePO::getType,query.getType()
|
|
|
- ).like(ObjectUtil.isNotNull(query.getDisable()),SysRolePO::getDisable,query.getDisable())
|
|
|
+ .like(StrUtil.isNotEmpty(query.getRoleCode()),SysRolePO::getCode,query.getRoleCode())
|
|
|
+ .like(StrUtil.isNotEmpty(query.getRoleName()),SysRolePO::getName,query.getRoleName())
|
|
|
+ .like(ObjectUtil.isNotNull(query.getDisable()),SysRolePO::getDisable,query.getDisable())
|
|
|
));
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public Set<SysMenuDTO> findUserMenus(String userId){
|
|
|
List<SysRoleDTO> roles = self.findAllRolesByUserId(userId);
|
|
|
+ //判断是否存在管理员账户
|
|
|
+ for (SysRoleDTO role : roles) {
|
|
|
+ if(StrUtil.equals(role.getType(),"sys")){
|
|
|
+ return tenantService.currentTenantMenus();
|
|
|
+ }
|
|
|
+ }
|
|
|
if (CollectionUtil.isEmpty(roles)) {
|
|
|
return new HashSet<>();
|
|
|
}
|
|
|
@@ -75,12 +82,9 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public List<RouteItemVO> findUserRouteMenus(String userId) {
|
|
|
- Set<SysMenuDTO> userMenus = findUserMenus(userId);
|
|
|
- return userMenus.stream()
|
|
|
- .filter(menu->!StrUtil.equals(MenuEnum.button.name(),menu.getMenuType()))
|
|
|
- .map(this::convertToRoute)
|
|
|
- .collect(Collectors.toList());
|
|
|
+ public Collection<SysRoleDTO> findAllSysRoles() {
|
|
|
+ return SysRoleMapper.INSTANCE.toSysRoleDTOList( roleRepository.selectList(new LambdaQueryWrapper<SysRolePO>()
|
|
|
+ .eq(SysRolePO::getType,"sys")));
|
|
|
}
|
|
|
|
|
|
;
|
|
|
@@ -110,18 +114,18 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|
|
@Override
|
|
|
public int deleteSysRoleByIds(Collection<String> ids) {
|
|
|
List<SysRolePO> roles = roleRepository.selectBatchIds(ids);
|
|
|
+ Optional<SysRolePO> adminRole = roles.stream()
|
|
|
+ .filter(po->StrUtil.equals(po.getType(), RoleEnum.sys.name()))
|
|
|
+ .findFirst();
|
|
|
+ if(adminRole.isPresent()){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统角色进行操作");
|
|
|
+ }
|
|
|
for (SysRolePO role : roles) {
|
|
|
Set<String> userIds = userRoleService.findUserByRoleId(role.getId());
|
|
|
if(CollectionUtil.isNotEmpty(userIds)){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("角色编码{%s}已被使用,无法删除",role.getRoleCode()));
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("角色编码{%s}已被使用,无法删除",role.getCode()));
|
|
|
}
|
|
|
}
|
|
|
- Optional<SysRolePO> adminRole = roles.stream()
|
|
|
- .filter(po->Boolean.TRUE.equals(po.getAdmin()))
|
|
|
- .findFirst();
|
|
|
- if(adminRole.isPresent()){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"管理员角色无法删除");
|
|
|
- }
|
|
|
return roleRepository.deleteBatchIds(ids);
|
|
|
}
|
|
|
|
|
|
@@ -132,56 +136,22 @@ public class SysRoleServiceImpl implements ISysRoleService {
|
|
|
|
|
|
private void validateRoleSource(SysRolePO source){
|
|
|
SysRolePO role = roleRepository.selectOne(new LambdaQueryWrapper<SysRolePO>()
|
|
|
- .eq(SysRolePO::getRoleName, source.getRoleName())
|
|
|
- .eq(SysRolePO::getRoleCode, source.getRoleCode())
|
|
|
+ .eq(SysRolePO::getCode, source.getCode())
|
|
|
.last("limit 1"));
|
|
|
if(role!=null&& StrUtil.equals(role.getId(),source.getId())){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("角色编码{%s}或角色名称{%s}不能重复",source.getRoleCode(),source.getRoleName()));
|
|
|
- }
|
|
|
- if(Boolean.TRUE.equals(source.getAdmin())){
|
|
|
- role = roleRepository.selectOne(new LambdaQueryWrapper<SysRolePO>()
|
|
|
- .eq(SysRolePO::getAdmin, true)
|
|
|
- .last("limit 1"));
|
|
|
- if(role!=null&& StrUtil.equals(role.getId(),source.getId())){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"管理员角色已存在,请勿重复添加");
|
|
|
- }else if(role!=null){
|
|
|
- throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"管理员角色无法操作");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- private RouteItemVO convertToRoute(SysMenuDTO item) {
|
|
|
- RouteItemVO node = SysMenuMapper.INSTANCE.toRouteItemVO(item);
|
|
|
- node.setPath(item.getRoutePath());
|
|
|
- node.setName(item.getRoutePath());
|
|
|
- // 一级目录
|
|
|
- if (Objects.equals(item.getMenuType(), MenuEnum.dir.name()) && (StrUtil.equals(item.getParentId(),"0")||StrUtil.isEmpty(item.getParentId()))) {
|
|
|
- node.setPath("/" + item.getRoutePath());
|
|
|
- node.setComponent(MenuConstants.LAYOUT);
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,String.format("角色编码{%s}不能重复",source.getCode()));
|
|
|
}
|
|
|
- // 外部链接
|
|
|
- if (Objects.equals(item.getMenuType(), MenuEnum.menu.name()) && Boolean.TRUE.equals(item.getLinkExternal())) {
|
|
|
- node.setComponent(MenuConstants.IFRAME);
|
|
|
+ if(StrUtil.equals(source.getType(), RoleEnum.sys.name())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统角色进行操作");
|
|
|
}
|
|
|
- RouteMetoVO routeMetoVO = new RouteMetoVO();
|
|
|
- routeMetoVO.setTitle(item.getName());
|
|
|
- routeMetoVO.setIcon(item.getIcon());
|
|
|
- routeMetoVO.setHideMenu(!Boolean.TRUE.equals(item.getVisible()));
|
|
|
- // 菜单
|
|
|
- if (Objects.equals(item.getMenuType(), MenuEnum.menu.name())) {
|
|
|
- routeMetoVO.setIgnoreKeepAlive(!Boolean.TRUE.equals(item.getKeepalive()));
|
|
|
- }
|
|
|
- // 外部链接
|
|
|
- if (Objects.equals(item.getMenuType(), MenuEnum.menu.name()) && Boolean.TRUE.equals(item.getLinkExternal())) {
|
|
|
- // 内嵌
|
|
|
- if (Boolean.TRUE.equals(item.getFrame())) {
|
|
|
- routeMetoVO.setFrameSrc(item.getLinkUrl());
|
|
|
- }else {
|
|
|
- node.setPath(item.getLinkUrl());
|
|
|
+ if(StrUtil.isNotEmpty(source.getId())){
|
|
|
+ SysRolePO sysRolePO = roleRepository.selectById(source.getId());
|
|
|
+ if(sysRolePO==null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if(StrUtil.equals(sysRolePO.getType(), RoleEnum.sys.name())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"无法对系统角色进行操作");
|
|
|
}
|
|
|
}
|
|
|
- node.setMeta(routeMetoVO);
|
|
|
- return node;
|
|
|
}
|
|
|
}
|