推送
This commit is contained in:
		| @ -4,6 +4,7 @@ import cn.dev33.satoken.stp.SaTokenInfo; | ||||
| import cn.dev33.satoken.stp.StpUtil; | ||||
| import cn.hutool.crypto.digest.BCrypt; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; | ||||
| import com.baomidou.mybatisplus.core.toolkit.StringUtils; | ||||
| import com.baomidou.mybatisplus.extension.plugins.pagination.Page; | ||||
| import com.yj.earth.annotation.CheckAuth; | ||||
| import com.yj.earth.annotation.EncryptResponse; | ||||
| @ -13,10 +14,7 @@ import com.yj.earth.business.domain.Role; | ||||
| import com.yj.earth.business.domain.User; | ||||
| import com.yj.earth.business.service.RoleService; | ||||
| import com.yj.earth.dto.relation.UserBindOrUnBindRoleDto; | ||||
| import com.yj.earth.dto.user.AddUserDto; | ||||
| import com.yj.earth.dto.user.UpdatePasswordDto; | ||||
| import com.yj.earth.dto.user.UpdateUserDto; | ||||
| import com.yj.earth.dto.user.UserLoginDto; | ||||
| import com.yj.earth.dto.user.*; | ||||
| import com.yj.earth.business.service.UserService; | ||||
| import com.yj.earth.common.util.ApiResponse; | ||||
| import io.swagger.v3.oas.annotations.Operation; | ||||
| @ -38,7 +36,6 @@ public class UserController { | ||||
|     @Resource | ||||
|     private RoleService roleService; | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "新增用户") | ||||
|     @PostMapping("/add") | ||||
|     @RoleAccess(roleNames = "管理员") | ||||
| @ -58,16 +55,6 @@ public class UserController { | ||||
|         return ApiResponse.success(null); | ||||
|     } | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "删除用户") | ||||
|     @PostMapping("/delete") | ||||
|     @RoleAccess(roleNames = "管理员") | ||||
|     public ApiResponse delete(@Parameter(description = "用户ID") String id) { | ||||
|         userService.removeById(id); | ||||
|         return ApiResponse.success(null); | ||||
|     } | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "更新信息") | ||||
|     @PostMapping("/update") | ||||
|     public ApiResponse update(@RequestBody UpdateUserDto updateUserDto) { | ||||
| @ -77,7 +64,6 @@ public class UserController { | ||||
|         return ApiResponse.success(null); | ||||
|     } | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "更新密码") | ||||
|     @PostMapping("/updatePassword") | ||||
|     public ApiResponse updatePassword(@RequestBody UpdatePasswordDto updatePasswordDto) { | ||||
| @ -93,19 +79,29 @@ public class UserController { | ||||
|         return ApiResponse.success(null); | ||||
|     } | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "用户详情") | ||||
|     @GetMapping("/getById") | ||||
|     public ApiResponse get(@Parameter(description = "用户ID") String id) { | ||||
|         return ApiResponse.success(userService.getById(id)); | ||||
|     } | ||||
|  | ||||
|     @CheckAuth | ||||
|     @Operation(summary = "用户列表") | ||||
|     @GetMapping("/list") | ||||
|     @RoleAccess(roleNames = "管理员") | ||||
|     public ApiResponse list(@Parameter(description = "分页数量") Integer pageNum, @Parameter(description = "分页大小") Integer pageSize) { | ||||
|         Page<User> userPage = userService.page(new Page<>(pageNum, pageSize)); | ||||
|     public ApiResponse list(@Parameter(description = "分页数量") Integer pageNum, | ||||
|                             @Parameter(description = "分页大小") Integer pageSize, | ||||
|                             @Parameter(description = "搜索字段") String searchKey, | ||||
|                             @Parameter(description = "角色ID") String roleId) { | ||||
|         LambdaQueryWrapper<User> wrapper = new LambdaQueryWrapper<>(); | ||||
|         // 根据用户名或者昵称进行模糊搜索 | ||||
|         if (StringUtils.isNotBlank(searchKey)) { | ||||
|             wrapper.like(User::getUsername, searchKey).or().like(User::getNickname, searchKey); | ||||
|         } | ||||
|         // 根据角色ID等值搜索 | ||||
|         if (StringUtils.isNotBlank(roleId)) { | ||||
|             wrapper.eq(User::getRoleId, roleId); | ||||
|         } | ||||
|         Page<User> userPage = userService.page(new Page<>(pageNum, pageSize), wrapper); | ||||
|         return ApiResponse.success(userPage); | ||||
|     } | ||||
|  | ||||
| @ -144,4 +140,22 @@ public class UserController { | ||||
|     public ApiResponse getCurrentUserInfo() { | ||||
|         return ApiResponse.success(userService.getById(StpUtil.getLoginIdAsString())); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "启用禁用用户数统计") | ||||
|     @GetMapping("/getUserStatusCount") | ||||
|     public ApiResponse getUserStatusCount() { | ||||
|         // 查询状态为1的用户数 | ||||
|         long useUserCount = userService.count(new LambdaQueryWrapper<User>().eq(User::getStatus, 1)); | ||||
|         // 查询状态为0的用户数 | ||||
|         long bindUserCount = userService.count(new LambdaQueryWrapper<User>().eq(User::getStatus, 0)); | ||||
|         return ApiResponse.success(Map.of("useUserCount", useUserCount, "bindUserCount", bindUserCount)); | ||||
|     } | ||||
|  | ||||
|     @Operation(summary = "删除用户") | ||||
|     @PostMapping("/deletes") | ||||
|     @RoleAccess(roleNames = "管理员") | ||||
|     public ApiResponse deletes(@RequestBody List<String> ids) { | ||||
|         userService.removeByIds(ids); | ||||
|         return ApiResponse.success(null); | ||||
|     } | ||||
| } | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 ZZX9599
					ZZX9599