package com.cool.store.utils;

import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.Random;

/**
 * 唯一性ID工具类
 *
 * @author Aaron
 * @ClassName UUIDUtils
 * @Description 唯一性ID工具类
 */
public class UUIDUtils {

    private static final String ID_PREFIX = "12";

    private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(CoolDateUtils.DATE_FORMAT_SEC_8);

    /**
     * 简化的UUID，去掉了横线，使用性能更好的ThreadLocalRandom生成UUID
     */
    public static String get32UUID() {
        return IdUtil.fastSimpleUUID();
    }
    public static String get8UUID() {
        return StringUtils.substring(IdUtil.fastSimpleUUID(),1,9);
    }

    public static Long get8LongUuid() {
        long uuid = (int) (Math.random() * 90000000 + 10000000);
        return uuid;
    }
    // 生成 UUID 方法
    public static String generateCustomUUID(Integer randomCount) {
        String today = LocalDate.now().format(DATE_FORMATTER);
        return ID_PREFIX + today + String.format("%04d", randomCount);
    }
}
