Compare commits
1 Commits
cursor/bc-
...
mentat-611
Author | SHA1 | Date | |
---|---|---|---|
![]() |
6cbcf13447 |
@@ -5,6 +5,8 @@ import cn.hutool.core.exceptions.ExceptionUtil;
|
|||||||
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
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.service.TenantFrameworkService;
|
||||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
|
||||||
|
import cn.iocoder.yudao.module.system.dal.dataobject.tenant.TenantDO;
|
||||||
|
import cn.iocoder.yudao.module.system.service.tenant.TenantService;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.aspectj.lang.ProceedingJoinPoint;
|
import org.aspectj.lang.ProceedingJoinPoint;
|
||||||
@@ -29,6 +31,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
public class TenantJobAspect {
|
public class TenantJobAspect {
|
||||||
|
|
||||||
private final TenantFrameworkService tenantFrameworkService;
|
private final TenantFrameworkService tenantFrameworkService;
|
||||||
|
private final TenantService tenantService;
|
||||||
|
|
||||||
@Around("@annotation(tenantJob)")
|
@Around("@annotation(tenantJob)")
|
||||||
public String around(ProceedingJoinPoint joinPoint, TenantJob tenantJob) {
|
public String around(ProceedingJoinPoint joinPoint, TenantJob tenantJob) {
|
||||||
@@ -44,6 +47,10 @@ public class TenantJobAspect {
|
|||||||
// TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况
|
// TODO 芋艿:先通过 parallel 实现并行;1)多个租户,是一条执行日志;2)异常的情况
|
||||||
TenantUtils.execute(tenantId, () -> {
|
TenantUtils.execute(tenantId, () -> {
|
||||||
try {
|
try {
|
||||||
|
TenantDO tenant = tenantService.getTenant(tenantId);
|
||||||
|
if (tenant.getStatus().equals(CommonStatusEnum.DISABLE.getStatus())) {
|
||||||
|
return; // Skip disabled tenants
|
||||||
|
}
|
||||||
joinPoint.proceed();
|
joinPoint.proceed();
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
results.put(tenantId, ExceptionUtil.getRootCauseMessage(e));
|
results.put(tenantId, ExceptionUtil.getRootCauseMessage(e));
|
||||||
@@ -53,4 +60,4 @@ public class TenantJobAspect {
|
|||||||
return JsonUtils.toJsonString(results);
|
return JsonUtils.toJsonString(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@@ -403,13 +403,37 @@ public class TenantServiceImplTest extends BaseDbUnitTest {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTenantJobAspect_skipDisabledTenants() {
|
||||||
|
// mock 租户
|
||||||
|
TenantDO enabledTenant = randomPojo(TenantDO.class, o -> o.setStatus(CommonStatusEnum.ENABLE.getStatus()));
|
||||||
|
TenantDO disabledTenant = randomPojo(TenantDO.class, o -> o.setStatus(CommonStatusEnum.DISABLE.getStatus()));
|
||||||
|
tenantMapper.insert(enabledTenant);
|
||||||
|
tenantMapper.insert(disabledTenant);
|
||||||
|
// mock tenantService
|
||||||
|
when(tenantService.getTenant(enabledTenant.getId())).thenReturn(enabledTenant);
|
||||||
|
when(tenantService.getTenant(disabledTenant.getId())).thenReturn(disabledTenant);
|
||||||
|
|
||||||
|
// mock tenantFrameworkService
|
||||||
|
when(tenantFrameworkService.getTenantIds()).thenReturn(Arrays.asList(enabledTenant.getId(), disabledTenant.getId()));
|
||||||
|
|
||||||
|
// mock joinPoint
|
||||||
|
ProceedingJoinPoint joinPoint = mock(ProceedingJoinPoint.class);
|
||||||
|
|
||||||
|
// 调用
|
||||||
|
TenantJobAspect aspect = new TenantJobAspect(tenantFrameworkService, tenantService);
|
||||||
|
aspect.around(joinPoint, mock(TenantJob.class));
|
||||||
|
|
||||||
|
// 断言
|
||||||
|
verify(joinPoint, times(1)).proceed();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHandleTenantMenu_disable() {
|
public void testHandleTenantMenu_disable() {
|
||||||
// 准备参数
|
// 准备参数
|
||||||
TenantMenuHandler handler = mock(TenantMenuHandler.class);
|
TenantMenuHandler handler = mock(TenantMenuHandler.class);
|
||||||
// mock 禁用
|
// mock 禁用
|
||||||
when(tenantProperties.getEnable()).thenReturn(false);
|
when(tenantProperties.getEnable()).thenReturn(false);
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
tenantService.handleTenantMenu(handler);
|
tenantService.handleTenantMenu(handler);
|
||||||
// 断言
|
// 断言
|
||||||
|
Reference in New Issue
Block a user