Commit 7127b465 authored by 施翔轲's avatar 施翔轲

定时批量禁用所有过期租户,6h/次

parent 652a71df
......@@ -3,6 +3,7 @@ package com.dsk;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup;
import org.springframework.scheduling.annotation.EnableScheduling;
/**
* 启动程序
......@@ -11,6 +12,7 @@ import org.springframework.boot.context.metrics.buffering.BufferingApplicationSt
*/
@SpringBootApplication
@EnableScheduling
public class DskOperateSysApplication {
public static void main(String[] args) {
......
package com.dsk.web.schedule;
import com.dsk.common.tenant.helper.TenantHelper;
import com.dsk.system.service.ISysTenantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
/**
* 租户相关定时任务类
*
* @author sxk
* @date 2023.09.06
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class TenantTimerTask {
private final ISysTenantService tenantService;
//@Value("${schedule.cronExpression}")
//private String cronExpression;
@Scheduled(cron = "0 0 0/6 * * *")
public void handleExpiredTenant() {
TenantHelper.ignore(tenantService::handleExpiredTenant);
}
}
\ No newline at end of file
......@@ -24,6 +24,11 @@ public interface ISysTenantService {
// */
// List<SysTenantVo> queryList(SysTenantBo bo);
/**
* 禁用所有已过期租户
*/
void handleExpiredTenant();
/**
* 查询租户
*/
......@@ -70,4 +75,5 @@ public interface ISysTenantService {
* 基于租户ID查询租户
*/
SysTenantVo queryByTenantId(String tenantId);
}
......@@ -32,6 +32,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
/**
......@@ -72,6 +73,22 @@ public class ISysTenantServiceImpl implements ISysTenantService {
return TableDataInfo.build(result);
}
/**
* 查询所有已过期租户
*/
@Override
public void handleExpiredTenant() {
Date now = new Date();
//查询所有已过期租户
List<SysTenant> tenantList = baseMapper.selectList(new LambdaQueryWrapper<SysTenant>()
.gt(SysTenant::getStartTime, now)
.or()
.lt(SysTenant::getExpireTime, now));
//批量禁用已过期租户
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