package com.mini.capi.utils;

import java.security.SecureRandom;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class vId {

    private static final SecureRandom RAND = new SecureRandom();
    private static final DateTimeFormatter DF = DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS");

    private vId() {}


    /**
     *
     * 时间戳唯一编号
     */
    public static String getUid() {
        // 17 位时间
        String tm = LocalDateTime.now().format(DF);
        // 25 位随机数字（高位补零）
        long rand = Math.abs(RAND.nextLong()) % (long) Math.pow(10, 15);
        return tm + String.format("%015d", rand);
    }

}
