|
|
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.google.common.collect.Lists;
|
|
|
+import com.xunmei.common.core.constant.CacheConstants;
|
|
|
import com.xunmei.common.core.constant.UserConstants;
|
|
|
import com.xunmei.common.core.domain.OrgTreeReq;
|
|
|
import com.xunmei.common.core.domain.OrgTreeResp;
|
|
|
@@ -22,6 +23,7 @@ import com.xunmei.common.core.utils.StringUtils;
|
|
|
import com.xunmei.common.core.utils.bean.BeanValidators;
|
|
|
import com.xunmei.common.core.web.page.TableDataInfo;
|
|
|
import com.xunmei.common.datascope.annotation.DataScope;
|
|
|
+import com.xunmei.common.redis.utils.RedisUtils;
|
|
|
import com.xunmei.common.security.utils.SecurityUtils;
|
|
|
import com.xunmei.system.api.domain.SysOrg;
|
|
|
import com.xunmei.system.api.domain.SysRole;
|
|
|
@@ -40,6 +42,7 @@ import com.xunmei.system.util.SecurityUserExport;
|
|
|
import com.xunmei.system.util.UserExport;
|
|
|
import com.xunmei.system.util.UserImport;
|
|
|
import com.xunmei.system.util.UserImportErrorMsg;
|
|
|
+import org.redisson.api.redisnode.RedisSingle;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@@ -52,6 +55,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
import javax.validation.Validator;
|
|
|
import java.net.URLEncoder;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.LocalDate;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.temporal.ChronoUnit;
|
|
|
@@ -256,7 +260,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public SysUser selectUserByUserName(String userName) {
|
|
|
- return userMapper.selectOne(new QueryWrapper<SysUser>().eq("username", userName).eq("deleted", 0));
|
|
|
+ String cacheKey= CacheConstants.USER_CACHE_SINGLE_KEY+userName;
|
|
|
+ if(RedisUtils.hasKey(cacheKey))
|
|
|
+ {
|
|
|
+ return RedisUtils.getCacheObject(cacheKey);
|
|
|
+ }
|
|
|
+ SysUser user = userMapper.selectOne(new QueryWrapper<SysUser>().eq("username", userName).eq("deleted", 0));
|
|
|
+ RedisUtils.setCacheObject(cacheKey,user, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -267,7 +278,14 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
*/
|
|
|
@Override
|
|
|
public SysUser selectUserById(Long userId) {
|
|
|
- return userMapper.selectById(userId);
|
|
|
+ String cacheKey= CacheConstants.USER_CACHE_SINGLE_KEY+userId.toString();
|
|
|
+ if(RedisUtils.hasKey(cacheKey))
|
|
|
+ {
|
|
|
+ return RedisUtils.getCacheObject(cacheKey);
|
|
|
+ }
|
|
|
+ SysUser user = userMapper.selectById(userId);
|
|
|
+ RedisUtils.setCacheObject(cacheKey,user, Duration.ofSeconds(CacheConstants.ORG_USER_EXPIRATION_TIME));
|
|
|
+ return user;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -666,7 +684,24 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
@Override
|
|
|
@Async
|
|
|
public void batchSaveOrUpdate(List<SysUser> sysUserList) {
|
|
|
- saveOrUpdateBatch(sysUserList);
|
|
|
+ if(ObjectUtil.isEmpty(sysUserList))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ // 同步人员数据较多25000条左右,直接一次保存事务和持锁时间较长容易锁表;改为500条一次
|
|
|
+ int batchSize = 500;
|
|
|
+ for (int i = 0; i < sysUserList.size(); i += batchSize) {
|
|
|
+ try{
|
|
|
+ int toIndex = Math.min(i + batchSize, sysUserList.size());
|
|
|
+ List<SysUser> subList = sysUserList.subList(i, toIndex);
|
|
|
+ saveOrUpdateBatch(subList);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ log.error("同步人员批量保存 batchSaveOrUpdate ,失败原因:{}", ex.getMessage()+ex.getStackTrace());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.clearUserCache();
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -1020,6 +1055,33 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|
|
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void clearUserCache() {
|
|
|
+ RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
|
|
|
+ RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_ID_KEY);
|
|
|
+ RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY);
|
|
|
+ RedisUtils.deleteByPrefix(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clearUserCacheByUserId(Long userId) {
|
|
|
+ RedisUtils.deleteObject(CacheConstants.USER_CACHE_SINGLE_KEY+userId.toString());
|
|
|
+ RedisUtils.deleteObject(CacheConstants.USER_CACHE_ROLE_ID_KEY+userId.toString());
|
|
|
+ RedisUtils.deleteObject(CacheConstants.USER_CACHE_ROLE_OBJECT_KEY+userId.toString());
|
|
|
+ RedisUtils.deleteObject(CacheConstants.USER_ROLE_PERMISSION_CACHE_KEY+userId.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void clearUserCacheByUserName(String userName) {
|
|
|
+ if(StringUtils.isEmpty(userName))
|
|
|
+ {
|
|
|
+ RedisUtils.deleteByPrefix(CacheConstants.USER_CACHE_SINGLE_KEY);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ RedisUtils.deleteObject(CacheConstants.USER_CACHE_SINGLE_KEY+userName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private void saveUserRole(Long userId, List<Long> roleIdList) {
|
|
|
List<SysUserRole> list = new ArrayList<>();
|
|
|
for (Long roleId : roleIdList) {
|