✨ 用户登录日志查询接口
✨ 用户登录日志查询接口
This commit is contained in:
commit
e3507b4ac5
@ -2,6 +2,9 @@ package com.rymcu.forest.mapper;
|
||||
|
||||
import com.rymcu.forest.core.mapper.Mapper;
|
||||
import com.rymcu.forest.entity.LoginRecord;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created on 2022/1/14 8:46.
|
||||
@ -11,4 +14,10 @@ import com.rymcu.forest.entity.LoginRecord;
|
||||
* @packageName com.rymcu.forest.mapper
|
||||
*/
|
||||
public interface LoginRecordMapper extends Mapper<LoginRecord> {
|
||||
/**
|
||||
* 获取用户登录记录
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
List<LoginRecord> selectLoginRecordByIdUser(@Param("idUser") Integer idUser);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.rymcu.forest.service;
|
||||
import com.rymcu.forest.core.service.Service;
|
||||
import com.rymcu.forest.entity.LoginRecord;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created on 2022/1/14 8:47.
|
||||
*
|
||||
@ -17,4 +19,11 @@ public interface LoginRecordService extends Service<LoginRecord> {
|
||||
* @return
|
||||
*/
|
||||
LoginRecord saveLoginRecord(Integer idUser);
|
||||
|
||||
/**
|
||||
* 获取用户登录记录
|
||||
* @param idUser
|
||||
* @return
|
||||
*/
|
||||
List<LoginRecord> findLoginRecordByIdUser(Integer idUser);
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import org.springframework.web.context.request.ServletRequestAttributes;
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
@ -49,4 +50,9 @@ public class LoginRecordServiceImpl extends AbstractService<LoginRecord> impleme
|
||||
loginRecordMapper.insertSelective(loginRecord);
|
||||
return loginRecord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<LoginRecord> findLoginRecordByIdUser(Integer idUser) {
|
||||
return loginRecordMapper.selectLoginRecordByIdUser(idUser);
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +1,23 @@
|
||||
package com.rymcu.forest.web.api.user;
|
||||
|
||||
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.core.service.security.annotation.SecurityInterceptor;
|
||||
import com.rymcu.forest.dto.*;
|
||||
import com.rymcu.forest.dto.ChangeEmailDTO;
|
||||
import com.rymcu.forest.dto.UpdatePasswordDTO;
|
||||
import com.rymcu.forest.dto.UserInfoDTO;
|
||||
import com.rymcu.forest.entity.LoginRecord;
|
||||
import com.rymcu.forest.entity.UserExtend;
|
||||
import com.rymcu.forest.service.LoginRecordService;
|
||||
import com.rymcu.forest.service.UserService;
|
||||
import com.rymcu.forest.util.Utils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -20,6 +29,8 @@ public class UserInfoController {
|
||||
|
||||
@Resource
|
||||
private UserService userService;
|
||||
@Resource
|
||||
private LoginRecordService loginRecordService;
|
||||
|
||||
@GetMapping("/detail/{idUser}")
|
||||
@SecurityInterceptor
|
||||
@ -31,7 +42,7 @@ public class UserInfoController {
|
||||
@GetMapping("/check-nickname")
|
||||
@SecurityInterceptor
|
||||
public GlobalResult checkNickname(@RequestParam Integer idUser, @RequestParam String nickname) {
|
||||
Map map = userService.checkNickname(idUser,nickname);
|
||||
Map map = userService.checkNickname(idUser, nickname);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
@ -63,4 +74,17 @@ public class UserInfoController {
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
@GetMapping("/login-records")
|
||||
@SecurityInterceptor
|
||||
public GlobalResult loginRecords(@RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "10") Integer rows, @RequestParam Integer idUser) {
|
||||
PageHelper.startPage(page, rows);
|
||||
List<LoginRecord> list = loginRecordService.findLoginRecordByIdUser(idUser);
|
||||
PageInfo<LoginRecord> pageInfo = new PageInfo<>(list);
|
||||
Map<String, Object> map = new HashMap<String, Object>(2);
|
||||
map.put("records", pageInfo.getList());
|
||||
Map pagination = Utils.getPagination(pageInfo);
|
||||
map.put("pagination", pagination);
|
||||
return GlobalResultGenerator.genSuccessResult(map);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,4 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
|
||||
<mapper namespace="com.rymcu.forest.mapper.LoginRecordMapper">
|
||||
<resultMap id="BaseResultMap" type="com.rymcu.forest.entity.LoginRecord">
|
||||
<result column="id" property="id"></result>
|
||||
<result column="id_user" property="idUser"></result>
|
||||
<result column="login_ip" property="loginIp"></result>
|
||||
<result column="login_browser" property="loginBrowser"></result>
|
||||
<result column="login_city" property="loginCity"></result>
|
||||
<result column="login_os" property="loginOS"></result>
|
||||
<result column="login_ua" property="loginUa"></result>
|
||||
<result column="created_time" property="createdTime"></result>
|
||||
</resultMap>
|
||||
<select id="selectLoginRecordByIdUser" resultMap="BaseResultMap">
|
||||
select id, id_user, login_ip, login_browser, login_city, login_os, created_time
|
||||
from forest_login_record
|
||||
where id_user = #{idUser} order by created_time desc
|
||||
</select>
|
||||
</mapper>
|
@ -1,6 +1,8 @@
|
||||
create database forest default character set utf8mb4 collate utf8mb4_unicode_ci;
|
||||
create
|
||||
database forest default character set utf8mb4 collate utf8mb4_unicode_ci;
|
||||
|
||||
use forest;
|
||||
use
|
||||
forest;
|
||||
|
||||
create table forest_article
|
||||
(
|
||||
@ -22,8 +24,7 @@ create table forest_article
|
||||
article_status char default '0' null comment '文章状态',
|
||||
article_thumbs_up_count int default 0 null comment '点赞总数',
|
||||
article_sponsor_count int default 0 null comment '赞赏总数'
|
||||
)
|
||||
comment ' ' collate = utf8mb4_unicode_ci;
|
||||
) comment ' ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_article_content
|
||||
(
|
||||
@ -32,8 +33,7 @@ create table forest_article_content
|
||||
article_content_html text null comment '文章内容Html',
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间'
|
||||
)
|
||||
comment ' ' collate = utf8mb4_unicode_ci;
|
||||
) comment ' ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create index forest_article_content_id_article_index
|
||||
on forest_article_content (id_article);
|
||||
@ -45,8 +45,7 @@ create table forest_article_thumbs_up
|
||||
id_article bigint null comment '文章表主键',
|
||||
id_user bigint null comment '用户表主键',
|
||||
thumbs_up_time datetime null comment '点赞时间'
|
||||
)
|
||||
comment '文章点赞表 ';
|
||||
) comment '文章点赞表 ';
|
||||
|
||||
create table forest_bank
|
||||
(
|
||||
@ -57,8 +56,7 @@ create table forest_bank
|
||||
bank_description varchar(512) null comment '银行描述',
|
||||
created_by bigint null comment '创建人',
|
||||
created_time datetime null comment '创建时间'
|
||||
)
|
||||
comment '银行表 ';
|
||||
) comment '银行表 ';
|
||||
|
||||
create table forest_bank_account
|
||||
(
|
||||
@ -70,8 +68,7 @@ create table forest_bank_account
|
||||
account_owner bigint null comment '账户所有者',
|
||||
created_time datetime null comment '创建时间',
|
||||
account_type char default '0' null comment '0: 普通账户 1: 银行账户'
|
||||
)
|
||||
comment '银行账户表 ';
|
||||
) comment '银行账户表 ';
|
||||
|
||||
create table forest_comment
|
||||
(
|
||||
@ -89,8 +86,7 @@ create table forest_comment
|
||||
comment_reply_count int null comment '回帖计数',
|
||||
comment_visible char null comment '0:所有人可见,1:仅楼主和自己可见',
|
||||
created_time datetime null comment '创建时间'
|
||||
)
|
||||
comment '评论表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '评论表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_currency_issue
|
||||
(
|
||||
@ -99,8 +95,7 @@ create table forest_currency_issue
|
||||
issue_value decimal(32, 8) null comment '发行数额',
|
||||
created_by bigint null comment '发行人',
|
||||
created_time datetime null comment '发行时间'
|
||||
)
|
||||
comment '货币发行表 ';
|
||||
) comment '货币发行表 ';
|
||||
|
||||
create table forest_currency_rule
|
||||
(
|
||||
@ -114,8 +109,7 @@ create table forest_currency_rule
|
||||
maximum_money decimal(32, 8) null comment '上限金额',
|
||||
repeat_days int default 0 null comment '重复(0: 不重复,单位:天)',
|
||||
status char default '0' null comment '状态'
|
||||
)
|
||||
comment '货币规则表 ';
|
||||
) comment '货币规则表 ';
|
||||
|
||||
create table forest_follow
|
||||
(
|
||||
@ -124,8 +118,7 @@ create table forest_follow
|
||||
follower_id bigint null comment '关注者 id',
|
||||
following_id bigint null comment '关注数据 id',
|
||||
following_type char null comment '0:用户,1:标签,2:帖子收藏,3:帖子关注'
|
||||
)
|
||||
comment '关注表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '关注表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_notification
|
||||
(
|
||||
@ -137,8 +130,7 @@ create table forest_notification
|
||||
has_read char default '0' null comment '是否已读',
|
||||
data_summary varchar(256) null comment '数据摘要',
|
||||
created_time datetime null comment '创建时间'
|
||||
)
|
||||
comment '通知表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '通知表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_portfolio
|
||||
(
|
||||
@ -151,8 +143,7 @@ create table forest_portfolio
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间',
|
||||
portfolio_description_html varchar(1024) null comment ' 作品集介绍HTML'
|
||||
)
|
||||
comment '作品集表' collate = utf8mb4_unicode_ci;
|
||||
) comment '作品集表' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_portfolio_article
|
||||
(
|
||||
@ -161,8 +152,7 @@ create table forest_portfolio_article
|
||||
id_portfolio bigint null comment '作品集表主键',
|
||||
id_article bigint null comment '文章表主键',
|
||||
sort_no int null comment '排序号'
|
||||
)
|
||||
comment '作品集与文章关系表' collate = utf8mb4_unicode_ci;
|
||||
) comment '作品集与文章关系表' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_role
|
||||
(
|
||||
@ -174,8 +164,7 @@ create table forest_role
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间',
|
||||
weights tinyint default 0 null comment '权重,数值越小权限越大;0:无权限'
|
||||
)
|
||||
comment ' ' collate = utf8mb4_unicode_ci;
|
||||
) comment ' ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_sponsor
|
||||
(
|
||||
@ -186,8 +175,7 @@ create table forest_sponsor
|
||||
sponsor bigint null comment '赞赏人',
|
||||
sponsorship_time datetime null comment '赞赏日期',
|
||||
sponsorship_money decimal(32, 8) null comment '赞赏金额'
|
||||
)
|
||||
comment '赞赏表 ';
|
||||
) comment '赞赏表 ';
|
||||
|
||||
create table forest_tag
|
||||
(
|
||||
@ -206,8 +194,7 @@ create table forest_tag
|
||||
tag_status char default '0' null comment '标签状态',
|
||||
tag_reservation char default '0' null comment '保留标签',
|
||||
tag_description_html text null
|
||||
)
|
||||
comment '标签表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '标签表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_tag_article
|
||||
(
|
||||
@ -219,8 +206,7 @@ create table forest_tag_article
|
||||
article_perfect int default 0 null comment '0:非优选1:优选 0',
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间'
|
||||
)
|
||||
comment '标签 - 帖子关联表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '标签 - 帖子关联表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create index forest_tag_article_id_tag_index
|
||||
on forest_tag_article (id_tag);
|
||||
@ -241,8 +227,7 @@ create table forest_topic
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间',
|
||||
topic_description_html text null comment '专题描述 Html'
|
||||
)
|
||||
comment '主题表' collate = utf8mb4_unicode_ci;
|
||||
) comment '主题表' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_topic_tag
|
||||
(
|
||||
@ -252,8 +237,7 @@ create table forest_topic_tag
|
||||
id_tag bigint null comment '标签id',
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间'
|
||||
)
|
||||
comment '专题- 标签关联表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '专题- 标签关联表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create index forest_topic_tag_id_topic_index
|
||||
on forest_topic_tag (id_topic);
|
||||
@ -269,8 +253,7 @@ create table forest_transaction_record
|
||||
money decimal(32, 8) null comment '交易金额',
|
||||
transaction_type char default '0' null comment '交易类型',
|
||||
transaction_time datetime null comment '交易时间'
|
||||
)
|
||||
comment '交易记录表 ';
|
||||
) comment '交易记录表 ';
|
||||
|
||||
create table forest_user
|
||||
(
|
||||
@ -290,8 +273,7 @@ create table forest_user
|
||||
updated_time datetime null comment '更新时间',
|
||||
last_login_time datetime null comment '最后登录时间',
|
||||
signature varchar(128) null comment '签名'
|
||||
)
|
||||
comment ' ' collate = utf8mb4_unicode_ci;
|
||||
) comment ' ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_user_extend
|
||||
(
|
||||
@ -301,16 +283,14 @@ create table forest_user_extend
|
||||
weixin varchar(32) null comment '微信',
|
||||
qq varchar(32) null comment 'qq',
|
||||
blog varchar(500) null comment '博客'
|
||||
)
|
||||
comment '用户扩展表 ';
|
||||
) comment '用户扩展表 ';
|
||||
|
||||
create table forest_user_role
|
||||
(
|
||||
id_user bigint not null comment '用户表主键',
|
||||
id_role bigint not null comment '角色表主键',
|
||||
created_time datetime null comment '创建时间'
|
||||
)
|
||||
comment ' ' collate = utf8mb4_unicode_ci;
|
||||
) comment ' ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_user_tag
|
||||
(
|
||||
@ -321,8 +301,7 @@ create table forest_user_tag
|
||||
type char null comment '0:创建者,1:帖子使用,2:用户自评标签',
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间'
|
||||
)
|
||||
comment '用户 - 标签关联表 ' collate = utf8mb4_unicode_ci;
|
||||
) comment '用户 - 标签关联表 ' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_visit
|
||||
(
|
||||
@ -337,8 +316,7 @@ create table forest_visit
|
||||
visit_referer_url varchar(256) null comment '上游链接',
|
||||
created_time datetime null comment '创建时间',
|
||||
expired_time datetime null comment '过期时间'
|
||||
)
|
||||
comment '浏览表' collate = utf8mb4_unicode_ci;
|
||||
) comment '浏览表' collate = utf8mb4_unicode_ci;
|
||||
|
||||
create table forest_lucene_user_dic
|
||||
(
|
||||
@ -368,16 +346,42 @@ values (1, 'admin', '8ce2dd866238958ac4f07870766813cdaa39a9b83a8c75e26aa50f23',
|
||||
insert into forest.forest_user_role (id_user, id_role, created_time)
|
||||
values (1, 1, '2021-01-25 18:22:12');
|
||||
|
||||
|
||||
CREATE TABLE `forest_file`
|
||||
create table forest_file
|
||||
(
|
||||
`id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
|
||||
`md5_value` varchar(40) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件md5值',
|
||||
`file_path` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '文件上传路径',
|
||||
`file_url` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '网络访问路径',
|
||||
`created_time` datetime DEFAULT NULL COMMENT '创建时间',
|
||||
`updated_time` datetime DEFAULT NULL COMMENT '更新时间',
|
||||
`created_by` int(11) DEFAULT NULL COMMENT '创建人',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `index_md5_value` (`md5_value`)
|
||||
) ENGINE=InnoDB AUTO_INCREMENT=81 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci comment '文件上传记录表';
|
||||
id int unsigned auto_increment comment 'id'
|
||||
primary key,
|
||||
md5_value varchar(40) not null comment '文件md5值',
|
||||
file_path varchar(255) not null comment '文件上传路径',
|
||||
file_url varchar(255) not null comment '网络访问路径',
|
||||
created_time datetime null comment '创建时间',
|
||||
updated_time datetime null comment '更新时间',
|
||||
created_by int null comment '创建人',
|
||||
file_size int null comment '文件大小',
|
||||
file_type varchar(10) null comment '文件类型'
|
||||
) comment '文件上传记录表';
|
||||
|
||||
create index index_md5_value_created_by
|
||||
on forest_file (md5_value, created_by);
|
||||
|
||||
create index index_created_by
|
||||
on forest_file (created_by);
|
||||
|
||||
create index index_md5_value
|
||||
on forest_file (md5_value);
|
||||
|
||||
create table forest_login_record
|
||||
(
|
||||
id bigint auto_increment comment '主键'
|
||||
primary key,
|
||||
id_user bigint not null comment '用户表主键',
|
||||
login_ip varchar(128) null comment '登录设备IP',
|
||||
login_ua varchar(512) null comment '登录设备UA',
|
||||
login_city varchar(128) null comment '登录设备所在城市',
|
||||
login_os varchar(64) null comment '登录设备操作系统',
|
||||
login_browser varchar(64) null comment '登录设备浏览器',
|
||||
created_time datetime null comment '登录时间',
|
||||
login_device_id varchar(512) null comment '登录设备/浏览器指纹',
|
||||
constraint forest_login_record_id_uindex
|
||||
unique (id)
|
||||
) comment '登录记录表';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user