From 779a0ccd39c1f9bc106fe14f5d3d24ab26c9ef40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=86=B7=E5=86=B7?= <2270033969@qq.com> Date: Tue, 13 Aug 2024 09:27:47 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E9=94=81=E5=AE=9A):=20=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E7=AE=A1=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit bug: 用户管理列表页切换状态不生效 Closes IAJID5 --- .../service/impl/SysUserServiceImpl.java | 678 +++++++++--------- pig-visual/pig-codegen/pom.xml | 2 +- 2 files changed, 346 insertions(+), 334 deletions(-) diff --git a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java index f65a2aca..cfe872d7 100644 --- a/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java +++ b/pig-upms/pig-upms-biz/src/main/java/com/pig4cloud/pig/admin/service/impl/SysUserServiceImpl.java @@ -68,382 +68,394 @@ import java.util.stream.Collectors; @AllArgsConstructor public class SysUserServiceImpl extends ServiceImpl 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 - */ - @Override - @Transactional(rollbackFor = Exception.class) - public Boolean saveUser(UserDTO userDto) { - SysUser sysUser = new SysUser(); - BeanUtils.copyProperties(userDto, sysUser); - sysUser.setDelFlag(CommonConstants.STATUS_NORMAL); - sysUser.setCreateBy(userDto.getUsername()); - sysUser.setPassword(ENCODER.encode(userDto.getPassword())); - baseMapper.insert(sysUser); - // 保存用户岗位信息 - Optional.ofNullable(userDto.getPost()).ifPresent(posts -> { - posts.stream().map(postId -> { - SysUserPost userPost = new SysUserPost(); - userPost.setUserId(sysUser.getUserId()); - userPost.setPostId(postId); - return userPost; - }).forEach(sysUserPostMapper::insert); - }); + /** + * 保存用户信息 + * + * @param userDto DTO 对象 + * @return success/fail + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean saveUser(UserDTO userDto) { + SysUser sysUser = new SysUser(); + BeanUtils.copyProperties(userDto, sysUser); + sysUser.setDelFlag(CommonConstants.STATUS_NORMAL); + sysUser.setCreateBy(userDto.getUsername()); + sysUser.setPassword(ENCODER.encode(userDto.getPassword())); + baseMapper.insert(sysUser); + // 保存用户岗位信息 + Optional.ofNullable(userDto.getPost()).ifPresent(posts -> { + posts.stream().map(postId -> { + SysUserPost userPost = new SysUserPost(); + userPost.setUserId(sysUser.getUserId()); + userPost.setPostId(postId); + return userPost; + }).forEach(sysUserPostMapper::insert); + }); - // 如果角色为空,赋默认角色 - if (CollUtil.isEmpty(userDto.getRole())) { - // 获取默认角色编码 - String defaultRole = ParamResolver.getStr("USER_DEFAULT_ROLE"); - // 默认角色 - SysRole sysRole = sysRoleService - .getOne(Wrappers.lambdaQuery().eq(SysRole::getRoleCode, defaultRole)); - userDto.setRole(Collections.singletonList(sysRole.getRoleId())); - } + // 如果角色为空,赋默认角色 + if (CollUtil.isEmpty(userDto.getRole())) { + // 获取默认角色编码 + String defaultRole = ParamResolver.getStr("USER_DEFAULT_ROLE"); + // 默认角色 + SysRole sysRole = sysRoleService + .getOne(Wrappers.lambdaQuery().eq(SysRole::getRoleCode, defaultRole)); + userDto.setRole(Collections.singletonList(sysRole.getRoleId())); + } - // 插入用户角色关系表 - userDto.getRole().stream().map(roleId -> { - SysUserRole userRole = new SysUserRole(); - userRole.setUserId(sysUser.getUserId()); - userRole.setRoleId(roleId); - return userRole; - }).forEach(sysUserRoleMapper::insert); - return Boolean.TRUE; - } + // 插入用户角色关系表 + userDto.getRole().stream().map(roleId -> { + SysUserRole userRole = new SysUserRole(); + userRole.setUserId(sysUser.getUserId()); + userRole.setRoleId(roleId); + return userRole; + }).forEach(sysUserRoleMapper::insert); + return Boolean.TRUE; + } - /** - * 通过查用户的全部信息 - * @param sysUser 用户 - * @return - */ - @Override - public UserInfo findUserInfo(SysUser sysUser) { - UserInfo userInfo = new UserInfo(); - userInfo.setSysUser(sysUser); - // 设置角色列表 (ID) - List roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId()) - .stream() - .map(SysRole::getRoleId) - .collect(Collectors.toList()); - userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class)); + /** + * 通过查用户的全部信息 + * + * @param sysUser 用户 + * @return + */ + @Override + public UserInfo findUserInfo(SysUser sysUser) { + UserInfo userInfo = new UserInfo(); + userInfo.setSysUser(sysUser); + // 设置角色列表 (ID) + List roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId()) + .stream() + .map(SysRole::getRoleId) + .collect(Collectors.toList()); + userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class)); - // 设置权限列表(menu.permission) - Set permissions = new HashSet<>(); - roleIds.forEach(roleId -> { - List permissionList = sysMenuService.findMenuByRoleId(roleId) - .stream() - .filter(menu -> StrUtil.isNotEmpty(menu.getPermission())) - .map(SysMenu::getPermission) - .collect(Collectors.toList()); - permissions.addAll(permissionList); - }); - userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class)); - return userInfo; - } + // 设置权限列表(menu.permission) + Set permissions = new HashSet<>(); + roleIds.forEach(roleId -> { + List permissionList = sysMenuService.findMenuByRoleId(roleId) + .stream() + .filter(menu -> StrUtil.isNotEmpty(menu.getPermission())) + .map(SysMenu::getPermission) + .collect(Collectors.toList()); + permissions.addAll(permissionList); + }); + userInfo.setPermissions(ArrayUtil.toArray(permissions, String.class)); + return userInfo; + } - /** - * 分页查询用户信息(含有角色信息) - * @param page 分页对象 - * @param userDTO 参数列表 - * @return - */ - @Override - public IPage getUsersWithRolePage(Page page, UserDTO userDTO) { - return baseMapper.getUserVosPage(page, userDTO); - } + /** + * 分页查询用户信息(含有角色信息) + * + * @param page 分页对象 + * @param userDTO 参数列表 + * @return + */ + @Override + public IPage getUsersWithRolePage(Page page, UserDTO userDTO) { + return baseMapper.getUserVosPage(page, userDTO); + } - /** - * 通过ID查询用户信息 - * @param id 用户ID - * @return 用户信息 - */ - @Override - public UserVO selectUserVoById(Long id) { - return baseMapper.getUserVoById(id); - } + /** + * 通过ID查询用户信息 + * + * @param id 用户ID + * @return 用户信息 + */ + @Override + public UserVO selectUserVoById(Long id) { + return baseMapper.getUserVoById(id); + } - /** - * 删除用户 - * @param ids 用户ID 列表 - * @return Boolean - */ - @Override - @Transactional(rollbackFor = Exception.class) - public Boolean deleteUserByIds(Long[] ids) { - // 删除 spring cache - List userList = baseMapper.selectBatchIds(CollUtil.toList(ids)); - Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS); - for (SysUser sysUser : userList) { - // 立即删除 - cache.evictIfPresent(sysUser.getUsername()); - } + /** + * 删除用户 + * + * @param ids 用户ID 列表 + * @return Boolean + */ + @Override + @Transactional(rollbackFor = Exception.class) + public Boolean deleteUserByIds(Long[] ids) { + // 删除 spring cache + List userList = baseMapper.selectBatchIds(CollUtil.toList(ids)); + Cache cache = cacheManager.getCache(CacheConstants.USER_DETAILS); + for (SysUser sysUser : userList) { + // 立即删除 + cache.evictIfPresent(sysUser.getUsername()); + } - sysUserRoleMapper.delete(Wrappers.lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids))); - this.removeBatchByIds(CollUtil.toList(ids)); - return Boolean.TRUE; - } + sysUserRoleMapper.delete(Wrappers.lambdaQuery().in(SysUserRole::getUserId, CollUtil.toList(ids))); + this.removeBatchByIds(CollUtil.toList(ids)); + return Boolean.TRUE; + } - @Override - @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username") - public R updateUserInfo(UserDTO userDto) { - SysUser sysUser = new SysUser(); - sysUser.setPhone(userDto.getPhone()); - sysUser.setUserId(SecurityUtils.getUser().getId()); - sysUser.setAvatar(userDto.getAvatar()); - sysUser.setNickname(userDto.getNickname()); - sysUser.setName(userDto.getName()); - sysUser.setEmail(userDto.getEmail()); - return R.ok(this.updateById(sysUser)); - } + @Override + @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username") + public R updateUserInfo(UserDTO userDto) { + SysUser sysUser = new SysUser(); + sysUser.setPhone(userDto.getPhone()); + sysUser.setUserId(SecurityUtils.getUser().getId()); + sysUser.setAvatar(userDto.getAvatar()); + sysUser.setNickname(userDto.getNickname()); + sysUser.setName(userDto.getName()); + sysUser.setEmail(userDto.getEmail()); + return R.ok(this.updateById(sysUser)); + } - @Override - @Transactional(rollbackFor = Exception.class) - @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username") - public Boolean updateUser(UserDTO userDto) { - // 更新用户表信息 - SysUser sysUser = new SysUser(); - BeanUtils.copyProperties(userDto, sysUser); - sysUser.setUpdateTime(LocalDateTime.now()); - if (StrUtil.isNotBlank(userDto.getPassword())) { - sysUser.setPassword(ENCODER.encode(userDto.getPassword())); - } - this.updateById(sysUser); + @Override + @Transactional(rollbackFor = Exception.class) + @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username") + public Boolean updateUser(UserDTO userDto) { + // 更新用户表信息 + SysUser sysUser = new SysUser(); + BeanUtils.copyProperties(userDto, sysUser); + sysUser.setUpdateTime(LocalDateTime.now()); + if (StrUtil.isNotBlank(userDto.getPassword())) { + sysUser.setPassword(ENCODER.encode(userDto.getPassword())); + } + this.updateById(sysUser); - // 更新用户角色表 - sysUserRoleMapper.delete(Wrappers.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 (Objects.nonNull(userDto.getRole())) { + sysUserRoleMapper.delete(Wrappers.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.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; - } - /** - * 查询全部的用户 - * @param userDTO 查询条件 - * @return list - */ - @Override - public List listUser(UserDTO userDTO) { - // 根据数据权限查询全部的用户信息 - List voList = baseMapper.selectVoList(userDTO); - // 转换成execl 对象输出 - return voList.stream().map(userVO -> { - 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()); - } + // 更新用户岗位表 + if (Objects.nonNull(userDto.getPost())) { + sysUserPostMapper.delete(Wrappers.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; + } - /** - * excel 导入用户, 插入正确的 错误的提示行号 - * @param excelVOList excel 列表数据 - * @param bindingResult 错误数据 - * @return ok fail - */ - @Override - public R importUser(List excelVOList, BindingResult bindingResult) { - // 通用校验获取失败的数据 - List errorMessageList = (List) bindingResult.getTarget(); - List deptList = sysDeptService.list(); - List roleList = sysRoleService.list(); - List postList = sysPostService.list(); + /** + * 查询全部的用户 + * + * @param userDTO 查询条件 + * @return list + */ + @Override + public List listUser(UserDTO userDTO) { + // 根据数据权限查询全部的用户信息 + List voList = baseMapper.selectVoList(userDTO); + // 转换成execl 对象输出 + return voList.stream().map(userVO -> { + 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) { - // 个性化校验逻辑 - List userList = this.list(); + /** + * excel 导入用户, 插入正确的 错误的提示行号 + * + * @param excelVOList excel 列表数据 + * @param bindingResult 错误数据 + * @return ok fail + */ + @Override + public R importUser(List excelVOList, BindingResult bindingResult) { + // 通用校验获取失败的数据 + List errorMessageList = (List) bindingResult.getTarget(); + List deptList = sysDeptService.list(); + List roleList = sysRoleService.list(); + List postList = sysPostService.list(); - Set errorMsg = new HashSet<>(); - // 校验用户名是否存在 - boolean exsitUserName = userList.stream() - .anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername())); + // 执行数据插入操作 组装 UserDto + for (UserExcelVO excel : excelVOList) { + // 个性化校验逻辑 + List userList = this.list(); - if (exsitUserName) { - errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername())); - } + Set errorMsg = new HashSet<>(); + // 校验用户名是否存在 + boolean exsitUserName = userList.stream() + .anyMatch(sysUser -> excel.getUsername().equals(sysUser.getUsername())); - // 判断输入的部门名称列表是否合法 - Optional deptOptional = deptList.stream() - .filter(dept -> excel.getDeptName().equals(dept.getName())) - .findFirst(); - if (!deptOptional.isPresent()) { - errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_DEPT_DEPTNAME_INEXISTENCE, excel.getDeptName())); - } + if (exsitUserName) { + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_USER_USERNAME_EXISTING, excel.getUsername())); + } - // 判断输入的角色名称列表是否合法 - List roleNameList = StrUtil.split(excel.getRoleNameList(), StrUtil.COMMA); - List roleCollList = roleList.stream() - .filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name))) - .collect(Collectors.toList()); + // 判断输入的部门名称列表是否合法 + Optional deptOptional = deptList.stream() + .filter(dept -> excel.getDeptName().equals(dept.getName())) + .findFirst(); + 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 roleNameList = StrUtil.split(excel.getRoleNameList(), StrUtil.COMMA); + List roleCollList = roleList.stream() + .filter(role -> roleNameList.stream().anyMatch(name -> role.getRoleName().equals(name))) + .collect(Collectors.toList()); - // 判断输入的部门名称列表是否合法 - List postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA); - List postCollList = postList.stream() - .filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name))) - .collect(Collectors.toList()); + if (roleCollList.size() != roleNameList.size()) { + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_ROLE_ROLENAME_INEXISTENCE, excel.getRoleNameList())); + } - if (postCollList.size() != postNameList.size()) { - errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList())); - } + // 判断输入的部门名称列表是否合法 + List postNameList = StrUtil.split(excel.getPostNameList(), StrUtil.COMMA); + List postCollList = postList.stream() + .filter(post -> postNameList.stream().anyMatch(name -> post.getPostName().equals(name))) + .collect(Collectors.toList()); - // 数据合法情况 - if (CollUtil.isEmpty(errorMsg)) { - insertExcelUser(excel, deptOptional, roleCollList, postCollList); - } - else { - // 数据不合法情况 - errorMessageList.add(new ErrorMessage(excel.getLineNum(), errorMsg)); - } + if (postCollList.size() != postNameList.size()) { + errorMsg.add(MsgUtils.getMessage(ErrorCodes.SYS_POST_POSTNAME_INEXISTENCE, excel.getPostNameList())); + } - } + // 数据合法情况 + 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(); - } + } - /** - * 插入excel User - */ - private void insertExcelUser(UserExcelVO excel, Optional deptOptional, List roleCollList, - List 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 postIdList = postCollList.stream().map(SysPost::getPostId).collect(Collectors.toList()); - userDTO.setPost(postIdList); - // 根据角色名称查询角色ID - List roleIdList = roleCollList.stream().map(SysRole::getRoleId).collect(Collectors.toList()); - userDTO.setRole(roleIdList); - // 插入用户 - this.saveUser(userDTO); - } + if (CollUtil.isNotEmpty(errorMessageList)) { + return R.failed(errorMessageList); + } + return R.ok(); + } - /** - * 注册用户 赋予用户默认角色 - * @param userDto 用户信息 - * @return success/false - */ - @Override - @Transactional(rollbackFor = Exception.class) - public R registerUser(UserDTO userDto) { - // 判断用户名是否存在 - SysUser sysUser = this.getOne(Wrappers.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)); - } + /** + * 插入excel User + */ + private void insertExcelUser(UserExcelVO excel, Optional deptOptional, List roleCollList, + List 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 postIdList = postCollList.stream().map(SysPost::getPostId).collect(Collectors.toList()); + userDTO.setPost(postIdList); + // 根据角色名称查询角色ID + List roleIdList = roleCollList.stream().map(SysRole::getRoleId).collect(Collectors.toList()); + userDTO.setRole(roleIdList); + // 插入用户 + this.saveUser(userDTO); + } - /** - * 锁定用户 - * @param username 用户名 - * @return - */ - @Override - @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#username") - public R lockUser(String username) { - SysUser sysUser = baseMapper.selectOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, username)); + /** + * 注册用户 赋予用户默认角色 + * + * @param userDto 用户信息 + * @return success/false + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R registerUser(UserDTO userDto) { + // 判断用户名是否存在 + SysUser sysUser = this.getOne(Wrappers.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); - } - return R.ok(); - } + /** + * 锁定用户 + * + * @param username 用户名 + * @return + */ + @Override + @CacheEvict(value = CacheConstants.USER_DETAILS, key = "#username") + public R lockUser(String username) { + SysUser sysUser = baseMapper.selectOne(Wrappers.lambdaQuery().eq(SysUser::getUsername, username)); - @Override - @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 (Objects.nonNull(sysUser)) { + sysUser.setLockFlag(CommonConstants.STATUS_LOCK); + baseMapper.updateById(sysUser); + } + return R.ok(); + } - if (StrUtil.isEmpty(userDto.getPassword())) { - return R.failed("原密码不能为空"); - } + @Override + @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())) { - log.info("原密码错误,修改个人信息失败:{}", userDto.getUsername()); - return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_UPDATE_PASSWORDERROR)); - } + if (StrUtil.isEmpty(userDto.getPassword())) { + return R.failed("原密码不能为空"); + } - if (StrUtil.isEmpty(userDto.getNewpassword1())) { - return R.failed("新密码不能为空"); - } - String password = ENCODER.encode(userDto.getNewpassword1()); + if (!ENCODER.matches(userDto.getPassword(), sysUser.getPassword())) { + log.info("原密码错误,修改个人信息失败:{}", userDto.getUsername()); + return R.failed(MsgUtils.getMessage(ErrorCodes.SYS_USER_UPDATE_PASSWORDERROR)); + } - this.update(Wrappers.lambdaUpdate() - .set(SysUser::getPassword, password) - .eq(SysUser::getUserId, sysUser.getUserId())); - return R.ok(); - } + if (StrUtil.isEmpty(userDto.getNewpassword1())) { + return R.failed("新密码不能为空"); + } + String password = ENCODER.encode(userDto.getNewpassword1()); - @Override - public R checkPassword(String password) { - SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId()); + this.update(Wrappers.lambdaUpdate() + .set(SysUser::getPassword, password) + .eq(SysUser::getUserId, sysUser.getUserId())); + return R.ok(); + } - if (!ENCODER.matches(password, sysUser.getPassword())) { - log.info("原密码错误"); - return R.failed("密码输入错误"); - } - else { - return R.ok(); - } - } + @Override + public R checkPassword(String password) { + SysUser sysUser = baseMapper.selectById(SecurityUtils.getUser().getId()); + + if (!ENCODER.matches(password, sysUser.getPassword())) { + log.info("原密码错误"); + return R.failed("密码输入错误"); + } else { + return R.ok(); + } + } } diff --git a/pig-visual/pig-codegen/pom.xml b/pig-visual/pig-codegen/pom.xml index c3fe29e1..31990373 100755 --- a/pig-visual/pig-codegen/pom.xml +++ b/pig-visual/pig-codegen/pom.xml @@ -16,7 +16,7 @@ 0.0.6 - 8.7.2-20240717 + 8.7.2-20240808 1.10