| | |
| | | package com.xiaopeng.operation.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.xiaopeng.api.feignClient.account.SysGroupMenuClient; |
| | | import com.xiaopeng.api.feignClient.account.SysRoleClient; |
| | | import com.xiaopeng.api.feignClient.account.SysUserRoleClient; |
| | | import com.xiaopeng.api.model.account.SysRole; |
| | | import com.xiaopeng.api.model.account.SysUserRole; |
| | | import com.xiaopeng.api.model.operation.SysMenu; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.security.service.TokenService; |
| | | import com.xiaopeng.operation.mapper.SysMenuMapper; |
| | | import com.xiaopeng.operation.service.ISysMenuService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.util.*; |
| | |
| | | * @author mitao |
| | | * @since 2026-02-03 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | public class SysMenuServiceImpl extends ServiceImpl<SysMenuMapper, SysMenu> implements ISysMenuService { |
| | | |
| | | @Autowired |
| | | private TokenService tokenService; |
| | | |
| | | @Autowired |
| | | private SysUserRoleClient sysUserRoleClient; |
| | | |
| | | @Autowired |
| | | private SysRoleClient sysRoleClient; |
| | | |
| | | @Autowired |
| | | private SysGroupMenuClient sysGroupMenuClient; |
| | | |
| | | /** |
| | | * 根据菜单ID列表查询菜单列表 |
| | |
| | | |
| | | @Override |
| | | public List<SysMenu> getPermission() { |
| | | try { |
| | | // 1. 获取当前登录用户ID |
| | | Long userId = tokenService.getLoginUser().getUserid(); |
| | | if (userId == null) { |
| | | log.warn("获取当前登录用户ID失败"); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | return Collections.emptyList(); |
| | | // 2. 查询用户角色关联 |
| | | R<SysUserRole> userRoleResult = sysUserRoleClient.selectSysUserRoleByUserId(userId); |
| | | if (userRoleResult == null || userRoleResult.getCode() != 200 || userRoleResult.getData() == null) { |
| | | log.warn("查询用户角色关联失败, userId={}", userId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | Long roleId = userRoleResult.getData().getRoleId(); |
| | | if (roleId == null) { |
| | | log.warn("用户未关联角色, userId={}", userId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 3. 查询角色信息 |
| | | R<SysRole> roleResult = sysRoleClient.getRoleById(roleId); |
| | | if (roleResult == null || roleResult.getCode() != 200 || roleResult.getData() == null) { |
| | | log.warn("查询角色信息失败, roleId={}", roleId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | Long groupId = roleResult.getData().getGroupId(); |
| | | if (groupId == null) { |
| | | log.warn("角色未关联权限组, roleId={}", roleId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 4. 查询权限组关联的菜单ID列表 |
| | | R<List<Long>> menuIdsResult = sysGroupMenuClient.selectMenuIdsByGroupId(groupId); |
| | | if (menuIdsResult == null || menuIdsResult.getCode() != 200 || menuIdsResult.getData() == null) { |
| | | log.warn("查询权限组菜单ID列表失败, groupId={}", groupId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | List<Long> menuIds = menuIdsResult.getData(); |
| | | if (menuIds.isEmpty()) { |
| | | log.info("权限组未关联菜单, groupId={}", groupId); |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | // 5. 查询菜单详情 |
| | | List<SysMenu> menus = this.listByIds(menuIds); |
| | | log.info("查询用户权限菜单成功, userId={}, menuCount={}", userId, menus.size()); |
| | | return menus; |
| | | |
| | | } catch (Exception e) { |
| | | log.error("查询用户权限菜单异常", e); |
| | | return Collections.emptyList(); |
| | | } |
| | | } |
| | | } |