From 837cdec2e60cd983eeb36908a76f9bb366017659 Mon Sep 17 00:00:00 2001 From: ronger Date: Sat, 10 Jul 2021 09:47:23 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=85=BC=E5=AE=B9=20token=20=E5=A4=B1?= =?UTF-8?q?=E6=95=88=E6=83=85=E6=99=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../forest/core/service/log/VisitAspect.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java b/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java index 0f51467..809e7ff 100644 --- a/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java +++ b/src/main/java/com/rymcu/forest/core/service/log/VisitAspect.java @@ -22,13 +22,11 @@ import org.springframework.web.servlet.HandlerMapping; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; -import java.util.Date; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * 浏览 + * * @author ronger */ @Aspect @@ -43,7 +41,8 @@ public class VisitAspect { private VisitService visitService; @Pointcut("@annotation(com.rymcu.forest.core.service.log.annotation.VisitLogger)") - public void pointCut() {} + public void pointCut() { + } /** * 保存系统操作日志 @@ -52,7 +51,7 @@ public class VisitAspect { * @return 方法执行结果 * @throws Throwable 调用出错 */ - @AfterReturning(value = "pointCut()", returning="obj") + @AfterReturning(value = "pointCut()", returning = "obj") public void save(JoinPoint joinPoint, Object obj) { logger.info("保存访问记录 start ..."); HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest(); @@ -69,9 +68,11 @@ public class VisitAspect { visit.setVisitRefererUrl(referer); visit.setCreatedTime(new Date()); String authHeader = request.getHeader(JwtConstants.AUTHORIZATION); - if(StringUtils.isNotBlank(authHeader)){ + if (StringUtils.isNotBlank(authHeader)) { TokenUser tokenUser = UserUtils.getTokenUser(authHeader); - visit.setVisitUserId(tokenUser.getIdUser()); + if (Objects.nonNull(tokenUser)) { + visit.setVisitUserId(tokenUser.getIdUser()); + } } visitService.save(visit);