diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ISysUserOnlineService.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ISysUserOnlineService.java deleted file mode 100644 index 8eb5448cd..000000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/ISysUserOnlineService.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.ruoyi.system.service; - -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.system.domain.SysUserOnline; - -/** - * 在线用户 服务层 - * - * @author ruoyi - */ -public interface ISysUserOnlineService -{ - /** - * 通过登录地址查询信息 - * - * @param ipaddr 登录地址 - * @param user 用户信息 - * @return 在线用户信息 - */ - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user); - - /** - * 通过用户名称查询信息 - * - * @param userName 用户名称 - * @param user 用户信息 - * @return 在线用户信息 - */ - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user); - - /** - * 通过登录地址/用户名称查询信息 - * - * @param ipaddr 登录地址 - * @param userName 用户名称 - * @param user 用户信息 - * @return 在线用户信息 - */ - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user); - - /** - * 设置在线用户信息 - * - * @param user 用户信息 - * @return 在线用户 - */ - public SysUserOnline loginUserToUserOnline(LoginUser user); -} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnline.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnline.java deleted file mode 100644 index 86bbb2daf..000000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnline.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.ruoyi.system.domain; - -/** - * 当前在线会话 - * - * @author ruoyi - */ -public class SysUserOnline { - /** - * 会话编号 - */ - private String tokenId; - - /** - * 部门名称 - */ - private String deptName; - - /** - * 用户名称 - */ - private String userName; - - /** - * 登录IP地址 - */ - private String ipaddr; - - /** - * 登录地址 - */ - private String loginLocation; - - /** - * 浏览器类型 - */ - private String browser; - - /** - * 操作系统 - */ - private String os; - - /** - * 登录时间 - */ - private Long loginTime; - -} diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineServiceImpl.java deleted file mode 100644 index f0a299826..000000000 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/monitor/SysUserOnlineServiceImpl.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.ruoyi.system.service.impl; - -import org.springframework.stereotype.Service; -import com.ruoyi.common.core.domain.model.LoginUser; -import com.ruoyi.common.utils.StringUtils; -import com.ruoyi.system.domain.SysUserOnline; -import com.ruoyi.system.service.ISysUserOnlineService; - -/** - * 在线用户 服务层处理 - * - * @author ruoyi - */ -@Service -public class SysUserOnlineServiceImpl implements ISysUserOnlineService { - /** - * 通过登录地址查询信息 - * - * @param ipaddr 登录地址 - * @param user 用户信息 - * @return 在线用户信息 - */ - @Override - public SysUserOnline selectOnlineByIpaddr(String ipaddr, LoginUser user) { - if (StringUtils.equals(ipaddr, user.getIpaddr())) { - return loginUserToUserOnline(user); - } - return null; - } - - /** - * 通过用户名称查询信息 - * - * @param userName 用户名称 - * @param user 用户信息 - * @return 在线用户信息 - */ - @Override - public SysUserOnline selectOnlineByUserName(String userName, LoginUser user) { - if (StringUtils.equals(userName, user.getUsername())) { - return loginUserToUserOnline(user); - } - return null; - } - - /** - * 通过登录地址/用户名称查询信息 - * - * @param ipaddr 登录地址 - * @param userName 用户名称 - * @param user 用户信息 - * @return 在线用户信息 - */ - @Override - public SysUserOnline selectOnlineByInfo(String ipaddr, String userName, LoginUser user) { - if (StringUtils.equals(ipaddr, user.getIpaddr()) && StringUtils.equals(userName, user.getUsername())) { - return loginUserToUserOnline(user); - } - return null; - } - - /** - * 设置在线用户信息 - * - * @param user 用户信息 - * @return 在线用户 - */ - @Override - public SysUserOnline loginUserToUserOnline(LoginUser user) { - if (StringUtils.isNull(user) || StringUtils.isNull(user.getUser())) { - return null; - } - SysUserOnline sysUserOnline = new SysUserOnline(); - sysUserOnline.setTokenId(user.getToken()); - sysUserOnline.setUserName(user.getUsername()); - sysUserOnline.setIpaddr(user.getIpaddr()); - sysUserOnline.setLoginLocation(user.getLoginLocation()); - sysUserOnline.setBrowser(user.getBrowser()); - sysUserOnline.setOs(user.getOs()); - sysUserOnline.setLoginTime(user.getLoginTime()); - if (StringUtils.isNotNull(user.getUser().getDept())) { - sysUserOnline.setDeptName(user.getUser().getDept().getDeptName()); - } - return sysUserOnline; - } -} diff --git a/ruoyi-admin/src/main/resources/application.yml b/ruoyi-admin/src/main/resources/application.yml index 8bc9dd382..afb292bcf 100644 --- a/ruoyi-admin/src/main/resources/application.yml +++ b/ruoyi-admin/src/main/resources/application.yml @@ -47,28 +47,6 @@ spring: restart: # 热部署开关 enabled: true - # redis 配置 - redis: - # 地址 - host: 127.0.0.1 - # 端口,默认为6379 - port: 6379 - # 数据库索引 - database: 0 - # 密码 - password: - # 连接超时时间 - timeout: 10s - lettuce: - pool: - # 连接池中的最小空闲连接 - min-idle: 0 - # 连接池中的最大空闲连接 - max-idle: 8 - # 连接池的最大数据库连接数 - max-active: 8 - # #连接池最大阻塞等待时间(使用负值表示没有限制) - max-wait: -1ms # 防止XSS攻击 xss: diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysAuthController.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysAuthController.java index bc986410b..71810f447 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysAuthController.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/SysAuthController.java @@ -3,10 +3,10 @@ package cn.iocoder.dashboard.modules.system.controller.auth; import cn.iocoder.dashboard.common.enums.CommonStatusEnum; import cn.iocoder.dashboard.common.pojo.CommonResult; import cn.iocoder.dashboard.framework.logger.operatelog.core.annotations.OperateLog; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginReqVO; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthLoginRespVO; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthLoginReqVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthLoginRespVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO; import cn.iocoder.dashboard.modules.system.convert.auth.SysAuthConvert; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java similarity index 95% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginReqVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java index af9753534..e3842acd7 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginReqVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginReqVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.controller.auth.vo; +package cn.iocoder.dashboard.modules.system.controller.auth.vo.auth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java similarity index 86% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginRespVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java index 5a1caeb6e..47e0872aa 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthLoginRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthLoginRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.controller.auth.vo; +package cn.iocoder.dashboard.modules.system.controller.auth.vo.auth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthMenuRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java similarity index 94% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthMenuRespVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java index 140c5b07a..28eadb40c 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthMenuRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthMenuRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.controller.auth.vo; +package cn.iocoder.dashboard.modules.system.controller.auth.vo.auth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthPermissionInfoRespVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java similarity index 94% rename from src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthPermissionInfoRespVO.java rename to src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java index c8594c446..c4cfa8bb0 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/SysAuthPermissionInfoRespVO.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/auth/SysAuthPermissionInfoRespVO.java @@ -1,4 +1,4 @@ -package cn.iocoder.dashboard.modules.system.controller.auth.vo; +package cn.iocoder.dashboard.modules.system.controller.auth.vo.auth; import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModelProperty; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/session/SysUserSessionPageReqVO.java b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/session/SysUserSessionPageReqVO.java new file mode 100644 index 000000000..e91198877 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/controller/auth/vo/session/SysUserSessionPageReqVO.java @@ -0,0 +1,12 @@ +package cn.iocoder.dashboard.modules.system.controller.auth.vo.session; + +import cn.iocoder.dashboard.common.pojo.PageParam; +import io.swagger.annotations.ApiModel; +import lombok.Data; +import lombok.EqualsAndHashCode; + +@ApiModel("在线用户 Session 分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +public class SysUserSessionPageReqVO extends PageParam { +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/convert/auth/SysAuthConvert.java b/src/main/java/cn/iocoder/dashboard/modules/system/convert/auth/SysAuthConvert.java index 6de7458c2..d36a37828 100644 --- a/src/main/java/cn/iocoder/dashboard/modules/system/convert/auth/SysAuthConvert.java +++ b/src/main/java/cn/iocoder/dashboard/modules/system/convert/auth/SysAuthConvert.java @@ -1,8 +1,8 @@ package cn.iocoder.dashboard.modules.system.convert.auth; import cn.iocoder.dashboard.framework.security.core.LoginUser; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthMenuRespVO; -import cn.iocoder.dashboard.modules.system.controller.auth.vo.SysAuthPermissionInfoRespVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthMenuRespVO; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.auth.SysAuthPermissionInfoRespVO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysMenuDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.permission.SysRoleDO; import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/auth/SysUserOnlineMapper.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/auth/SysUserOnlineMapper.java new file mode 100644 index 000000000..fdc317a39 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dao/auth/SysUserOnlineMapper.java @@ -0,0 +1,7 @@ +package cn.iocoder.dashboard.modules.system.dal.mysql.dao.auth; + +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.auth.SysUserSessionDO; +import com.baomidou.mybatisplus.core.mapper.BaseMapper; + +public interface SysUserOnlineMapper extends BaseMapper { +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/auth/SysUserSessionDO.java b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/auth/SysUserSessionDO.java new file mode 100644 index 000000000..3964ef9c6 --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/dal/mysql/dataobject/auth/SysUserSessionDO.java @@ -0,0 +1,38 @@ +package cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.auth; + +import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.user.SysUserDO; +import com.baomidou.mybatisplus.annotation.TableId; +import com.baomidou.mybatisplus.annotation.TableName; +import lombok.Data; +import lombok.EqualsAndHashCode; + +/** + * 在线用户表 + */ +@TableName(value = "sys_user_session", autoResultMap = true) +@Data +@EqualsAndHashCode(callSuper = true) +public class SysUserSessionDO extends BaseDO { + + /** + * 会话编号, 即 sessionId + */ + @TableId + private String id; + /** + * 用户编号 + * + * 外键 {@link SysUserDO#getId()} + */ + private Long userId; + /** + * 用户 IP + */ + private String userIp; + /** + * 浏览器 UA + */ + private String userAgent; + +} diff --git a/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserOnlineService.java b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserOnlineService.java new file mode 100644 index 000000000..62198809a --- /dev/null +++ b/src/main/java/cn/iocoder/dashboard/modules/system/service/auth/SysUserOnlineService.java @@ -0,0 +1,40 @@ +package cn.iocoder.dashboard.modules.system.service.auth; + +import cn.iocoder.dashboard.common.pojo.PageResult; +import cn.iocoder.dashboard.modules.system.controller.auth.vo.session.SysUserSessionPageReqVO; +import cn.iocoder.dashboard.modules.system.dal.mysql.dataobject.auth.SysUserSessionDO; + +import java.util.Date; + +/** + * 在线用户 Session Service 接口 + */ +public interface SysUserOnlineService { + + /** + * 创建在线用户 Session + * + * @param sessionId Session 编号 + * @param userId 用户编号 + * @param userIp 用户 IP + * @param userAgent 用户 UA + */ + void createUserOnline(String sessionId, Long userId, String userIp, String userAgent); + + /** + * 更新在线用户 Session 的更新时间 + * + * @param sessionId Session 编号 + * @param updateTime 更新时间 + */ + void updateUserOnlineUpdateTime(String sessionId, Date updateTime); + + /** + * 获得在线用户分页列表 + * + * @param reqVO 分页条件 + * @return 份额与列表 + */ + PageResult getUserSessionPage(SysUserSessionPageReqVO reqVO); + +}