package com.wx.application.util;

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

/**
 *   @description : UUID生成类
 *   ---------------------------------
 *   @author zj
 *   @since 2017-10-27
 */
public class UUIDGenerator { 

    public static String getUUID(){ 
        String s = UUID.randomUUID().toString(); 
        //去掉“-”符号 
        return s.substring(0,8)+s.substring(9,13)+s.substring(14,18)+s.substring(19,23)+s.substring(24); 
    } 
    
    /** 
     * 获得指定数目的UUID 
     * @param number int 需要获得的UUID数量 
     * @return String[] UUID数组 
     */ 
    public static String[] getUUID(int number){ 
        if(number < 1){ 
            return null; 
        } 
        String[] ss = new String[number]; 
        for(int i=0;i<number;i++){ 
            ss[i] = getUUID(); 
        } 
        return ss; 
    }
    
    /**
     * 获得一个UUID2.0
     * 年月日时分秒+5位随机数
     * @return String UUID 
     */
    public static String getRanNumUUID(){ 
    	SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");  
    	Date date = new Date();      	  
        String str = simpleDateFormat.format(date); 
        Random random = new Random();         
        int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数 
        return str+rannum;// 当前时间  
    }
    
    public static Long getLongUUID(){
    	return Long.valueOf(getRanLongUUID());
    }
    
    public static String getRanLongUUID(){
    	long s = System.currentTimeMillis();
    	Random random = new Random();         
    	int rannum = (int) (random.nextDouble() * (99999 - 10000 + 1)) + 10000;// 获取5位随机数 
        return String.valueOf(s) + rannum;
    }
    
}