package com.changhu.common.utils;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import lombok.extern.slf4j.Slf4j;

/**
 * author: luozhun
 * desc: SnowFlakeIdUtil
 * createTime: 2023/8/16 17:33
 */
@Slf4j
public class SnowFlakeIdUtil {

    //todo 暂时先固定靶
    private static final Snowflake snowflake = IdUtil.getSnowflake(1, 0);

    /**
     * 系统默认雪花id生成
     *
     * @return 雪花id
     */
    public static synchronized long snowflakeId() {
        return snowflake.nextId();
    }

    /**
     * 指定生成雪花id
     *
     * @param workerId     机器id
     * @param datacenterId 数据中心id
     * @return 雪花id
     */
    public static synchronized long snowflakeId(long workerId, long datacenterId) {
        return IdUtil.getSnowflake(workerId, datacenterId).nextId();
    }
}
