package com.dsk.web.schedule;

import com.dsk.common.tenant.helper.TenantHelper;
import com.dsk.cscec.service.AdvisoryBodyService;
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;
    private final AdvisoryBodyService advisoryBodyService;

    /**
     * 每10分钟扫描并禁用已过期租户账号
     */
    @Scheduled(cron = "0 0/10 * * * ? ")
    public void updateExpiredTenantStatus() {
        log.info("执行定时禁用已过期租户账号(10min/次)");
        TenantHelper.ignore(tenantService::handleExpiredTenant);
    }

    /**
     * 每小时更新一次咨询机构经营范围
     */
    @Scheduled(cron = "0 0 * 1/1 * ? ")
    public void updateAdvisoryBodyBusinessScope() {
        log.info("执行定时更新咨询机构经营范围(1h/次)");
        TenantHelper.ignore(advisoryBodyService::updateAdvisoryBodyBusinessScope);
    }

}