package pwc.taxtech.atms.service.impl;

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

import javax.annotation.PostConstruct;

@Component
public class DistributedIdService extends BaseService {
    @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();
    }
}