/**
* 批次号生成
* 生成规则:当天日期[8位]+序列号[24位],如:20181031383385283484579432669936
* @return
*/
public static String getRandomBatchNum() {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
String format = dateFormat.format(new Date());
int max=24;
int min=24;
Random random = new Random();
int s = random.nextInt(max)%(max-min+1) + min;
StringBuffer buffer =new StringBuffer();
for(int i=0;i<s;i++){
Integer val = (int)(Math.random()*9+1);
buffer.append(val.toString());
}
return format+buffer.toString();
}
/**
* 生成唯一序列 规则:当前时间+6位随机数(yyyyMMddHHmmss123345)
* @param shortTableName 表名(缩写) 例:uc - user_customer
* @return
* @throws Exception
*/
public static synchronized String getSequence(String shortTableName) throws Exception {
String currentDate = getCurrentDate("yyyyMMddHHmmssS");
String random = random(8);
return shortTableName + currentDate + random;
}