From fa9d9dd92c40f027c1faf699b19aba4c2cea6aca Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 6 Dec 2021 20:33:15 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/rymcu/forest/dto/UserInfoDTO.java | 6 ++++++ .../com/rymcu/forest/mapper/UserMapper.java | 2 +- .../com/rymcu/forest/service/UserService.java | 2 +- .../forest/service/impl/UserServiceImpl.java | 17 +++++++++++++++-- .../forest/web/api/admin/AdminController.java | 9 +++------ src/main/java/mapper/UserMapper.xml | 3 ++- 6 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/rymcu/forest/dto/UserInfoDTO.java b/src/main/java/com/rymcu/forest/dto/UserInfoDTO.java index 84d3cdb..60ff5e3 100644 --- a/src/main/java/com/rymcu/forest/dto/UserInfoDTO.java +++ b/src/main/java/com/rymcu/forest/dto/UserInfoDTO.java @@ -3,6 +3,7 @@ package com.rymcu.forest.dto; import com.alibaba.fastjson.annotation.JSONField; import lombok.Data; +import javax.persistence.Column; import java.io.Serializable; import java.util.Date; @@ -40,4 +41,9 @@ public class UserInfoDTO implements Serializable { @JSONField(format = "yyyy-MM-dd HH:mm") private Date lastOnlineTime; + @JSONField(format = "yyyy-MM-dd HH:mm:ss") + private Date createdTime; + + private Integer onlineStatus; + } diff --git a/src/main/java/com/rymcu/forest/mapper/UserMapper.java b/src/main/java/com/rymcu/forest/mapper/UserMapper.java index f5e4948..851ed2a 100644 --- a/src/main/java/com/rymcu/forest/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/UserMapper.java @@ -145,7 +145,7 @@ public interface UserMapper extends Mapper { * @param searchDTO * @return */ - List selectUsers(@Param("searchDTO") UserSearchDTO searchDTO); + List selectUsers(@Param("searchDTO") UserSearchDTO searchDTO); /** * 更新用户最后在线时间 diff --git a/src/main/java/com/rymcu/forest/service/UserService.java b/src/main/java/com/rymcu/forest/service/UserService.java index c43623b..161669b 100644 --- a/src/main/java/com/rymcu/forest/service/UserService.java +++ b/src/main/java/com/rymcu/forest/service/UserService.java @@ -142,7 +142,7 @@ public interface UserService extends Service { * @param searchDTO * @return */ - List findUsers(UserSearchDTO searchDTO); + List findUsers(UserSearchDTO searchDTO); /** * 通过邮箱查询用户信息 diff --git a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java index 2febd6a..0084bd4 100644 --- a/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/UserServiceImpl.java @@ -6,6 +6,7 @@ import com.rymcu.forest.dto.*; import com.rymcu.forest.entity.Role; import com.rymcu.forest.entity.User; import com.rymcu.forest.entity.UserExtend; +import com.rymcu.forest.jwt.def.JwtConstants; import com.rymcu.forest.jwt.service.TokenManager; import com.rymcu.forest.lucene.model.UserLucene; import com.rymcu.forest.lucene.util.UserIndexUtil; @@ -282,8 +283,20 @@ public class UserServiceImpl extends AbstractService implements UserServic } @Override - public List findUsers(UserSearchDTO searchDTO) { - return userMapper.selectUsers(searchDTO); + public List findUsers(UserSearchDTO searchDTO) { + List users = userMapper.selectUsers(searchDTO); + users.forEach(user -> { + user.setOnlineStatus(getUserOnlineStatus(user.getEmail())); + }); + return users; + } + + private Integer getUserOnlineStatus(String email) { + String lastOnlineTime = redisService.get(JwtConstants.LAST_ONLINE + email); + if (StringUtils.isBlank(lastOnlineTime)) { + return 0; + } + return 1; } @Override diff --git a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java index 216ea56..b4a297a 100644 --- a/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java +++ b/src/main/java/com/rymcu/forest/web/api/admin/AdminController.java @@ -4,10 +4,7 @@ import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageInfo; import com.rymcu.forest.core.result.GlobalResult; import com.rymcu.forest.core.result.GlobalResultGenerator; -import com.rymcu.forest.dto.ArticleDTO; -import com.rymcu.forest.dto.ArticleSearchDTO; -import com.rymcu.forest.dto.CommentDTO; -import com.rymcu.forest.dto.UserSearchDTO; +import com.rymcu.forest.dto.*; import com.rymcu.forest.dto.admin.TopicTagDTO; import com.rymcu.forest.dto.admin.UserRoleDTO; import com.rymcu.forest.entity.*; @@ -47,8 +44,8 @@ public class AdminController { @GetMapping("/users") public GlobalResult> users(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, UserSearchDTO searchDTO){ PageHelper.startPage(page, rows); - List list = userService.findUsers(searchDTO); - PageInfo pageInfo = new PageInfo<>(list); + List list = userService.findUsers(searchDTO); + PageInfo pageInfo = new PageInfo<>(list); Map map = new HashMap(2); map.put("users", pageInfo.getList()); Map pagination = Utils.getPagination(pageInfo); diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index 3d36a53..52eba12 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -33,6 +33,7 @@ + @@ -105,7 +106,7 @@ - select id, nickname, sex, avatar_type, avatar_url, email, account, status, last_login_time, created_time, last_online_time from forest_user