diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java index 149cc45bd7..3189c554dc 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/evaluationindex/indexcal/impl/CpcIndexCalculateServiceImpl.java @@ -41,6 +41,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Slf4j @@ -82,28 +83,18 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { int pageSize = IndexCalConstant.PAGE_SIZE; List list = null; - Map preLastCpcScoreTotalMap = new HashMap<>(); - //当前最后一条记录 - //CpcScoreEntity currentLastCpcScore = null; - //当前第一条记录 - //CpcScoreEntity currentFirstCpcScore = null; + Map cpcScoreTotalMap = new HashMap<>(); + Map userTotalCount = new HashMap<>(); + //删除总分 然后插入 + cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCalConstant.DELETE_SIZE, NumConstant.ONE_STR); do { - Map cpcScoreTotalMap = new HashMap<>(); + List result = new ArrayList<>(); //获取数据 list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), (pageNo - NumConstant.ONE) * pageSize, pageSize); pageNo++; if (CollectionUtils.isEmpty(list)) { log.warn("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId()); } else { - //获取最后一条 - //currentLastCpcScore = list.get(list.size() - 1); - //获取第一条 - //currentFirstCpcScore = list.get(0); - /*if (preLastCpcScoreTotalMap.containsKey(currentFirstCpcScore.getUserId())) { - cpcScoreTotalMap.putAll(preLastCpcScoreTotalMap); - preLastCpcScoreTotalMap.clear(); - preLastCpcScoreTotalMap.put(currentLastCpcScore.getUserId(), null); - }*/ Map> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); userGroupMap.forEach((userId, partScoreList) -> { CpcScoreEntity totalEntity = null; @@ -121,27 +112,26 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR); totalEntity.setWeight(new BigDecimal(NumConstant.ONE_NEG)); cpcScoreTotalMap.put(userId, totalEntity); - - /* if (preLastCpcScoreTotalMap.containsKey(part.getUserId())) { - preLastCpcScoreTotalMap.put(part.getUserId(), part); - } else { - }*/ } //自建群活跃度——议题转项目率 有阈值 >60%按60%算 BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight()); + AtomicInteger atomicInteger = userTotalCount.get(part.getUserId()); + + if (atomicInteger == null) { + atomicInteger = new AtomicInteger(0); + userTotalCount.put(part.getUserId(), atomicInteger); + } + int totalCount = atomicInteger.addAndGet(1); + //todo 次代码限制了 党员的 4级指标的个数 看看是否还有更好的方式 + if (totalCount == 3) { + result.add(totalEntity); + } log.info("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total); totalEntity.setScore(totalEntity.getScore().add(total)); } }); } - - //没查询到数据 就把上次的放进去 - if (list == null || list.size() < pageSize || !CollectionUtils.isEmpty(preLastCpcScoreTotalMap)) { - cpcScoreTotalMap.putAll(preLastCpcScoreTotalMap); - } - //删除总分 然后插入 - cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCalConstant.DELETE_SIZE, NumConstant.ONE_STR); - insertCpcScoreBatch(formDTO, cpcScoreTotalMap.values().stream().collect(Collectors.toList()), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); + insertCpcScoreBatch(formDTO, result, IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); } while (!CollectionUtils.isEmpty(list)); } @@ -180,7 +170,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { */ public void insertCpcScoreBatch(CalculateCommonFormDTO formDTO, List values, String indexCode) { if (CollectionUtils.isEmpty(values)) { - log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode); + log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode); return; } List> partition = ListUtils.partition(values, IndexCalConstant.INSERT_SIZE); @@ -338,7 +328,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { */ public void insertCpcSubScoreBatch(CalculateCommonFormDTO formDTO, List subList, String parentIndexCode) { if (CollectionUtils.isEmpty(subList)) { - log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode); + log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode); return; } List> partition = ListUtils.partition(subList, IndexCalConstant.INSERT_SIZE);