批次號生成
阿新 • • 發佈:2018-12-04
gets row 當前時間 日期 mss ext integer 批次 format
/**
* 批次號生成
* 生成規則:當天日期[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;}
批次號生成