From af9298e087d457ebe7ccb292e2b09ce684b94d6e Mon Sep 17 00:00:00 2001 From: jianjun Date: Wed, 2 Sep 2020 16:21:50 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=88=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/CpcIndexCalculateServiceImpl.java | 19 ++++-- .../mapper/indexscore/CpcScoreDao.xml | 6 +- .../stats/test/normalizing/DemoScoreCal.java | 64 +++++++++++++++++++ 3 files changed, 81 insertions(+), 8 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java index fd79fc52e9..5afa73df18 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -88,16 +88,17 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { totalEntity.setScore(new BigDecimal(0)); cpcScoreTotalMap.put(userId, totalEntity); } - //todo 自建群活跃度——议题转项目率 有阈值 >60%按60%算 + //自建群活跃度——议题转项目率 有阈值 >60%按60%算 BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight()); log.info("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total); totalEntity.setScore(totalEntity.getScore().add(total)); } }); - insertBatch(cpcScoreTotalMap.values().stream().collect(Collectors.toList())); + deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(),cpcScoreTotalMap.values().stream().collect(Collectors.toList())); } - private void insertBatch(Collection values) { + private void deleteAndInsertBatch(String customerId, String monthId, String indexCode, Collection values) { + cpcScoreDao.deleteByMonthId(customerId, monthId, indexCode); cpcScoreDao.insertBatch(values); } @@ -198,14 +199,14 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { */ @Transactional(rollbackFor = Exception.class) public void saveCpcScore(CalculateCommonFormDTO formDTO, Map indexDetails, String parentIndexCode, HashMap result) { - cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), parentIndexCode); + List list = new ArrayList<>(); result.forEach((userId, score) -> { CpcScoreEntity cpcScoreEntity = indexDetails.get(userId); cpcScoreEntity.setScore(score); list.add(cpcScoreEntity); }); - this.insertBatch(list); + this.deleteAndInsertBatch(formDTO.getCustomerId(),formDTO.getMonthId(),parentIndexCode,list); } @@ -234,9 +235,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { String minValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MIN); //最大值key String maxValueKey = fieldName.concat(StrConstant.UNDER_LINE).concat(StrConstant.MAX); - minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); maxValue = new BigDecimal(String.valueOf(minAndMaxMap.get(maxValueKey))); - + minValue = new BigDecimal(String.valueOf(minAndMaxMap.get(minValueKey))); + //如果最大值超过阈值 则最大值为阈值 + if (new BigDecimal(NumConstant.ONE_NEG).compareTo(index.getThreshold()) != NumConstant.ZERO + && maxValue.compareTo(new BigDecimal(NumConstant.ONE_NEG)) == NumConstant.ONE){ + maxValue = index.getThreshold(); + } //分值计算器 ScoreCalculator scoreCalculator = new BigDecimalScoreCalculator(minValue, maxValue, diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml index c3483cbc32..0eb4b7774a 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml +++ b/epmet-module/data-statistical/data-statistical-server/src/main/resources/mapper/indexscore/CpcScoreDao.xml @@ -19,7 +19,11 @@ - delete from fact_index_cpc_score where CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} and MONTH_ID = #{monthId,jdbcType=VARCHAR} and INDEX_CODE = #{indexCode,jdbcType=VARCHAR} + delete from fact_index_cpc_score + where + CUSTOMER_ID = #{customerId,jdbcType=VARCHAR} + and MONTH_ID = #{monthId,jdbcType=VARCHAR} + and INDEX_CODE = #{indexCode,jdbcType=VARCHAR}