From 53a3c14e4a1bc8d62d88cc793628fbadc3961d91 Mon Sep 17 00:00:00 2001 From: jianjun Date: Wed, 23 Sep 2020 23:15:42 +0800 Subject: [PATCH 01/12] =?UTF-8?q?=E5=BC=95=E5=85=A5redisson=E5=88=86?= =?UTF-8?q?=E5=B8=83=E5=BC=8F=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- epmet-commons/epmet-commons-tools/pom.xml | 7 +++ .../commons/tools/config/RedissonConfig.java | 56 +++++++++++++++++ .../src/main/resources/logback-spring.xml | 10 +++ .../com/epmet/stats/test/RedissonTest.java | 61 +++++++++++++++++++ 4 files changed, 134 insertions(+) create mode 100644 epmet-commons/epmet-commons-tools/src/main/java/com/epmet/commons/tools/config/RedissonConfig.java create mode 100644 epmet-module/data-statistical/data-statistical-server/src/test/java/com/epmet/stats/test/RedissonTest.java 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-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(); + } + } + } + +} From 1f9be1b1cd8111231adfd68661e0915243bfec64 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 20 Oct 2020 09:08:40 +0800 Subject: [PATCH 02/12] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E5=92=8C=E8=87=AA=E8=BA=AB=E6=9D=83=E9=87=8D=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexcal/impl/DeptScoreServiceImpl.java | 11 +++++++---- .../indexcal/impl/GridCorreLationServiceImpl.java | 7 +++++-- .../impl/IndexCalculateCommunityServiceImpl.java | 7 +++++-- .../impl/IndexCalculateDistrictServiceImpl.java | 7 +++++-- .../impl/IndexCalculateStreetServiceImpl.java | 8 ++++++-- 5 files changed, 28 insertions(+), 12 deletions(-) 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<>(); @@ -154,10 +157,10 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { 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())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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..0b0ad32dc8 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<>(); @@ -162,10 +165,10 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni 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())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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..f295a69d83 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<>(); @@ -160,10 +163,10 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict 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())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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..842e9e3c81 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 -> { @@ -163,10 +167,10 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ 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())); + scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(scoreEntity.getSelfWeight().add(score.getWeight())); + scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore); }); From 8702bcdf1de0f81882e382a8eb8b17723a3de712 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 20 Oct 2020 09:34:10 +0800 Subject: [PATCH 03/12] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E5=92=8C=E8=87=AA=E8=BA=AB=E6=9D=83=E9=87=8D=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexcal/impl/GridCorreLationServiceImpl.java | 6 ++---- .../indexcal/impl/IndexCalculateCommunityServiceImpl.java | 7 +++---- .../indexcal/impl/IndexCalculateDistrictServiceImpl.java | 6 ++---- .../indexcal/impl/IndexCalculateStreetServiceImpl.java | 6 ++---- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java index 7a65b73f72..aadeb397b8 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java @@ -151,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.get(ProjectConstant.XIA_JI)); + scoreEntity.setSubWeight(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(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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 0b0ad32dc8..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 @@ -159,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(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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 f295a69d83..7ffd2dd146 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 @@ -157,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.get(ProjectConstant.XIA_JI)); + scoreEntity.setSubWeight(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(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } 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 842e9e3c81..d900716881 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 @@ -161,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.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(weightMap.get(ProjectConstant.XIA_JI)); } else { scoreEntity.setSelfScore(scoreEntity.getSelfScore().add(partScore)); - scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN)); } log.debug("=====key" + key + ",grid:{},originScore:{},weight:{},finalScore:{},total", score.getAgencyId(), score.getScore(), score.getWeight(), partScore); }); From 95cff7bbeb37ffb48102da1761590b236d4f9a0e Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 20 Oct 2020 09:59:44 +0800 Subject: [PATCH 04/12] =?UTF-8?q?=E8=B0=83=E6=95=B4=E4=B8=8B=E7=BA=A7?= =?UTF-8?q?=E5=92=8C=E8=87=AA=E8=BA=AB=E6=9D=83=E9=87=8D=E4=B8=8D=E5=AF=B9?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexcal/impl/GridCorreLationServiceImpl.java | 4 ++-- .../indexcal/impl/IndexCalculateDistrictServiceImpl.java | 4 ++-- .../indexcal/impl/IndexCalculateStreetServiceImpl.java | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java index aadeb397b8..231db8eaae 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/GridCorreLationServiceImpl.java @@ -151,8 +151,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService { scoreEntity.setSelfScore(new BigDecimal(0)); scoreEntity.setSubScore(new BigDecimal(0)); scoreEntity.setParentIndexCode(index.getIndexCode()); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); + 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())) { 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 7ffd2dd146..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 @@ -157,8 +157,8 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict scoreEntity.setSelfScore(new BigDecimal(0)); scoreEntity.setSubScore(new BigDecimal(0)); scoreEntity.setParentIndexCode(index.getIndexCode()); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.ZI_SHEN)); + 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())) { 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 d900716881..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 @@ -161,8 +161,8 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ scoreEntity.setSelfScore(new BigDecimal(0)); scoreEntity.setSubScore(new BigDecimal(0)); scoreEntity.setParentIndexCode(index.getIndexCode()); - scoreEntity.setSubWeight(weightMap.get(ProjectConstant.XIA_JI)); - scoreEntity.setSelfWeight(weightMap.get(ProjectConstant.ZI_SHEN)); + 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())) { From 95b592c6570affe2aa3c65945d02d93be0de7381 Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 20 Oct 2020 13:45:03 +0800 Subject: [PATCH 05/12] =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=8C=87=E6=A0=87?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E7=BB=93=E6=9E=9C=E6=95=B0=E6=8D=AE=E5=88=B0?= =?UTF-8?q?=E5=A4=A7=E5=B1=8F=E5=8E=BB=E6=8E=89=E4=BA=8B=E5=8A=A1=EF=BC=8C?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=88=86=E5=B8=83=E5=BC=8F=E9=94=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../epmet/commons/tools/redis/RedisKeys.java | 8 ++ .../impl/FactIndexCollectServiceImpl.java | 74 ++++++++++++------- 2 files changed, 57 insertions(+), 25 deletions(-) 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/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..640698d058 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) @@ -199,34 +205,52 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { } @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(); + } + } } /** From 9639e7f6ec20a89d36e50506e5d0df23490c73ae Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 20 Oct 2020 14:24:04 +0800 Subject: [PATCH 06/12] =?UTF-8?q?=E4=BF=AE=E6=94=B9Dockerfile=20=20ENTRYPO?= =?UTF-8?q?INT=EF=BC=8C=E5=A2=9E=E5=8A=A0exec?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data-statistical/data-statistical-server/Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 From c6bc8e288551947ca1fc91a521de7db4d756fd2a Mon Sep 17 00:00:00 2001 From: wxz Date: Tue, 20 Oct 2020 14:27:03 +0800 Subject: [PATCH 07/12] =?UTF-8?q?preDestory=E5=A2=9E=E5=8A=A0=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/controller/IndexCalculateController.java | 1 + 1 file changed, 1 insertion(+) 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)); From 9fe57ebb8c745813543489cbcf7a9a2c82b639f0 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 20 Oct 2020 15:00:54 +0800 Subject: [PATCH 08/12] =?UTF-8?q?screen=5Findex=5Fdata=5Fmonthly=E8=A1=A8?= =?UTF-8?q?=E9=87=8C=E7=BC=BA=E5=B0=91=E6=95=B0=E6=8D=AE=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=A4=87=E6=B3=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../indexcoll/impl/FactIndexCollectServiceImpl.java | 7 +++++++ 1 file changed, 7 insertions(+) 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 640698d058..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 @@ -204,6 +204,13 @@ public class FactIndexCollectServiceImpl implements FactIndexCollectService { } } + /** + * @Description 目前只支持到区县级别,区县级以上的未实现 + * @Param monthId + * @Param customerId + * @author zxc + * @date 2020/10/20 2:59 下午 + */ @Override public void insertScreenIndexDataMonthlyAndYearly(String monthId, String customerId) { if (NumConstant.SIX != monthId.length()) { From cb8d5497e009302a964089ded3e1ce85cef17278 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 20 Oct 2020 17:43:45 +0800 Subject: [PATCH 09/12] =?UTF-8?q?=E8=AE=A1=E7=AE=97=E5=99=A8=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/commons/tools/constant/NumConstant.java | 1 + .../epmet/support/normalizing/batch/BatchScoreCalculator.java | 2 ++ 2 files changed, 3 insertions(+) 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-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)); From 3884978e90446daba3352d0f611b0e7ecdc0e41c Mon Sep 17 00:00:00 2001 From: jianjun Date: Tue, 20 Oct 2020 17:50:39 +0800 Subject: [PATCH 10/12] =?UTF-8?q?=E5=BD=92=E4=B8=80=E5=8C=BA=E9=97=B4=20?= =?UTF-8?q?=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/com/epmet/support/normalizing/ScoreConstants.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 { From 2920d759a7f3ce9da986dee6a3a371c6514c39b7 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 20 Oct 2020 17:54:06 +0800 Subject: [PATCH 11/12] =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../test/java/resources/数据值略小时可能的情况.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 epmet-module/data-statistical/data-statistical-server/src/test/java/resources/数据值略小时可能的情况.txt 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..b317962bea --- /dev/null +++ b/epmet-module/data-statistical/data-statistical-server/src/test/java/resources/数据值略小时可能的情况.txt @@ -0,0 +1,3 @@ +1. 当数据偏小时,可能社区下没有网格,例如 网格发文数量得分就为0; +2. screen_index_data_monthly中的 数据条数 与客户下(组织数 + 直属部门数 + 网格数)的和不统一, + 原因:数据插入的时候,只算到了区县级,区县级以上的没有计算,少了 市级和省级agency \ No newline at end of file From 284e16f34cc14b0b5cd1de00d13e9083ba5e4cbf Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Tue, 20 Oct 2020 17:57:35 +0800 Subject: [PATCH 12/12] =?UTF-8?q?=E8=AF=B4=E6=98=8E=E6=96=87=E6=A1=A3?= =?UTF-8?q?=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/resources/数据值略小时可能的情况.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 index b317962bea..cb778584e1 100644 --- 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 @@ -1,3 +1,7 @@ 1. 当数据偏小时,可能社区下没有网格,例如 网格发文数量得分就为0; 2. screen_index_data_monthly中的 数据条数 与客户下(组织数 + 直属部门数 + 网格数)的和不统一, - 原因:数据插入的时候,只算到了区县级,区县级以上的没有计算,少了 市级和省级agency \ No newline at end of file + 原因:数据插入的时候,只算到了区县级,区县级以上的没有计算,少了 市级和省级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