!433 更新登录日志以及在线用户展示信息

* update 更新登录日志, 在线用户展示信息(增加 客户端, 设备类型)
feature/model
MichelleChung 1 year ago committed by 疯狂的狮子Li
parent f708492681
commit 29118ae78c

@ -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 配置

@ -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 配置

@ -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 配置

@ -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 配置

@ -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();

@ -34,6 +34,16 @@ public class UserOnlineDTO implements Serializable {
*/
private String userName;
/**
*
*/
private String clientKey;
/**
*
*/
private String deviceType;
/**
* IP
*/

@ -112,6 +112,16 @@ public class LoginUser implements Serializable {
*/
private Long roleId;
/**
*
*/
private String clientKey;
/**
*
*/
private String deviceType;
/**
* id
*/

@ -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);

@ -37,6 +37,16 @@ public class SysLogininfor implements Serializable {
*/
private String userName;
/**
*
*/
private String clientKey;
/**
*
*/
private String deviceType;
/**
* 0 1
*/

@ -26,6 +26,16 @@ public class SysUserOnline {
*/
private String userName;
/**
*
*/
private String clientKey;
/**
*
*/
private String deviceType;
/**
* IP
*/

@ -33,6 +33,16 @@ public class SysLogininforBo {
*/
private String userName;
/**
*
*/
private String clientKey;
/**
*
*/
private String deviceType;
/**
* IP
*/

@ -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
*/

@ -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);

@ -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 '浏览器类型';

@ -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 '浏览器类型';

@ -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 '浏览器类型',

@ -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',

@ -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 '设备类型';

@ -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 '设备类型';

@ -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

@ -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`;
Loading…
Cancel
Save