✨ 用户登录日志查询接口
This commit is contained in:
parent
c981e71dfa
commit
73f4eaddc5
@ -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>
|
Loading…
Reference in New Issue
Block a user