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; ...@@ -6,14 +6,16 @@ import cn.hutool.core.util.StrUtil;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.Random; import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
public class OrderUtil { public class OrderUtil {
public static final String DEFAULT_MID = "00"; public static final String DEFAULT_MID = "00";
public static final String APP_MID = "01"; public static final String APP_MID = "01";
public static final String COMPANY_MID = "05";
static Date today = new Date(); static Date today = new Date();
static int orderIndex = 0; static AtomicInteger orderIndex = new AtomicInteger(0);
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static String getIndex(String midFix) { private static String getIndex(String midFix) {
...@@ -24,19 +26,19 @@ public class OrderUtil { ...@@ -24,19 +26,19 @@ public class OrderUtil {
SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat outFormat = new SimpleDateFormat("yyyyMMddHHmmss");
String currTime = outFormat.format(n); 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()) { if (n.getYear() == today.getYear() && n.getMonth() == today.getMonth() && n.getDay() == today.getDay()) {
orderIndex += 1; orderIndex.getAndIncrement();
} else { } else {
today = n; today = n;
orderIndex = 1; orderIndex = new AtomicInteger(1);
} }
} else { } else {
today = n; today = n;
orderIndex = 1; orderIndex = new AtomicInteger(1);
} }
if (orderIndex > 9999) { if (orderIndex.intValue() > 9999) {
orderIndex = 1; orderIndex = new AtomicInteger(1);
} }
String indexString = String.format("%s%s%04d", currTime, midFix, orderIndex); String indexString = String.format("%s%s%04d", currTime, midFix, orderIndex);
return indexString; return indexString;
...@@ -83,3 +85,4 @@ public class OrderUtil { ...@@ -83,3 +85,4 @@ public class OrderUtil {
return MD5.GetMD5String(String.valueOf(random.nextInt(10000))); 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