package com.tofly.feesapi.common.util;

import com.tofly.common.core.util.StringUtil;
import io.netty.util.internal.ThreadLocalRandom;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.UUID;

public class GuidGenerator {

    public static String getGuid() {
        UUID uuid = UUID.randomUUID();
        return uuid.toString().replace("-", "").toUpperCase();
    }

    public static String getSflsbh() {
        return getSflsbh("S", "");
    }

    public static String getSflsbh(String yhbh) {
        return getSflsbh("S", yhbh);
    }

    public static String getSflsbh(String type, String yhbh) {
        String prefix = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
        long random = ThreadLocalRandom.current().nextInt(10000);
        if (StringUtil.isNotEmpty(yhbh)) {
            return String.format("%s%s%05d%s", type, prefix, random, yhbh);
        }
        return String.format("%s%s%05d", type, prefix, random);
    }
    public static String getQflsbh() {
        return getSflsbh("Q", "");
    }

    public static String getQflsbh(String yhbh) {
        return getSflsbh("Q", yhbh);
    }
    public static String getQflsbh(String type, String yhbh) {
        String prefix = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"));
        long random = ThreadLocalRandom.current().nextInt(10000);
        if (StringUtil.isNotEmpty(yhbh)) {
            return String.format("%s%s%05d%s", type, prefix, random, yhbh);
        }
        return String.format("%s%s%05d", type, prefix, random);
    }

}
