1、生成订单号
import org.apache.commons.lang3.RandomStringUtils;
public final class OrderUtils {
/**
* 生成20位长度订单号
*
* @param id 商户ID
* @return 20位长度订单号
*/
public static String genOrderNo(long id) {
final int limit = 8;
final String sid = String.valueOf(id);
final int length = sid.length();
return DateFormatUtils.ISO_8601_SIMPLE_DATE_FORMAT.format(System.currentTimeMillis())
+ (length >= limit ? sid.substring(length - limit, length) : String.format("%0" + limit + "d", id))
+ RandomStringUtils.random(4, false, true);
}
}
标签:String,订单号,id,length,limit,常用工具,final
From: https://www.cnblogs.com/javalouvre/p/17919031.html