package com.bonus.sgzb.material.config;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * 后端生产随机编码通用方法（格式：今日年月日日期-随机4位编码  20240328-0001）
 * @Author ma_sh
 * @create 2024/3/28 17:42
 */
public class FieldGenerator {

    public static String generateField() {
        LocalDate today = LocalDate.now();
        String currentDate = today.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
        // 生成UUID并取后4位，转换为纯数字类型
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        String uuidLast4Digits = uuid.substring(uuid.length() - 7);
        int uuidLast4DigitsNumeric = Integer.parseInt(uuidLast4Digits, 16);
        return currentDate + "-" + String.format("%07d", uuidLast4DigitsNumeric % 10000);
    }
}
