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