diff --git a/epmet-commons/epmet-commons-tools/pom.xml b/epmet-commons/epmet-commons-tools/pom.xml
index 1a21a9a30e..e2fd786edf 100644
--- a/epmet-commons/epmet-commons-tools/pom.xml
+++ b/epmet-commons/epmet-commons-tools/pom.xml
@@ -49,6 +49,13 @@
org.springframework.boot
spring-boot-starter-data-redis
+
+
+ org.redisson
+ redisson
+ 3.12.5
+
+
com.fasterxml.jackson.core
jackson-databind
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/RedissonConfig.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/RedissonConfig.java
new file mode 100644
index 0000000000..8a96e5ccbd
--- /dev/null
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/RedissonConfig.java
@@ -0,0 +1,56 @@
+package com.epmet.commons.tools.config;
+
+import com.epmet.commons.tools.constant.NumConstant;
+import com.epmet.commons.tools.constant.StrConstant;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.redisson.Redisson;
+import org.redisson.api.RedissonClient;
+import org.redisson.codec.JsonJacksonCodec;
+import org.redisson.config.Config;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * redisson 配置类
+ */
+@Slf4j
+@Configuration
+public class RedissonConfig {
+
+ @Value("${spring.redis.host}")
+ private String host;
+ @Value("${spring.redis.port}")
+ private String port;
+ @Value("${spring.redis.password}")
+ private String password;
+
+
+ @Bean
+ public RedissonClient getRedisson() {
+ if (StringUtils.isBlank(host)) {
+ log.warn("getRedisson redis param is null,don't need to init redissonClient");
+ return null;
+ }
+
+ try {
+ Config config = new Config();
+ config.setCodec(new JsonJacksonCodec());
+ config.setThreads(NumConstant.FOUR);
+ config.setNettyThreads(NumConstant.FOUR);
+ //redis://ip:port
+ //redis的部署方式有单节点部署、主从方式部署、哨兵方式部署、集群方式部署
+ config.useSingleServer().setAddress("redis://".concat(host).concat(StrConstant.COLON).concat(port));
+ config.useSingleServer().setPassword(password);
+ config.useSingleServer().setConnectTimeout(NumConstant.ONE_THOUSAND * NumConstant.FIVE);
+ config.useSingleServer().setDatabase(NumConstant.TEN);
+ return Redisson.create(config);
+ } catch (Exception e) {
+ log.error("初始化redisson失败", e);
+ return null;
+ }
+
+ }
+
+}
\ No newline at end of file
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java
index 75c8c1cac9..01af04ae04 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/constant/NumConstant.java
@@ -39,6 +39,7 @@ public interface NumConstant {
int SIXTY = 60;
int ONE_HUNDRED = 100;
BigDecimal ONE_HUNDRED_DECIMAL = new BigDecimal(100);
+ BigDecimal ZERO_DECIMAL = new BigDecimal(0);
int ONE_THOUSAND = 1000;
int MAX = 99999999;
int EIGHTY_EIGHT = 88;
diff --git a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
index 12567a30d2..9de850cdfd 100644
--- a/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
+++ b/epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/redis/RedisKeys.java
@@ -330,9 +330,17 @@ public class RedisKeys {
/**
* 获取计算标记的key前缀
+ *
* @return
*/
public static String getCustomerStatsCalKeyPrefix() {
return rootPrefix.concat("stats:calflag");
}
+
+ /**
+ * 插入大屏指标数据分布式锁 key
+ */
+ public static String getScreenIndexDataLockKey() {
+ return rootPrefix.concat("stats:indexcal:lock");
+ }
}
diff --git a/epmet-module/data-statistical/data-statistical-server/Dockerfile b/epmet-module/data-statistical/data-statistical-server/Dockerfile
index 074bc1d2de..55d058c4b8 100644
--- a/epmet-module/data-statistical/data-statistical-server/Dockerfile
+++ b/epmet-module/data-statistical/data-statistical-server/Dockerfile
@@ -8,4 +8,5 @@ COPY ./target/*.jar ./data-stats.jar
EXPOSE 8108
-ENTRYPOINT ["sh", "-c", "$RUN_INSTRUCT"]
\ No newline at end of file
+#ENTRYPOINT ["sh", "-c", "$RUN_INSTRUCT"]
+ENTRYPOINT ["sh","-c","exec $RUN_INSTRUCT"]
\ No newline at end of file
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
index 420838dec5..11e082057a 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/controller/IndexCalculateController.java
@@ -60,6 +60,7 @@ public class IndexCalculateController {
@PreDestroy
public void saveCalStatus() {
+ log.info("data-statical-server服务被关闭,执行保存计算状态的动作");
// 实例销毁之前,将正在本实例中执行计算的客户列表的计算状态修改为pendding,等待其他实例重新计算
futureMap.forEach((customerId, future) -> {
CalculateFlagModel flag = (CalculateFlagModel) redisUtils.get(RedisKeys.getCustomerStatsCalFlag(customerId));
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java
index f4d97de2aa..00ebad6b5d 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/DeptScoreServiceImpl.java
@@ -140,12 +140,15 @@ public class DeptScoreServiceImpl extends BaseServiceImpl> selfSubParentMap = new HashMap<>();
selfSubParentMap.put(ProjectConstant.ZI_SHEN, new HashSet<>());
selfSubParentMap.put(ProjectConstant.XIA_JI, new HashSet<>());
+ Map weightMap = new HashMap<>();
selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标
if (o.getAllIndexCodePath().indexOf(ProjectConstant.XIA_JI) > -1) {
selfSubParentMap.get(ProjectConstant.XIA_JI).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.XIA_JI, weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)).add(o.getWeight()));
} else {
selfSubParentMap.get(ProjectConstant.ZI_SHEN).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.ZI_SHEN, weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)).add(o.getWeight()));
}
});
Map insertMap = new HashMap<>();
@@ -158,16 +161,16 @@ public class DeptScoreServiceImpl extends BaseServiceImpl> selfSubParentMap = new HashMap<>();
selfSubParentMap.put(ProjectConstant.ZI_SHEN, new HashSet<>());
selfSubParentMap.put(ProjectConstant.XIA_JI, new HashSet<>());
+ Map weightMap = new HashMap<>();
selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标
if (o.getAllIndexCodePath().indexOf(ProjectConstant.XIA_JI) > -1) {
selfSubParentMap.get(ProjectConstant.XIA_JI).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.XIA_JI, weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)).add(o.getWeight()));
} else {
selfSubParentMap.get(ProjectConstant.ZI_SHEN).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.ZI_SHEN, weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)).add(o.getWeight()));
}
});
Map insertMap = new HashMap<>();
@@ -148,16 +151,14 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
scoreEntity.setSelfScore(new BigDecimal(0));
scoreEntity.setSubScore(new BigDecimal(0));
scoreEntity.setParentIndexCode(index.getIndexCode());
- scoreEntity.setSelfWeight(new BigDecimal(0));
- scoreEntity.setSubWeight(new BigDecimal(0));
+ scoreEntity.setSubWeight(weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)));
+ scoreEntity.setSelfWeight(weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)));
}
BigDecimal partScore = score.getScore().multiply(score.getWeight());
if (selfSubParentMap.get(ProjectConstant.XIA_JI).contains(score.getIndexCode())) {
scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore));
- scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight()));
} else {
scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore));
- scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight()));
}
log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getGridId(), score.getScore(), score.getWeight(), partScore);
});
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java
index 34b95afaf4..bd290fd73d 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateCommunityServiceImpl.java
@@ -138,12 +138,15 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni
Map> selfSubParentMap = new HashMap<>();
selfSubParentMap.put(ProjectConstant.ZI_SHEN, new HashSet<>());
selfSubParentMap.put(ProjectConstant.XIA_JI, new HashSet<>());
+ Map weightMap = new HashMap<>();
selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标
if (o.getAllIndexCodePath().indexOf(ProjectConstant.XIA_JI) > -1) {
selfSubParentMap.get(ProjectConstant.XIA_JI).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.XIA_JI, weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)).add(o.getWeight()));
} else {
selfSubParentMap.get(ProjectConstant.ZI_SHEN).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.ZI_SHEN, weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)).add(o.getWeight()));
}
});
Map insertMap = new HashMap<>();
@@ -156,16 +159,15 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni
scoreEntity.setSelfScore(new BigDecimal(0));
scoreEntity.setSubScore(new BigDecimal(0));
scoreEntity.setParentIndexCode(index.getIndexCode());
- scoreEntity.setSelfWeight(new BigDecimal(0));
- scoreEntity.setSubWeight(new BigDecimal(0));
+ scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI));
+ scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN));
}
BigDecimal partScore = score.getScore().multiply(score.getWeight());
+
if (selfSubParentMap.get(ProjectConstant.XIA_JI).contains(score.getIndexCode())) {
scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore));
- scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight()));
} else {
scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore));
- scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight()));
}
log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore);
});
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java
index cc640e1853..35d59bf71b 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateDistrictServiceImpl.java
@@ -136,12 +136,15 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict
Map> selfSubParentMap = new HashMap<>();
selfSubParentMap.put(ProjectConstant.ZI_SHEN, new HashSet<>());
selfSubParentMap.put(ProjectConstant.XIA_JI, new HashSet<>());
+ Map weightMap = new HashMap<>();
selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标
if (o.getAllIndexCodePath().indexOf(ProjectConstant.XIA_JI) > -1) {
selfSubParentMap.get(ProjectConstant.XIA_JI).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.XIA_JI, weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)).add(o.getWeight()));
} else {
selfSubParentMap.get(ProjectConstant.ZI_SHEN).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.ZI_SHEN, weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)).add(o.getWeight()));
}
});
Map insertMap = new HashMap<>();
@@ -154,16 +157,14 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict
scoreEntity.setSelfScore(new BigDecimal(0));
scoreEntity.setSubScore(new BigDecimal(0));
scoreEntity.setParentIndexCode(index.getIndexCode());
- scoreEntity.setSelfWeight(new BigDecimal(0));
- scoreEntity.setSubWeight(new BigDecimal(0));
+ scoreEntity.setSubWeight(weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)));
+ scoreEntity.setSelfWeight(weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)));
}
BigDecimal partScore = score.getScore().multiply(score.getWeight());
if (selfSubParentMap.get(ProjectConstant.XIA_JI).contains(score.getIndexCode())) {
scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore));
- scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight()));
} else {
scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore));
- scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight()));
}
log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore);
});
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java
index d7637f8e5a..468aa668a7 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/IndexCalculateStreetServiceImpl.java
@@ -139,13 +139,17 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ
Map> selfSubParentMap = new HashMap<>();
selfSubParentMap.put(ProjectConstant.ZI_SHEN, new HashSet<>());
selfSubParentMap.put(ProjectConstant.XIA_JI, new HashSet<>());
+ Map weightMap = new HashMap<>();
selfSubIndexList.forEach(o -> {
//找出自身 和下级的指标
if (o.getAllIndexCodePath().indexOf(ProjectConstant.XIA_JI) > -1) {
selfSubParentMap.get(ProjectConstant.XIA_JI).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.XIA_JI, weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)).add(o.getWeight()));
} else {
selfSubParentMap.get(ProjectConstant.ZI_SHEN).add(o.getIndexCode());
+ weightMap.put(ProjectConstant.ZI_SHEN, weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)).add(o.getWeight()));
}
+
});
Map insertMap = new HashMap<>();
subScore.forEach(score -> {
@@ -157,16 +161,14 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ
scoreEntity.setSelfScore(new BigDecimal(0));
scoreEntity.setSubScore(new BigDecimal(0));
scoreEntity.setParentIndexCode(index.getIndexCode());
- scoreEntity.setSelfWeight(new BigDecimal(0));
- scoreEntity.setSubWeight(new BigDecimal(0));
+ scoreEntity.setSubWeight(weightMap.getOrDefault(ProjectConstant.XIA_JI, new BigDecimal(0)));
+ scoreEntity.setSelfWeight(weightMap.getOrDefault(ProjectConstant.ZI_SHEN, new BigDecimal(0)));
}
BigDecimal partScore = score.getScore().multiply(score.getWeight());
if (selfSubParentMap.get(ProjectConstant.XIA_JI).contains(score.getIndexCode())) {
scoreEntity.setSubScore(scoreEntity.getSubScore().add(partScore));
- scoreEntity.setSubWeight(scoreEntity.getSubWeight().add(score.getWeight()));
} else {
scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore));
- scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight()));
}
log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore);
});
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java
index bec0782a46..83ad985174 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcoll/impl/FactIndexCollectServiceImpl.java
@@ -3,6 +3,7 @@ package com.epmet.service.evaluationindex.indexcoll.impl;
import com.epmet.commons.dynamic.datasource.annotation.DataSource;
import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.commons.tools.constant.StrConstant;
+import com.epmet.commons.tools.redis.RedisKeys;
import com.epmet.commons.tools.utils.ConvertUtils;
import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.OrgTypeConstant;
@@ -27,6 +28,8 @@ import com.epmet.service.evaluationindex.indexcoll.FactIndexCollectService;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import lombok.extern.slf4j.Slf4j;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -38,6 +41,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
/**
@@ -84,6 +88,8 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
private ScreenCustomerDeptDao screenCustomerDeptDao;
@Autowired
private ScreenCustomerAgencyDao screenCustomerAgencyDao;
+ @Autowired
+ private RedissonClient redissonClient;
@Override
@Transactional(rollbackFor = Exception.class)
@@ -198,35 +204,60 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService {
}
}
+ /**
+ * @Description 目前只支持到区县级别,区县级以上的未实现
+ * @Param monthId
+ * @Param customerId
+ * @author zxc
+ * @date 2020/10/20 2:59 下午
+ */
@Override
- @Transactional(rollbackFor = Exception.class)
public void insertScreenIndexDataMonthlyAndYearly(String monthId, String customerId) {
- if (NumConstant.SIX != monthId.length()){
+ if (NumConstant.SIX != monthId.length()) {
throw new RuntimeException("入参monthId格式不正确:monthId =" + monthId);
}
- allParentIds.cleanUp();
- // 根据网格类型,删除 指数-指数数据(每月数值)表中 匹配的数据
- this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.GRID);
- // 开始处理 网格相关分值表
- this.startHandleIndexGridScore(monthId, customerId);
-
- // 根据组织类型,删除 指数-指数数据(每月数值)表中 匹配的数据
- this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.AGENCY);
- // 开始处理 社区相关分值表
- this.startHandleIndexCommunityScore(monthId, customerId);
-
- // 根据部门类型,删除 指数-指数数据(每月数值)表中 匹配的数据
- this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.DEPARTMENT);
- // 开始处理 区直部门分值表
- this.startHandleIndexDeptScore(monthId, customerId);
-
- // 同样是 组织类型,所以不再重复删除了
- // 开始处理 区/街道相关分数表
- this.startHandleIndexAgencyScore(monthId, customerId);
-
- // 根据年,汇总今年各项得到,计算平均值后 插入年表 screen_index_data_yearly
- this.insertIndexDataYear(monthId, customerId);
- allParentIds.invalidateAll();
+ RLock lock = redissonClient.getLock(RedisKeys.getScreenIndexDataLockKey());
+ try {
+ AtomicInteger tryTimes = new AtomicInteger(0);
+ boolean lockFlag = false;
+ do {
+ lockFlag = lock.tryLock(1, 10, TimeUnit.MINUTES);
+ } while (!lockFlag && tryTimes.addAndGet(1) < 3);
+ if (!lockFlag) {
+ log.error("插入大屏指数方法获取锁失败");
+ return;
+ }
+ allParentIds.cleanUp();
+ // 根据网格类型,删除 指数-指数数据(每月数值)表中 匹配的数据
+ this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.GRID);
+ // 开始处理 网格相关分值表
+ this.startHandleIndexGridScore(monthId, customerId);
+
+ // 根据组织类型,删除 指数-指数数据(每月数值)表中 匹配的数据
+ this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.AGENCY);
+ // 开始处理 社区相关分值表
+ this.startHandleIndexCommunityScore(monthId, customerId);
+
+ // 根据部门类型,删除 指数-指数数据(每月数值)表中 匹配的数据
+ this.batchDelIndexDataMonthly(customerId, monthId, OrgTypeConstant.DEPARTMENT);
+ // 开始处理 区直部门分值表
+ this.startHandleIndexDeptScore(monthId, customerId);
+
+ // 同样是 组织类型,所以不再重复删除了
+ // 开始处理 区/街道相关分数表
+ this.startHandleIndexAgencyScore(monthId, customerId);
+
+ // 根据年,汇总今年各项得到,计算平均值后 插入年表 screen_index_data_yearly
+ this.insertIndexDataYear(monthId, customerId);
+ allParentIds.invalidateAll();
+ } catch (InterruptedException inter) {
+ log.error("插入计算指标数据异常", inter);
+ } finally {
+ //判断是否是当前线程 持有锁
+ if (lock.isHeldByCurrentThread()) {
+ lock.unlock();
+ }
+ }
}
/**
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreConstants.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreConstants.java
index 28a24f7a14..599e566540 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreConstants.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/ScoreConstants.java
@@ -3,7 +3,7 @@ package com.epmet.support.normalizing;
import java.math.BigDecimal;
/**
- * 分值常量
+ * 分值常量 归一区间
*/
public class ScoreConstants {
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
index cfa2dc941f..900b15aaf5 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/support/normalizing/batch/BatchScoreCalculator.java
@@ -1,6 +1,7 @@
package com.epmet.support.normalizing.batch;
import com.alibaba.fastjson.JSON;
+import com.epmet.commons.tools.constant.NumConstant;
import com.epmet.support.normalizing.BigDecimalScoreCalculator;
import com.epmet.support.normalizing.Correlation;
import com.epmet.support.normalizing.ScoreCalculator;
@@ -79,6 +80,7 @@ public class BatchScoreCalculator {
}else {
//如果不需要归一 则 直接value*权重
if (idx.isScore()) {
+ vo.setSampleValue(new BigDecimal(vo.getSampleValue().toString()).compareTo(NumConstant.ZERO_DECIMAL) == NumConstant.ZERO ? ScoreConstants.MIN_SCORE : new BigDecimal(vo.getSampleValue().toString()));
normalizeValue = getFinalSampleValue(vo.getSampleValue(), threshold);
} else {
normalizeValue = scoreCalculator.normalize(getFinalSampleValue(vo.getSampleValue(), threshold));
diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/logback-spring.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/logback-spring.xml
index 99ae63af58..f099678400 100644
--- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/logback-spring.xml
+++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/logback-spring.xml
@@ -149,6 +149,16 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java
new file mode 100644
index 0000000000..6f01774eab
--- /dev/null
+++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java
@@ -0,0 +1,61 @@
+package com.epmet.stats.test;
+
+import com.epmet.DataStatsApplication;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.redisson.api.RLock;
+import org.redisson.api.RedissonClient;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.context.junit4.SpringRunner;
+
+import java.util.concurrent.TimeUnit;
+
+/**
+ * desc:redisson测试类
+ */
+@Slf4j
+@RunWith(value = SpringRunner.class)
+@SpringBootTest(classes = {DataStatsApplication.class})
+public class RedissonTest {
+
+ @Autowired
+ private RedissonClient redissonClient;
+
+ @Test
+ public void lockTest() {
+ //获取一个名为 lockName 的锁实例
+ RLock lock = redissonClient.getLock("lockName");
+ try {
+ // 尝试加锁(推荐使用)
+ // 参数1 等待时长 waitTime:5 等待时长是5秒 如果5秒内还获取不到锁 则返回false,
+ // 参数2 持有时长 leaseTime:5 持有锁时长超过5秒 就释放锁 此时如果继续lock.unlock()会抛出异常
+ // 参数3 时间单位
+ boolean bs = lock.tryLock(5, 6, TimeUnit.SECONDS);
+
+ //如果获取不到锁 会一直阻塞到着 直至获取到锁 不推荐使用
+ //lock.lock();
+
+ //异步方式
+ /* RFuture future = lock.lockAsync();
+ if (future.isSuccess()){
+ //todo something
+ }*/
+ if (bs) {
+ // 业务代码
+ System.out.println("进入业务代码: " + 123);
+ } else {
+ Thread.sleep(300);
+ }
+ } catch (Exception e) {
+ log.error("lockTest exception", e);
+ } finally {
+ //判断是否是当前线程 持有锁
+ if (lock.isHeldByCurrentThread()) {
+ lock.unlock();
+ }
+ }
+ }
+
+}
diff --git a/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/数据值略小时可能的情况.txt b/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/数据值略小时可能的情况.txt
new file mode 100644
index 0000000000..cb778584e1
--- /dev/null
+++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/数据值略小时可能的情况.txt
@@ -0,0 +1,7 @@
+1. 当数据偏小时,可能社区下没有网格,例如 网格发文数量得分就为0;
+2. screen_index_data_monthly中的 数据条数 与客户下(组织数 + 直属部门数 + 网格数)的和不统一,
+ 原因:数据插入的时候,只算到了区县级,区县级以上的没有计算,少了 市级和省级agency
+
+文档地址:
+ 1. 大屏指标项文档说明:https://www.kdocs.cn/view/l/svtSfaUyzNYZ?f=130
+ 2. 大屏或手机端:https://www.kdocs.cn/view/l/suilmk0Ziss1?f=130
\ No newline at end of file