From 3eb13125cb15f4ea65853ab7910c8ae8d201292e Mon Sep 17 00:00:00 2001 From: Guoqs <123@jsowell.com> Date: Thu, 21 Nov 2024 16:01:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E6=96=B9=E6=B3=95=E8=80=97?= =?UTF-8?q?=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/jsowell/service/TempService.java | 2 + .../jsowell/common/annotation/CostTime.java | 15 +++++++ jsowell-framework/pom.xml | 4 ++ .../framework/aspectj/CostTimeAspect.java | 39 +++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 100644 jsowell-common/src/main/java/com/jsowell/common/annotation/CostTime.java create mode 100644 jsowell-framework/src/main/java/com/jsowell/framework/aspectj/CostTimeAspect.java diff --git a/jsowell-admin/src/main/java/com/jsowell/service/TempService.java b/jsowell-admin/src/main/java/com/jsowell/service/TempService.java index 8ef31a78e..58fa26b5c 100644 --- a/jsowell-admin/src/main/java/com/jsowell/service/TempService.java +++ b/jsowell-admin/src/main/java/com/jsowell/service/TempService.java @@ -14,6 +14,7 @@ import com.jsowell.adapay.response.QueryPaymentConfirmDetailResponse; import com.jsowell.adapay.service.AdapayService; import com.jsowell.adapay.vo.OrderSplitResult; import com.jsowell.adapay.vo.PaymentInfo; +import com.jsowell.common.annotation.CostTime; import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.enums.adapay.AdapayStatusEnum; import com.jsowell.common.enums.ykc.*; @@ -592,6 +593,7 @@ public class TempService { /** * 校验是否为并充订单 */ + @CostTime public Map> checkCombinedChargingOrder(List orderCodeList) throws BaseAdaPayException { Map> resultMap = Maps.newHashMap(); List combinedChargingOrderList = Lists.newArrayList(); diff --git a/jsowell-common/src/main/java/com/jsowell/common/annotation/CostTime.java b/jsowell-common/src/main/java/com/jsowell/common/annotation/CostTime.java new file mode 100644 index 000000000..2467192de --- /dev/null +++ b/jsowell-common/src/main/java/com/jsowell/common/annotation/CostTime.java @@ -0,0 +1,15 @@ +package com.jsowell.common.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 统计函数执行耗时 + */ +@Target({ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface CostTime { + +} \ No newline at end of file diff --git a/jsowell-framework/pom.xml b/jsowell-framework/pom.xml index bcadd8a8b..e31ffef36 100644 --- a/jsowell-framework/pom.xml +++ b/jsowell-framework/pom.xml @@ -68,6 +68,10 @@ + + org.projectlombok + lombok + diff --git a/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/CostTimeAspect.java b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/CostTimeAspect.java new file mode 100644 index 000000000..4851327d4 --- /dev/null +++ b/jsowell-framework/src/main/java/com/jsowell/framework/aspectj/CostTimeAspect.java @@ -0,0 +1,39 @@ +package com.jsowell.framework.aspectj; + +import lombok.extern.slf4j.Slf4j; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +@Aspect +@Component// 使用spring容器进行管理 +@Slf4j +public class CostTimeAspect { + /** + * 首先定义一个切点 + */ + // @org.aspectj.lang.annotation.Pointcut("@annotation(com.counttime.annotation.entity.CostTime)") + @org.aspectj.lang.annotation.Pointcut("@annotation(com.jsowell.common.annotation.CostTime)") + public void countTime() { + + } + + @Around("countTime()") + public Object doAround(ProceedingJoinPoint joinPoint) { + Object obj = null; + try { + long beginTime = System.currentTimeMillis(); + obj = joinPoint.proceed(); + // 获取方法名称 + String methodName = joinPoint.getSignature().getName(); + // 获取类名称 + String className = joinPoint.getSignature().getDeclaringTypeName(); + log.info("统计方法耗时, 类:[{}], 方法:[{}], 耗时时间为:[{}]", className, methodName, (System.currentTimeMillis() - beginTime) / 1000 + "秒"); + } catch (Throwable throwable) { + throwable.printStackTrace(); + } + return obj; + } +} +