| | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import com.ruoyi.common.annotation.Log; |
| | | import com.ruoyi.common.constant.CacheConstants; |
| | | import com.ruoyi.common.constant.CacheNames; |
| | | 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.enums.BusinessType; |
| | | import com.ruoyi.common.utils.StreamUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.redis.RedisUtils; |
| | | import com.ruoyi.common.utils.redis.CacheUtils; |
| | | import com.ruoyi.system.domain.SysUserOnline; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.RequiredArgsConstructor; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | |
| | | * |
| | | * @author Lion Li |
| | | */ |
| | | @Tag(name = "在线用户监控", description = "在线用户监控管理") |
| | | @RequiredArgsConstructor |
| | | @RestController |
| | | @RequestMapping("/monitor/online") |
| | |
| | | List<UserOnlineDTO> userOnlineDTOList = new ArrayList<>(); |
| | | for (String key : keys) { |
| | | String token = key.replace(CacheConstants.LOGIN_TOKEN_KEY, ""); |
| | | // 如果已经过期则踢下线 |
| | | // 如果已经过期则跳过 |
| | | if (StpUtil.stpLogic.getTokenActivityTimeoutByToken(token) < 0) { |
| | | continue; |
| | | } |
| | | userOnlineDTOList.add(RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token)); |
| | | UserOnlineDTO dto = CacheUtils.get(CacheNames.ONLINE_TOKEN, token); |
| | | userOnlineDTOList.add(dto); |
| | | } |
| | | if (StringUtils.isNotEmpty(ipaddr) && StringUtils.isNotEmpty(userName)) { |
| | | userOnlineDTOList = StreamUtils.filter(userOnlineDTOList, userOnline -> |