mirror of
https://github.com/continew-org/continew-admin.git
synced 2025-09-10 20:57:14 +08:00
feat: 在线用户增加最后活跃时间显示
This commit is contained in:
@@ -16,8 +16,11 @@
|
||||
|
||||
package top.continew.admin.auth.model.resp;
|
||||
|
||||
import cn.crane4j.annotation.Assemble;
|
||||
import cn.crane4j.annotation.Mapping;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.continew.starter.extension.crud.constant.ContainerPool;
|
||||
|
||||
import java.io.Serial;
|
||||
import java.io.Serializable;
|
||||
@@ -40,6 +43,7 @@ public class OnlineUserResp implements Serializable {
|
||||
* ID
|
||||
*/
|
||||
@Schema(description = "ID", example = "1")
|
||||
@Assemble(container = ContainerPool.USER_NICKNAME, props = @Mapping(ref = "nickname"))
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
@@ -89,4 +93,10 @@ public class OnlineUserResp implements Serializable {
|
||||
*/
|
||||
@Schema(description = "登录时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
private LocalDateTime loginTime;
|
||||
|
||||
/**
|
||||
* 最后活跃时间
|
||||
*/
|
||||
@Schema(description = "最后活跃时间", example = "2023-08-08 08:08:08", type = "string")
|
||||
private LocalDateTime lastActiveTime;
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package top.continew.admin.auth.service.impl;
|
||||
|
||||
import cn.crane4j.annotation.AutoOperate;
|
||||
import cn.dev33.satoken.dao.SaTokenDao;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
@@ -49,11 +50,17 @@ import java.util.List;
|
||||
public class OnlineUserServiceImpl implements OnlineUserService {
|
||||
|
||||
@Override
|
||||
@AutoOperate(type = OnlineUserResp.class, on = "list")
|
||||
public PageResp<OnlineUserResp> page(OnlineUserQuery query, PageQuery pageQuery) {
|
||||
List<LoginUser> loginUserList = this.list(query);
|
||||
List<OnlineUserResp> list = BeanUtil.copyToList(loginUserList, OnlineUserResp.class);
|
||||
PageResp<OnlineUserResp> pageResp = PageResp.build(pageQuery.getPage(), pageQuery.getSize(), list);
|
||||
pageResp.getList().forEach(u -> u.setNickname(LoginHelper.getNickname(u.getId())));
|
||||
pageResp.getList().forEach(u -> {
|
||||
long lastActiveTime = StpUtil.getStpLogic().getTokenLastActiveTime(u.getToken());
|
||||
if (SaTokenDao.NOT_VALUE_EXPIRE != lastActiveTime) {
|
||||
u.setLastActiveTime(DateUtil.toLocalDateTime(new Date(lastActiveTime)));
|
||||
}
|
||||
});
|
||||
return pageResp;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user