From 6de131f358ad93894f0e99395ebe9d1438101914 Mon Sep 17 00:00:00 2001 From: lhc Date: Tue, 2 Sep 2025 14:20:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6?= =?UTF-8?q?=E4=BB=BB=E5=8A=A1=E5=86=99=E5=9C=A8controller=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E7=94=9F=E6=95=88=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/datasource/aop/DataSourceAop.java | 16 +++--- .../base/module/log/RequestLogAspect.java | 52 ++++++++++--------- hcframe-parent/pom.xml | 28 +++++----- 3 files changed, 51 insertions(+), 45 deletions(-) diff --git a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/datasource/aop/DataSourceAop.java b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/datasource/aop/DataSourceAop.java index 3d46fde..5d945bf 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/datasource/aop/DataSourceAop.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/datasource/aop/DataSourceAop.java @@ -52,13 +52,15 @@ public class DataSourceAop { @Before("log()") public void doBefore(JoinPoint joinPoint) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - if (isMulti) { - String key = request.getParameter("datasourceKey"); - if (StringUtils.isBlank(key)) { - DBContextHolder.setDataSource(DataUnit.MASTER); - } else { - DBContextHolder.setDataSource(key); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + if (isMulti) { + String key = request.getParameter("datasourceKey"); + if (StringUtils.isBlank(key)) { + DBContextHolder.setDataSource(DataUnit.MASTER); + } else { + DBContextHolder.setDataSource(key); + } } } } diff --git a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java index fff4a6a..382cd65 100644 --- a/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java +++ b/hcframe-parent/hcframe-base/src/main/java/com/taixingyiji/base/module/log/RequestLogAspect.java @@ -45,38 +45,42 @@ public class RequestLogAspect { public Object doAround(ProceedingJoinPoint proceedingJoinPoint) throws Throwable { long start = System.currentTimeMillis(); - ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); Object result = proceedingJoinPoint.proceed(); - - if (frameConfig.getShowControllerLog()) { - RequestInfo requestInfo = new RequestInfo(); - requestInfo.setIp(request.getRemoteAddr()); - requestInfo.setUrl(request.getRequestURL().toString()); - requestInfo.setHttpMethod(request.getMethod()); - requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(), - proceedingJoinPoint.getSignature().getName())); - requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint)); - requestInfo.setResult(result); - requestInfo.setTimeCost(System.currentTimeMillis() - start); - LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo)); + ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + if (frameConfig.getShowControllerLog()) { + RequestInfo requestInfo = new RequestInfo(); + requestInfo.setIp(request.getRemoteAddr()); + requestInfo.setUrl(request.getRequestURL().toString()); + requestInfo.setHttpMethod(request.getMethod()); + requestInfo.setClassMethod(String.format("%s.%s", proceedingJoinPoint.getSignature().getDeclaringTypeName(), + proceedingJoinPoint.getSignature().getName())); + requestInfo.setRequestParams(getRequestParamsByProceedingJoinPoint(proceedingJoinPoint)); + requestInfo.setResult(result); + requestInfo.setTimeCost(System.currentTimeMillis() - start); + LOGGER.info("Request Info : {}", JSON.toJSONString(requestInfo)); + } } + return result; } @AfterThrowing(pointcut = "requestServer()", throwing = "e") public void doAfterThrow(JoinPoint joinPoint, RuntimeException e) { ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); - HttpServletRequest request = attributes.getRequest(); - RequestErrorInfo requestErrorInfo = new RequestErrorInfo(); - requestErrorInfo.setIp(request.getRemoteAddr()); - requestErrorInfo.setUrl(request.getRequestURL().toString()); - requestErrorInfo.setHttpMethod(request.getMethod()); - requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(), - joinPoint.getSignature().getName())); - requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint)); - requestErrorInfo.setException(e); - LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo)); + if (attributes != null) { + HttpServletRequest request = attributes.getRequest(); + RequestErrorInfo requestErrorInfo = new RequestErrorInfo(); + requestErrorInfo.setIp(request.getRemoteAddr()); + requestErrorInfo.setUrl(request.getRequestURL().toString()); + requestErrorInfo.setHttpMethod(request.getMethod()); + requestErrorInfo.setClassMethod(String.format("%s.%s", joinPoint.getSignature().getDeclaringTypeName(), + joinPoint.getSignature().getName())); + requestErrorInfo.setRequestParams(getRequestParamsByJoinPoint(joinPoint)); + requestErrorInfo.setException(e); + LOGGER.error("Error Request Info : {}", JSON.toJSONString(requestErrorInfo)); + } } /** diff --git a/hcframe-parent/pom.xml b/hcframe-parent/pom.xml index 0851d43..d46fffb 100644 --- a/hcframe-parent/pom.xml +++ b/hcframe-parent/pom.xml @@ -230,25 +230,25 @@ - - releases - Releases - http://192.168.0.123:8081/repository/maven-releases/ - - - snapshots - Snapshot - http://192.168.0.123:8081/repository/maven-snapshots/ - - + - + - + - + + + releases-hc + Releases + https://qs.taixingyiji.com:8082/repository/maven-releases/ + + + snapshots-hc + Snapshot + https://qs.taixingyiji.com:8082/repository/maven-snapshots/ +