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 cbd108601..3abede7f4 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 void handle(Authentication authentication) { log.info("用户:{} 退出成功", authentication.getPrincipal()); SysLog logVo = SysLogUtils.getSysLog(); logVo.setTitle("退出成功"); - // 发送异步日志事件 - Long startTime = System.currentTimeMillis(); - Long endTime = System.currentTimeMillis(); - logVo.setTime(endTime - startTime); // 设置对应的token - WebUtils.getRequest().ifPresent(request -> 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)); }