From 73f4eaddc5854f521767761862d5a5f156a330d8 Mon Sep 17 00:00:00 2001 From: ronger Date: Fri, 14 Jan 2022 11:59:57 +0800 Subject: [PATCH] =?UTF-8?q?:sparkles:=20=E7=94=A8=E6=88=B7=E7=99=BB?= =?UTF-8?q?=E5=BD=95=E6=97=A5=E5=BF=97=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/mapper/LoginRecordMapper.java | 9 ++++++ .../forest/service/LoginRecordService.java | 9 ++++++ .../service/impl/LoginRecordServiceImpl.java | 6 ++++ .../web/api/user/UserInfoController.java | 28 +++++++++++++++++-- src/main/java/mapper/LoginRecordMapper.xml | 15 ++++++++++ 5 files changed, 65 insertions(+), 2 deletions(-) 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