mirror of
https://github.com/suyiiyii/SIMS.git
synced 2025-06-03 12:56:10 +08:00
管理员查看用户信息
This commit is contained in:
parent
1ed92e6bdf
commit
0820b9b651
24
src/main/java/top/suyiiyii/sims/VO/UserVO.java
Normal file
24
src/main/java/top/suyiiyii/sims/VO/UserVO.java
Normal file
@ -0,0 +1,24 @@
|
||||
package top.suyiiyii.sims.VO;
|
||||
|
||||
import lombok.Data;
|
||||
import top.suyiiyii.sims.entity.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/15 16:04
|
||||
* @PackageName:top.suyiiyii.sims.VO
|
||||
* @ClassName: UserVO
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class UserVO {
|
||||
private Integer userId;
|
||||
private String username;
|
||||
private String grade;
|
||||
private String group;
|
||||
private List<String> roles; // 角色名称列表
|
||||
|
||||
}
|
@ -4,7 +4,9 @@ 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 top.suyiiyii.sims.VO.UserVO;
|
||||
import top.suyiiyii.sims.common.Result;
|
||||
import top.suyiiyii.sims.dto.UserDTO;
|
||||
import top.suyiiyii.sims.entity.User;
|
||||
import top.suyiiyii.sims.service.RoleService;
|
||||
import top.suyiiyii.sims.service.UserService;
|
||||
@ -37,5 +39,16 @@ public class AdminController {
|
||||
List<User> users = userService.selectAll();
|
||||
return Result.success(users);
|
||||
}
|
||||
|
||||
/**
|
||||
* @author: tortoise
|
||||
* @date: 2024/8/15 16:27
|
||||
* @Description: TODO 查看所有成员的信息(姓名,学号,年级,组别,担任角色)
|
||||
* @param
|
||||
* @return: top.suyiiyii.sims.common.Result
|
||||
*/
|
||||
@GetMapping("/findAllUsers")
|
||||
public Result findAllUsers() {
|
||||
List<UserVO> userList = userService.findAllUsers();
|
||||
return Result.success(userList);
|
||||
}
|
||||
}
|
||||
|
21
src/main/java/top/suyiiyii/sims/dto/UserDTO.java
Normal file
21
src/main/java/top/suyiiyii/sims/dto/UserDTO.java
Normal file
@ -0,0 +1,21 @@
|
||||
package top.suyiiyii.sims.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author tortoise
|
||||
* @Date 2024/8/15 15:36
|
||||
* @PackageName:top.suyiiyii.sims.dto
|
||||
* @ClassName: UserDTO
|
||||
* @Description: TODO
|
||||
* @Version 1.0
|
||||
*/
|
||||
@Data
|
||||
public class UserDTO {
|
||||
private Long userId;
|
||||
private String username;
|
||||
private List<String> roles; // 角色名称列表
|
||||
private List<String> permissions; // 权限列表
|
||||
}
|
@ -30,6 +30,7 @@ public class User {
|
||||
private String password;
|
||||
private String name;
|
||||
private String email;
|
||||
private String grade;
|
||||
private String group;
|
||||
@TableField(exist = false)
|
||||
private String token;
|
||||
|
@ -53,5 +53,6 @@ public interface RoleMapper {
|
||||
"(SELECT role_id FROM user_role WHERE user_id = #{user_id})")
|
||||
List<UserRole> selectRolesById(@Param("user_id") int id);
|
||||
|
||||
|
||||
@Select("SELECT role_name FROM role WHERE role_id=#{roleId}")
|
||||
List<String> selectRoleNamesByRoleId(Integer roleId);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ public interface UserMapper extends BaseMapper<User> {
|
||||
* 查询所有用户信息
|
||||
* @return 用户列表
|
||||
*/
|
||||
@Select("SELECT id, user_id, username, password, name, email, `group` FROM user")
|
||||
@Select("SELECT id, user_id, username, password, name, email,grade, `group` FROM user")
|
||||
List<User> selectAll();
|
||||
|
||||
@Select("select * from user where username = #{username}")
|
||||
|
@ -5,7 +5,9 @@ package top.suyiiyii.sims.service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import top.suyiiyii.sims.VO.UserVO;
|
||||
import top.suyiiyii.sims.common.Result;
|
||||
import top.suyiiyii.sims.dto.UserDTO;
|
||||
import top.suyiiyii.sims.entity.*;
|
||||
import top.suyiiyii.sims.exception.ServiceException;
|
||||
import top.suyiiyii.sims.mapper.PermissionsMapper;
|
||||
@ -109,13 +111,35 @@ public class UserService {
|
||||
userMapper.addUser(user);
|
||||
return user;
|
||||
}
|
||||
|
||||
public User selectByUsername(String username) {
|
||||
return userMapper.selectByUserName(username);
|
||||
}
|
||||
|
||||
public void updatePassword(User user) {
|
||||
userMapper.updatePassword(user);
|
||||
}
|
||||
public List<UserVO> findAllUsers(){
|
||||
List<User> users = userMapper.selectAll();
|
||||
List<UserVO> userVOS = new ArrayList<>();
|
||||
|
||||
for (User user : users) {
|
||||
UserVO userVO = new UserVO();
|
||||
userVO.setUserId(user.getId());
|
||||
userVO.setUsername(user.getUsername());
|
||||
userVO.setGrade(user.getGrade());
|
||||
userVO.setGroup(user.getGroup());
|
||||
userVO.setRoles(new ArrayList<>());
|
||||
Integer id = user.getId();
|
||||
List<UserRole> userRoles = roleMapper.selectRolesById(id);
|
||||
for (UserRole userRole : userRoles) {
|
||||
Integer roleId = userRole.getRoleId();
|
||||
// 获取一个角色的名称列表
|
||||
List<String> roleNameList = roleMapper.selectRoleNamesByRoleId(roleId);
|
||||
// 累加角色名称到用户的角色列表中
|
||||
userVO.getRoles().addAll(roleNameList);
|
||||
}
|
||||
userVOS.add(userVO);
|
||||
}
|
||||
return userVOS;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user