mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-10-26 20:57:11 +08:00
新增:新增系统管理/用户管理重置密码、分配角色功能
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright (c) 2022-present Charles7c Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotEmpty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
|
||||
/**
|
||||
* 修改用户角色信息
|
||||
*
|
||||
* @author Charles7c
|
||||
* @since 2023/2/24 23:05
|
||||
*/
|
||||
@Data
|
||||
@Schema(description = "修改用户角色信息")
|
||||
public class UpdateUserRoleRequest implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@Schema(description = "所属角色")
|
||||
@NotEmpty(message = "所属角色不能为空")
|
||||
private List<Long> roleIds;
|
||||
}
|
||||
@@ -18,10 +18,7 @@ package top.charles7c.cnadmin.system.model.request;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Null;
|
||||
import javax.validation.constraints.Pattern;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -106,12 +103,14 @@ public class UserRequest extends BaseRequest {
|
||||
/**
|
||||
* 部门 ID
|
||||
*/
|
||||
@Schema(description = "部门 ID")
|
||||
@Schema(description = "所属部门")
|
||||
@NotNull(message = "所属部门不能为空")
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 角色 ID 列表
|
||||
*/
|
||||
@Schema(description = "角色 ID 列表")
|
||||
@Schema(description = "所属角色")
|
||||
@NotEmpty(message = "所属角色不能为空")
|
||||
private List<Long> roleIds;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
import top.charles7c.cnadmin.common.base.BaseService;
|
||||
import top.charles7c.cnadmin.system.model.entity.UserDO;
|
||||
import top.charles7c.cnadmin.system.model.query.UserQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.UpdateUserRoleRequest;
|
||||
import top.charles7c.cnadmin.system.model.request.UserRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.UserDetailVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.UserVO;
|
||||
@@ -79,6 +80,24 @@ public interface UserService extends BaseService<UserVO, UserDetailVO, UserQuery
|
||||
*/
|
||||
void updateEmail(String newEmail, String currentPassword, Long userId);
|
||||
|
||||
/**
|
||||
* 重置密码
|
||||
*
|
||||
* @param userId
|
||||
* 用户 ID
|
||||
*/
|
||||
void resetPassword(Long userId);
|
||||
|
||||
/**
|
||||
* 修改角色
|
||||
*
|
||||
* @param request
|
||||
* 修改信息
|
||||
* @param userId
|
||||
* 用户 ID
|
||||
*/
|
||||
void updateUserRole(UpdateUserRoleRequest request, Long userId);
|
||||
|
||||
/**
|
||||
* 根据部门 ID 列表查询
|
||||
*
|
||||
|
||||
@@ -47,6 +47,7 @@ import top.charles7c.cnadmin.common.util.validate.CheckUtils;
|
||||
import top.charles7c.cnadmin.system.mapper.UserMapper;
|
||||
import top.charles7c.cnadmin.system.model.entity.UserDO;
|
||||
import top.charles7c.cnadmin.system.model.query.UserQuery;
|
||||
import top.charles7c.cnadmin.system.model.request.UpdateUserRoleRequest;
|
||||
import top.charles7c.cnadmin.system.model.request.UserRequest;
|
||||
import top.charles7c.cnadmin.system.model.vo.UserDetailVO;
|
||||
import top.charles7c.cnadmin.system.model.vo.UserVO;
|
||||
@@ -173,7 +174,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updatePassword(String oldPassword, String newPassword, Long userId) {
|
||||
CheckUtils.throwIfEqual(newPassword, oldPassword, "新密码不能与当前密码相同");
|
||||
UserDO userDO = this.getById(userId);
|
||||
UserDO userDO = super.getById(userId);
|
||||
CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(oldPassword, userId.toString()), userDO.getPassword(), "当前密码错误");
|
||||
|
||||
// 更新密码和密码重置时间
|
||||
@@ -190,7 +191,7 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateEmail(String newEmail, String currentPassword, Long userId) {
|
||||
UserDO userDO = this.getById(userId);
|
||||
UserDO userDO = super.getById(userId);
|
||||
CheckUtils.throwIfNotEqual(SecureUtils.md5Salt(currentPassword, userId.toString()), userDO.getPassword(),
|
||||
"当前密码错误");
|
||||
Long count = super.lambdaQuery().eq(UserDO::getEmail, newEmail).count();
|
||||
@@ -206,6 +207,21 @@ public class UserServiceImpl extends BaseServiceImpl<UserMapper, UserDO, UserVO,
|
||||
LoginHelper.updateLoginUser(loginUser);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetPassword(Long userId) {
|
||||
UserDO userDO = super.getById(userId);
|
||||
userDO.setPassword(SecureUtils.md5Salt(Constants.DEFAULT_PASSWORD, userId.toString()));
|
||||
userDO.setPwdResetTime(LocalDateTime.now());
|
||||
baseMapper.updateById(userDO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserRole(UpdateUserRoleRequest request, Long userId) {
|
||||
super.getById(userId);
|
||||
// 保存用户和角色关联
|
||||
userRoleService.save(request.getRoleIds(), userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByDeptIds(List<Long> deptIds) {
|
||||
return super.lambdaQuery().in(UserDO::getDeptId, deptIds).count();
|
||||
|
||||
Reference in New Issue
Block a user