yangys
2025-11-14 fca5c28c79b061f4db3658f6d9e043024f326962
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package com.qianwen.mdc.collect.config;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
 
import com.hy.properties.IdGeneratorOptions;
 
/**
 * 漂移雪花算法的option生成配置
 */
@Configuration
public class WFGIdGeneratorConfig {
 
    @Autowired
    private WfgProperties wftProperties;
    
    @Bean(name="idGeneratorOptions") //bean的name必须为该值!!!
    public IdGeneratorOptions buildOptions() {
        IdGeneratorOptions options = new IdGeneratorOptions();
        options.setBaseTime(wftProperties.getBaseTime());
        
        options.setWorkerId(wftProperties.getWorkerId());
        options.setDataCenterId((short)wftProperties.getDataCenterId());
        options.setDataCenterIdBitLength(wftProperties.getDataCenterIdBitLength());
        options.setMaxSeqNumber(wftProperties.getMaxSeqNumber());
        options.setMethod(wftProperties.getMethod());
        options.setMinSeqNumber(wftProperties.getMinSeqNumber());
        options.setSeqBitLength(wftProperties.getSeqBitLength());
        options.setTopOverCostCount(wftProperties.getTopOverCostCount());
        options.setWorkerIdBitLength(wftProperties.getWorkerIdBitLength());
        return options;
    }
}