|
|
@@ -17,6 +17,8 @@ import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.*;
|
|
|
+import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
+import java.util.concurrent.atomic.AtomicLong;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
@@ -44,6 +46,37 @@ public class DataCountService {
|
|
|
MultiValueMap<String, IndustrialPark> buildMap = new LinkedMultiValueMap<>();
|
|
|
List<IndustrialPark> allPark = new ArrayList<>();
|
|
|
|
|
|
+ //简单限制统计频率
|
|
|
+ private static final long INTERVAL_MILLIS = 250;
|
|
|
+
|
|
|
+ private final AtomicLong lastStartTime = new AtomicLong(0);
|
|
|
+
|
|
|
+ private final AtomicBoolean running = new AtomicBoolean(false);
|
|
|
+
|
|
|
+ @PostConstruct
|
|
|
+ public void tryCount() {
|
|
|
+ long now = System.currentTimeMillis();
|
|
|
+ long last = lastStartTime.get();
|
|
|
+
|
|
|
+ if (now - last < INTERVAL_MILLIS) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!running.compareAndSet(false, true)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (now - lastStartTime.get() < INTERVAL_MILLIS) {
|
|
|
+ running.set(false);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ count(now);
|
|
|
+ } finally {
|
|
|
+ running.set(false);
|
|
|
+ }
|
|
|
+ }
|
|
|
@NoArgsConstructor
|
|
|
private static class EnterpriseEconomicCount{
|
|
|
BigDecimal tax = BigDecimal.ZERO;
|
|
|
@@ -58,8 +91,8 @@ public class DataCountService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @PostConstruct
|
|
|
- public void count() {
|
|
|
+ public void count(long startTime) {
|
|
|
+ lastStartTime.set(startTime);
|
|
|
tempCacheTownData = new JSONObject();
|
|
|
tempCacheParkData = new HashMap<>();
|
|
|
tempCacheBuildData = new HashMap<>();
|
|
|
@@ -411,11 +444,6 @@ public class DataCountService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void tryCount() {
|
|
|
- if (!counted) {
|
|
|
- count();
|
|
|
- }
|
|
|
- }
|
|
|
|
|
|
public JSONObject getTownData() {
|
|
|
tryCount();
|