Merge branch 'master' into master

This commit is contained in:
ronger 2022-01-14 12:05:13 +08:00 committed by GitHub
commit 9379c7f564
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 102 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -346,21 +346,41 @@ 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 '创建人',
`file_size` int(11) DEFAULT NULL COMMENT '文件大小',
`file_type` varchar(10) COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '文件类型',
PRIMARY KEY (`id`),
KEY `index_md5_value` (`md5_value`) USING BTREE,
KEY `index_created_by` (`created_by`),
KEY `inddex_md5_value_created_by` (`md5_value`,`created_by`),
KEY `index_file_type` (`file_type`)
) ENGINE=InnoDB AUTO_INCREMENT=92 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 '登录记录表';