diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java index c284e3df..edb12c92 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/EmailAuthStrategy.java @@ -60,6 +60,8 @@ public class EmailAuthStrategy implements IAuthStrategy { loginService.checkLogin(LoginType.EMAIL, tenantId, user.getUserName(), () -> !validateEmailCode(tenantId, email, emailCode)); // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 LoginUser loginUser = loginService.buildLoginUser(user); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java index 401dfb20..46bd5661 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/PasswordAuthStrategy.java @@ -70,6 +70,8 @@ public class PasswordAuthStrategy implements IAuthStrategy { loginService.checkLogin(LoginType.PASSWORD, tenantId, username, () -> !BCrypt.checkpw(password, user.getPassword())); // 此处可根据登录用户的数据不同 自行创建 loginUser LoginUser loginUser = loginService.buildLoginUser(user); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java index 3fd05691..0ddb7535 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SmsAuthStrategy.java @@ -60,6 +60,8 @@ public class SmsAuthStrategy implements IAuthStrategy { loginService.checkLogin(LoginType.SMS, tenantId, user.getUserName(), () -> !validateSmsCode(tenantId, phonenumber, smsCode)); // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 LoginUser loginUser = loginService.buildLoginUser(user); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java index d0d4b433..2b055df0 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/SocialAuthStrategy.java @@ -97,6 +97,8 @@ public class SocialAuthStrategy implements IAuthStrategy { // 此处可根据登录用户的数据不同 自行创建 loginUser 属性不够用继承扩展就行了 LoginUser loginUser = loginService.buildLoginUser(user); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); SaLoginModel model = new SaLoginModel(); model.setDevice(client.getDeviceType()); // 自定义分配 不同用户体系 不同 token 授权时间 不设置默认走全局 yml 配置 diff --git a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java index 7096f136..5016e5bc 100644 --- a/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java +++ b/ruoyi-admin/src/main/java/org/dromara/web/service/impl/XcxAuthStrategy.java @@ -54,6 +54,8 @@ public class XcxAuthStrategy implements IAuthStrategy { loginUser.setUsername(user.getUserName()); loginUser.setNickname(user.getNickName()); loginUser.setUserType(user.getUserType()); + loginUser.setClientKey(client.getClientKey()); + loginUser.setDeviceType(client.getDeviceType()); loginUser.setOpenid(openid); SaLoginModel model = new SaLoginModel(); diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/UserOnlineDTO.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/UserOnlineDTO.java index 0e8def81..43d8c3c1 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/UserOnlineDTO.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/dto/UserOnlineDTO.java @@ -34,6 +34,16 @@ public class UserOnlineDTO implements Serializable { */ private String userName; + /** + * 客户端 + */ + private String clientKey; + + /** + * 设备类型 + */ + private String deviceType; + /** * 登录IP地址 */ diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginUser.java b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginUser.java index 66262680..e2671243 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginUser.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/org/dromara/common/core/domain/model/LoginUser.java @@ -112,6 +112,16 @@ public class LoginUser implements Serializable { */ private Long roleId; + /** + * 客户端 + */ + private String clientKey; + + /** + * 设备类型 + */ + private String deviceType; + /** * 获取登录id */ diff --git a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java index 11245e09..80034f11 100644 --- a/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java +++ b/ruoyi-common/ruoyi-common-satoken/src/main/java/org/dromara/common/satoken/listener/UserActionListener.java @@ -49,6 +49,8 @@ public class UserActionListener implements SaTokenListener { dto.setLoginTime(System.currentTimeMillis()); dto.setTokenId(tokenValue); dto.setUserName(user.getUsername()); + dto.setClientKey(user.getClientKey()); + dto.setDeviceType(user.getDeviceType()); dto.setDeptName(user.getDeptName()); if(tokenConfig.getTimeout() == -1) { RedisUtils.setCacheObject(CacheConstants.ONLINE_TOKEN_KEY + tokenValue, dto); diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysLogininfor.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysLogininfor.java index f08dd61d..c57dc0a5 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysLogininfor.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysLogininfor.java @@ -37,6 +37,16 @@ public class SysLogininfor implements Serializable { */ private String userName; + /** + * 客户端 + */ + private String clientKey; + + /** + * 设备类型 + */ + private String deviceType; + /** * 登录状态 0成功 1失败 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysUserOnline.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysUserOnline.java index fca680a3..6def906e 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysUserOnline.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/SysUserOnline.java @@ -26,6 +26,16 @@ public class SysUserOnline { */ private String userName; + /** + * 客户端 + */ + private String clientKey; + + /** + * 设备类型 + */ + private String deviceType; + /** * 登录IP地址 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysLogininforBo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysLogininforBo.java index 564f86bf..46461627 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysLogininforBo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/bo/SysLogininforBo.java @@ -33,6 +33,16 @@ public class SysLogininforBo { */ private String userName; + /** + * 客户端 + */ + private String clientKey; + + /** + * 设备类型 + */ + private String deviceType; + /** * 登录IP地址 */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysLogininforVo.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysLogininforVo.java index cf9720e9..de19aeab 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysLogininforVo.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/domain/vo/SysLogininforVo.java @@ -45,6 +45,19 @@ public class SysLogininforVo implements Serializable { @ExcelProperty(value = "用户账号") private String userName; + /** + * 客户端 + */ + @ExcelProperty(value = "客户端") + private String clientKey; + + /** + * 设备类型 + */ + @ExcelProperty(value = "设备类型", converter = ExcelDictConvert.class) + @ExcelDictFormat(dictType = "sys_device_type") + private String deviceType; + /** * 登录状态(0成功 1失败) */ diff --git a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java index d1c071e0..d215d595 100644 --- a/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java +++ b/ruoyi-modules/ruoyi-system/src/main/java/org/dromara/system/service/impl/SysLogininforServiceImpl.java @@ -1,5 +1,6 @@ package org.dromara.system.service.impl; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.http.useragent.UserAgent; import cn.hutool.http.useragent.UserAgentUtil; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; @@ -12,10 +13,14 @@ import org.dromara.common.mybatis.core.page.TableDataInfo; import org.dromara.common.core.utils.ServletUtils; import org.dromara.common.core.utils.StringUtils; import org.dromara.common.core.utils.ip.AddressUtils; +import org.dromara.common.satoken.utils.LoginHelper; +import org.dromara.system.domain.SysClient; import org.dromara.system.domain.SysLogininfor; import org.dromara.system.domain.bo.SysLogininforBo; import org.dromara.system.domain.vo.SysLogininforVo; +import org.dromara.system.mapper.SysClientMapper; import org.dromara.system.mapper.SysLogininforMapper; +import org.dromara.system.service.ISysClientService; import org.dromara.system.service.ISysLogininforService; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -41,6 +46,8 @@ public class SysLogininforServiceImpl implements ISysLogininforService { private final SysLogininforMapper baseMapper; + private final ISysClientService clientService; + /** * 记录登录信息 * @@ -52,6 +59,12 @@ public class SysLogininforServiceImpl implements ISysLogininforService { HttpServletRequest request = logininforEvent.getRequest(); final UserAgent userAgent = UserAgentUtil.parse(request.getHeader("User-Agent")); final String ip = ServletUtils.getClientIP(request); + // 客户端信息 + String clientid = request.getHeader(LoginHelper.CLIENT_KEY); + SysClient client = null; + if (StringUtils.isNotBlank(clientid)) { + client = clientService.queryByClientId(clientid); + } String address = AddressUtils.getRealAddressByIP(ip); StringBuilder s = new StringBuilder(); @@ -70,6 +83,10 @@ public class SysLogininforServiceImpl implements ISysLogininforService { SysLogininforBo logininfor = new SysLogininforBo(); logininfor.setTenantId(logininforEvent.getTenantId()); logininfor.setUserName(logininforEvent.getUsername()); + if (ObjectUtil.isNotNull(client)) { + logininfor.setClientKey(client.getClientKey()); + logininfor.setDeviceType(client.getDeviceType()); + } logininfor.setIpaddr(ip); logininfor.setLoginLocation(address); logininfor.setBrowser(browser); diff --git a/script/sql/oracle/oracle_ry_vue_5.X.sql b/script/sql/oracle/oracle_ry_vue_5.X.sql index ecab07c9..1100fa92 100644 --- a/script/sql/oracle/oracle_ry_vue_5.X.sql +++ b/script/sql/oracle/oracle_ry_vue_5.X.sql @@ -925,6 +925,8 @@ create table sys_logininfor ( info_id number(20) not null, tenant_id varchar2(20) default '000000', user_name varchar2(50) default '', + client_key varchar2(32) default '', + device_type varchar2(32) default '', ipaddr varchar2(128) default '', login_location varchar2(255) default '', browser varchar2(50) default '', @@ -942,6 +944,8 @@ comment on table sys_logininfor is '系统访问记录'; comment on column sys_logininfor.info_id is '访问ID'; comment on column sys_logininfor.tenant_id is '租户编号'; comment on column sys_logininfor.user_name is '登录账号'; +comment on column sys_logininfor.client_key is '客户端'; +comment on column sys_logininfor.device_type is '设备类型'; comment on column sys_logininfor.ipaddr is '登录IP地址'; comment on column sys_logininfor.login_location is '登录地点'; comment on column sys_logininfor.browser is '浏览器类型'; diff --git a/script/sql/postgres/postgres_ry_vue_5.X.sql b/script/sql/postgres/postgres_ry_vue_5.X.sql index 5992e6aa..48860dc7 100644 --- a/script/sql/postgres/postgres_ry_vue_5.X.sql +++ b/script/sql/postgres/postgres_ry_vue_5.X.sql @@ -946,6 +946,8 @@ create table if not exists sys_logininfor info_id int8, tenant_id varchar(20) default '000000'::varchar, user_name varchar(50) default ''::varchar, + client_key varchar(32) default ''::varchar, + device_type varchar(32) default ''::varchar, ipaddr varchar(128) default ''::varchar, login_location varchar(255) default ''::varchar, browser varchar(50) default ''::varchar, @@ -963,6 +965,8 @@ comment on table sys_logininfor is '系统访问记录'; comment on column sys_logininfor.info_id is '访问ID'; comment on column sys_logininfor.tenant_id is '租户编号'; comment on column sys_logininfor.user_name is '用户账号'; +comment on column sys_logininfor.client_key is '客户端'; +comment on column sys_logininfor.device_type is '设备类型'; comment on column sys_logininfor.ipaddr is '登录IP地址'; comment on column sys_logininfor.login_location is '登录地点'; comment on column sys_logininfor.browser is '浏览器类型'; diff --git a/script/sql/ry_vue_5.X.sql b/script/sql/ry_vue_5.X.sql index 596dd414..09f15ff2 100644 --- a/script/sql/ry_vue_5.X.sql +++ b/script/sql/ry_vue_5.X.sql @@ -699,6 +699,8 @@ create table sys_logininfor ( info_id bigint(20) not null comment '访问ID', tenant_id varchar(20) default '000000' comment '租户编号', user_name varchar(50) default '' comment '用户账号', + client_key varchar(32) default '' comment '客户端', + device_type varchar(32) default '' comment '设备类型', ipaddr varchar(128) default '' comment '登录IP地址', login_location varchar(255) default '' comment '登录地点', browser varchar(50) default '' comment '浏览器类型', diff --git a/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql b/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql index f16edb1d..2045c587 100644 --- a/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql +++ b/script/sql/sqlserver/sqlserver_ry_vue_5.X.sql @@ -1383,6 +1383,8 @@ CREATE TABLE sys_logininfor info_id bigint NOT NULL, tenant_id nvarchar(20) DEFAULT ('000000') NULL, user_name nvarchar(50) DEFAULT '' NULL, + client_key nvarchar(32) DEFAULT '' NULL, + device_type nvarchar(32) DEFAULT '' NULL, ipaddr nvarchar(128) DEFAULT '' NULL, login_location nvarchar(255) DEFAULT '' NULL, browser nvarchar(50) DEFAULT '' NULL, @@ -1420,6 +1422,18 @@ EXEC sys.sp_addextendedproperty 'TABLE', N'sys_logininfor', 'COLUMN', N'user_name' GO +EXEC sys.sp_addextendedproperty + 'MS_Description', N'客户端' , + 'SCHEMA', N'dbo', + 'TABLE', N'sys_logininfor', + 'COLUMN', N'client_key' +GO +EXEC sys.sp_addextendedproperty + 'MS_Description', N'设备类型' , + 'SCHEMA', N'dbo', + 'TABLE', N'sys_logininfor', + 'COLUMN', N'device_type' +GO EXEC sys.sp_addextendedproperty 'MS_Description', N'登录IP地址' , 'SCHEMA', N'dbo', diff --git a/script/sql/update/oracle/update_5.1.0-5.1.1.sql b/script/sql/update/oracle/update_5.1.0-5.1.1.sql new file mode 100644 index 00000000..53825837 --- /dev/null +++ b/script/sql/update/oracle/update_5.1.0-5.1.1.sql @@ -0,0 +1,5 @@ +ALTER TABLE sys_logininfor ADD (client_key VARCHAR(32) DEFAULT ''); +COMMENT ON COLUMN sys_logininfor.client_key IS '客户端'; + +ALTER TABLE sys_logininfor ADD (device_type VARCHAR(32) DEFAULT ''); +COMMENT ON COLUMN sys_logininfor.device_type IS '设备类型'; diff --git a/script/sql/update/postgres/update_5.1.0-5.1.1.sql b/script/sql/update/postgres/update_5.1.0-5.1.1.sql new file mode 100644 index 00000000..29f55076 --- /dev/null +++ b/script/sql/update/postgres/update_5.1.0-5.1.1.sql @@ -0,0 +1,5 @@ +ALTER TABLE sys_logininfor ADD client_key varchar(32) default ''::varchar; +COMMENT ON COLUMN sys_logininfor.client_key IS '客户端'; + +ALTER TABLE sys_logininfor ADD device_type varchar(32) default ''::varchar; +COMMENT ON COLUMN sys_logininfor.device_type IS '设备类型'; diff --git a/script/sql/update/sqlserver/update_5.1.0-5.1.1.sql b/script/sql/update/sqlserver/update_5.1.0-5.1.1.sql new file mode 100644 index 00000000..2238536f --- /dev/null +++ b/script/sql/update/sqlserver/update_5.1.0-5.1.1.sql @@ -0,0 +1,19 @@ +ALTER TABLE sys_logininfor ADD client_key nvarchar(32) DEFAULT '' NULL +GO + +EXEC sp_addextendedproperty + 'MS_Description', N'客户端', + 'SCHEMA', N'dbo', + 'TABLE', N'sys_logininfor', + 'COLUMN', N'client_key' +GO + +ALTER TABLE sys_logininfor ADD device_type nvarchar(32) DEFAULT '' NULL +GO + +EXEC sp_addextendedproperty + 'MS_Description', N'设备类型', + 'SCHEMA', N'dbo', + 'TABLE', N'sys_logininfor', + 'COLUMN', N'device_type' +GO diff --git a/script/sql/update/update_5.1.0-5.1.1.sql b/script/sql/update/update_5.1.0-5.1.1.sql new file mode 100644 index 00000000..5383fe66 --- /dev/null +++ b/script/sql/update/update_5.1.0-5.1.1.sql @@ -0,0 +1,3 @@ +ALTER TABLE sys_logininfor + ADD COLUMN client_key VARCHAR(32) NULL DEFAULT NULL COMMENT '客户端' AFTER `user_type`, + ADD COLUMN device_type VARCHAR(32) NULL DEFAULT NULL COMMENT '设备类型' AFTER `client_key`;