!154 add 新增在线登录设备管理

* add 新增在线登录设备管理
2.X
AprilWind 10 months ago committed by 疯狂的狮子Li
parent 261a92e574
commit c57c3cf5ef

@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
/**
* 线
@ -86,4 +87,43 @@ public class SysUserOnlineController extends BaseController {
}
return R.ok();
}
/**
* 线
*/
@GetMapping()
public TableDataInfo<SysUserOnline> getInfo() {
// 获取指定账号 id 的 token 集合
List<String> tokenIds = StpUtil.getTokenValueListByLoginId(StpUtil.getLoginIdAsString());
List<SysUserOnline> userOnlineDTOList = tokenIds.stream()
.filter(token -> StpUtil.stpLogic.getTokenActiveTimeoutByToken(token) >= -1)
.map(token -> (SysUserOnline) RedisUtils.getCacheObject(CacheConstants.ONLINE_TOKEN_KEY + token))
.collect(Collectors.toList());
//复制和处理 SysUserOnline 对象列表
Collections.reverse(userOnlineDTOList);
userOnlineDTOList.removeAll(Collections.singleton(null));
List<SysUserOnline> userOnlineList = BeanUtil.copyToList(userOnlineDTOList, SysUserOnline.class);
return TableDataInfo.build(userOnlineList);
}
/**
* 退线
*
* @param tokenId token
*/
@Log(title = "在线设备", businessType = BusinessType.FORCE)
@PostMapping("/{tokenId}")
public R<Void> remove(@PathVariable("tokenId") String tokenId) {
try {
// 获取指定账号 id 的 token 集合
List<String> keys = StpUtil.getTokenValueListByLoginId(StpUtil.getLoginIdAsString());
keys.stream()
.filter(key -> key.equals(tokenId))
.findFirst()
.ifPresent(key -> StpUtil.kickoutByTokenValue(tokenId));
} catch (NotLoginException ignored) {
}
return R.ok();
}
}

Loading…
Cancel
Save