package com.dcs.hnyz.cache;

import com.dcs.hnyz.cache.builder.ActionCacheBuilder;
import com.dcs.hnyz.cache.builder.DeviceToRegistersMapBuilder;
import com.dcs.hnyz.cache.builder.RegisterCodeMapBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.event.ApplicationReadyEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * RegisterCodeCacheInitializer
 * 初始化 缓存
 * @author: hmy
 * @date: 2025/5/27 14:28
 */
@Slf4j
@Component
public class CacheInitializer {

    @Resource
    private RegisterCodeMapBuilder registerCodeMapBuilder;
    @Resource
    private ActionCacheBuilder actionCacheBuilder;
    @Resource
    private DeviceToRegistersMapBuilder deviceToRegistersMapBuilder;

    @EventListener(ApplicationReadyEvent.class)
    public void init() {
        log.info("系统启动完成，开始构建 缓存...");
        registerCodeMapBuilder.build();//设备id->寄存器主数据项code映射缓存
        actionCacheBuilder.build();//动作配置缓存
        deviceToRegistersMapBuilder.build();//设备code->寄存器codeList映射缓存

        log.info(" 缓存构建完成");
    }
}