Commit 13322653 authored by 施翔轲's avatar 施翔轲

优化定时批量禁用所有过期租户

parent b679eb19
...@@ -20,11 +20,12 @@ public class TenantTimerTask { ...@@ -20,11 +20,12 @@ public class TenantTimerTask {
private final ISysTenantService tenantService; private final ISysTenantService tenantService;
//@Value("${schedule.cronExpression}") /**
//private String cronExpression; * 每6小时扫描并禁用已过期租户账号
*/
@Scheduled(cron = "0 0 0/6 * * *") @Scheduled(cron = "0 0 0/6 * * *")
public void handleExpiredTenant() { public void updateExpiredTenantStatus() {
log.info("执行定时禁用已过期租户账号(6h/次)");
TenantHelper.ignore(tenantService::handleExpiredTenant); TenantHelper.ignore(tenantService::handleExpiredTenant);
} }
......
...@@ -74,19 +74,22 @@ public class ISysTenantServiceImpl implements ISysTenantService { ...@@ -74,19 +74,22 @@ public class ISysTenantServiceImpl implements ISysTenantService {
} }
/** /**
* 查询所有已过期租户 * 禁用所有已过期租户
*/ */
@Override @Override
public void handleExpiredTenant() { public void handleExpiredTenant() {
Date now = new Date(); Date now = new Date();
//查询所有已过期租户 //查询所有已过期租户
List<SysTenant> tenantList = baseMapper.selectList(new LambdaQueryWrapper<SysTenant>() List<SysTenant> tenantList = baseMapper.selectList(new LambdaQueryWrapper<SysTenant>()
.eq(SysTenant::getStatus, TenantConstants.NORMAL)
.gt(SysTenant::getStartTime, now) .gt(SysTenant::getStartTime, now)
.or() .or()
.lt(SysTenant::getExpireTime, now)); .lt(SysTenant::getExpireTime, now));
//批量禁用已过期租户 //批量禁用已过期租户
tenantList.forEach(sysTenant -> sysTenant.setStatus(TenantConstants.DISABLE)); if (!tenantList.isEmpty()) {
baseMapper.updateBatchById(tenantList); tenantList.forEach(sysTenant -> sysTenant.setStatus(TenantConstants.DISABLE));
baseMapper.updateBatchById(tenantList);
}
} }
// /** // /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment