This commit is contained in:
caozehui
2025-01-10 09:13:44 +08:00
parent a415a410bf
commit e6e92a5503

View File

@@ -1,16 +1,21 @@
package com.njcn.gather.system.log.aop;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.alibaba.fastjson.JSONObject;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import com.njcn.common.bean.CustomCacheUtil;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.SecurityConstants;
import com.njcn.db.mybatisplus.constant.UserConstant;
import com.njcn.gather.system.log.pojo.po.SysLogAudit;
import com.njcn.gather.system.log.service.ISysLogAuditService;
import com.njcn.gather.user.user.pojo.po.SysUser;
import com.njcn.web.utils.HttpServletUtil;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.util.Strings;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
@@ -45,8 +50,17 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
@Around("logPointcut()")
public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
//String username = customCacheUtil.get(UserConstant.USER_NAME, false);
String username = "";
HttpServletRequest request = HttpServletUtil.getRequest();
String authorization = request.getHeader(SecurityConstants.AUTHORIZATION_KEY);
if (StrUtil.isNotBlank(authorization)) {
String tokenStr = authorization.replace(SecurityConstants.AUTHORIZATION_PREFIX, Strings.EMPTY);
CustomCacheUtil customCacheUtil = SpringUtil.getBean(CustomCacheUtil.CACHE_NAME);
String userjson = customCacheUtil.get(tokenStr, false);
SysUser user = JSONObject.parseObject(userjson, SysUser.class);
username = user.getName();
}
// String operationType = "";
// String operateResult = "成功";
// Integer level = 0;
@@ -55,9 +69,9 @@ public class LogAdvice implements ApplicationListener<ContextRefreshedEvent> {
Object result = null;
try {
result = joinPoint.proceed();
//addLogToQueue(joinPoint, username, "操作日志", "成功", 0, 0);
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, "操作日志", "成功", 0, 0);
} catch (Throwable e) {
//addLogToQueue(joinPoint, username, "告警日志", "失败", 1, 1);
addLogToQueue(joinPoint, "".equals(username) ? UserConstant.UNKNOWN_USER_ID : username, "告警日志", "失败", 1, 1);
throw e;
}
return result;