package com.dxhy.config.runner;

import com.dxhy.common.constant.DbConstant;
import com.dxhy.common.datasource.config.DynamicContextHolder;
import com.dxhy.jxpt.baseService.config.service.SysDictdetaService;
import com.dxhy.jxpt.baseService.config.service.SysTabulateDeptService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.Ordered;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @description 服务启动后，自动刷新redis缓存，规则数据，发票类型,黑名单，城市，用户，企业信息会被刷新到redis缓存中
 */
@Slf4j
@Component
public class AutoFreshRedisCatchRunner implements CommandLineRunner, Ordered {

    @Resource
    private SysDictdetaService sysDictdetaService;
    @Resource
    private SysTabulateDeptService sysTabulateDeptService;

    @Override
    public void run(String... args) {
        DynamicContextHolder.push(DbConstant.BASICS_READ);
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>刷新 业务字典 缓存开始........................");
        sysDictdetaService.refreshCache();
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>刷新 业务字典 缓存结束........................");
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>刷新 显示列表 缓存开始........................");
        sysTabulateDeptService.refreshCache("");
        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>刷新 显示列表 缓存结束........................");
    }

    @Override
    public int getOrder() {
        return 0;
    }
}