package com.cusc.nirvana.user.rnr.fp.common.util;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * Description SnowflakeUtil function
 *
 * @author zx
 * @version 1.0
 * @date 2022-06-15 10:42
 */
@Component
@Slf4j
public class SnowflakeUtil {
    //为终端ID
    private long workerId = 0;
    //数据中心ID
    private long datacenterId = 1;
    private Snowflake snowflake = IdUtil.getSnowflake(workerId, datacenterId);

    public synchronized long snowflakeId() {
        return snowflake.nextId();
    }

    public synchronized String snowflakeIdStr() {
        return snowflake.nextIdStr();
    }

    public synchronized long snowflakeId(long workerId, long datacenterId) {
        Snowflake snowflake = IdUtil.getSnowflake(workerId, datacenterId);
        return snowflake.nextId();
    }
}
