最近研究了一下实际到货单号的使用,发现有很多的方式可以去生成,除了md5加上uuid等方式,还有DistributedAtomicInteger
Date now = new Date();
String nowtime = format.format(now);//“yyyyMMddHHmmssSSS”
DistributedAtomicInteger atomicInteger = new DistributedAtomicInteger(Recipes_DistAtomicInt.getClient(), CPU_ARRIVEYORDER_BILLCODE_CREATE_PATH + nowtime, new RetryNTimes(3, 1000));
String code = String.valueOf(atomicInteger.increment().postValue());
int codelength = code.length();
String templ = codelength >= 3 ? code : “000”.substring(codelength) + code;
String billcode = “DH” + nowtime + templ;
return billcode;