| | |
| | | import cn.dev33.satoken.stp.StpUtil; |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.Constants; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.core.controller.BaseController; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.domain.dto.UserOnlineDTO; |
| | | import com.ruoyi.common.core.page.TableDataInfo; |
| | | import com.ruoyi.common.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StreamUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.redis.RedisUtils; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * 在线用户监控 |
| | |
| | | List<String> keys = StpUtil.searchTokenValue("", -1, 0); |
| | | List<UserOnlineDTO> userOnlineDTOList = new ArrayList<>(); |
| | | for (String key : keys) { |
| | | String token = key.replace(Constants.LOGIN_TOKEN_KEY, ""); |
| | | String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, ""); |
| | | // 如果已经过期则踢下线 |
| | | if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < 0) { |
| | | continue; |
| | | } |
| | | userOnlineDTOList.add(RedisUtils.getCacheObject(Constants.ONLINE_TOKEN_KEY + token)); |
| | | userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token)); |
| | | } |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> |
| | | StringUtils.equals(ipaddr, userOnline.getIpaddr()) && |
| | | StringUtils.equals(userName, userOnline.getUserName()) |
| | | ).collect(Collectors.toList()); |
| | | ); |
| | | } else if (StringUtils.isNotEmpty(ipaddr)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | StringUtils.equals(ipaddr, userOnline.getIpaddr())) |
| | | .collect(Collectors.toList()); |
| | | userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> |
| | | StringUtils.equals(ipaddr, userOnline.getIpaddr()) |
| | | ); |
| | | } else if (StringUtils.isNotEmpty(userName)) { |
| | | userOnlineDTOList = userOnlineDTOList.stream().filter(userOnline -> |
| | | userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> |
| | | StringUtils.equals(userName, userOnline.getUserName()) |
| | | ).collect(Collectors.toList()); |
| | | ); |
| | | } |
| | | Collections.reverse(userOnlineDTOList); |
| | | userOnlineDTOList.removeAll(Collections.singleton(null)); |