增加配置

This commit is contained in:
GYJ
2025-03-06 15:34:07 +08:00
parent d5941e5ed0
commit 98e1b9a345
4 changed files with 39 additions and 27 deletions

View File

@@ -4,12 +4,14 @@ import cn.hutool.core.thread.ThreadUtil;
import com.google.gson.Gson;
import com.sqx.common.utils.HttpContextUtils;
import com.sqx.common.utils.IPUtils;
import com.sqx.modules.common.service.CommonInfoService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
@@ -27,6 +29,9 @@ import javax.servlet.http.HttpServletRequest;
//@Profile({"dev"})
public class AppApiMethodAspect {
@Autowired
private CommonInfoService commonInfoService;
@Pointcut("!execution(public * (com.sqx.modules.sys.controller.SysLoginController).*(..)) " +
"&& execution(public * (com.sqx.modules.*.controller..*).*(..)))")
public void pkg() {
@@ -50,31 +55,35 @@ public class AppApiMethodAspect {
// 执行被拦截的方法
Object result = pjp.proceed();
long end = System.currentTimeMillis();
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String method = request.getMethod();
String requestUrl = request.getRequestURL().toString();
String requestIp = IPUtils.getIpAddr(request);
long useTime = end - start;
ThreadUtil.execAsync(() -> {
//请求的参数
String value = commonInfoService.findOne(933).getValue();
if ("1".equals(value)) {
HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
String method = request.getMethod();
String requestUrl = request.getRequestURL().toString();
String requestIp = IPUtils.getIpAddr(request);
long useTime = end - start;
ThreadUtil.execAsync(() -> {
//请求的参数
// String resultJson = new Gson().toJson(result);
String resultJson = "1";
try {
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
log.info("\n>>>>>> {} {}" +
"\n>>>>>> IP: {} " +
"\n>>>>>> execute time:{}ms " +
"\n>>>>>> Request: {}" +
"\n>>>>>> Response: {}",
method, requestUrl, requestIp, useTime,
params,
resultJson
);
String resultJson = "1";
try {
if (StringUtils.isNotBlank(resultJson) && !"null".equals(resultJson)) {
log.info("\n>>>>>> {} {}" +
"\n>>>>>> IP: {} " +
"\n>>>>>> execute time:{}ms " +
"\n>>>>>> Request: {}" +
"\n>>>>>> Response: {}",
method, requestUrl, requestIp, useTime,
params,
resultJson
);
}
} catch (Exception e) {
log.error("Request 为空" + e.getMessage());
}
} catch (Exception e) {
log.error("Request 为空" + e.getMessage());
}
});
});
}
return result;
}
}