public class Order {
private static int orderNum = 0001;
public static String getOrderNo(){
long No = 0;
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
String nowdate = sdf.format(new Date());
No = Long.parseLong(nowdate)*10000;//这里如果一天订单多的话可以用一万或更大
No+=getNo();
return getUserId()+No;
}
public static int getNo(){//返回当天的订单数+1
orderNum++;
return orderNum;
}
public static String getUserId(){
return "123";
}
public static String RandomStringId(){
UUID uuid = UUID.randomUUID();
return uuid.toString();
}
}
也可以user+随机数+流水号(流水号为全局递增变量) 服务器重启就生成新的随机数