🎨 修改更新用户最后登录时间方式

This commit is contained in:
ronger 2020-09-14 10:37:36 +08:00
parent 0a8f00d89e
commit 8d75008023
4 changed files with 17 additions and 4 deletions

View File

@ -23,6 +23,8 @@ import java.util.Map;
/** /**
* 全局异常处理器 * 全局异常处理器
*
* @author ronger
* */ * */
@RestControllerAdvice @RestControllerAdvice
public class BaseExceptionHandler { public class BaseExceptionHandler {
@ -46,7 +48,8 @@ public class BaseExceptionHandler {
result.setCode(1000002); result.setCode(1000002);
result.setMessage("用户无权限"); result.setMessage("用户无权限");
logger.info("用户无权限"); logger.info("用户无权限");
}else if (ex instanceof ServiceException) {//业务失败的异常账号或密码错误 }else if (ex instanceof ServiceException) {
//业务失败的异常账号或密码错误
result.setCode(((ServiceException) ex).getCode()); result.setCode(((ServiceException) ex).getCode());
result.setMessage(ex.getMessage()); result.setMessage(ex.getMessage());
logger.info(ex.getMessage()); logger.info(ex.getMessage());
@ -88,7 +91,8 @@ public class BaseExceptionHandler {
} else if (ex instanceof UnauthorizedException) { } else if (ex instanceof UnauthorizedException) {
attributes.put("code", "1000002"); attributes.put("code", "1000002");
attributes.put("message", "用户无权限"); attributes.put("message", "用户无权限");
} else if (ex instanceof ServiceException) {//业务失败的异常账号或密码错误 } else if (ex instanceof ServiceException) {
//业务失败的异常账号或密码错误
attributes.put("code",((ServiceException) ex).getCode()); attributes.put("code",((ServiceException) ex).getCode());
attributes.put("message",ex.getMessage()); attributes.put("message",ex.getMessage());
logger.info(ex.getMessage()); logger.info(ex.getMessage());

View File

@ -113,4 +113,11 @@ public interface UserMapper extends Mapper<User> {
* @return * @return
*/ */
Author selectAuthor(@Param("id") Integer id); Author selectAuthor(@Param("id") Integer id);
/**
* 更新用户最后登录时间
* @param idUser
* @return
*/
Integer updateLastLoginTime(@Param("idUser") Integer idUser);
} }

View File

@ -100,8 +100,7 @@ public class UserServiceImpl extends AbstractService<User> implements UserServic
user = userMapper.selectOne(user); user = userMapper.selectOne(user);
if(user != null){ if(user != null){
if(Utils.comparePwd(password, user.getPassword())){ if(Utils.comparePwd(password, user.getPassword())){
user.setLastLoginTime(new Date()); userMapper.updateLastLoginTime(user.getIdUser());
userMapper.updateByPrimaryKeySelective(user);
TokenUser tokenUser = new TokenUser(); TokenUser tokenUser = new TokenUser();
BeanCopierUtil.copy(user, tokenUser); BeanCopierUtil.copy(user, tokenUser);
tokenUser.setToken(tokenManager.createToken(account)); tokenUser.setToken(tokenManager.createToken(account));

View File

@ -65,6 +65,9 @@
</if> </if>
where id = #{idUser} where id = #{idUser}
</update> </update>
<update id="updateLastLoginTime">
update vertical_user set last_login_time = sysdate where id = #{idUser}
</update>
<select id="findByAccount" resultMap="BaseResultMap"> <select id="findByAccount" resultMap="BaseResultMap">
select id, nickname, account, password, status from vertical_user where account = #{account} and status = 0 select id, nickname, account, password, status from vertical_user where account = #{account} and status = 0