overview统计
This commit is contained in:
@@ -18,6 +18,8 @@ import org.xyzh.common.core.domain.LoginDomain;
|
||||
import org.xyzh.common.redis.service.RedisService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -34,6 +36,11 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
|
||||
private static final String REDIS_LOGIN_PREFIX = "login:token:";
|
||||
|
||||
/**
|
||||
* @description UV统计key前缀,例如 stat:uv:20251114
|
||||
*/
|
||||
private static final String REDIS_UV_PREFIX = "stat:uv:";
|
||||
|
||||
private static final Logger logger = LoggerFactory.getLogger(JwtAuthenticationFilter.class);
|
||||
|
||||
@Autowired
|
||||
@@ -89,8 +96,17 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter {
|
||||
new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
|
||||
authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
||||
SecurityContextHolder.getContext().setAuthentication(authentication);
|
||||
|
||||
|
||||
logger.debug("用户认证成功(从缓存),userId: {}", userId);
|
||||
|
||||
// 记录UV:以用户ID为维度,按天去重
|
||||
try {
|
||||
String today = LocalDate.now().format(DateTimeFormatter.BASIC_ISO_DATE);
|
||||
String uvKey = REDIS_UV_PREFIX + today;
|
||||
redisService.sAdd(uvKey, userId);
|
||||
} catch (Exception e) {
|
||||
logger.warn("记录UV失败, userId={}: {}", userId, e.getMessage());
|
||||
}
|
||||
} else {
|
||||
logger.warn("Redis缓存中未找到用户登录信息,userId: {}, 可能已过期或未登录", userId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user