码迷,mamicode.com
首页 > 其他好文 > 详细

批次号生成

时间:2018-12-04 14:51:06      阅读:1222      评论:0      收藏:0      [点我收藏+]

标签:bat   customer   getc   string   date()   ble   tom   append   hmm   

/**
* 批次号生成
* 生成规则:当天日期[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;
}

批次号生成

标签:bat   customer   getc   string   date()   ble   tom   append   hmm   

原文地址:https://www.cnblogs.com/SmileWindy/p/10063640.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!