From 42fc9204bf768cfb3e353acf80ee18e157c142da Mon Sep 17 00:00:00 2001 From: carl <2331890842@qq.com> Date: Sun, 1 Dec 2024 10:52:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(logout):=20=E7=99=BB=E5=87=BA=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86=E4=B8=AD=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E8=80=97=E6=97=B6=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/PigLogoutSuccessEventHandler.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigLogoutSuccessEventHandler.java b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigLogoutSuccessEventHandler.java index cbd10860..3abede7f 100644 --- a/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigLogoutSuccessEventHandler.java +++ b/pig-auth/src/main/java/com/pig4cloud/pig/auth/support/handler/PigLogoutSuccessEventHandler.java @@ -16,7 +16,9 @@ package com.pig4cloud.pig.auth.support.handler; +import cn.hutool.core.util.StrUtil; import com.pig4cloud.pig.admin.api.entity.SysLog; +import com.pig4cloud.pig.common.core.constant.CommonConstants; import com.pig4cloud.pig.common.core.util.SpringContextHolder; import com.pig4cloud.pig.common.core.util.WebUtils; import com.pig4cloud.pig.common.log.event.SysLogEvent; @@ -57,19 +59,25 @@ public class PigLogoutSuccessEventHandler implements ApplicationListener logVo.setParams(request.getHeader(HttpHeaders.AUTHORIZATION))); + WebUtils.getRequest().ifPresent(request -> { + logVo.setParams(request.getHeader(HttpHeaders.AUTHORIZATION)); + // 计算请求耗时 + String startTimeStr = request.getHeader(CommonConstants.REQUEST_START_TIME); + if (StrUtil.isNotBlank(startTimeStr)) { + Long startTime = Long.parseLong(startTimeStr); + Long endTime = System.currentTimeMillis(); + logVo.setTime(endTime - startTime); + } + }); // 这边设置ServiceId if (authentication instanceof PreAuthenticatedAuthenticationToken) { logVo.setServiceId(authentication.getCredentials().toString()); } logVo.setCreateBy(authentication.getName()); + // 发送异步日志事件 SpringContextHolder.publishEvent(new SysLogEvent(logVo)); }