From 8d750080235724dce6be0da673ee0e59c456f30d Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 14 Sep 2020 10:37:36 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BF=AE=E6=94=B9=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E6=9C=80=E5=90=8E=E7=99=BB=E5=BD=95=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/rymcu/vertical/config/BaseExceptionHandler.java | 8 ++++++-- src/main/java/com/rymcu/vertical/mapper/UserMapper.java | 7 +++++++ .../com/rymcu/vertical/service/impl/UserServiceImpl.java | 3 +-- src/main/java/mapper/UserMapper.xml | 3 +++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/rymcu/vertical/config/BaseExceptionHandler.java b/src/main/java/com/rymcu/vertical/config/BaseExceptionHandler.java index fc47680..9ebe05e 100644 --- a/src/main/java/com/rymcu/vertical/config/BaseExceptionHandler.java +++ b/src/main/java/com/rymcu/vertical/config/BaseExceptionHandler.java @@ -23,6 +23,8 @@ import java.util.Map; /** * 全局异常处理器 + * + * @author ronger * */ @RestControllerAdvice public class BaseExceptionHandler { @@ -46,7 +48,8 @@ public class BaseExceptionHandler { result.setCode(1000002); result.setMessage("用户无权限"); logger.info("用户无权限"); - }else if (ex instanceof ServiceException) {//业务失败的异常,如“账号或密码错误” + }else if (ex instanceof ServiceException) { + //业务失败的异常,如“账号或密码错误” result.setCode(((ServiceException) ex).getCode()); result.setMessage(ex.getMessage()); logger.info(ex.getMessage()); @@ -88,7 +91,8 @@ public class BaseExceptionHandler { } else if (ex instanceof UnauthorizedException) { attributes.put("code", "1000002"); attributes.put("message", "用户无权限"); - } else if (ex instanceof ServiceException) {//业务失败的异常,如“账号或密码错误” + } else if (ex instanceof ServiceException) { + //业务失败的异常,如“账号或密码错误” attributes.put("code",((ServiceException) ex).getCode()); attributes.put("message",ex.getMessage()); logger.info(ex.getMessage()); diff --git a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java index ce95279..de1eae8 100644 --- a/src/main/java/com/rymcu/vertical/mapper/UserMapper.java +++ b/src/main/java/com/rymcu/vertical/mapper/UserMapper.java @@ -113,4 +113,11 @@ public interface UserMapper extends Mapper { * @return */ Author selectAuthor(@Param("id") Integer id); + + /** + * 更新用户最后登录时间 + * @param idUser + * @return + */ + Integer updateLastLoginTime(@Param("idUser") Integer idUser); } \ No newline at end of file diff --git a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java index dc8ef02..c565045 100644 --- a/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java +++ b/src/main/java/com/rymcu/vertical/service/impl/UserServiceImpl.java @@ -100,8 +100,7 @@ public class UserServiceImpl extends AbstractService implements UserServic user = userMapper.selectOne(user); if(user != null){ if(Utils.comparePwd(password, user.getPassword())){ - user.setLastLoginTime(new Date()); - userMapper.updateByPrimaryKeySelective(user); + userMapper.updateLastLoginTime(user.getIdUser()); TokenUser tokenUser = new TokenUser(); BeanCopierUtil.copy(user, tokenUser); tokenUser.setToken(tokenManager.createToken(account)); diff --git a/src/main/java/mapper/UserMapper.xml b/src/main/java/mapper/UserMapper.xml index f134db4..e4af70d 100644 --- a/src/main/java/mapper/UserMapper.xml +++ b/src/main/java/mapper/UserMapper.xml @@ -65,6 +65,9 @@ where id = #{idUser} + + update vertical_user set last_login_time = sysdate where id = #{idUser} +