From ba8b1496ba9881719e522d0a60a8c86baa7be08b Mon Sep 17 00:00:00 2001
From: liusuyi <1951119284@qq.com>
Date: Sat, 20 Dec 2025 10:34:23 +0800
Subject: [PATCH] 优化飞行状态

---
 ard-admin/src/main/java/com/ard/web/controller/monitor/SysUserOnlineController.java |   55 ++++++++++++++++++++++++++-----------------------------
 1 files changed, 26 insertions(+), 29 deletions(-)

diff --git a/ard-admin/src/main/java/com/ard/web/controller/monitor/SysUserOnlineController.java b/ard-admin/src/main/java/com/ard/web/controller/monitor/SysUserOnlineController.java
index 1cc4a66..3f17016 100644
--- a/ard-admin/src/main/java/com/ard/web/controller/monitor/SysUserOnlineController.java
+++ b/ard-admin/src/main/java/com/ard/web/controller/monitor/SysUserOnlineController.java
@@ -4,6 +4,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
+
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -25,13 +26,12 @@
 
 /**
  * 在线用户监控
- * 
+ *
  * @author ard
  */
 @RestController
 @RequestMapping("/monitor/online")
-public class SysUserOnlineController extends BaseController
-{
+public class SysUserOnlineController extends BaseController {
     @Autowired
     private ISysUserOnlineService userOnlineService;
 
@@ -40,27 +40,18 @@
 
     @PreAuthorize("@ss.hasPermi('monitor:online:list')")
     @GetMapping("/list1")
-    public TableDataInfo list1(String ipaddr, String userName)
-    {
+    public TableDataInfo list1(String ipaddr, String userName) {
         Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
         List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>();
-        for (String key : keys)
-        {
+        for (String key : keys) {
             LoginUser user = redisCache.getCacheObject(key);
-            if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName))
-            {
+            if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) {
                 userOnlineList.add(userOnlineService.selectOnlineByInfo(ipaddr, userName, user));
-            }
-            else if (StringUtils.isNotEmpty(ipaddr))
-            {
+            } else if (StringUtils.isNotEmpty(ipaddr)) {
                 userOnlineList.add(userOnlineService.selectOnlineByIpaddr(ipaddr, user));
-            }
-            else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser()))
-            {
+            } else if (StringUtils.isNotEmpty(userName) && StringUtils.isNotNull(user.getUser())) {
                 userOnlineList.add(userOnlineService.selectOnlineByUserName(userName, user));
-            }
-            else
-            {
+            } else {
                 userOnlineList.add(userOnlineService.loginUserToUserOnline(user));
             }
         }
@@ -68,10 +59,10 @@
         userOnlineList.removeAll(Collections.singleton(null));
         return getDataTable(userOnlineList);
     }
+
     @PreAuthorize("@ss.hasPermi('monitor:online:list')")
     @GetMapping("/list")
-    public TableDataInfo list(String ipaddr, String userName)
-    {
+    public TableDataInfo list(String ipaddr, String userName) {
         startPage();  // ❗ Ruoyi 分页
 
         Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
@@ -80,8 +71,7 @@
         boolean searchIp = StringUtils.isNotEmpty(ipaddr);
         boolean searchName = StringUtils.isNotEmpty(userName);
 
-        for (String key : keys)
-        {
+        for (String key : keys) {
             LoginUser loginUser = redisCache.getCacheObject(key);
             if (loginUser == null || loginUser.getUser() == null)
                 continue;
@@ -93,15 +83,13 @@
             boolean match = true;
 
             // ⭐ IP 模糊匹配
-            if (searchIp)
-            {
+            if (searchIp) {
                 String userIp = loginUser.getIpaddr();
                 match = userIp != null && userIp.contains(ipaddr);
             }
 
             // ⭐ 用户名模糊匹配
-            if (match && searchName)
-            {
+            if (match && searchName) {
                 String nick = loginUser.getUsername();
                 match = nick != null && nick.contains(userName);
             }
@@ -120,9 +108,18 @@
     @PreAuthorize("@ss.hasPermi('monitor:online:forceLogout')")
     @Log(title = "在线用户", businessType = BusinessType.FORCE)
     @DeleteMapping("/{tokenId}")
-    public AjaxResult forceLogout(@PathVariable String tokenId)
-    {
-        redisCache.deleteObject(CacheConstants.LOGIN_TOKEN_KEY + tokenId);
+    public AjaxResult forceLogout(@PathVariable String tokenId) {
+        String tokenKey = CacheConstants.LOGIN_TOKEN_KEY + tokenId;
+
+        LoginUser loginUser = redisCache.getCacheObject(tokenKey);
+
+        if (loginUser != null && loginUser.getUser() != null) {
+            Long userId = loginUser.getUser().getUserId();
+            redisCache.deleteObject(CacheConstants.LOGIN_USERID_KEY + userId);
+        }
+
+        redisCache.deleteObject(tokenKey);
+
         return success();
     }
 }

--
Gitblit v1.9.3