feat(修改): 查询所有角色

This commit is contained in:
bunny 2024-03-24 00:03:32 +08:00
parent dba4410eba
commit 825f9893f4
7 changed files with 55 additions and 6 deletions

View File

@ -0,0 +1,26 @@
package com.atguigu.spzx.manger.controller;
import com.atguigu.spzx.model.entity.system.SysMenu;
import com.atguigu.spzx.model.vo.result.Result;
import com.atguigu.spzx.model.vo.result.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(value = "/admin/system/sysMenu")
public class SysMenuController {
@Autowired
private SysMenuService sysMenuService;
@GetMapping("/findNodes")
public Result<List<SysMenu>> findNodes() {
List<SysMenu> list = sysMenuService.findNodes();
return Result.build(list, ResultCodeEnum.SUCCESS);
}
}

View File

@ -49,9 +49,9 @@ public class SysRoleController {
} }
@Operation(summary = "查询所有角色", description = "查询所有角色信息") @Operation(summary = "查询所有角色", description = "查询所有角色信息")
@GetMapping(value = "findAllRoles") @GetMapping(value = "findAllRoles/{userId}")
public Result<AllRolesVo> findAllRoles() { public Result<AllRolesVo> findAllRoles(@PathVariable(value = "userId") Long userId) {
AllRolesVo allRolesList = sysRoleService.findAllRoles(); AllRolesVo allRolesList = sysRoleService.findAllRoles(userId);
return Result.success(allRolesList); return Result.success(allRolesList);
} }

View File

@ -2,6 +2,8 @@ package com.atguigu.spzx.manger.mapper;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper @Mapper
public interface SysRoleUserMapper { public interface SysRoleUserMapper {
/** /**
@ -18,4 +20,11 @@ public interface SysRoleUserMapper {
* @param roleId 角色id * @param roleId 角色id
*/ */
void doAssign(Long userId, Long roleId); void doAssign(Long userId, Long roleId);
/**
* 根据用户id查询内容
*
* @param userId 用户id
*/
List<Long> findSysUserRoleByUserId(Long userId);
} }

View File

@ -43,7 +43,7 @@ public interface SysRoleService {
* *
* @return 所有角色信息 * @return 所有角色信息
*/ */
AllRolesVo findAllRoles(); AllRolesVo findAllRoles(Long userId);
/** /**
* 保存角色数据 * 保存角色数据

View File

@ -84,9 +84,13 @@ public class SysRoleServiceImpl implements SysRoleService {
* @return 所有角色信息 * @return 所有角色信息
*/ */
@Override @Override
public AllRolesVo findAllRoles() { public AllRolesVo findAllRoles(Long userId) {
// 查询所有的角色数据
List<SysRole> sysRoleList = sysRoleMapper.findAllRoles(); List<SysRole> sysRoleList = sysRoleMapper.findAllRoles();
return AllRolesVo.builder().allRolesList(sysRoleList).build();
// 查询当前登录用户的角色数据
List<Long> sysRoles = sysRoleUserMapper.findSysUserRoleByUserId(userId);
return AllRolesVo.builder().allRolesList(sysRoleList).sysUserRoles(sysRoles).build();
} }
/** /**

View File

@ -14,4 +14,12 @@
from sys_user_role from sys_user_role
where user_id = #{userId} where user_id = #{userId}
</delete> </delete>
<!-- 根据用户id查询内容 -->
<select id="findSysUserRoleByUserId" resultType="java.lang.Long">
select role_id
from sys_user_role sur
where sur.user_id = #{userId}
and is_deleted = 0
</select>
</mapper> </mapper>

View File

@ -17,4 +17,6 @@ import java.util.List;
public class AllRolesVo { public class AllRolesVo {
@Schema(description = "所有角色") @Schema(description = "所有角色")
private List<SysRole> allRolesList; private List<SysRole> allRolesList;
@Schema(description = "所有用户的角色")
private List<Long> sysUserRoles;
} }