package com.qiaoba.module.tenant.runner;

import com.qiaoba.common.base.constant.TenantConstant;
import com.qiaoba.common.base.context.BaseContext;
import com.qiaoba.module.tenant.service.SysTenantService;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

/**
 * 项目启动完成后-将主库中的租户信息同步到 Redis 中
 *
 * @author ailanyin
 * @version 1.0
 * @since 2022-09-22 04:20:28
 */
@Component
@RequiredArgsConstructor
public class SysTenantRunner implements ApplicationRunner {

    private final SysTenantService sysTenantService;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        BaseContext.setTenantId(TenantConstant.DEFAULT_TENANT_ID);
        sysTenantService.resetCache();
        BaseContext.clearTenantId();
    }
}
