diff --git a/src/main/java/com/rymcu/forest/mapper/LoginRecordMapper.java b/src/main/java/com/rymcu/forest/mapper/LoginRecordMapper.java index 400d4c9..6c05ac9 100644 --- a/src/main/java/com/rymcu/forest/mapper/LoginRecordMapper.java +++ b/src/main/java/com/rymcu/forest/mapper/LoginRecordMapper.java @@ -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 { + /** + * 获取用户登录记录 + * @param idUser + * @return + */ + List selectLoginRecordByIdUser(@Param("idUser") Integer idUser); } diff --git a/src/main/java/com/rymcu/forest/service/LoginRecordService.java b/src/main/java/com/rymcu/forest/service/LoginRecordService.java index 0ef3fc8..9d618fe 100644 --- a/src/main/java/com/rymcu/forest/service/LoginRecordService.java +++ b/src/main/java/com/rymcu/forest/service/LoginRecordService.java @@ -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 { * @return */ LoginRecord saveLoginRecord(Integer idUser); + + /** + * 获取用户登录记录 + * @param idUser + * @return + */ + List findLoginRecordByIdUser(Integer idUser); } diff --git a/src/main/java/com/rymcu/forest/service/impl/LoginRecordServiceImpl.java b/src/main/java/com/rymcu/forest/service/impl/LoginRecordServiceImpl.java index 60ab7bb..b253b36 100644 --- a/src/main/java/com/rymcu/forest/service/impl/LoginRecordServiceImpl.java +++ b/src/main/java/com/rymcu/forest/service/impl/LoginRecordServiceImpl.java @@ -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 impleme loginRecordMapper.insertSelective(loginRecord); return loginRecord; } + + @Override + public List findLoginRecordByIdUser(Integer idUser) { + return loginRecordMapper.selectLoginRecordByIdUser(idUser); + } } diff --git a/src/main/java/com/rymcu/forest/web/api/user/UserInfoController.java b/src/main/java/com/rymcu/forest/web/api/user/UserInfoController.java index c657376..94e8746 100644 --- a/src/main/java/com/rymcu/forest/web/api/user/UserInfoController.java +++ b/src/main/java/com/rymcu/forest/web/api/user/UserInfoController.java @@ -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 list = loginRecordService.findLoginRecordByIdUser(idUser); + PageInfo pageInfo = new PageInfo<>(list); + Map map = new HashMap(2); + map.put("records", pageInfo.getList()); + Map pagination = Utils.getPagination(pageInfo); + map.put("pagination", pagination); + return GlobalResultGenerator.genSuccessResult(map); + } + } diff --git a/src/main/java/mapper/LoginRecordMapper.xml b/src/main/java/mapper/LoginRecordMapper.xml index fcf529f..2a5e318 100644 --- a/src/main/java/mapper/LoginRecordMapper.xml +++ b/src/main/java/mapper/LoginRecordMapper.xml @@ -1,4 +1,19 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/static/forest.sql b/src/main/resources/static/forest.sql index a0e4b18..294f772 100644 --- a/src/main/resources/static/forest.sql +++ b/src/main/resources/static/forest.sql @@ -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='文件上传记录表'; \ No newline at end of file + 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 '登录记录表';