|
|
@@ -1,7 +1,7 @@
|
|
|
package com.lxq.system.biz.service.impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
+import cn.hutool.core.text.CharSequenceUtil;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
@@ -19,10 +19,10 @@ import com.lxq.common.security.util.SecurityUtils;
|
|
|
import com.lxq.system.biz.domain.dto.UserDTO;
|
|
|
import com.lxq.system.biz.domain.dto.UserInfo;
|
|
|
import com.lxq.system.biz.domain.vo.UserVO;
|
|
|
-import com.lxq.system.biz.model.*;
|
|
|
import com.lxq.system.biz.mapper.SysUserMapper;
|
|
|
import com.lxq.system.biz.mapper.SysUserPostMapper;
|
|
|
import com.lxq.system.biz.mapper.SysUserRoleMapper;
|
|
|
+import com.lxq.system.biz.model.*;
|
|
|
import com.lxq.system.biz.service.SysMenuService;
|
|
|
import com.lxq.system.biz.service.SysPublicParamService;
|
|
|
import com.lxq.system.biz.service.SysRoleService;
|
|
|
@@ -40,7 +40,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* sys用户服务
|
|
|
@@ -81,17 +80,15 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
sysUser.setCreateBy(userDto.getUsername());
|
|
|
sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
|
|
List<SysUser> list = this.list(new LambdaQueryWrapper<SysUser>().eq(SysUser::getUsername, userDto.getUsername()));
|
|
|
- AssertUtil.isTrue(CollectionUtil.isEmpty(list),"用户名称已经存在!");
|
|
|
+ AssertUtil.isTrue(CollUtil.isEmpty(list),"用户名称已经存在!");
|
|
|
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);
|
|
|
- });
|
|
|
+ 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())) {
|
|
|
// 获取默认角色编码
|
|
|
@@ -133,7 +130,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
List<Long> roleIds = sysRoleService.findRolesByUserId(sysUser.getUserId())
|
|
|
.stream()
|
|
|
.map(SysRole::getRoleId)
|
|
|
- .collect(Collectors.toList());
|
|
|
+ .toList();
|
|
|
userInfo.setRoles(ArrayUtil.toArray(roleIds, Long.class));
|
|
|
|
|
|
// 设置权限列表(menu.permission)
|
|
|
@@ -154,7 +151,6 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
* 分页查询用户信息(含有角色信息)
|
|
|
* @param page 分页对象
|
|
|
* @param userDTO 参数列表
|
|
|
- * @return
|
|
|
*/
|
|
|
@Override
|
|
|
public IPage getUsersWithRolePage(Page page, UserDTO userDTO) {
|
|
|
@@ -196,11 +192,10 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
|
|
public R<Boolean> updateUserInfo(UserDTO userDto) {
|
|
|
- UserVO userVO = baseMapper.getUserVoByUsername(userDto.getUsername());
|
|
|
|
|
|
SysUser sysUser = new SysUser();
|
|
|
sysUser.setPhone(userDto.getPhone());
|
|
|
- sysUser.setUserId(userVO.getUserId());
|
|
|
+ sysUser.setUserId(SecurityUtils.getUser().getId());
|
|
|
sysUser.setAvatar(userDto.getAvatar());
|
|
|
sysUser.setNickname(userDto.getNickname());
|
|
|
sysUser.setName(userDto.getName());
|
|
|
@@ -218,8 +213,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
SysUser sysUser = new SysUser();
|
|
|
BeanUtils.copyProperties(userDto, sysUser);
|
|
|
sysUser.setUpdateTime(LocalDateTime.now());
|
|
|
- if (StrUtil.isNotBlank(userDto.getNewPwd()) && !user.getPassword().equals(userDto.getNewPwd())) {
|
|
|
- sysUser.setPassword(ENCODER.encode(userDto.getNewPwd()));
|
|
|
+ if (CharSequenceUtil.isNotBlank(userDto.getPassword()) && !user.getPassword().equals(userDto.getPassword())) {
|
|
|
+ sysUser.setPassword(ENCODER.encode(userDto.getPassword()));
|
|
|
}
|
|
|
this.updateById(sysUser);
|
|
|
|
|
|
@@ -262,12 +257,13 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@CacheEvict(value = CacheConstants.USER_DETAILS, key = "#userDto.username")
|
|
|
public R changePassword(UserDTO userDto) {
|
|
|
- UserVO userVO = baseMapper.getUserVoByUsername(userDto.getUsername());
|
|
|
+
|
|
|
+ SysUser userVO = getById(SecurityUtils.getUser().getId());
|
|
|
if (Objects.isNull(userVO)) {
|
|
|
return R.failed("用户不存在");
|
|
|
}
|
|
|
|
|
|
- if (StrUtil.isEmpty(userDto.getPassword())) {
|
|
|
+ if (CharSequenceUtil.isEmpty(userDto.getPassword())) {
|
|
|
return R.failed("原密码不能为空");
|
|
|
}
|
|
|
|
|
|
@@ -276,7 +272,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
return R.failed(ErrorTypeEnum.SYS_USER_UPDATE_PASSWORD_ERROR);
|
|
|
}
|
|
|
|
|
|
- if (StrUtil.isEmpty(userDto.getNewPwd())) {
|
|
|
+ if (CharSequenceUtil.isEmpty(userDto.getNewPwd())) {
|
|
|
return R.failed("新密码不能为空");
|
|
|
}
|
|
|
String password = ENCODER.encode(userDto.getNewPwd());
|