| 
						
						
							
								
							
						
						
					 | 
					@ -41,6 +41,7 @@ import java.util.ArrayList; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.HashMap; | 
					 | 
					 | 
					import java.util.HashMap; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.List; | 
					 | 
					 | 
					import java.util.List; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.Map; | 
					 | 
					 | 
					import java.util.Map; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import java.util.concurrent.atomic.AtomicInteger; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import java.util.stream.Collectors; | 
					 | 
					 | 
					import java.util.stream.Collectors; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@Slf4j | 
					 | 
					 | 
					@Slf4j | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -77,33 +78,23 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); | 
					 | 
					 | 
					            log.warn("cpcIndexCalculate customerId:{} have not any indexGroupDetail", formDTO.getCustomerId()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            throw new RenException("客户【党员相关】指标权重信息不存在"); | 
					 | 
					 | 
					            throw new RenException("客户【党员相关】指标权重信息不存在"); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>(); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o)); | 
					 | 
					 | 
					        Map<String, IndexGroupDetailEntity> indexWeightMap = parentIndexDetails.stream().collect(Collectors.toMap(IndexGroupDetailEntity::getIndexCode, o -> o)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        int pageNo = NumConstant.ONE; | 
					 | 
					 | 
					        int pageNo = NumConstant.ONE; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        int pageSize = IndexCalConstant.PAGE_SIZE; | 
					 | 
					 | 
					        int pageSize = IndexCalConstant.PAGE_SIZE; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<CpcScoreEntity> list = null; | 
					 | 
					 | 
					        List<CpcScoreEntity> list = null; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        Map<String, CpcScoreEntity> preLastCpcScoreTotalMap = new HashMap<>(); | 
					 | 
					 | 
					        Map<String, CpcScoreEntity> cpcScoreTotalMap = new HashMap<>(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        //当前最后一条记录
 | 
					 | 
					 | 
					        Map<String, AtomicInteger> userTotalCount = new HashMap<>(); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        //CpcScoreEntity currentLastCpcScore = null;
 | 
					 | 
					 | 
					        //删除总分 然后插入
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        //当前第一条记录
 | 
					 | 
					 | 
					        cpcScoreDao.deleteByMonthId(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), IndexCalConstant.DELETE_SIZE, NumConstant.ONE_STR); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					        //CpcScoreEntity currentFirstCpcScore = null;
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					        do { | 
					 | 
					 | 
					        do { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            List<CpcScoreEntity> result = new ArrayList<>(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            //获取数据
 | 
					 | 
					 | 
					            //获取数据
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), (pageNo - NumConstant.ONE) * pageSize, pageSize); | 
					 | 
					 | 
					            list = cpcScoreDao.getPartScore(formDTO.getCustomerId(), formDTO.getMonthId(), IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode(), (pageNo - NumConstant.ONE) * pageSize, pageSize); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            pageNo++; | 
					 | 
					 | 
					            pageNo++; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            if (CollectionUtils.isEmpty(list)) { | 
					 | 
					 | 
					            if (CollectionUtils.isEmpty(list)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                log.warn("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId()); | 
					 | 
					 | 
					                log.warn("calculateTotalScore cpcScoreDao.getPartScore return empty,customerId:{},monthId:{}", formDTO.getCustomerId(), formDTO.getMonthId()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } else { | 
					 | 
					 | 
					            } 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<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); | 
					 | 
					 | 
					                Map<String, List<CpcScoreEntity>> userGroupMap = list.stream().collect(Collectors.groupingBy(CpcScoreEntity::getUserId)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                userGroupMap.forEach((userId, partScoreList) -> { | 
					 | 
					 | 
					                userGroupMap.forEach((userId, partScoreList) -> { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    CpcScoreEntity totalEntity = null; | 
					 | 
					 | 
					                    CpcScoreEntity totalEntity = null; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -121,28 +112,27 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR); | 
					 | 
					 | 
					                            totalEntity.setAllParentIndexCode(NumConstant.ZERO_STR); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            totalEntity.setWeight(new BigDecimal(NumConstant.ONE_NEG)); | 
					 | 
					 | 
					                            totalEntity.setWeight(new BigDecimal(NumConstant.ONE_NEG)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            cpcScoreTotalMap.put(userId, totalEntity); | 
					 | 
					 | 
					                            cpcScoreTotalMap.put(userId, totalEntity); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                           /* if (preLastCpcScoreTotalMap.containsKey(part.getUserId())) { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                                preLastCpcScoreTotalMap.put(part.getUserId(), part); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            } else { | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                            }*/ | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        } | 
					 | 
					 | 
					                        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        //自建群活跃度——议题转项目率 有阈值 >60%按60%算
 | 
					 | 
					 | 
					                        //自建群活跃度——议题转项目率 有阈值 >60%按60%算
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        BigDecimal total = part.getScore().multiply(indexGroupDetailEntity.getWeight()); | 
					 | 
					 | 
					                        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); | 
					 | 
					 | 
					                        log.info("userId:{},分数:{},权重:{},total:{}", userId, part.getScore(), indexGroupDetailEntity.getWeight(), total); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        totalEntity.setScore(totalEntity.getScore().add(total)); | 
					 | 
					 | 
					                        totalEntity.setScore(totalEntity.getScore().add(total)); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    } | 
					 | 
					 | 
					                    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                }); | 
					 | 
					 | 
					                }); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            } | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					            insertCpcScoreBatch(formDTO, result, IndexCodeEnum.DANG_YUAN_XIANG_GUAN.getCode()); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            //没查询到数据 就把上次的放进去
 | 
					 | 
					 | 
					        } while (!CollectionUtils.isEmpty(list) && list.size() == pageSize); | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					            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)); | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -180,7 +170,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public void insertCpcScoreBatch(CalculateCommonFormDTO formDTO, List<CpcScoreEntity> values, String indexCode) { | 
					 | 
					 | 
					    public void insertCpcScoreBatch(CalculateCommonFormDTO formDTO, List<CpcScoreEntity> values, String indexCode) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if (CollectionUtils.isEmpty(values)) { | 
					 | 
					 | 
					        if (CollectionUtils.isEmpty(values)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode); | 
					 | 
					 | 
					            log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), indexCode); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            return; | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<List<CpcScoreEntity>> partition = ListUtils.partition(values, IndexCalConstant.INSERT_SIZE); | 
					 | 
					 | 
					        List<List<CpcScoreEntity>> partition = ListUtils.partition(values, IndexCalConstant.INSERT_SIZE); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -338,7 +328,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public void insertCpcSubScoreBatch(CalculateCommonFormDTO formDTO, List<CpcSubScoreEntity> subList, String parentIndexCode) { | 
					 | 
					 | 
					    public void insertCpcSubScoreBatch(CalculateCommonFormDTO formDTO, List<CpcSubScoreEntity> subList, String parentIndexCode) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        if (CollectionUtils.isEmpty(subList)) { | 
					 | 
					 | 
					        if (CollectionUtils.isEmpty(subList)) { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            log.error("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode); | 
					 | 
					 | 
					            log.warn("insertCpcScoreBatch要插入的数据为空,param:{},indexCode:{}", JSON.toJSONString(formDTO), parentIndexCode); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            return; | 
					 | 
					 | 
					            return; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        List<List<CpcSubScoreEntity>> partition = ListUtils.partition(subList, IndexCalConstant.INSERT_SIZE); | 
					 | 
					 | 
					        List<List<CpcSubScoreEntity>> partition = ListUtils.partition(subList, IndexCalConstant.INSERT_SIZE); | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -385,7 +375,8 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    ScoreConstants.MAX_SCORE, | 
					 | 
					 | 
					                    ScoreConstants.MAX_SCORE, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    Correlation.getCorrelation(index.getCorrelation()) | 
					 | 
					 | 
					                    Correlation.getCorrelation(index.getCorrelation()) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            ); | 
					 | 
					 | 
					            ); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            IndexInputVO indexInputVO = new IndexInputVO(index.getIndexCode(), index.getAllParentIndexCode(), new ArrayList<>(), index.getThreshold(), index.getWeight(), scoreCalculator); | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            IndexInputVO indexInputVO = new IndexInputVO(index.getIndexCode(), index.getAllParentIndexCode(), new ArrayList<>(), index.getThreshold(), index.getWeight(), IndexCodeEnum.isAvgIndex(index.getIndexCode()), scoreCalculator); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            map.put(index.getIndexCode(), indexInputVO); | 
					 | 
					 | 
					            map.put(index.getIndexCode(), indexInputVO); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        return map; | 
					 | 
					 | 
					        return map; | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |