package com.yanzhu.common.core.utils;

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

/**
 * 编号工具类
 *
 * @author JiangYuQi
 * @date 2023-11-07
 */
public class NoUtils {

    private static int Seq = 0;
    private static final String PREFIX = "S";

    /**
     * 生成任务编号
     * @author JiangYuQi
     * @date 2023-11-07
     */
    public static String nextNo(){
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("YY");
        String dateString = formatter.format(currentTime);
        String prefix = String.format("%03d", getNextSequence());
        return PREFIX+dateString+System.currentTimeMillis()+prefix;
    }

    private static synchronized int getNextSequence() {
        if (Seq >= 99) {
            Seq = 0;
        }
        return ++Seq;
    }

}
