| | |
| | | */ |
| | | package com.vci.ubcs.system.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.vci.ubcs.system.entity.Menu; |
| | | import com.vci.ubcs.system.mapper.RoleMapper; |
| | | import com.vci.ubcs.system.service.IMenuService; |
| | | import com.vci.ubcs.system.service.IRoleMenuService; |
| | | import com.vci.ubcs.system.service.IRoleScopeService; |
| | | import com.vci.ubcs.system.service.IRoleService; |
| | | import com.vci.ubcs.system.vo.DeptVO; |
| | | import com.vci.ubcs.system.wrapper.RoleWrapper; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.log.annotation.GrantLog; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.core.tool.constant.BladeConstant; |
| | | import org.springblade.core.tool.constant.RoleConstant; |
| | | import org.springblade.core.tool.node.ForestNodeMerger; |
| | | import org.springblade.core.tool.node.TreeNode; |
| | | import org.springblade.core.tool.utils.CollectionUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import com.vci.ubcs.system.entity.Role; |
| | | import com.vci.ubcs.system.entity.RoleMenu; |
| | | import com.vci.ubcs.system.entity.RoleScope; |
| | | import com.vci.ubcs.system.vo.RoleVO; |
| | | import org.springblade.core.tool.utils.StringUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.validation.annotation.Validated; |
| | |
| | | |
| | | private final IRoleMenuService roleMenuService; |
| | | private final IRoleScopeService roleScopeService; |
| | | private final IMenuService menuService; |
| | | |
| | | @Override |
| | | public IPage<RoleVO> selectRolePage(IPage<RoleVO> page, RoleVO role) { |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<RoleVO> roleList(String tenantId) { |
| | | // 这里判断我们自己配置的管理组租户,可以查询所有 |
| | | List<RoleVO> tree = baseMapper.roleList(tenantId.equals(tenantId) ? "":tenantId); |
| | | return tree; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public boolean grant(@NotEmpty List<Long> roleIds, List<Long> menuIds, List<Long> dataScopeIds, List<Long> apiScopeIds) { |
| | | return grantRoleMenu(roleIds, menuIds) && grantDataScope(roleIds, dataScopeIds) && grantApiScope(roleIds, apiScopeIds); |
| | | } |
| | | |
| | | /** |
| | | * 角色权限配置日志记录 |
| | | * @param roleRes |
| | | * @return |
| | | */ |
| | | @Override |
| | | @GrantLog("grantRole") |
| | | public boolean grantLog(String roleRes, boolean isException) { |
| | | |
| | | return false; |
| | | } |
| | | |
| | | /** |
| | | * 获取角色授权日志的信息 |
| | | * @param roleId |
| | | * @return |
| | | */ |
| | | @Override |
| | | public String getGrantRoleResString(List<Long> roleId) { |
| | | // 获取到菜单信息,再获取到角色信息,进行拼接 |
| | | List<TreeNode> menuTree = menuService.grantTreeByRoleIds(roleId); |
| | | List<String> roleNames = this.baseMapper.getRoleNames(new Long[]{roleId.get(0)}); |
| | | String res = roleNames.get(0) + "授权为:{" + JSON.toJSONString(menuTree)+"}"; |
| | | return res; |
| | | } |
| | | |
| | | private boolean grantRoleMenu(List<Long> roleIds, List<Long> menuIds) { |
| | |
| | | |
| | | @Override |
| | | public String getRoleIds(String tenantId, String roleNames) { |
| | | List<Role> roleList = baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getTenantId, tenantId).in(Role::getRoleName, Func.toStrList(roleNames))); |
| | | List<Role> roleList = baseMapper.selectList(Wrappers.<Role>query().lambda().eq(Role::getTenantId, tenantId).in(Role::getRoleAlias, Func.toStrList(roleNames))); |
| | | if (roleList != null && roleList.size() > 0) { |
| | | return roleList.stream().map(role -> Func.toStr(role.getId())).distinct().collect(Collectors.joining(",")); |
| | | } |
| | | return null; |
| | | return ""; |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | } |
| | | if (Func.isEmpty(role.getParentId())) { |
| | | role.setTenantId(AuthUtil.getTenantId()); |
| | | role.setParentId(BladeConstant.TOP_PARENT_ID); |
| | | // 前端传了是属于那个租户id下的角色 |
| | | if(Func.isEmpty(role.getTenantId())){ |
| | | role.setTenantId(AuthUtil.getTenantId()); |
| | | } |
| | | } |
| | | if (role.getParentId() > 0) { |
| | | Role parent = getById(role.getParentId()); |