package com.hwrj.cloud.portal.util;

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

public class UUIDUtils {
    public UUIDUtils() {
    }

    public static String randomUUID() {
        String uuid = UUID.randomUUID().toString();
        return replace(uuid);
    }

    public static String replace(String uuid) {
        return uuid.replaceAll("-", "");
    }

    public static synchronized String randomOrder() {
        String code = "";
        Random rand = new Random();

        for(int a = 0; a < 4; ++a) {
            code = code + rand.nextInt(10);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String orderNo = sdf.format(new Date()).substring(2) + code;
        return orderNo;
    }

    public static String randomOrderLeng(Integer leng) {
        String code = "";
        Random rand = new Random();

        for(int a = 0; a < leng; ++a) {
            code = code + rand.nextInt(10);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("SSS");
        String orderNo = "G" + sdf.format(new Date()) + code;
        return orderNo;
    }

    public static String randomCertLeng(Integer leng) {
        String code = "";
        Random rand = new Random();

        for(int a = 0; a < leng; ++a) {
            code = code + rand.nextInt(10);
        }

        return code;
    }

    public static String setCodeString(Integer lengs, String leng) {
        String s = "";

        for(int i = 1; i < leng.length(); ++i) {
            s = s + "0";
        }

        Integer n = lengs - leng.length();
        String code = randomCertLeng(n) + s;
        return code;
    }
}

