|
|
@@ -118,7 +118,7 @@ public class DataCountService {
|
|
|
long now = System.currentTimeMillis();
|
|
|
long last = lastStartTime.get();
|
|
|
|
|
|
- if (now - last < INTERVAL_MILLIS) {
|
|
|
+ if (now - last < INTERVAL_MILLIS&&cacheBuildData!=null&&cacheParkData!=null||cacheTownData!=null) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
@@ -179,6 +179,7 @@ public class DataCountService {
|
|
|
List<Order> allOrder = dmsService.query(authService.getTokenOfServiceAccount(), DMSQuery.ORDER, Order.class, now);
|
|
|
List<LeaseDetail> lastLeaseDetail = dmsService.query(authService.getTokenOfServiceAccount(), DMSQuery.LAST_LEASE_DETAIL, LeaseDetail.class, now);
|
|
|
List<LeaseDetail> lastYearLease = dmsService.query(authService.getTokenOfServiceAccount(), DMSQuery.LAST_YEAR_LEASE_DETAIL, LeaseDetail.class, now);
|
|
|
+ List<P18EnterpriseEconomic> needP18EnterpriseEconomic = dmsService.query(authService.getTokenOfServiceAccount(), DMSQuery.THIS_YEAR_P18_ENTERPRISE_ECONOMIC, P18EnterpriseEconomic.class, now);
|
|
|
//处理一下拿到的数据,建一建索引
|
|
|
Map<String, List<EnterpriseEconomic>> enterpriseEconomicMap = new HashMap<>();
|
|
|
inDateEnterpriseEconomic.forEach(e -> {
|
|
|
@@ -208,13 +209,15 @@ public class DataCountService {
|
|
|
))
|
|
|
.values());
|
|
|
|
|
|
+ Map<String,BigDecimal> p18EnterpriseEconomicMap = mergeP118EnterpriseEconomicMap(needP18EnterpriseEconomic);
|
|
|
+
|
|
|
//楼宇/企业/企业经济数据遍历,全镇级/产业园级/楼栋级一并处理
|
|
|
|
|
|
//遍历并计算企业相关的结果
|
|
|
countEnterprise(allEnterprise, enterpriseEconomicMap, now);
|
|
|
|
|
|
//遍历计算产业园相关
|
|
|
- countIndustrialPark(allIndustrialPark);
|
|
|
+ countIndustrialPark(allIndustrialPark,p18EnterpriseEconomicMap);
|
|
|
|
|
|
//企呼我应
|
|
|
countOrder(allOrder);
|
|
|
@@ -231,6 +234,41 @@ public class DataCountService {
|
|
|
cacheBuildData = tempCacheBuildData;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 合并18项经济指标数据为营收数据,按企业合并
|
|
|
+ * @param needP18EnterpriseEconomic 18项经济指标数据
|
|
|
+ * @return 企业编码->营收数据
|
|
|
+ */
|
|
|
+ private Map<String, BigDecimal> mergeP118EnterpriseEconomicMap(List<P18EnterpriseEconomic> needP18EnterpriseEconomic) {
|
|
|
+ return needP18EnterpriseEconomic.stream()
|
|
|
+ .collect(Collectors.groupingBy(P18EnterpriseEconomic::getCEnterpriseCode))
|
|
|
+ .entrySet()
|
|
|
+ .stream()
|
|
|
+ .collect(Collectors.toMap(
|
|
|
+ Map.Entry::getKey,
|
|
|
+ e -> e.getValue().stream()
|
|
|
+ .map(this::getRevenue)
|
|
|
+ .reduce(BigDecimal::add)
|
|
|
+ .orElse(BigDecimal.ZERO)
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取营收数据
|
|
|
+ */
|
|
|
+ private BigDecimal getRevenue(P18EnterpriseEconomic p18){
|
|
|
+ return mergeAll(
|
|
|
+ p18.getCGsjyyysZf(),
|
|
|
+ p18.getCGsrxyys(),
|
|
|
+ p18.getCGsrlzyfwyys(),
|
|
|
+ p18.getCGshzyys(),
|
|
|
+ p18.getCGskjfwyys(),
|
|
|
+ p18.getCGswhtyhylyys(),
|
|
|
+ p18.getCQtfwy()
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
private void countHistoryData(List<Enterprise> allEnterprise, List<IndustrialPark> allIndustrialPark, List<LeaseDetail> lastYearLease, LocalDate now) {
|
|
|
//历史企业总数统计
|
|
|
//历史数据,所以不论企业现状如何
|
|
|
@@ -287,7 +325,7 @@ public class DataCountService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void countIndustrialPark(List<IndustrialPark> allIndustrialPark) {
|
|
|
+ private void countIndustrialPark(List<IndustrialPark> allIndustrialPark, Map<String, BigDecimal> p18EnterpriseEconomicMap) {
|
|
|
//简单统计并按父级编码建映射
|
|
|
simpleCountPark(allIndustrialPark);
|
|
|
Map<EnterpriseLevel, Map<String, Integer>> enterPriceLevelCountByPark = new HashMap<>();
|
|
|
@@ -310,6 +348,7 @@ public class DataCountService {
|
|
|
int enterPriceGsCount = 0;
|
|
|
Set<String> inParkEnterpriseCode = new HashSet<>();
|
|
|
List<String> aliveEnterprise = new ArrayList<>();
|
|
|
+ List<String> gsEnterprise = new ArrayList<>();
|
|
|
int usedRoomCount = 0;
|
|
|
|
|
|
allBuild = buildMap.get(parkCode);
|
|
|
@@ -418,6 +457,7 @@ public class DataCountService {
|
|
|
allGsProductByYtdThisYear = allGsProductByYtdThisYear.add(ytdThisYear.product);
|
|
|
allGsProductByYtdLastYear = allGsProductByYtdLastYear.add(ytdLastYear.product);
|
|
|
|
|
|
+ gsEnterprise.add(enterpriseCode);
|
|
|
}
|
|
|
|
|
|
aliveEnterprise.add(enterpriseCode);
|
|
|
@@ -454,15 +494,14 @@ public class DataCountService {
|
|
|
parkDataCount.put("enterPriseIndustry", enterPriceIndustryCount);
|
|
|
|
|
|
JSONArray topRevenue = new JSONArray();
|
|
|
- List<String> sortedEnterprise = aliveEnterprise.stream().sorted((a, b) -> {
|
|
|
- BigDecimal ar = economicCountBy12Month.get(a).revenue;
|
|
|
- BigDecimal br = economicCountBy12Month.get(b).revenue;
|
|
|
- return ar.compareTo(br) * -1;
|
|
|
- }).limit(10).collect(Collectors.toList());
|
|
|
+ List<String> sortedEnterprise = gsEnterprise
|
|
|
+ .stream()
|
|
|
+ .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 = economicCountBy12Month.get(enterPriseCode).product;
|
|
|
+ BigDecimal product =nullToZero( p18EnterpriseEconomicMap.get(enterPriseCode));
|
|
|
outPut.put("enterPriceCode", enterPriseCode);
|
|
|
outPut.put("enterPriceName", enterPrice.getCEnterpriseName());
|
|
|
if (product.compareTo(BigDecimal.ZERO)==0){
|
|
|
@@ -793,5 +832,15 @@ public class DataCountService {
|
|
|
return cacheBuildData.get(buildCode);
|
|
|
}
|
|
|
|
|
|
+ private static BigDecimal nullToZero(BigDecimal value){
|
|
|
+ return value == null ? BigDecimal.ZERO : value;
|
|
|
+ }
|
|
|
+ private static BigDecimal mergeAll(BigDecimal... values){
|
|
|
+ return Arrays.stream(values)
|
|
|
+ .map(DataCountService::nullToZero)
|
|
|
+ .reduce(BigDecimal::add)
|
|
|
+ .orElse(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|