自定义运单编号规则
伪代码
public class Test {
private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
private static final AtomicInteger sequenceGenerator = new AtomicInteger(0);
public static synchronized String generateWaybillCode(String CUSTOMER_ID) {
String currentDate = dateFormat.format(new Date());
int sequence = sequenceGenerator.incrementAndGet();
String waybillCode = CUSTOMER_ID + "-" + currentDate + "-" + String.format("%05d", sequence);
return waybillCode;
}
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
System.out.println(generateWaybillCode("HXSY"));
}
}
}
运行结果
HXSY-20240813-00001
HXSY-20240813-00002
HXSY-20240813-00003
HXSY-20240813-00004
HXSY-20240813-00005
HXSY-20240813-00006
HXSY-20240813-00007
HXSY-20240813-00008
HXSY-20240813-00009
HXSY-20240813-00010
简单的运单编号生成 不足之处 请指正. 不喜勿喷.