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); - } - }