DistributedIdService.java 706 Bytes
Newer Older
1 2 3 4 5 6 7 8 9
package pwc.taxtech.atms.service.impl;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import pwc.taxtech.atms.common.util.SnowFlake;

import javax.annotation.PostConstruct;

@Component
eddie.woo's avatar
eddie.woo committed
10
public class DistributedIdService {
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
    @Value("${distributed_id_datacenter}")
    private Integer dataCenterId;
    @Value("${distributed_id_machine}")
    private Integer machineId;

    private SnowFlake snowFlake;

    @PostConstruct
    public void init() {
        snowFlake = new SnowFlake(dataCenterId, machineId);
    }

    /**
     * 获取Id
     *
     * @return long
     */
    public long nextId() {
        return snowFlake.nextId();
    }
}