mirror of
https://gitee.com/republicline/rax-remote-v2.git
synced 2025-08-24 06:14:56 +08:00
用户导入,修改,密码
This commit is contained in:
parent
9355c44b13
commit
8f6775ebe6
|
@ -129,7 +129,8 @@ public class SysUserController {
|
|||
@PutMapping
|
||||
@PreAuthorize("@pms.hasPermission('sys_user_edit')")
|
||||
public R updateUser(@Valid @RequestBody UserDTO userDto) {
|
||||
return R.ok(userService.updateUser(userDto));
|
||||
Boolean b = userService.updateUser(userDto);
|
||||
return R.ok(b);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -138,8 +139,8 @@ public class SysUserController {
|
|||
* @param userDTO 查询参数列表
|
||||
* @return 用户集合
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
public R getUserPage(@ParameterObject Page page, @ParameterObject UserDTO userDTO) {
|
||||
@PostMapping("/page")
|
||||
public R getUserPage(Page page, UserDTO userDTO) {
|
||||
return R.ok(userService.getUsersWithRolePage(page, userDTO));
|
||||
}
|
||||
|
||||
|
@ -189,6 +190,7 @@ public class SysUserController {
|
|||
return userService.lockUser(username);
|
||||
}
|
||||
|
||||
@SysLog("个人修改密码")
|
||||
@PutMapping("/password")
|
||||
public R password(@RequestBody UserDTO userDto) {
|
||||
String username = SecurityUtils.getUser().getUsername();
|
||||
|
@ -201,4 +203,10 @@ public class SysUserController {
|
|||
return userService.checkPassword(password);
|
||||
}
|
||||
|
||||
@SysLog("管理员修改密码")
|
||||
@PostMapping("/modifyPw")
|
||||
public R modifyPw(UserDTO userDto) {
|
||||
return userService.modifyPw(userDto);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -112,4 +112,11 @@ public interface SysUserService extends IService<SysUser> {
|
|||
*/
|
||||
R checkPassword(String password);
|
||||
|
||||
/**
|
||||
* 管理员修改密码
|
||||
* @param userDto
|
||||
* @return
|
||||
*/
|
||||
R modifyPw(UserDTO userDto);
|
||||
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.springframework.validation.BindingResult;
|
|||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
|
@ -69,6 +70,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
private final RedisTemplate redisTemplate;
|
||||
|
||||
private final static String PASSWD_PATTERN = "^(?=.*\\d)(?=.*[a-zA-Z])(?=.*[^\\da-zA-Z\\s]).{9,15}$";
|
||||
|
||||
/**
|
||||
* 保存用户信息
|
||||
*
|
||||
|
@ -202,6 +205,9 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
sysUser.setNickname(userDto.getNickname());
|
||||
sysUser.setName(userDto.getName());
|
||||
sysUser.setEmail(userDto.getEmail());
|
||||
if (StringUtils.hasText(userDto.getLockFlag())) {
|
||||
sysUser.setLockFlag(userDto.getLockFlag());
|
||||
}
|
||||
return R.ok(this.updateById(sysUser));
|
||||
}
|
||||
|
||||
|
@ -218,23 +224,27 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
}
|
||||
this.updateById(sysUser);
|
||||
|
||||
// 更新用户角色表
|
||||
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
||||
userDto.getRole().stream().map(roleId -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(sysUser.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
return userRole;
|
||||
}).forEach(SysUserRole::insert);
|
||||
if (userDto.getRole() != null) {
|
||||
// 更新用户角色表
|
||||
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
||||
userDto.getRole().stream().map(roleId -> {
|
||||
SysUserRole userRole = new SysUserRole();
|
||||
userRole.setUserId(sysUser.getUserId());
|
||||
userRole.setRoleId(roleId);
|
||||
return userRole;
|
||||
}).forEach(SysUserRole::insert);
|
||||
}
|
||||
|
||||
// 更新用户岗位表
|
||||
sysUserPostMapper.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||
userDto.getPost().stream().map(postId -> {
|
||||
SysUserPost userPost = new SysUserPost();
|
||||
userPost.setUserId(sysUser.getUserId());
|
||||
userPost.setPostId(postId);
|
||||
return userPost;
|
||||
}).forEach(SysUserPost::insert);
|
||||
if (userDto.getPost() != null) {
|
||||
// 更新用户岗位表
|
||||
sysUserPostMapper.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||
userDto.getPost().stream().map(postId -> {
|
||||
SysUserPost userPost = new SysUserPost();
|
||||
userPost.setUserId(sysUser.getUserId());
|
||||
userPost.setPostId(postId);
|
||||
return userPost;
|
||||
}).forEach(SysUserPost::insert);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
|
||||
|
@ -457,4 +467,26 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public R modifyPw(UserDTO userDto) {
|
||||
UserVO userVO = baseMapper.getUserVoByUsername(userDto.getUsername());
|
||||
if (Objects.isNull(userVO)) {
|
||||
return R.failed("用户不存在");
|
||||
}
|
||||
if (!StringUtils.hasText(userDto.getPassword())) {
|
||||
return R.failed("密码不能为空");
|
||||
}
|
||||
|
||||
boolean matches = Pattern.matches(PASSWD_PATTERN, userDto.getPassword());
|
||||
if (!matches) {
|
||||
return R.failed("密码至少包含字母、数字、特殊字符,不少于9位,最多15位");
|
||||
}
|
||||
|
||||
String password = ENCODER.encode(userDto.getPassword());
|
||||
this.update(Wrappers.<SysUser>lambdaUpdate()
|
||||
.set(SysUser::getPassword, password)
|
||||
.eq(SysUser::getUserId, userVO.getUserId()));
|
||||
|
||||
return R.ok();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
server:
|
||||
port: 8888
|
||||
port: 9999
|
||||
servlet:
|
||||
context-path: /admin
|
||||
|
||||
|
|
Binary file not shown.
|
@ -117,6 +117,10 @@
|
|||
LEFT JOIN sys_dept d ON d.dept_id = u.dept_id
|
||||
<where>
|
||||
u.del_flag = '0'
|
||||
<if test="query.name != null and query.name != ''">
|
||||
<bind name="nameLike" value="'%' + query.name + '%'"/>
|
||||
AND u.name LIKE #{nameLike}
|
||||
</if>
|
||||
<if test="query.username != null and query.username != ''">
|
||||
<bind name="usernameLike" value="'%'+query.username+'%'"/>
|
||||
AND u.username LIKE #{usernameLike}
|
||||
|
|
Loading…
Reference in New Issue
Block a user