mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-22 12:48:58 +08:00
fix(锁定): 用户管理
bug: 用户管理列表页切换状态不生效 Closes IAJID5
This commit is contained in:
parent
6affe64e92
commit
779a0ccd39
@ -68,382 +68,394 @@ import java.util.stream.Collectors;
|
|||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> implements SysUserService {
|
||||||
|
|
||||||
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
private static final PasswordEncoder ENCODER = new BCryptPasswordEncoder();
|
||||||
|
|
||||||
private final SysMenuService sysMenuService;
|
private final SysMenuService sysMenuService;
|
||||||
|
|
||||||
private final SysRoleService sysRoleService;
|
private final SysRoleService sysRoleService;
|
||||||
|
|
||||||
private final SysPostService sysPostService;
|
private final SysPostService sysPostService;
|
||||||
|
|
||||||
private final SysDeptService sysDeptService;
|
private final SysDeptService sysDeptService;
|
||||||
|
|
||||||
private final SysUserRoleMapper sysUserRoleMapper;
|
private final SysUserRoleMapper sysUserRoleMapper;
|
||||||
|
|
||||||
private final SysUserPostMapper sysUserPostMapper;
|
private final SysUserPostMapper sysUserPostMapper;
|
||||||
|
|
||||||
private final CacheManager cacheManager;
|
private final CacheManager cacheManager;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 保存用户信息
|
* 保存用户信息
|
||||||
* @param userDto DTO 对象
|
*
|
||||||
* @return success/fail
|
* @param userDto DTO 对象
|
||||||
*/
|
* @return success/fail
|
||||||
@Override
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Override
|
||||||
public Boolean saveUser(UserDTO userDto) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
SysUser sysUser = new SysUser();
|
public Boolean saveUser(UserDTO userDto) {
|
||||||
BeanUtils.copyProperties(userDto, sysUser);
|
SysUser sysUser = new SysUser();
|
||||||
sysUser.setDelFlag(CommonConstants.STATUS_NORMAL);
|
BeanUtils.copyProperties(userDto, sysUser);
|
||||||
sysUser.setCreateBy(userDto.getUsername());
|
sysUser.setDelFlag(CommonConstants.STATUS_NORMAL);
|
||||||
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
sysUser.setCreateBy(userDto.getUsername());
|
||||||
baseMapper.insert(sysUser);
|
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
||||||
// 保存用户岗位信息
|
baseMapper.insert(sysUser);
|
||||||
Optional.ofNullable(userDto.getPost()).ifPresent(posts -> {
|
// 保存用户岗位信息
|
||||||
posts.stream().map(postId -> {
|
Optional.ofNullable(userDto.getPost()).ifPresent(posts -> {
|
||||||
SysUserPost userPost = new SysUserPost();
|
posts.stream().map(postId -> {
|
||||||
userPost.setUserId(sysUser.getUserId());
|
SysUserPost userPost = new SysUserPost();
|
||||||
userPost.setPostId(postId);
|
userPost.setUserId(sysUser.getUserId());
|
||||||
return userPost;
|
userPost.setPostId(postId);
|
||||||
}).forEach(sysUserPostMapper::insert);
|
return userPost;
|
||||||
});
|
}).forEach(sysUserPostMapper::insert);
|
||||||
|
});
|
||||||
|
|
||||||
// 如果角色为空,赋默认角色
|
// 如果角色为空,赋默认角色
|
||||||
if (CollUtil.isEmpty(userDto.getRole())) {
|
if (CollUtil.isEmpty(userDto.getRole())) {
|
||||||
// 获取默认角色编码
|
// 获取默认角色编码
|
||||||
String defaultRole = ParamResolver.getStr("USER_DEFAULT_ROLE");
|
String defaultRole = ParamResolver.getStr("USER_DEFAULT_ROLE");
|
||||||
// 默认角色
|
// 默认角色
|
||||||
SysRole sysRole = sysRoleService
|
SysRole sysRole = sysRoleService
|
||||||
.getOne(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getRoleCode, defaultRole));
|
.getOne(Wrappers.<SysRole>lambdaQuery().eq(SysRole::getRoleCode, defaultRole));
|
||||||
userDto.setRole(Collections.singletonList(sysRole.getRoleId()));
|
userDto.setRole(Collections.singletonList(sysRole.getRoleId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 插入用户角色关系表
|
// 插入用户角色关系表
|
||||||
userDto.getRole().stream().map(roleId -> {
|
userDto.getRole().stream().map(roleId -> {
|
||||||
SysUserRole userRole = new SysUserRole();
|
SysUserRole userRole = new SysUserRole();
|
||||||
userRole.setUserId(sysUser.getUserId());
|
userRole.setUserId(sysUser.getUserId());
|
||||||
userRole.setRoleId(roleId);
|
userRole.setRoleId(roleId);
|
||||||
return userRole;
|
return userRole;
|
||||||
}).forEach(sysUserRoleMapper::insert);
|
}).forEach(sysUserRoleMapper::insert);
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过查用户的全部信息
|
* 通过查用户的全部信息
|
||||||
* @param sysUser 用户
|
*
|
||||||
* @return
|
* @param sysUser 用户
|
||||||
*/
|
* @return
|
||||||
@Override
|
*/
|
||||||
public UserInfo findUserInfo(SysUser sysUser) {
|
@Override
|
||||||
UserInfo userInfo = new UserInfo();
|
public UserInfo findUserInfo(SysUser sysUser) {
|
||||||
userInfo.setSysUser(sysUser);
|
UserInfo userInfo = new UserInfo();
|
||||||
// 设置角色列表 (ID)
|
userInfo.setSysUser(sysUser);
|
||||||
List<Long> roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId())
|
// 设置角色列表 (ID)
|
||||||
.stream()
|
List<Long> roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId())
|
||||||
.map(SysRole::getRoleId)
|
.stream()
|
||||||
.collect(Collectors.toList());
|
.map(SysRole::getRoleId)
|
||||||
userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
.collect(Collectors.toList());
|
||||||
|
userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
||||||
|
|
||||||
// 设置权限列表(menu.permission)
|
// 设置权限列表(menu.permission)
|
||||||
Set<String> permissions = new HashSet<>();
|
Set<String> permissions = new HashSet<>();
|
||||||
roleIds.forEach(roleId -> {
|
roleIds.forEach(roleId -> {
|
||||||
List<String> permissionList = sysMenuService.findMenuByRoleId(roleId)
|
List<String> permissionList = sysMenuService.findMenuByRoleId(roleId)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(menu -> StrUtil.isNotEmpty(menu.getPermission()))
|
.filter(menu -> StrUtil.isNotEmpty(menu.getPermission()))
|
||||||
.map(SysMenu::getPermission)
|
.map(SysMenu::getPermission)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
permissions.addAll(permissionList);
|
permissions.addAll(permissionList);
|
||||||
});
|
});
|
||||||
userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class));
|
userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class));
|
||||||
return userInfo;
|
return userInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分页查询用户信息(含有角色信息)
|
* 分页查询用户信息(含有角色信息)
|
||||||
* @param page 分页对象
|
*
|
||||||
* @param userDTO 参数列表
|
* @param page 分页对象
|
||||||
* @return
|
* @param userDTO 参数列表
|
||||||
*/
|
* @return
|
||||||
@Override
|
*/
|
||||||
public IPage getUsersWithRolePage(Page page, UserDTO userDTO) {
|
@Override
|
||||||
return baseMapper.getUserVosPage(page, userDTO);
|
public IPage getUsersWithRolePage(Page page, UserDTO userDTO) {
|
||||||
}
|
return baseMapper.getUserVosPage(page, userDTO);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过ID查询用户信息
|
* 通过ID查询用户信息
|
||||||
* @param id 用户ID
|
*
|
||||||
* @return 用户信息
|
* @param id 用户ID
|
||||||
*/
|
* @return 用户信息
|
||||||
@Override
|
*/
|
||||||
public UserVO selectUserVoById(Long id) {
|
@Override
|
||||||
return baseMapper.getUserVoById(id);
|
public UserVO selectUserVoById(Long id) {
|
||||||
}
|
return baseMapper.getUserVoById(id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 删除用户
|
* 删除用户
|
||||||
* @param ids 用户ID 列表
|
*
|
||||||
* @return Boolean
|
* @param ids 用户ID 列表
|
||||||
*/
|
* @return Boolean
|
||||||
@Override
|
*/
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Override
|
||||||
public Boolean deleteUserByIds(Long[] ids) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
// 删除 spring cache
|
public Boolean deleteUserByIds(Long[] ids) {
|
||||||
List<SysUser> userList = baseMapper.selectBatchIds(CollUtil.toList(ids));
|
// 删除 spring cache
|
||||||
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
List<SysUser> userList = baseMapper.selectBatchIds(CollUtil.toList(ids));
|
||||||
for (SysUser sysUser : userList) {
|
Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS);
|
||||||
// 立即删除
|
for (SysUser sysUser : userList) {
|
||||||
cache.evictIfPresent(sysUser.getUsername());
|
// 立即删除
|
||||||
}
|
cache.evictIfPresent(sysUser.getUsername());
|
||||||
|
}
|
||||||
|
|
||||||
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids)));
|
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids)));
|
||||||
this.removeBatchByIds(CollUtil.toList(ids));
|
this.removeBatchByIds(CollUtil.toList(ids));
|
||||||
return Boolean.TRUE;
|
return Boolean.TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
||||||
public R<Boolean> updateUserInfo(UserDTO userDto) {
|
public R<Boolean> updateUserInfo(UserDTO userDto) {
|
||||||
SysUser sysUser = new SysUser();
|
SysUser sysUser = new SysUser();
|
||||||
sysUser.setPhone(userDto.getPhone());
|
sysUser.setPhone(userDto.getPhone());
|
||||||
sysUser.setUserId(SecurityUtils.getUser().getId());
|
sysUser.setUserId(SecurityUtils.getUser().getId());
|
||||||
sysUser.setAvatar(userDto.getAvatar());
|
sysUser.setAvatar(userDto.getAvatar());
|
||||||
sysUser.setNickname(userDto.getNickname());
|
sysUser.setNickname(userDto.getNickname());
|
||||||
sysUser.setName(userDto.getName());
|
sysUser.setName(userDto.getName());
|
||||||
sysUser.setEmail(userDto.getEmail());
|
sysUser.setEmail(userDto.getEmail());
|
||||||
return R.ok(this.updateById(sysUser));
|
return R.ok(this.updateById(sysUser));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
||||||
public Boolean updateUser(UserDTO userDto) {
|
public Boolean updateUser(UserDTO userDto) {
|
||||||
// 更新用户表信息
|
// 更新用户表信息
|
||||||
SysUser sysUser = new SysUser();
|
SysUser sysUser = new SysUser();
|
||||||
BeanUtils.copyProperties(userDto, sysUser);
|
BeanUtils.copyProperties(userDto, sysUser);
|
||||||
sysUser.setUpdateTime(LocalDateTime.now());
|
sysUser.setUpdateTime(LocalDateTime.now());
|
||||||
if (StrUtil.isNotBlank(userDto.getPassword())) {
|
if (StrUtil.isNotBlank(userDto.getPassword())) {
|
||||||
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
||||||
}
|
}
|
||||||
this.updateById(sysUser);
|
this.updateById(sysUser);
|
||||||
|
|
||||||
// 更新用户角色表
|
// 更新用户角色表
|
||||||
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
if (Objects.nonNull(userDto.getRole())) {
|
||||||
userDto.getRole().stream().map(roleId -> {
|
sysUserRoleMapper.delete(Wrappers.<SysUserRole>lambdaQuery().eq(SysUserRole::getUserId, userDto.getUserId()));
|
||||||
SysUserRole userRole = new SysUserRole();
|
userDto.getRole().stream().map(roleId -> {
|
||||||
userRole.setUserId(sysUser.getUserId());
|
SysUserRole userRole = new SysUserRole();
|
||||||
userRole.setRoleId(roleId);
|
userRole.setUserId(sysUser.getUserId());
|
||||||
return userRole;
|
userRole.setRoleId(roleId);
|
||||||
}).forEach(SysUserRole::insert);
|
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);
|
|
||||||
return Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// 更新用户岗位表
|
||||||
* 查询全部的用户
|
if (Objects.nonNull(userDto.getPost())) {
|
||||||
* @param userDTO 查询条件
|
sysUserPostMapper.delete(Wrappers.<SysUserPost>lambdaQuery().eq(SysUserPost::getUserId, userDto.getUserId()));
|
||||||
* @return list
|
userDto.getPost().stream().map(postId -> {
|
||||||
*/
|
SysUserPost userPost = new SysUserPost();
|
||||||
@Override
|
userPost.setUserId(sysUser.getUserId());
|
||||||
public List<UserExcelVO> listUser(UserDTO userDTO) {
|
userPost.setPostId(postId);
|
||||||
// 根据数据权限查询全部的用户信息
|
return userPost;
|
||||||
List<UserVO> voList = baseMapper.selectVoList(userDTO);
|
}).forEach(SysUserPost::insert);
|
||||||
// 转换成execl 对象输出
|
}
|
||||||
return voList.stream().map(userVO -> {
|
return Boolean.TRUE;
|
||||||
UserExcelVO excelVO = new UserExcelVO();
|
}
|
||||||
BeanUtils.copyProperties(userVO, excelVO);
|
|
||||||
String roleNameList = userVO.getRoleList()
|
|
||||||
.stream()
|
|
||||||
.map(SysRole::getRoleName)
|
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
|
||||||
excelVO.setRoleNameList(roleNameList);
|
|
||||||
String postNameList = userVO.getPostList()
|
|
||||||
.stream()
|
|
||||||
.map(SysPost::getPostName)
|
|
||||||
.collect(Collectors.joining(StrUtil.COMMA));
|
|
||||||
excelVO.setPostNameList(postNameList);
|
|
||||||
return excelVO;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* excel 导入用户, 插入正确的 错误的提示行号
|
* 查询全部的用户
|
||||||
* @param excelVOList excel 列表数据
|
*
|
||||||
* @param bindingResult 错误数据
|
* @param userDTO 查询条件
|
||||||
* @return ok fail
|
* @return list
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public R importUser(List<UserExcelVO> excelVOList, BindingResult bindingResult) {
|
public List<UserExcelVO> listUser(UserDTO userDTO) {
|
||||||
// 通用校验获取失败的数据
|
// 根据数据权限查询全部的用户信息
|
||||||
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
List<UserVO> voList = baseMapper.selectVoList(userDTO);
|
||||||
List<SysDept> deptList = sysDeptService.list();
|
// 转换成execl 对象输出
|
||||||
List<SysRole> roleList = sysRoleService.list();
|
return voList.stream().map(userVO -> {
|
||||||
List<SysPost> postList = sysPostService.list();
|
UserExcelVO excelVO = new UserExcelVO();
|
||||||
|
BeanUtils.copyProperties(userVO, excelVO);
|
||||||
|
String roleNameList = userVO.getRoleList()
|
||||||
|
.stream()
|
||||||
|
.map(SysRole::getRoleName)
|
||||||
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
|
excelVO.setRoleNameList(roleNameList);
|
||||||
|
String postNameList = userVO.getPostList()
|
||||||
|
.stream()
|
||||||
|
.map(SysPost::getPostName)
|
||||||
|
.collect(Collectors.joining(StrUtil.COMMA));
|
||||||
|
excelVO.setPostNameList(postNameList);
|
||||||
|
return excelVO;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
// 执行数据插入操作 组装 UserDto
|
/**
|
||||||
for (UserExcelVO excel : excelVOList) {
|
* excel 导入用户, 插入正确的 错误的提示行号
|
||||||
// 个性化校验逻辑
|
*
|
||||||
List<SysUser> userList = this.list();
|
* @param excelVOList excel 列表数据
|
||||||
|
* @param bindingResult 错误数据
|
||||||
|
* @return ok fail
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public R importUser(List<UserExcelVO> excelVOList, BindingResult bindingResult) {
|
||||||
|
// 通用校验获取失败的数据
|
||||||
|
List<ErrorMessage> errorMessageList = (List<ErrorMessage>) bindingResult.getTarget();
|
||||||
|
List<SysDept> deptList = sysDeptService.list();
|
||||||
|
List<SysRole> roleList = sysRoleService.list();
|
||||||
|
List<SysPost> postList = sysPostService.list();
|
||||||
|
|
||||||
Set<String> errorMsg = new HashSet<>();
|
// 执行数据插入操作 组装 UserDto
|
||||||
// 校验用户名是否存在
|
for (UserExcelVO excel : excelVOList) {
|
||||||
boolean exsitUserName = userList.stream()
|
// 个性化校验逻辑
|
||||||
.anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername()));
|
List<SysUser> userList = this.list();
|
||||||
|
|
||||||
if (exsitUserName) {
|
Set<String> errorMsg = new HashSet<>();
|
||||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername()));
|
// 校验用户名是否存在
|
||||||
}
|
boolean exsitUserName = userList.stream()
|
||||||
|
.anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername()));
|
||||||
|
|
||||||
// 判断输入的部门名称列表是否合法
|
if (exsitUserName) {
|
||||||
Optional<SysDept> deptOptional = deptList.stream()
|
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername()));
|
||||||
.filter(dept -> excel.getDeptName().equals(dept.getName()))
|
}
|
||||||
.findFirst();
|
|
||||||
if (!deptOptional.isPresent()) {
|
|
||||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_DEPT_DEPTNAME_INEXISTENCE, excel.getDeptName()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 判断输入的角色名称列表是否合法
|
// 判断输入的部门名称列表是否合法
|
||||||
List<String> roleNameList = StrUtil.split(excel.getRoleNameList(), StrUtil.COMMA);
|
Optional<SysDept> deptOptional = deptList.stream()
|
||||||
List<SysRole> roleCollList = roleList.stream()
|
.filter(dept -> excel.getDeptName().equals(dept.getName()))
|
||||||
.filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name)))
|
.findFirst();
|
||||||
.collect(Collectors.toList());
|
if (!deptOptional.isPresent()) {
|
||||||
|
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_DEPT_DEPTNAME_INEXISTENCE, excel.getDeptName()));
|
||||||
|
}
|
||||||
|
|
||||||
if (roleCollList.size() != roleNameList.size()) {
|
// 判断输入的角色名称列表是否合法
|
||||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_ROLENAME_INEXISTENCE, excel.getRoleNameList()));
|
List<String> roleNameList = StrUtil.split(excel.getRoleNameList(), StrUtil.COMMA);
|
||||||
}
|
List<SysRole> roleCollList = roleList.stream()
|
||||||
|
.filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 判断输入的部门名称列表是否合法
|
if (roleCollList.size() != roleNameList.size()) {
|
||||||
List<String> postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA);
|
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_ROLENAME_INEXISTENCE, excel.getRoleNameList()));
|
||||||
List<SysPost> postCollList = postList.stream()
|
}
|
||||||
.filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name)))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
if (postCollList.size() != postNameList.size()) {
|
// 判断输入的部门名称列表是否合法
|
||||||
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList()));
|
List<String> postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA);
|
||||||
}
|
List<SysPost> postCollList = postList.stream()
|
||||||
|
.filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name)))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// 数据合法情况
|
if (postCollList.size() != postNameList.size()) {
|
||||||
if (CollUtil.isEmpty(errorMsg)) {
|
errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList()));
|
||||||
insertExcelUser(excel, deptOptional, roleCollList, postCollList);
|
}
|
||||||
}
|
|
||||||
else {
|
|
||||||
// 数据不合法情况
|
|
||||||
errorMessageList.add(new ErrorMessage(excel.getLineNum(), errorMsg));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// 数据合法情况
|
||||||
|
if (CollUtil.isEmpty(errorMsg)) {
|
||||||
|
insertExcelUser(excel, deptOptional, roleCollList, postCollList);
|
||||||
|
} else {
|
||||||
|
// 数据不合法情况
|
||||||
|
errorMessageList.add(new ErrorMessage(excel.getLineNum(), errorMsg));
|
||||||
|
}
|
||||||
|
|
||||||
if (CollUtil.isNotEmpty(errorMessageList)) {
|
}
|
||||||
return R.failed(errorMessageList);
|
|
||||||
}
|
|
||||||
return R.ok();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
if (CollUtil.isNotEmpty(errorMessageList)) {
|
||||||
* 插入excel User
|
return R.failed(errorMessageList);
|
||||||
*/
|
}
|
||||||
private void insertExcelUser(UserExcelVO excel, Optional<SysDept> deptOptional, List<SysRole> roleCollList,
|
return R.ok();
|
||||||
List<SysPost> postCollList) {
|
}
|
||||||
UserDTO userDTO = new UserDTO();
|
|
||||||
userDTO.setUsername(excel.getUsername());
|
|
||||||
userDTO.setPhone(excel.getPhone());
|
|
||||||
userDTO.setNickname(excel.getNickname());
|
|
||||||
userDTO.setName(excel.getName());
|
|
||||||
userDTO.setEmail(excel.getEmail());
|
|
||||||
// 批量导入初始密码为手机号
|
|
||||||
userDTO.setPassword(userDTO.getPhone());
|
|
||||||
// 根据部门名称查询部门ID
|
|
||||||
userDTO.setDeptId(deptOptional.get().getDeptId());
|
|
||||||
// 插入岗位名称
|
|
||||||
List<Long> postIdList = postCollList.stream().map(SysPost::getPostId).collect(Collectors.toList());
|
|
||||||
userDTO.setPost(postIdList);
|
|
||||||
// 根据角色名称查询角色ID
|
|
||||||
List<Long> roleIdList = roleCollList.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
|
||||||
userDTO.setRole(roleIdList);
|
|
||||||
// 插入用户
|
|
||||||
this.saveUser(userDTO);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注册用户 赋予用户默认角色
|
* 插入excel User
|
||||||
* @param userDto 用户信息
|
*/
|
||||||
* @return success/false
|
private void insertExcelUser(UserExcelVO excel, Optional<SysDept> deptOptional, List<SysRole> roleCollList,
|
||||||
*/
|
List<SysPost> postCollList) {
|
||||||
@Override
|
UserDTO userDTO = new UserDTO();
|
||||||
@Transactional(rollbackFor = Exception.class)
|
userDTO.setUsername(excel.getUsername());
|
||||||
public R<Boolean> registerUser(UserDTO userDto) {
|
userDTO.setPhone(excel.getPhone());
|
||||||
// 判断用户名是否存在
|
userDTO.setNickname(excel.getNickname());
|
||||||
SysUser sysUser = this.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userDto.getUsername()));
|
userDTO.setName(excel.getName());
|
||||||
if (sysUser != null) {
|
userDTO.setEmail(excel.getEmail());
|
||||||
String message = MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, userDto.getUsername());
|
// 批量导入初始密码为手机号
|
||||||
return R.failed(message);
|
userDTO.setPassword(userDTO.getPhone());
|
||||||
}
|
// 根据部门名称查询部门ID
|
||||||
return R.ok(saveUser(userDto));
|
userDTO.setDeptId(deptOptional.get().getDeptId());
|
||||||
}
|
// 插入岗位名称
|
||||||
|
List<Long> postIdList = postCollList.stream().map(SysPost::getPostId).collect(Collectors.toList());
|
||||||
|
userDTO.setPost(postIdList);
|
||||||
|
// 根据角色名称查询角色ID
|
||||||
|
List<Long> roleIdList = roleCollList.stream().map(SysRole::getRoleId).collect(Collectors.toList());
|
||||||
|
userDTO.setRole(roleIdList);
|
||||||
|
// 插入用户
|
||||||
|
this.saveUser(userDTO);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 锁定用户
|
* 注册用户 赋予用户默认角色
|
||||||
* @param username 用户名
|
*
|
||||||
* @return
|
* @param userDto 用户信息
|
||||||
*/
|
* @return success/false
|
||||||
@Override
|
*/
|
||||||
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#username")
|
@Override
|
||||||
public R<Boolean> lockUser(String username) {
|
@Transactional(rollbackFor = Exception.class)
|
||||||
SysUser sysUser = baseMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
public R<Boolean> registerUser(UserDTO userDto) {
|
||||||
|
// 判断用户名是否存在
|
||||||
|
SysUser sysUser = this.getOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, userDto.getUsername()));
|
||||||
|
if (sysUser != null) {
|
||||||
|
String message = MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, userDto.getUsername());
|
||||||
|
return R.failed(message);
|
||||||
|
}
|
||||||
|
return R.ok(saveUser(userDto));
|
||||||
|
}
|
||||||
|
|
||||||
if (Objects.nonNull(sysUser)) {
|
/**
|
||||||
sysUser.setLockFlag(CommonConstants.STATUS_LOCK);
|
* 锁定用户
|
||||||
baseMapper.updateById(sysUser);
|
*
|
||||||
}
|
* @param username 用户名
|
||||||
return R.ok();
|
* @return
|
||||||
}
|
*/
|
||||||
|
@Override
|
||||||
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#username")
|
||||||
|
public R<Boolean> lockUser(String username) {
|
||||||
|
SysUser sysUser = baseMapper.selectOne(Wrappers.<SysUser>lambdaQuery().eq(SysUser::getUsername, username));
|
||||||
|
|
||||||
@Override
|
if (Objects.nonNull(sysUser)) {
|
||||||
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
sysUser.setLockFlag(CommonConstants.STATUS_LOCK);
|
||||||
public R changePassword(UserDTO userDto) {
|
baseMapper.updateById(sysUser);
|
||||||
SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId());
|
}
|
||||||
if (Objects.isNull(sysUser)) {
|
return R.ok();
|
||||||
return R.failed("用户不存在");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (StrUtil.isEmpty(userDto.getPassword())) {
|
@Override
|
||||||
return R.failed("原密码不能为空");
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
||||||
}
|
public R changePassword(UserDTO userDto) {
|
||||||
|
SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId());
|
||||||
|
if (Objects.isNull(sysUser)) {
|
||||||
|
return R.failed("用户不存在");
|
||||||
|
}
|
||||||
|
|
||||||
if (!ENCODER.matches(userDto.getPassword(), sysUser.getPassword())) {
|
if (StrUtil.isEmpty(userDto.getPassword())) {
|
||||||
log.info("原密码错误,修改个人信息失败:{}", userDto.getUsername());
|
return R.failed("原密码不能为空");
|
||||||
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_UPDATE_PASSWORDERROR));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (StrUtil.isEmpty(userDto.getNewpassword1())) {
|
if (!ENCODER.matches(userDto.getPassword(), sysUser.getPassword())) {
|
||||||
return R.failed("新密码不能为空");
|
log.info("原密码错误,修改个人信息失败:{}", userDto.getUsername());
|
||||||
}
|
return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_UPDATE_PASSWORDERROR));
|
||||||
String password = ENCODER.encode(userDto.getNewpassword1());
|
}
|
||||||
|
|
||||||
this.update(Wrappers.<SysUser>lambdaUpdate()
|
if (StrUtil.isEmpty(userDto.getNewpassword1())) {
|
||||||
.set(SysUser::getPassword, password)
|
return R.failed("新密码不能为空");
|
||||||
.eq(SysUser::getUserId, sysUser.getUserId()));
|
}
|
||||||
return R.ok();
|
String password = ENCODER.encode(userDto.getNewpassword1());
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
this.update(Wrappers.<SysUser>lambdaUpdate()
|
||||||
public R checkPassword(String password) {
|
.set(SysUser::getPassword, password)
|
||||||
SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId());
|
.eq(SysUser::getUserId, sysUser.getUserId()));
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
|
||||||
if (!ENCODER.matches(password, sysUser.getPassword())) {
|
@Override
|
||||||
log.info("原密码错误");
|
public R checkPassword(String password) {
|
||||||
return R.failed("密码输入错误");
|
SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId());
|
||||||
}
|
|
||||||
else {
|
if (!ENCODER.matches(password, sysUser.getPassword())) {
|
||||||
return R.ok();
|
log.info("原密码错误");
|
||||||
}
|
return R.failed("密码输入错误");
|
||||||
}
|
} else {
|
||||||
|
return R.ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<screw.version>0.0.6</screw.version>
|
<screw.version>0.0.6</screw.version>
|
||||||
<anyline.version>8.7.2-20240717</anyline.version>
|
<anyline.version>8.7.2-20240808</anyline.version>
|
||||||
<configuration.version>1.10</configuration.version>
|
<configuration.version>1.10</configuration.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user