| | |
| | | import com.ard.common.core.redis.RedisCache; |
| | | import com.ard.common.enums.BusinessType; |
| | | import com.ard.common.utils.StringUtils; |
| | | import com.ard.system.system.domain.SysUserOnline; |
| | | import com.ard.system.system.service.ISysUserOnlineService; |
| | | import com.ard.system.domain.SysUserOnline; |
| | | import com.ard.system.service.ISysUserOnlineService; |
| | | |
| | | /** |
| | | * 在线用户监控 |
| | | * |
| | | * @author ruoyi |
| | | * @author ard |
| | | */ |
| | | @RestController |
| | | @RequestMapping("/monitor/online") |
| | |
| | | private RedisCache redisCache; |
| | | |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(String ipaddr, String userName) |
| | | @GetMapping("/list1") |
| | | public TableDataInfo list1(String ipaddr, String userName) |
| | | { |
| | | Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> userOnlineList = new ArrayList<SysUserOnline>(); |
| | |
| | | userOnlineList.removeAll(Collections.singleton(null)); |
| | | return getDataTable(userOnlineList); |
| | | } |
| | | @PreAuthorize("@ss.hasPermi('monitor:online:list')") |
| | | @GetMapping("/list") |
| | | public TableDataInfo list(String ipaddr, String userName) |
| | | { |
| | | startPage(); // ❗ Ruoyi 分页 |
| | | |
| | | Collection<String> keys = redisCache.keys(CacheConstants.LOGIN_TOKEN_KEY + "*"); |
| | | List<SysUserOnline> resultList = new ArrayList<>(); |
| | | |
| | | boolean searchIp = StringUtils.isNotEmpty(ipaddr); |
| | | boolean searchName = StringUtils.isNotEmpty(userName); |
| | | |
| | | for (String key : keys) |
| | | { |
| | | LoginUser loginUser = redisCache.getCacheObject(key); |
| | | if (loginUser == null || loginUser.getUser() == null) |
| | | continue; |
| | | |
| | | // 转换成 SysUserOnline |
| | | SysUserOnline onlineUser = userOnlineService.loginUserToUserOnline(loginUser); |
| | | if (onlineUser == null) continue; |
| | | |
| | | boolean match = true; |
| | | |
| | | // ⭐ IP 模糊匹配 |
| | | if (searchIp) |
| | | { |
| | | String userIp = loginUser.getIpaddr(); |
| | | match = userIp != null && userIp.contains(ipaddr); |
| | | } |
| | | |
| | | // ⭐ 用户名模糊匹配 |
| | | if (match && searchName) |
| | | { |
| | | String nick = loginUser.getUsername(); |
| | | match = nick != null && nick.contains(userName); |
| | | } |
| | | |
| | | if (match) |
| | | resultList.add(onlineUser); |
| | | } |
| | | |
| | | Collections.reverse(resultList); |
| | | return getDataTable(resultList); |
| | | } |
| | | |
| | | /** |
| | | * 强退用户 |