feat: 新增updateRole接口
This commit is contained in:
parent
e257e53d69
commit
ee21f94ba7
@ -60,6 +60,7 @@ public class SecurityConfig {
|
|||||||
.authorizeHttpRequests(auth -> auth
|
.authorizeHttpRequests(auth -> auth
|
||||||
.requestMatchers("/auth/**").permitAll()
|
.requestMatchers("/auth/**").permitAll()
|
||||||
.requestMatchers("/auth/register").permitAll()
|
.requestMatchers("/auth/register").permitAll()
|
||||||
|
// .requestMatchers("/user/**").permitAll()
|
||||||
.anyRequest().access((authenticationSupplier, requestAuthorizationContext) -> {
|
.anyRequest().access((authenticationSupplier, requestAuthorizationContext) -> {
|
||||||
HttpServletRequest request = requestAuthorizationContext.getRequest();
|
HttpServletRequest request = requestAuthorizationContext.getRequest();
|
||||||
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package asia.yulinling.workflow.controller;
|
package asia.yulinling.workflow.controller;
|
||||||
|
|
||||||
import asia.yulinling.workflow.dto.request.PageParam;
|
import asia.yulinling.workflow.dto.request.PageParam;
|
||||||
|
import asia.yulinling.workflow.dto.request.RoleUserRequest;
|
||||||
import asia.yulinling.workflow.dto.request.UpdateUserRequest;
|
import asia.yulinling.workflow.dto.request.UpdateUserRequest;
|
||||||
import asia.yulinling.workflow.dto.response.PageResult;
|
import asia.yulinling.workflow.dto.response.PageResult;
|
||||||
import asia.yulinling.workflow.model.ApiResponse;
|
import asia.yulinling.workflow.model.ApiResponse;
|
||||||
@ -34,4 +35,9 @@ public class UserController {
|
|||||||
public ApiResponse<PageResult<UserVO>> usersPage(PageParam pageParam) {
|
public ApiResponse<PageResult<UserVO>> usersPage(PageParam pageParam) {
|
||||||
return userService.getUserListByPage(pageParam);
|
return userService.getUserListByPage(pageParam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/updateRole")
|
||||||
|
public ApiResponse<?> updateUserRole(@RequestBody RoleUserRequest roleUserRequest) {
|
||||||
|
return userService.updateUserRole(roleUserRequest.getRoleId(), roleUserRequest.getUserId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,24 @@
|
|||||||
|
package asia.yulinling.workflow.dto.request;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
* 角色用户请求类
|
||||||
|
* </p>
|
||||||
|
*
|
||||||
|
* @author YLL
|
||||||
|
* @since 2025/6/25
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class RoleUserRequest {
|
||||||
|
/**
|
||||||
|
* 角色Id
|
||||||
|
*/
|
||||||
|
private Long roleId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用户Id
|
||||||
|
*/
|
||||||
|
private Long userId;
|
||||||
|
}
|
||||||
@ -76,7 +76,7 @@ public class ApiResponse<T> {
|
|||||||
* @param message 返回内容
|
* @param message 返回内容
|
||||||
* @return ApiResponse
|
* @return ApiResponse
|
||||||
*/
|
*/
|
||||||
public static ApiResponse<Void> ofMessage(String message) {
|
public static ApiResponse<Void> ofSuccessMessage(String message) {
|
||||||
return of(Status.SUCCESS.getCode(), message, null);
|
return of(Status.SUCCESS.getCode(), message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -39,5 +39,5 @@ public interface UserService {
|
|||||||
*
|
*
|
||||||
* @return 请求结果
|
* @return 请求结果
|
||||||
*/
|
*/
|
||||||
ApiResponse<?> updateUserRole();
|
ApiResponse<?> updateUserRole(Long roleId, Long userId);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,15 +1,21 @@
|
|||||||
package asia.yulinling.workflow.service.impl;
|
package asia.yulinling.workflow.service.impl;
|
||||||
|
|
||||||
|
import asia.yulinling.workflow.constant.Status;
|
||||||
import asia.yulinling.workflow.dto.request.PageParam;
|
import asia.yulinling.workflow.dto.request.PageParam;
|
||||||
import asia.yulinling.workflow.dto.request.UpdateUserRequest;
|
import asia.yulinling.workflow.dto.request.UpdateUserRequest;
|
||||||
import asia.yulinling.workflow.dto.response.PageResult;
|
import asia.yulinling.workflow.dto.response.PageResult;
|
||||||
|
import asia.yulinling.workflow.mapper.RoleMapper;
|
||||||
|
import asia.yulinling.workflow.mapper.RoleUserMapper;
|
||||||
import asia.yulinling.workflow.mapper.UserMapper;
|
import asia.yulinling.workflow.mapper.UserMapper;
|
||||||
import asia.yulinling.workflow.model.ApiResponse;
|
import asia.yulinling.workflow.model.ApiResponse;
|
||||||
|
import asia.yulinling.workflow.model.entity.Role;
|
||||||
|
import asia.yulinling.workflow.model.entity.RoleUser;
|
||||||
import asia.yulinling.workflow.model.entity.User;
|
import asia.yulinling.workflow.model.entity.User;
|
||||||
import asia.yulinling.workflow.model.vo.user.UserVO;
|
import asia.yulinling.workflow.model.vo.user.UserVO;
|
||||||
import asia.yulinling.workflow.scope.RequestScopeData;
|
import asia.yulinling.workflow.scope.RequestScopeData;
|
||||||
import asia.yulinling.workflow.service.UserService;
|
import asia.yulinling.workflow.service.UserService;
|
||||||
import asia.yulinling.workflow.utils.PageUtil;
|
import asia.yulinling.workflow.utils.PageUtil;
|
||||||
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -38,6 +44,8 @@ public class UserServiceImpl implements UserService {
|
|||||||
/** 注入用户Mapper */
|
/** 注入用户Mapper */
|
||||||
private final UserMapper userMapper;
|
private final UserMapper userMapper;
|
||||||
private final RequestScopeData scopeData;
|
private final RequestScopeData scopeData;
|
||||||
|
private final RoleUserMapper roleUserMapper;
|
||||||
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取用户列表分页
|
* 获取用户列表分页
|
||||||
@ -87,7 +95,7 @@ public class UserServiceImpl implements UserService {
|
|||||||
|
|
||||||
if (!requestUserId.equals(userId)) {
|
if (!requestUserId.equals(userId)) {
|
||||||
log.error("user id not match, scopeData: {}, requestUserId: {}", requestUserId, userId);
|
log.error("user id not match, scopeData: {}, requestUserId: {}", requestUserId, userId);
|
||||||
throw new RuntimeException("用户Id不匹配");
|
return ApiResponse.ofStatus(Status.BAD_REQUEST, "用户Id不匹配");
|
||||||
}
|
}
|
||||||
|
|
||||||
User user = new User();
|
User user = new User();
|
||||||
@ -110,7 +118,30 @@ public class UserServiceImpl implements UserService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ApiResponse<?> updateUserRole() {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
return null;
|
public ApiResponse<?> updateUserRole(Long roleId, Long userId) {
|
||||||
|
|
||||||
|
LambdaQueryWrapper<Role> roleUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
||||||
|
roleUserLambdaQueryWrapper.eq(Role::getId, roleId);
|
||||||
|
if (!roleMapper.exists(roleUserLambdaQueryWrapper)) {
|
||||||
|
return ApiResponse.ofStatus(Status.PARAM_NOT_MATCH, "角色不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
LambdaQueryWrapper<RoleUser> roleUserLambdaQueryWrapper2 = new LambdaQueryWrapper<>();
|
||||||
|
roleUserLambdaQueryWrapper2.eq(RoleUser::getUserId, userId);
|
||||||
|
if (!roleUserMapper.exists(roleUserLambdaQueryWrapper2)) {
|
||||||
|
return ApiResponse.ofStatus(Status.PARAM_NOT_MATCH, "用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
LambdaUpdateWrapper<RoleUser> roleUserLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
||||||
|
roleUserLambdaUpdateWrapper.eq(RoleUser::getUserId, userId);
|
||||||
|
roleUserLambdaUpdateWrapper.set(RoleUser::getRoleId, roleId);
|
||||||
|
roleUserMapper.update(null, roleUserLambdaUpdateWrapper);
|
||||||
|
return ApiResponse.ofSuccess("更新成功");
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("update user role error:{}", e.getMessage());
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user