package com.bz.rmcp.alarm.config;

import com.bz.rmcp.alarm.util.Utils;
import com.zcxk.core.common.pojo.SnowIdDto;
import com.zcxk.core.common.util.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;

@Configuration
public class SnowflakeIdWorkerConfig {

    @Autowired
    private RedisTemplate redisTemplate;
    @Value("${spring.application.name}")
    private String appName;

    @Bean
    public SnowflakeIdWorker snowflakeIdWorker() {
        SnowIdDto dto = Utils.calculateDataIdAndWorkId(redisTemplate,appName);
        return new SnowflakeIdWorker(dto.getWorkerId(), dto.getDataCenterId());
    }
}
