|
|
@@ -18,6 +18,7 @@ import javax.annotation.PostConstruct;
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.time.LocalDate;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
@@ -48,9 +49,11 @@ public class DataCountService {
|
|
|
MultiValueMap<String, IndustrialPark> buildMap = new LinkedMultiValueMap<>();
|
|
|
List<IndustrialPark> allPark = new ArrayList<>();
|
|
|
|
|
|
- private Map<String,String> nationalIndustryToMerged = new HashMap<>();
|
|
|
- private Map<String,String> nationalIndustryMap = new HashMap<>();
|
|
|
- private Map<String,String> regTypeMap = new HashMap<>();
|
|
|
+ private Map<String, String> nationalIndustryToMerged = new HashMap<>();
|
|
|
+ private Map<String, String> nationalIndustryMap = new HashMap<>();
|
|
|
+ private Map<String, String> regTypeMap = new HashMap<>();
|
|
|
+
|
|
|
+ private static final DateTimeFormatter YEAR_MONTH_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM");
|
|
|
|
|
|
@PostConstruct
|
|
|
public void init() {
|
|
|
@@ -58,8 +61,9 @@ public class DataCountService {
|
|
|
initRegType();
|
|
|
initNationalIndustry();
|
|
|
}
|
|
|
- private void initNationalIndustryToMerged () {
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
+
|
|
|
+ private void initNationalIndustryToMerged() {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("F", "批发和零售业");
|
|
|
map.put("I", "信息传输、软件和信息技术服务业");
|
|
|
map.put("L", "租赁和商务服务业");
|
|
|
@@ -69,8 +73,8 @@ public class DataCountService {
|
|
|
nationalIndustryToMerged = map;
|
|
|
}
|
|
|
|
|
|
- private void initRegType(){
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
+ private void initRegType() {
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("1", "注册实体型");
|
|
|
map.put("2", "注册非实体型");
|
|
|
map.put("3", "实体非注册型");
|
|
|
@@ -80,7 +84,7 @@ public class DataCountService {
|
|
|
|
|
|
|
|
|
private void initNationalIndustry() {
|
|
|
- Map<String,String> map = new HashMap<>();
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
map.put("A", "农、林、牧、渔业");
|
|
|
map.put("B", "采矿业");
|
|
|
map.put("C", "制造业");
|
|
|
@@ -106,7 +110,7 @@ public class DataCountService {
|
|
|
|
|
|
//简单限制统计频率
|
|
|
@Value("${app.count-cache-length}")
|
|
|
- private long INTERVAL_MILLIS ;
|
|
|
+ private long INTERVAL_MILLIS;
|
|
|
|
|
|
private final AtomicLong lastStartTime = new AtomicLong(0);
|
|
|
|
|
|
@@ -118,7 +122,7 @@ public class DataCountService {
|
|
|
long now = System.currentTimeMillis();
|
|
|
long last = lastStartTime.get();
|
|
|
|
|
|
- if (now - last < INTERVAL_MILLIS&&cacheBuildData!=null&&cacheParkData!=null||cacheTownData!=null) {
|
|
|
+ if (now - last < INTERVAL_MILLIS && cacheBuildData != null && cacheParkData != null || cacheTownData != null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -197,7 +201,7 @@ public class DataCountService {
|
|
|
.collect(Collectors.toMap(
|
|
|
LeaseDetail::getCRoomCode,
|
|
|
p -> p,
|
|
|
- (existing, replacement) ->{
|
|
|
+ (existing, replacement) -> {
|
|
|
LocalDate existingEnd = existing.getCEndDate();
|
|
|
LocalDate replacementEnd = replacement.getCEndDate();
|
|
|
|
|
|
@@ -209,7 +213,7 @@ public class DataCountService {
|
|
|
))
|
|
|
.values());
|
|
|
|
|
|
- Map<String,BigDecimal> p18EnterpriseEconomicMap = mergeP118EnterpriseEconomicMap(needP18EnterpriseEconomic);
|
|
|
+ Map<String, BigDecimal> p18EnterpriseEconomicMap = mergeP118EnterpriseEconomicMap(needP18EnterpriseEconomic);
|
|
|
|
|
|
//楼宇/企业/企业经济数据遍历,全镇级/产业园级/楼栋级一并处理
|
|
|
|
|
|
@@ -217,13 +221,13 @@ public class DataCountService {
|
|
|
countEnterprise(allEnterprise, enterpriseEconomicMap, now);
|
|
|
|
|
|
//遍历计算产业园相关
|
|
|
- countIndustrialPark(allIndustrialPark,p18EnterpriseEconomicMap);
|
|
|
+ countIndustrialPark(allIndustrialPark, p18EnterpriseEconomicMap);
|
|
|
|
|
|
//企呼我应
|
|
|
countOrder(allOrder);
|
|
|
|
|
|
//租赁信息相关统计
|
|
|
- countLease(lastLeaseDetail,now);
|
|
|
+ countLease(lastLeaseDetail, now);
|
|
|
|
|
|
countRoomStatusByLease(lastLeaseDetail, now);
|
|
|
|
|
|
@@ -237,6 +241,7 @@ public class DataCountService {
|
|
|
|
|
|
/**
|
|
|
* 合并18项经济指标数据为营收数据,按企业合并
|
|
|
+ *
|
|
|
* @param needP18EnterpriseEconomic 18项经济指标数据
|
|
|
* @return 企业编码->营收数据
|
|
|
*/
|
|
|
@@ -257,7 +262,7 @@ public class DataCountService {
|
|
|
/**
|
|
|
* 获取营收数据
|
|
|
*/
|
|
|
- private BigDecimal getRevenue(P18EnterpriseEconomic p18){
|
|
|
+ private BigDecimal getRevenue(P18EnterpriseEconomic p18) {
|
|
|
return mergeAll(
|
|
|
p18.getCGsjyyysZf(),
|
|
|
p18.getCGsrxyys(),
|
|
|
@@ -270,26 +275,42 @@ public class DataCountService {
|
|
|
}
|
|
|
|
|
|
private void countHistoryData(List<Enterprise> allEnterprise, List<IndustrialPark> allIndustrialPark, List<LeaseDetail> lastYearLease, LocalDate now) {
|
|
|
- //历史企业总数统计
|
|
|
- //历史数据,所以不论企业现状如何
|
|
|
- Map<String, List<Enterprise>> enterpriseMap = TimeUtil.split(allEnterprise, now);
|
|
|
- Map<String, Integer> enterpriseByMonth = enterpriseMap.entrySet()
|
|
|
- .stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size()));
|
|
|
-
|
|
|
- //历史异地企业统计
|
|
|
- //同上
|
|
|
- Map<String, List<Enterprise>> enterpriseInTownMap = TimeUtil.split(allEnterprise
|
|
|
- .stream()
|
|
|
- .filter(e -> Objects.equals(e.getCSsxqCode(), "#YIDIQIYE"))
|
|
|
- .collect(Collectors.toList()), now);
|
|
|
- Map<String, Integer> enterpriseInTownByMonth = enterpriseInTownMap.entrySet()
|
|
|
- .stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size()));
|
|
|
+
|
|
|
+ Map<String, List<LeaseDetail>> leaseStartMap = TimeUtil.split(lastYearLease, now, LeaseDetail::getCStartDate, LeaseDetail::getCStartDate);
|
|
|
+
|
|
|
+ Map<String, List<Enterprise>> leaseStartEnterpriseMap = leaseStartMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().stream()
|
|
|
+ .map(LeaseDetail::getCEnterpriseCode)
|
|
|
+ .distinct()
|
|
|
+ .map(code -> allEnterprise.stream()
|
|
|
+ .filter(enterprise -> Objects.equals(enterprise.getCUnifiedSocialCreditCode(), code))
|
|
|
+ .findFirst()
|
|
|
+ .orElse(null))
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .collect(Collectors.toList())
|
|
|
+ ));
|
|
|
+ Map<String, Integer> enterpriseByMonth = leaseStartEnterpriseMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().size()
|
|
|
+ ));
|
|
|
+ Map<String, Long> enterpriseInTownByMonth = leaseStartEnterpriseMap.entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().stream()
|
|
|
+ .filter(enterprise ->
|
|
|
+ Objects.equals(enterprise.getRegType(), "1") || Objects.equals(enterprise.getRegType(), "2")
|
|
|
+ )
|
|
|
+ .count()
|
|
|
+ ));
|
|
|
|
|
|
//历史房间总数统计
|
|
|
Map<String, List<IndustrialPark>> industrialParkMap = TimeUtil.split(allIndustrialPark
|
|
|
- .stream()
|
|
|
- .filter(e -> Objects.equals(e.getCResourceType(), "1"))
|
|
|
- .collect(Collectors.toList()),
|
|
|
+ .stream()
|
|
|
+ .filter(e -> Objects.equals(e.getCResourceType(), "1"))
|
|
|
+ .collect(Collectors.toList()),
|
|
|
now);
|
|
|
Map<String, Integer> roomByMonth = industrialParkMap.entrySet().stream().collect(
|
|
|
Collectors.toMap(Map.Entry::getKey, e -> e.getValue().size())
|
|
|
@@ -496,18 +517,18 @@ public class DataCountService {
|
|
|
JSONArray topRevenue = new JSONArray();
|
|
|
List<String> sortedEnterprise = gsEnterprise
|
|
|
.stream()
|
|
|
- .sorted(Comparator.comparing(p18EnterpriseEconomicMap::get,Comparator.nullsFirst(BigDecimal::compareTo)).reversed())
|
|
|
+ .sorted(Comparator.comparing(p18EnterpriseEconomicMap::get, Comparator.nullsFirst(BigDecimal::compareTo)).reversed())
|
|
|
.limit(10).collect(Collectors.toList());
|
|
|
for (String enterPriseCode : sortedEnterprise) {
|
|
|
JSONObject outPut = new JSONObject();
|
|
|
Enterprise enterPrice = aliveEnterpriseMap.get(enterPriseCode);
|
|
|
- BigDecimal product =nullToZero( p18EnterpriseEconomicMap.get(enterPriseCode));
|
|
|
+ BigDecimal product = nullToZero(p18EnterpriseEconomicMap.get(enterPriseCode));
|
|
|
outPut.put("enterPriceCode", enterPriseCode);
|
|
|
outPut.put("enterPriceName", enterPrice.getCEnterpriseName());
|
|
|
- if (product.compareTo(BigDecimal.ZERO)==0){
|
|
|
- outPut.put("enterPriceRevenue","暂无");
|
|
|
- }else {
|
|
|
- outPut.put("enterPriceRevenue",product);
|
|
|
+ if (product.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ outPut.put("enterPriceRevenue", "暂无");
|
|
|
+ } else {
|
|
|
+ outPut.put("enterPriceRevenue", product);
|
|
|
}
|
|
|
topRevenue.add(outPut);
|
|
|
}
|
|
|
@@ -530,7 +551,14 @@ public class DataCountService {
|
|
|
));
|
|
|
enterPriceLevelCountByPark.put(level, sortedDesc);
|
|
|
}
|
|
|
- tempCacheTownData.put("enterpriseLevelCountByPark", enterPriceLevelCountByPark);
|
|
|
+ tempCacheTownData.put("enterpriseLevelCountByPark", enterPriceLevelCountByPark
|
|
|
+ .entrySet().stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ e -> e.getKey().getDisplayLevel(),
|
|
|
+ Map.Entry::getValue,
|
|
|
+ (e1, e2) -> e1
|
|
|
+ )
|
|
|
+ ));
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -577,9 +605,9 @@ public class DataCountService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- BigDecimal totalFloorArea = allPark.stream().map(IndustrialPark::getCFloorArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
- BigDecimal totalBuildArea = allPark.stream().map(IndustrialPark::getCBuildingArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
- BigDecimal totalVacantArea = allPark.stream().map(IndustrialPark::getCVacantArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO,BigDecimal::add);
|
|
|
+ BigDecimal totalFloorArea = allPark.stream().map(IndustrialPark::getCFloorArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalBuildArea = allPark.stream().map(IndustrialPark::getCBuildingArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalVacantArea = allPark.stream().map(IndustrialPark::getCVacantArea).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
tempCacheTownData.put("parkCount", parkCount);
|
|
|
tempCacheTownData.put("parkType", parkTypeCount);
|
|
|
@@ -598,7 +626,7 @@ public class DataCountService {
|
|
|
Map<String, Integer> regTypeCount = new HashMap<>();
|
|
|
|
|
|
for (Enterprise enterPrise : allEnterprise) {
|
|
|
- boolean isInTown =Arrays.asList("1","3","4").contains(Optional.ofNullable(enterPrise.getRegType()).orElse("1"));
|
|
|
+ boolean isInTown = Arrays.asList("1", "3", "4").contains(Optional.ofNullable(enterPrise.getRegType()).orElse("1"));
|
|
|
boolean isGsqy = "2".equals(Optional.ofNullable(enterPrise.getIsGsqy()).orElse("1"));
|
|
|
boolean isAlive = true;
|
|
|
|
|
|
@@ -613,7 +641,7 @@ public class DataCountService {
|
|
|
|
|
|
String nationalIndustryCode = enterPrise.getCNationalIndustryCode();
|
|
|
String mergedNationalIndustry = null;
|
|
|
- if (nationalIndustryCode!=null&& !nationalIndustryCode.isEmpty()) {
|
|
|
+ if (nationalIndustryCode != null && !nationalIndustryCode.isEmpty()) {
|
|
|
String prefix = nationalIndustryCode.substring(0, 1);
|
|
|
String industry = nationalIndustryMap.get(prefix);
|
|
|
if (industryCount.containsKey(industry)) {
|
|
|
@@ -623,7 +651,7 @@ public class DataCountService {
|
|
|
}
|
|
|
mergedNationalIndustry = nationalIndustryToMerged.get(prefix);
|
|
|
}
|
|
|
- if (mergedNationalIndustry==null)mergedNationalIndustry = "其他";
|
|
|
+ if (mergedNationalIndustry == null) mergedNationalIndustry = "其他";
|
|
|
if (nationalIndustryCount.containsKey(mergedNationalIndustry)) {
|
|
|
nationalIndustryCount.put(mergedNationalIndustry, nationalIndustryCount.get(mergedNationalIndustry) + 1);
|
|
|
} else {
|
|
|
@@ -631,7 +659,7 @@ public class DataCountService {
|
|
|
}
|
|
|
String regType = enterPrise.getRegType();
|
|
|
String regTypeChinese = null;
|
|
|
- if (regType!=null&& !regType.isEmpty()){
|
|
|
+ if (regType != null && !regType.isEmpty()) {
|
|
|
regTypeChinese = regTypeMap.get(regType);
|
|
|
}
|
|
|
if (regTypeChinese == null) regTypeChinese = "其他";
|
|
|
@@ -706,7 +734,7 @@ public class DataCountService {
|
|
|
tempCacheTownData.put("orderCount", orderCount);
|
|
|
}
|
|
|
|
|
|
- private void countLease(List<LeaseDetail> allLease,LocalDate now) {
|
|
|
+ private void countLease(List<LeaseDetail> allLease, LocalDate now) {
|
|
|
List<LeaseDetail> timeoutIn1Month = new ArrayList<>();
|
|
|
List<LeaseDetail> timeoutIn3Month = new ArrayList<>();
|
|
|
|
|
|
@@ -832,10 +860,11 @@ public class DataCountService {
|
|
|
return cacheBuildData.get(buildCode);
|
|
|
}
|
|
|
|
|
|
- private static BigDecimal nullToZero(BigDecimal value){
|
|
|
+ private static BigDecimal nullToZero(BigDecimal value) {
|
|
|
return value == null ? BigDecimal.ZERO : value;
|
|
|
}
|
|
|
- private static BigDecimal mergeAll(BigDecimal... values){
|
|
|
+
|
|
|
+ private static BigDecimal mergeAll(BigDecimal... values) {
|
|
|
return Arrays.stream(values)
|
|
|
.map(DataCountService::nullToZero)
|
|
|
.reduce(BigDecimal::add)
|