From 34e7c3f02685993f356a7779b7f5c3d2ae5f505a Mon Sep 17 00:00:00 2001 From: peihongwei Date: Tue, 5 Jan 2021 18:09:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8=E7=BA=BF=E7=94=A8=E6=88=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../roses/kernel/auth/api/SessionManagerApi.java | 8 ++++++++ .../kernel/auth/session/DefaultSessionManager.java | 7 +++++++ .../stylefeng/roses/kernel/system/UserServiceApi.java | 7 +++++++ .../modular/user/controller/SysUserController.java | 11 +++++++++++ .../modular/user/service/impl/SysUserServiceImpl.java | 9 +++++++++ 5 files changed, 42 insertions(+) diff --git a/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/SessionManagerApi.java b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/SessionManagerApi.java index cbc140b73..342805a32 100644 --- a/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/SessionManagerApi.java +++ b/kernel-d-auth/auth-api/src/main/java/cn/stylefeng/roses/kernel/auth/api/SessionManagerApi.java @@ -2,6 +2,8 @@ package cn.stylefeng.roses.kernel.auth.api; import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; +import java.util.List; + /** * 用户会话管理 *

@@ -83,4 +85,10 @@ public interface SessionManagerApi { */ void destroySessionCookie(); + /** + * 获取在线用户列表 + * @return + */ + List onlineUserList(); + } diff --git a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/DefaultSessionManager.java b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/DefaultSessionManager.java index 89b8c527d..39675bb4a 100644 --- a/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/DefaultSessionManager.java +++ b/kernel-d-auth/auth-sdk/src/main/java/cn/stylefeng/roses/kernel/auth/session/DefaultSessionManager.java @@ -10,7 +10,10 @@ import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletResponse; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; +import java.util.List; import java.util.Set; /** @@ -166,4 +169,8 @@ public class DefaultSessionManager implements SessionManagerApi { } } + @Override + public List onlineUserList() { + return new ArrayList<>(loginUserCache.getAllValues()); + } } diff --git a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/UserServiceApi.java b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/UserServiceApi.java index ea878834b..7db22b30c 100644 --- a/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/UserServiceApi.java +++ b/kernel-s-system/system-api/src/main/java/cn/stylefeng/roses/kernel/system/UserServiceApi.java @@ -1,5 +1,6 @@ package cn.stylefeng.roses.kernel.system; +import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser; import cn.stylefeng.roses.kernel.system.pojo.user.UserLoginInfoDTO; import java.util.Date; @@ -73,4 +74,10 @@ public interface UserServiceApi { */ List getUserBindDataScope(Long userId); + /** + * 获取在线用户列表 + * @return + */ + List onlineUserList(); + } diff --git a/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/controller/SysUserController.java b/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/controller/SysUserController.java index e6c55e5c5..e40e1c5d6 100644 --- a/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/controller/SysUserController.java +++ b/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/controller/SysUserController.java @@ -240,4 +240,15 @@ public class SysUserController { return new SuccessResponseData(sysUserService.detail(sysUserRequest)); } + /** + * 当前在线用户列表 + * + * @author fengshuonan + * @date 2021/1/1 19:01 + */ + @GetResource(name = "当前在线用户列表", path = "/sysUser/onlineUserList", requiredPermission = false) + public ResponseData onlineUserList() { + return new SuccessResponseData(sysUserService.onlineUserList()); + } + } diff --git a/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/service/impl/SysUserServiceImpl.java b/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/service/impl/SysUserServiceImpl.java index 4947dbb39..cfa796066 100644 --- a/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/service/impl/SysUserServiceImpl.java +++ b/kernel-s-system/system-business-user/src/main/java/cn/stylefeng/roses/kernel/system/modular/user/service/impl/SysUserServiceImpl.java @@ -2,6 +2,7 @@ package cn.stylefeng.roses.kernel.system.modular.user.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.util.ObjectUtil; +import cn.stylefeng.roses.kernel.auth.api.SessionManagerApi; import cn.stylefeng.roses.kernel.auth.api.context.LoginContext; import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander; import cn.stylefeng.roses.kernel.auth.api.password.PasswordStoredEncryptApi; @@ -91,6 +92,9 @@ public class SysUserServiceImpl extends ServiceImpl impl @Resource private PasswordStoredEncryptApi passwordStoredEncryptApi; + @Resource + private SessionManagerApi sessionManagerApi; + @Override @Transactional(rollbackFor = Exception.class) public void add(SysUserRequest sysUserRequest) { @@ -451,6 +455,11 @@ public class SysUserServiceImpl extends ServiceImpl impl return sysUserDataScopeService.getUserDataScopeIdList(userId); } + @Override + public List onlineUserList() { + return sessionManagerApi.onlineUserList(); + } + /** * 获取系统用户 *