package com.ruoyi.common.utils;

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

    private static final String PREFIX = "jhcf";
    private static int COUNTER = 0;

    /**
     * 生成appId
     *
     * @author JiangYuQi
     * @date 2023-11-07
     */
    public static String createAppId() {
        long timestamp = System.currentTimeMillis();
        String sequencePart = String.format("%03d", getContractNextSequence());
        return PREFIX + timestamp+ StringUtils.randomString(10) + sequencePart;
    }

    private static synchronized int getContractNextSequence() {
        if (COUNTER >= 999) {
            COUNTER = 0;
        }
        return ++COUNTER;
    }

}
