package org.springblade.modules.app.utils;

import com.wn.common.tools.date.DateUtils;
import lombok.extern.slf4j.Slf4j;

import java.util.Date;
import java.util.Random;

/**
 * @author qa
 * @date 2019/2/23
 */
@Slf4j
public class StringTools {
    /**
     * 随机生成号码，当前时间+随机五位数
     */
    public static String generateCode() {
        return generateCode(null);
    }

    /**
     * 随机生成号码，前缀+当前时间+随机五位数
     */
    public static String generateCode(String preFix) {
        preFix = preFix == null ? "" : preFix;
        String str = DateUtils.format(new Date(), DateUtils.FORMAT_TIMESTAMP);
        Random random = new Random();
        int ranNum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;
        return preFix + str + ranNum;
    }

    public static String generateChannelCode(String preFix) {
        preFix = preFix == null ? "" : preFix;
        String str = System.currentTimeMillis() + "";
        Random random = new Random();
        return preFix + str;
    }
}
