角色菜单id获取接口
This commit is contained in:
parent
26a3aab8cb
commit
919f727049
|
|
@ -8,11 +8,14 @@ import com.czg.account.entity.SysRole;
|
|||
import com.czg.account.service.SysRoleService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.czg.resp.CzgResult;
|
||||
import com.czg.sa.StpKit;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* 角色管理
|
||||
|
|
@ -37,6 +40,18 @@ public class RoleController {
|
|||
return CzgResult.success(roleService.getList(pageDTO, key, startTime, endTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取角色对应的菜单
|
||||
* 权限标识: role:menu
|
||||
* @param id 角色id
|
||||
* @return 分页数据
|
||||
*/
|
||||
@SaAdminCheckPermission(value = "role:menu")
|
||||
@GetMapping("/menu")
|
||||
public CzgResult<List<Long>> getRoleMenu(@RequestParam Integer id) {
|
||||
return CzgResult.success(roleService.getRoleMenu(StpKit.USER.getLoginIdAsLong(), id));
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增角色
|
||||
* 权限标识: role:add
|
||||
|
|
|
|||
|
|
@ -24,4 +24,6 @@ public interface SysRoleService extends IService<SysRole> {
|
|||
Boolean add(RoleAddDTO roleAddDTO);
|
||||
|
||||
Boolean edit(RoleEditDTO roleEditDTO);
|
||||
|
||||
List<Long> getRoleMenu(long loginIdAsLong, Integer id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -67,6 +67,15 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> imp
|
|||
return page(new Page<>(pageDTO.page(), pageDTO.size()), queryWrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Long> getRoleMenu(long userId, Integer id) {
|
||||
SysRole role = queryChain().eq(SysRole::getId, id).eq(SysRole::getCreateUserId, userId).one();
|
||||
if (role == null) {
|
||||
throw new ApiNotPrintException("角色不存在");
|
||||
}
|
||||
return sysRolesMenusService.queryChain().eq(SysRolesMenus::getRoleId, id).list().stream().map(SysRolesMenus::getMenuId).toList();
|
||||
}
|
||||
|
||||
public boolean addMenu(Long roleId, List<Long> menuIds) {
|
||||
long count = sysMenuService.queryChain().in(SysMenu::getMenuId, menuIds).count();
|
||||
if (count != menuIds.size()) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue