From b80a928fec6ad9b066e957ed15aca6699986c2bc Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 16 Sep 2023 14:13:53 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=A4=9A=E7=A7=9F=E6=88=B7?= =?UTF-8?q?=20Job=20=E7=9A=84=E5=AE=9E=E7=8E=B0=EF=BC=8C=E4=BF=9D=E6=8C=81?= =?UTF-8?q?=E5=92=8C=20boot=20=E7=89=88=E6=9C=AC=E5=B0=BD=E9=87=8F?= =?UTF-8?q?=E4=B8=80=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tenant/core/job/TenantJobAspect.java | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java index 9c4c755cd..a0c39c631 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-tenant/src/main/java/cn/iocoder/yudao/framework/tenant/core/job/TenantJobAspect.java @@ -7,16 +7,13 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.tenant.core.service.TenantFrameworkService; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import com.xxl.job.core.context.XxlJobHelper; -import com.xxl.job.core.handler.annotation.XxlJob; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.lang3.exception.ExceptionUtils; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; -import org.aspectj.lang.reflect.MethodSignature; -import java.lang.annotation.Annotation; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -36,20 +33,8 @@ public class TenantJobAspect { private final TenantFrameworkService tenantFrameworkService; - @Around("@annotation(xxlJob)") - public Object around(ProceedingJoinPoint joinPoint, XxlJob xxlJob) throws Throwable { - // 如果非多租户 Job,则跳过 - TenantJob tenantJob = getClassAnnotation(joinPoint, TenantJob.class); - if (tenantJob == null) { - return joinPoint.proceed(); - } - - // 如果是多租户 Job,则会按照租户逐个执行 Job 的逻辑 - execute(joinPoint, xxlJob); - return null; // JobHandler 无返回 - } - - private void execute(ProceedingJoinPoint joinPoint, XxlJob xxlJob) { + @Around("@annotation(tenantJob)") + public void around(ProceedingJoinPoint joinPoint, TenantJob tenantJob) { // 获得租户列表 List tenantIds = tenantFrameworkService.getTenantIds(); if (CollUtil.isEmpty(tenantIds)) { @@ -67,7 +52,7 @@ public class TenantJobAspect { results.put(tenantId, ExceptionUtil.getRootCauseMessage(e)); // 打印异常 XxlJobHelper.log(StrUtil.format("[多租户({}) 执行任务({}),发生异常:{}]", - tenantId, xxlJob.value(), ExceptionUtils.getStackTrace(e))); + tenantId, joinPoint.getSignature(), ExceptionUtils.getStackTrace(e))); } }); }); @@ -77,9 +62,4 @@ public class TenantJobAspect { } } - @SuppressWarnings("SameParameterValue") - private static T getClassAnnotation(ProceedingJoinPoint joinPoint, Class annotationClass) { - return ((MethodSignature) joinPoint.getSignature()).getMethod().getDeclaringClass().getAnnotation(annotationClass); - } - }