Commit 1ba8ba26 authored by 周健威's avatar 周健威

Merge branch 'master-tiande' into dev-tiande

parents 0e6f3180 fc0e230d
......@@ -6,14 +6,16 @@ import cn.hutool.core.util.StrUtil;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
public class OrderUtil {
public static final String DEFAULT_MID = "00";
public static final String APP_MID = "01";
public static final String COMPANY_MID = "05";
static Date today = new Date();
static int orderIndex = 0;
static AtomicInteger orderIndex = new AtomicInteger(0);
@SuppressWarnings("deprecation")
private static String getIndex(String midFix) {
......@@ -24,19 +26,19 @@ public class OrderUtil {
SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currTime = outFormat.format(n);
if (orderIndex > 0) {
if (orderIndex.intValue() > 0) {
if (n.getYear() == today.getYear() && n.getMonth() == today.getMonth() && n.getDay() == today.getDay()) {
orderIndex += 1;
orderIndex.getAndIncrement();
} else {
today = n;
orderIndex = 1;
orderIndex = new AtomicInteger(1);
}
} else {
today = n;
orderIndex = 1;
orderIndex = new AtomicInteger(1);
}
if (orderIndex > 9999) {
orderIndex = 1;
if (orderIndex.intValue() > 9999) {
orderIndex = new AtomicInteger(1);
}
String indexString = String.format("%s%s%04d", currTime, midFix, orderIndex);
return indexString;
......@@ -44,7 +46,7 @@ public class OrderUtil {
/**
* 生成订单号
*
*
* @param preFixString
* @return
*/
......@@ -66,7 +68,7 @@ public class OrderUtil {
/**
* 获取时间戳
*
*
* @return
*/
public static String GetTimestamp() {
......@@ -75,7 +77,7 @@ public class OrderUtil {
/**
* 生成随机数
*
*
* @return
*/
public static String CreateNoncestr() {
......@@ -83,3 +85,4 @@ public class OrderUtil {
return MD5.GetMD5String(String.valueOf(random.nextInt(10000)));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment