Commit 23823d6b authored by 周健威's avatar 周健威

修改

parent 8d731f98
...@@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; ...@@ -6,6 +6,7 @@ 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 {
...@@ -14,7 +15,7 @@ public class OrderUtil { ...@@ -14,7 +15,7 @@ public class OrderUtil {
public static final String COMPANY_MID = "05"; 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) {
...@@ -25,19 +26,19 @@ public class OrderUtil { ...@@ -25,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;
......
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