|
|
@ -79,39 +79,64 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { |
|
|
|
} |
|
|
|
Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>(); |
|
|
|
Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o)); |
|
|
|
int pageNo = NumConstant.ONE; |
|
|
|
int pageSize = IndexCalConstant.PAGE_SIZE; |
|
|
|
List<CpcScoreEntity> list = null; |
|
|
|
|
|
|
|
//获取数据
|
|
|
|
List<CpcScoreEntity> list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); |
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
log.error("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId()); |
|
|
|
throw new RenException("客户四级指标分值记录不存在"); |
|
|
|
} |
|
|
|
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); |
|
|
|
userGroupMap.forEach((userId, partScoreList) -> { |
|
|
|
CpcScoreEntity totalEntity = null; |
|
|
|
for (CpcScoreEntity part : partScoreList) { |
|
|
|
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap.get(part.getIndexCode()); |
|
|
|
if (indexGroupDetailEntity == null) { |
|
|
|
log.error(" indexCode:{} 在指标明细中不存在", part.getIndexCode()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (totalEntity == null) { |
|
|
|
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class); |
|
|
|
totalEntity.setIsTotal(NumConstant.ONE_STR); |
|
|
|
totalEntity.setIndexCode(IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); |
|
|
|
totalEntity.setScore(new BigDecimal(NumConstant.ZERO)); |
|
|
|
totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR); |
|
|
|
cpcScoreTotalMap.put(userId, totalEntity); |
|
|
|
Map<String, CpcScoreEntity> preLastCpcScoreTotalMap = new HashMap<>(); |
|
|
|
CpcScoreEntity currentLastCpcScore = null; |
|
|
|
do { |
|
|
|
//获取数据
|
|
|
|
list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), (pageNo - NumConstant.ONE) * pageSize, pageSize); |
|
|
|
pageNo++; |
|
|
|
if (CollectionUtils.isEmpty(list)) { |
|
|
|
log.error("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId()); |
|
|
|
} else { |
|
|
|
//获取最后一条
|
|
|
|
currentLastCpcScore = list.get(list.size() - 1); |
|
|
|
if (preLastCpcScoreTotalMap.containsKey(currentLastCpcScore.getUserId())) { |
|
|
|
cpcScoreTotalMap.putAll(preLastCpcScoreTotalMap); |
|
|
|
preLastCpcScoreTotalMap.put(currentLastCpcScore.getUserId(), null); |
|
|
|
} |
|
|
|
//自建群活跃度——议题转项目率 有阈值 >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)); |
|
|
|
Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); |
|
|
|
userGroupMap.forEach((userId, partScoreList) -> { |
|
|
|
CpcScoreEntity totalEntity = null; |
|
|
|
for (CpcScoreEntity part : partScoreList) { |
|
|
|
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap.get(part.getIndexCode()); |
|
|
|
if (indexGroupDetailEntity == null) { |
|
|
|
log.error(" indexCode:{} 在指标明细中不存在", part.getIndexCode()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (totalEntity == null) { |
|
|
|
totalEntity = ConvertUtils.sourceToTarget(part, CpcScoreEntity.class); |
|
|
|
totalEntity.setIsTotal(NumConstant.ONE_STR); |
|
|
|
totalEntity.setIndexCode(IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); |
|
|
|
totalEntity.setScore(new BigDecimal(NumConstant.ZERO)); |
|
|
|
totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR); |
|
|
|
|
|
|
|
if (preLastCpcScoreTotalMap.containsKey(part.getUserId())) { |
|
|
|
preLastCpcScoreTotalMap.put(part.getUserId(), part); |
|
|
|
} else { |
|
|
|
cpcScoreTotalMap.put(userId, totalEntity); |
|
|
|
} |
|
|
|
} |
|
|
|
//自建群活跃度——议题转项目率 有阈值 >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)); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
|
|
//删除总分 然后插入
|
|
|
|
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()); |
|
|
|
|
|
|
|
//没查询到数据 就把上次的放进去
|
|
|
|
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()); |
|
|
|
} while (!CollectionUtils.isEmpty(list)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|