package com.dsk.web.schedule;

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

import javax.annotation.Resource;

/**
 * 租户相关定时任务类
 *
 * @author sxk
 * @date 2023.09.06
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class TenantTimerTask {
    @Resource
    private ISysTenantService tenantService;
    @Resource
    private AdvisoryBodyService advisoryBodyService;
    @Resource
    private CbProjectRecordService projectRecordService;

    /**
     * 每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);
    }

    /**
     * 每2分钟刷新一次项目台账列表内"解析中"项目的状态
     */
    @Scheduled(cron = "0 0/2 * * * ?")
    public void updateCbProjectRecordParseStatus() {
        log.info("每2分钟刷新一次项目台账列表内\"解析中\"项目的状态");
        TenantHelper.ignore(projectRecordService::updateCbProjectRecordParseStatus);
    }
}