浏览代码

用户信息存redis

sangwenwei 1 年之前
父节点
当前提交
51d3f8a204

+ 13 - 1
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/controller/UserController.java

@@ -17,6 +17,7 @@ import com.google.gson.Gson;
 import com.jeeplus.aop.demo.annotation.DemoMode;
 import com.jeeplus.common.SecurityUtils;
 import com.jeeplus.common.TokenProvider;
+import com.jeeplus.common.constant.CacheNames;
 import com.jeeplus.common.constant.CommonConstants;
 import com.jeeplus.common.excel.ExcelOptions;
 import com.jeeplus.common.excel.annotation.ExportMode;
@@ -49,6 +50,7 @@ import org.springframework.web.multipart.MultipartFile;
 
 import javax.servlet.http.HttpServletResponse;
 import javax.validation.Valid;
+import javax.validation.constraints.NotNull;
 import java.io.IOException;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -228,7 +230,7 @@ public class UserController {
             queryWrapper.isNull("a.is_admin");
             if (ObjectUtil.isNotEmpty(userDTO)){
                 if (ObjectUtil.isNotEmpty(userDTO.getCompanyDTO()) && ObjectUtil.isNotEmpty(userDTO.getOfficeDTO())) {
-                    OfficeDTO officeDTO = UserUtils.getCurrentUserDTO().getOfficeDTO();
+                    String id = UserUtils.getCurrentUserDTO().getCompanyDTO().getId();
                     if (StringUtils.isNotBlank(userDTO.getCertType())) {
                         //获取当前登陆人是否事中审公司人员
                         /*if(officeDTO.getParentIds().contains("1615171302381182978")){
@@ -595,6 +597,16 @@ public class UserController {
     @ApiOperation(value = "导入用户excel")
     public ResponseEntity importFile(MultipartFile file) throws IOException {
         String result = UserEasyExcel.newInstance ( userService, UserWrapper.INSTANCE ).importExcel ( file, UserDTO.class );
+        List<UserDTO> allUserInfo = userService.getAllUserInfo();
+        if (redisUtils.hasKey("user:cache:user:all:info")){
+            //先清除redis中的数据
+            redisUtils.delete(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info");
+            //再次将人员信息存入到redis中
+            redisUtils.set(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info",allUserInfo);
+        }else {
+            //将人员信息存入到redis中
+            redisUtils.set(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info",allUserInfo);
+        }
         return ResponseEntity.ok ( result );
     }
 

+ 17 - 7
jeeplus-modules/jeeplus-system/src/main/java/com/jeeplus/sys/service/UserService.java

@@ -261,6 +261,8 @@ public class UserService extends ServiceImpl <UserMapper, User> {
      */
     public IPage <UserDTO> userFindPage(Page <UserDTO> page, QueryWrapper queryWrapper) {
         queryWrapper.eq ( "a.del_flag", CommonConstants.NOT_DELETED ); // 排除已经删除
+
+
         return baseMapper.userFindPage ( page, queryWrapper );
 
     }
@@ -337,12 +339,6 @@ public class UserService extends ServiceImpl <UserMapper, User> {
             user.setManageOfficeIds(userDTO.getManageOfficeIds());
         }
         super.saveOrUpdate ( user );
-        if ( StrUtil.isBlank ( userDTO.getId ( ) ) ) {
-            userDTO.setId ( user.getId ( ) );
-            userDTO.setName(user.getName());
-            users.add(userDTO);
-            redisUtils.append(CacheNames.USER_CACHE_USER_ALL_INFO, String.valueOf(users));
-        }
         // 更新用户与角色关联
         baseMapper.deleteUserRole ( userDTO.getId ( ) );
         if ( userDTO.getRoleDTOList ( ) != null ) {
@@ -360,6 +356,21 @@ public class UserService extends ServiceImpl <UserMapper, User> {
             } );
         }
         UserUtils.deleteCache ( userDTO );
+        //判断redis中是否有这个key
+        if (redisUtils.hasKey("user:cache:user:all:info")){
+            //先清除redis中的数据
+            redisUtils.delete(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info");
+            //获取全部的人员信息
+            List<UserDTO> allUserInfo = userMapper.getAllUserInfo();
+            //再次将人员信息存入到redis中
+            redisUtils.set(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info",allUserInfo);
+        }else {
+            //获取全部的人员信息
+            List<UserDTO> allUserInfo = userMapper.getAllUserInfo();
+            //再次将人员信息存入到redis中
+            redisUtils.set(CacheNames.USER_CACHE_USER_ALL_INFO,"user:cache:user:all:info",allUserInfo);
+        }
+
     }
 
 
@@ -554,7 +565,6 @@ public class UserService extends ServiceImpl <UserMapper, User> {
      */
     public List<UserDTO> getAllUserInfo() {
         List<UserDTO> allUserInfo = userMapper.getAllUserInfo();
-        RedisUtils.getInstance().set(CacheNames.USER_CACHE_USER_ALL_INFO,allUserInfo);
         return allUserInfo;
     }