|
@@ -1,6 +1,7 @@
|
|
|
package com.vber.system.service.impl;
|
|
package com.vber.system.service.impl;
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.hutool.core.convert.Convert;
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
@@ -9,18 +10,18 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import lombok.RequiredArgsConstructor;
|
|
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import com.vber.common.core.constant.CacheNames;
|
|
import com.vber.common.core.constant.CacheNames;
|
|
|
import com.vber.common.core.constant.UserConstants;
|
|
import com.vber.common.core.constant.UserConstants;
|
|
|
import com.vber.common.core.exception.ServiceException;
|
|
import com.vber.common.core.exception.ServiceException;
|
|
|
import com.vber.common.core.service.UserService;
|
|
import com.vber.common.core.service.UserService;
|
|
|
import com.vber.common.core.utils.MapstructUtils;
|
|
import com.vber.common.core.utils.MapstructUtils;
|
|
|
|
|
+import com.vber.common.core.utils.SpringUtils;
|
|
|
import com.vber.common.core.utils.StreamUtils;
|
|
import com.vber.common.core.utils.StreamUtils;
|
|
|
import com.vber.common.core.utils.StringUtils;
|
|
import com.vber.common.core.utils.StringUtils;
|
|
|
import com.vber.common.mybatis.core.page.PageQuery;
|
|
import com.vber.common.mybatis.core.page.PageQuery;
|
|
|
import com.vber.common.mybatis.core.page.TableDataInfo;
|
|
import com.vber.common.mybatis.core.page.TableDataInfo;
|
|
|
import com.vber.common.mybatis.helper.DataBaseHelper;
|
|
import com.vber.common.mybatis.helper.DataBaseHelper;
|
|
|
|
|
+import com.vber.common.redis.utils.CacheUtils;
|
|
|
import com.vber.common.satoken.utils.LoginHelper;
|
|
import com.vber.common.satoken.utils.LoginHelper;
|
|
|
import com.vber.system.domain.SysOrg;
|
|
import com.vber.system.domain.SysOrg;
|
|
|
import com.vber.system.domain.SysUser;
|
|
import com.vber.system.domain.SysUser;
|
|
@@ -32,10 +33,16 @@ import com.vber.system.domain.vo.SysRoleVo;
|
|
|
import com.vber.system.domain.vo.SysUserVo;
|
|
import com.vber.system.domain.vo.SysUserVo;
|
|
|
import com.vber.system.mapper.*;
|
|
import com.vber.system.mapper.*;
|
|
|
import com.vber.system.service.ISysUserService;
|
|
import com.vber.system.service.ISysUserService;
|
|
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import org.springframework.cache.CacheManager;
|
|
|
|
|
+import org.springframework.cache.annotation.CacheEvict;
|
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
import org.springframework.cache.annotation.Cacheable;
|
|
|
|
|
+import org.springframework.cache.annotation.Caching;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -55,6 +62,7 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
private final SysPostMapper postMapper;
|
|
private final SysPostMapper postMapper;
|
|
|
private final SysUserRoleMapper userRoleMapper;
|
|
private final SysUserRoleMapper userRoleMapper;
|
|
|
private final SysUserPostMapper userPostMapper;
|
|
private final SysUserPostMapper userPostMapper;
|
|
|
|
|
+ private final CacheManager cacheManager;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public TableDataInfo<SysUserVo> selectPageUserList(SysUserBo user, PageQuery pageQuery) {
|
|
public TableDataInfo<SysUserVo> selectPageUserList(SysUserBo user, PageQuery pageQuery) {
|
|
@@ -309,6 +317,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ @Caching(evict = {
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_NICKNAME, key = "#user.userId"),
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_PHONE, key = "#user.userId"),
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_EMAIL, key = "#user.userId"),
|
|
|
|
|
+ })
|
|
|
public int updateUser(SysUserBo user) {
|
|
public int updateUser(SysUserBo user) {
|
|
|
// 新增用户与角色管理
|
|
// 新增用户与角色管理
|
|
|
insertUserRole(user, true);
|
|
insertUserRole(user, true);
|
|
@@ -357,6 +370,11 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
* @return 结果
|
|
* @return 结果
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Caching(evict = {
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_NICKNAME, key = "#user.userId"),
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_PHONE, key = "#user.userId"),
|
|
|
|
|
+ @CacheEvict(value = CacheNames.SYS_EMAIL, key = "#user.userId"),
|
|
|
|
|
+ })
|
|
|
public int updateUserProfile(SysUserBo user) {
|
|
public int updateUserProfile(SysUserBo user) {
|
|
|
return baseMapper.update(null,
|
|
return baseMapper.update(null,
|
|
|
new LambdaUpdateWrapper<SysUser>()
|
|
new LambdaUpdateWrapper<SysUser>()
|
|
@@ -503,6 +521,15 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
checkUserDataScope(userId);
|
|
checkUserDataScope(userId);
|
|
|
}
|
|
}
|
|
|
List<Long> ids = List.of(userIds);
|
|
List<Long> ids = List.of(userIds);
|
|
|
|
|
+ if (CollUtil.isEmpty(ids)) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ ids.forEach(userId -> {
|
|
|
|
|
+ CacheUtils.evict(CacheNames.SYS_USER_NAME, userId);
|
|
|
|
|
+ CacheUtils.evict(CacheNames.SYS_NICKNAME, userId);
|
|
|
|
|
+ CacheUtils.evict(CacheNames.SYS_PHONE, userId);
|
|
|
|
|
+ CacheUtils.evict(CacheNames.SYS_EMAIL, userId);
|
|
|
|
|
+ });
|
|
|
// 删除用户与角色关联
|
|
// 删除用户与角色关联
|
|
|
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
|
|
userRoleMapper.delete(new LambdaQueryWrapper<SysUserRole>().in(SysUserRole::getUserId, ids));
|
|
|
// 删除用户与岗位表
|
|
// 删除用户与岗位表
|
|
@@ -518,8 +545,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
/**
|
|
/**
|
|
|
* 通过组织机构id查询当前组织机构所有用户
|
|
* 通过组织机构id查询当前组织机构所有用户
|
|
|
*
|
|
*
|
|
|
- * @param orgId
|
|
|
|
|
- * @return
|
|
|
|
|
|
|
+ * @param orgId 组织结构ID
|
|
|
|
|
+ * @return 用户信息集合
|
|
|
*/
|
|
*/
|
|
|
@Override
|
|
@Override
|
|
|
public List<SysUserVo> selectUserListByOrg(Long orgId) {
|
|
public List<SysUserVo> selectUserListByOrg(Long orgId) {
|
|
@@ -529,8 +556,8 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
return baseMapper.selectVoList(lqw);
|
|
return baseMapper.selectVoList(lqw);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- @Cacheable(cacheNames = CacheNames.SYS_USER_NAME, key = "#userId")
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Cacheable(cacheNames = CacheNames.SYS_USER_NAME, key = "#userId")
|
|
|
public String selectUserNameById(Long userId) {
|
|
public String selectUserNameById(Long userId) {
|
|
|
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
|
SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
|
|
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
|
|
.select(SysUser::getUserName).eq(SysUser::getUserId, userId));
|
|
@@ -544,4 +571,44 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
|
|
|
.select(SysUser::getNickName).eq(SysUser::getUserId, userId));
|
|
.select(SysUser::getNickName).eq(SysUser::getUserId, userId));
|
|
|
return ObjectUtil.isNull(sysUser) ? null : sysUser.getNickName();
|
|
return ObjectUtil.isNull(sysUser) ? null : sysUser.getNickName();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public String selectNicknameByIds(String userIds) {
|
|
|
|
|
+ List<String> list = new ArrayList<>();
|
|
|
|
|
+ for (Long id : StringUtils.splitTo(userIds, Convert::toLong)) {
|
|
|
|
|
+ String nickname = SpringUtils.getAopProxy(this).selectNicknameById(id);
|
|
|
|
|
+ if (StringUtils.isNotBlank(nickname)) {
|
|
|
|
|
+ list.add(nickname);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ return String.join(StringUtils.SEPARATOR, list);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过用户ID查询用户手机号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户id
|
|
|
|
|
+ * @return 用户手机号
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Cacheable(cacheNames = CacheNames.SYS_PHONE, key = "#userId")
|
|
|
|
|
+ public String selectPhonenumberById(Long userId) {
|
|
|
|
|
+ SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
|
|
|
|
+ .select(SysUser::getPhonenumber).eq(SysUser::getUserId, userId));
|
|
|
|
|
+ return ObjectUtil.isNull(sysUser) ? null : sysUser.getPhonenumber();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 通过用户ID查询用户邮箱
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param userId 用户id
|
|
|
|
|
+ * @return 用户邮箱
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Cacheable(cacheNames = CacheNames.SYS_EMAIL, key = "#userId")
|
|
|
|
|
+ public String selectEmailById(Long userId) {
|
|
|
|
|
+ SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
|
|
|
|
|
+ .select(SysUser::getEmail).eq(SysUser::getUserId, userId));
|
|
|
|
|
+ return ObjectUtil.isNull(sysUser) ? null : sysUser.getEmail();
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|