mirror of
https://gitee.com/log4j/pig.git
synced 2024-12-22 04:47:10 +08:00
Merge pull request #1139 from Awei-996/jdk17
fix(logout): 登出成功事件处理中请求耗时计算错误
This commit is contained in:
commit
092ae11be7
@ -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<LogoutS
|
||||
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));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user