package com.ruoyi.xq.manager;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.ruoyi.xq.enums.common.TraceIdEnum;

public class TraceIdManager {

    private static final Snowflake SNOWFLAKE;

    static {
        int dataId = 1;
        String id = System.getProperty("DATA_ID");
        if(id != null){
            dataId = Integer.parseInt(id);
        }
        SNOWFLAKE = IdUtil.getSnowflake(1, dataId);
    }

    public static String gen(TraceIdEnum traceIdEnum){
        return traceIdEnum.getCode() + SNOWFLAKE.nextIdStr();
    }


}
