Skip to content

Commit

Permalink
feat: 在线用户增加最后活跃时间显示
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed May 13, 2024
1 parent fac7c86 commit 926497a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

/**
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,11 +50,17 @@
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;
}

Expand Down

0 comments on commit 926497a

Please sign in to comment.