• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

诺曼底Windy

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

批次号生成

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

posted on 2018-12-04 13:38  诺曼底Windy  阅读(801)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3