wangliang 3 lat temu
rodzic
commit
ab7ff031b0

+ 1 - 1
distributed-print/src/main/java/com/qmth/distributed/print/api/SysController.java

@@ -170,7 +170,7 @@ public class SysController {
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
     @ApiResponses({@ApiResponse(code = 200, message = "返回信息", response = EditResult.class)})
     public Result logout() throws NoSuchAlgorithmException {
     public Result logout() throws NoSuchAlgorithmException {
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
         SysUser sysUser = (SysUser) ServletUtil.getRequestUser();
-        teachcloudCommonService.removeUserInfo(sysUser.getId());
+        teachcloudCommonService.removeUserInfo(sysUser.getId(), false);
         return ResultUtil.ok();
         return ResultUtil.ok();
     }
     }
 
 

+ 2 - 1
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/TeachcloudCommonService.java

@@ -90,8 +90,9 @@ public interface TeachcloudCommonService {
      * 删除用户信息
      * 删除用户信息
      *
      *
      * @param userId
      * @param userId
+     * @param all
      */
      */
-    public void removeUserInfo(Long userId) throws NoSuchAlgorithmException;
+    public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException;
 
 
     /**
     /**
      * 修改角色状态
      * 修改角色状态

+ 2 - 2
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysRoleServiceImpl.java

@@ -146,7 +146,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
                     //绑定该角色的用户都需要清除鉴权缓存
                     //绑定该角色的用户都需要清除鉴权缓存
                     List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
                     List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
                     for (SysUserRole s : sysUserRoleList) {
                     for (SysUserRole s : sysUserRoleList) {
-                        commonService.removeUserInfo(s.getUserId());
+                        commonService.removeUserInfo(s.getUserId(), true);
                     }
                     }
                 }
                 }
             } else {
             } else {
@@ -178,7 +178,7 @@ public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> impl
         if (!role.getEnable()) {
         if (!role.getEnable()) {
             List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
             List<SysUserRole> sysUserRoleList = sysUserRoleService.listByRoleId(role.getId());
             for (SysUserRole s : sysUserRoleList) {
             for (SysUserRole s : sysUserRoleList) {
-                commonService.removeUserInfo(s.getUserId());
+                commonService.removeUserInfo(s.getUserId(), true);
             }
             }
         }
         }
         return true;
         return true;

+ 5 - 5
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/SysUserServiceImpl.java

@@ -105,7 +105,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         boolean success = this.update(updateWrapper);
         boolean success = this.update(updateWrapper);
         //如果状态为禁用,需要踢下线重新登录
         //如果状态为禁用,需要踢下线重新登录
         if (!user.getEnable()) {
         if (!user.getEnable()) {
-            commonService.removeUserInfo(user.getId());
+            commonService.removeUserInfo(user.getId(), true);
         }
         }
         return success;
         return success;
     }
     }
@@ -121,7 +121,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
 
         //如果原密码和旧密码不一致,需要重新登录
         //如果原密码和旧密码不一致,需要重新登录
         if (!Objects.equals(user.getPassword(), oldPassword)) {
         if (!Objects.equals(user.getPassword(), oldPassword)) {
-            commonService.removeUserInfo(user.getId());
+            commonService.removeUserInfo(user.getId(), false);
         }
         }
         return this.updateById(user);
         return this.updateById(user);
     }
     }
@@ -141,7 +141,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
         boolean success = this.updateById(sysUser);
         boolean success = this.updateById(sysUser);
         //如果原密码和旧密码不一致,需要重新登录
         //如果原密码和旧密码不一致,需要重新登录
         if (!Objects.equals(user.getOldPassword(), sysUser.getPassword())) {
         if (!Objects.equals(user.getOldPassword(), sysUser.getPassword())) {
-            commonService.removeUserInfo(sysUser.getId());
+            commonService.removeUserInfo(sysUser.getId(), false);
         }
         }
         return success;
         return success;
     }
     }
@@ -293,7 +293,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
 
 
                     cacheService.removeUserRolePrivilegeCache(sysUser.getId());
                     cacheService.removeUserRolePrivilegeCache(sysUser.getId());
                     commonService.addUserRolePrivilege(sysUser, userSaveParams.getRoleIds());
                     commonService.addUserRolePrivilege(sysUser, userSaveParams.getRoleIds());
-                    commonService.removeUserInfo(sysUser.getId());
+                    commonService.removeUserInfo(sysUser.getId(), true);
                 }
                 }
                 //如果修改了机构或手机号,需更新用户缓存
                 //如果修改了机构或手机号,需更新用户缓存
                 if (Objects.nonNull(dbUser.getOrgId())) {
                 if (Objects.nonNull(dbUser.getOrgId())) {
@@ -396,7 +396,7 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
                 }
                 }
                 //如果修改了角色,需要重新登录
                 //如果修改了角色,需要重新登录
                 if (count == 0 || dbUserRolesList.size() != userRolesList.size()) {
                 if (count == 0 || dbUserRolesList.size() != userRolesList.size()) {
-                    commonService.removeUserInfo(sysUser.getId());
+                    commonService.removeUserInfo(sysUser.getId(), true);
                 }
                 }
                 //如果修改了机构或手机号,需更新用户缓存
                 //如果修改了机构或手机号,需更新用户缓存
                 if (Objects.nonNull(dbUser.getOrgId())) {
                 if (Objects.nonNull(dbUser.getOrgId())) {

+ 13 - 6
teachcloud-common/src/main/java/com/qmth/teachcloud/common/service/impl/TeachcloudCommonServiceImpl.java

@@ -291,18 +291,25 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
      * 删除用户信息
      * 删除用户信息
      *
      *
      * @param userId
      * @param userId
+     * @param all
      */
      */
     @Override
     @Override
-    public void removeUserInfo(Long userId) throws NoSuchAlgorithmException {
+    public void removeUserInfo(Long userId, boolean all) throws NoSuchAlgorithmException {
         AuthBean authBean = cacheService.userAuthCache(userId);
         AuthBean authBean = cacheService.userAuthCache(userId);
         if (Objects.isNull(authBean)) {
         if (Objects.isNull(authBean)) {
             throw ExceptionResultEnum.NOT_LOGIN.exception();
             throw ExceptionResultEnum.NOT_LOGIN.exception();
         }
         }
-        for (Platform p : Platform.values()) {
-            Set<String> roleNames = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
-            String sessionId = SessionUtil.digest(userId, Math.abs(roleNames.toString().hashCode()), p.name());
-            tbSessionService.removeById(sessionId);
-            redisUtil.deleteUserSession(sessionId);
+        if (all) {
+            for (Platform p : Platform.values()) {
+                Set<String> roleNames = authBean.getRoleList().stream().map(s -> s.getName()).collect(Collectors.toSet());
+                String sessionId = SessionUtil.digest(userId, Math.abs(roleNames.toString().hashCode()), p.name());
+                tbSessionService.removeById(sessionId);
+                redisUtil.deleteUserSession(sessionId);
+            }
+        } else {
+            TBSession tbSession = (TBSession) ServletUtil.getRequestSession();
+            tbSessionService.removeById(tbSession.getId());
+            redisUtil.deleteUserSession(tbSession.getId());
         }
         }
         cacheService.removeUserCache(userId);
         cacheService.removeUserCache(userId);
         cacheService.removeUserAuthCache(userId);
         cacheService.removeUserAuthCache(userId);