package com.tuoheng.admin.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/**
 * @author chenjiandong
 * @description: 生成随机序列号
 * @date 2022/11/9 15:59
 */
public class GenerateDroneSerialNumber {

    public static String[] chars = new String[] {
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
        "A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
    };


    public static String generateShortUuid() {
        StringBuffer shortBuffer = new StringBuffer();
        String uuid = UUID.randomUUID().toString().replace("-", "");
        for (int i = 0; i < 8; i++) {
            String str = uuid.substring(i * 4, i * 4 + 4);
            int x = Integer.parseInt(str, 16);
            shortBuffer.append(chars[x % 34]);
        }
        return shortBuffer.toString();

    }

    public static String getDateCode() {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("YYMM");
        String sdfDateCode = sdf.format(d);
        System.out.println("格式化后的日期年月code：" + sdfDateCode);
        return sdfDateCode;
    }

}
