|  |  | @ -81,29 +81,52 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni | 
			
		
	
		
			
				
					|  |  |  |     private CommunitySelfSubScoreDao communitySelfSubScoreDao; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @param customerId | 
			
		
	
		
			
				
					|  |  |  |      * @param monthId | 
			
		
	
		
			
				
					|  |  |  |      * @param form | 
			
		
	
		
			
				
					|  |  |  |      * @Description 计算社区相关总分 | 
			
		
	
		
			
				
					|  |  |  |      * @author zxc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2020/9/1 4:12 下午 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public Boolean calCommunityAll(String customerId, String monthId) { | 
			
		
	
		
			
				
					|  |  |  |         Boolean aBoolean = communityPartyCalculate(customerId, monthId);//党建能力
 | 
			
		
	
		
			
				
					|  |  |  |         if (!aBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException("calculate community-party-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Boolean bBoolean = communityGovernAbilityCalculate(customerId, monthId);// 治理能力
 | 
			
		
	
		
			
				
					|  |  |  |         if (!bBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException("calculate community-govern-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Boolean cBoolean = communityServiceAbilityCalculate(customerId, monthId);// 服务能力
 | 
			
		
	
		
			
				
					|  |  |  |         if (!cBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException("calculate community-service-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         Boolean dBoolean = communityRelate(customerId, monthId); | 
			
		
	
		
			
				
					|  |  |  |         if (!dBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |             throw new RenException("calculate community-all insert failure ......"); | 
			
		
	
		
			
				
					|  |  |  |     public Boolean calCommunityAll(CalculateCommonFormDTO form) { | 
			
		
	
		
			
				
					|  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
			
				
					|  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
			
				
					|  |  |  |         if (StringUtils.isEmpty(form.getCustomerAreaCode())) { | 
			
		
	
		
			
				
					|  |  |  |             Boolean aBoolean = communityPartyCalculate(customerId, monthId);//党建能力
 | 
			
		
	
		
			
				
					|  |  |  |             if (!aBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-party-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             Boolean bBoolean = communityGovernAbilityCalculate(customerId, monthId);// 治理能力
 | 
			
		
	
		
			
				
					|  |  |  |             if (!bBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-govern-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             Boolean cBoolean = communityServiceAbilityCalculate(customerId, monthId);// 服务能力
 | 
			
		
	
		
			
				
					|  |  |  |             if (!cBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-service-ability failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             Boolean dBoolean = communityRelate(customerId, monthId); | 
			
		
	
		
			
				
					|  |  |  |             if (!dBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-all insert failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         }else { | 
			
		
	
		
			
				
					|  |  |  |             // 党建能力
 | 
			
		
	
		
			
				
					|  |  |  |             Boolean aBoolean = communityPartyCalculateExistsSub(form); | 
			
		
	
		
			
				
					|  |  |  |             if (!aBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-party-ability-exists-sub failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             // 治理能力
 | 
			
		
	
		
			
				
					|  |  |  |             Boolean bBoolean = communityGovernAbilityCalculateExistsSub(form); | 
			
		
	
		
			
				
					|  |  |  |             if (!bBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-govern-ability-exists-sub failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             // 服务能力
 | 
			
		
	
		
			
				
					|  |  |  |             Boolean cBoolean = communityServiceAbilityCalculateExistsSub(form); | 
			
		
	
		
			
				
					|  |  |  |             if (!cBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-service-ability-exists-sub failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             Boolean dBoolean = communityRelateExistsSub(form); | 
			
		
	
		
			
				
					|  |  |  |             if (!dBoolean.equals(true)) { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException("calculate community-all-exists-sub insert failure ......"); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         //计算自身和下级
 | 
			
		
	
		
			
				
					|  |  |  |         CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); | 
			
		
	
	
		
			
				
					|  |  | @ -565,4 +588,269 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni | 
			
		
	
		
			
				
					|  |  |  |         result.setFiveLevel(resultFive); | 
			
		
	
		
			
				
					|  |  |  |         return result; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description  社区名义发文数量计算【党建能力】存在下级客户 | 
			
		
	
		
			
				
					|  |  |  |      * @Param form | 
			
		
	
		
			
				
					|  |  |  |      * @author zxc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2021/1/15 上午9:18 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public Boolean communityPartyCalculateExistsSub(CalculateCommonFormDTO form) { | 
			
		
	
		
			
				
					|  |  |  |         // 党建能力
 | 
			
		
	
		
			
				
					|  |  |  |         // 根据all_parent_index_code  获取指标明细
 | 
			
		
	
		
			
				
					|  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(form.getCustomerId(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(detailListByParentCode)) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); | 
			
		
	
		
			
				
					|  |  |  |             return true; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IndexInputVO> indexInputVOS = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> pid = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         //下属所有网格的党建能力平均值
 | 
			
		
	
		
			
				
					|  |  |  |         detailListByParentCode.forEach(detail -> { | 
			
		
	
		
			
				
					|  |  |  |             if (IndexCodeEnum.XIA_SHU_SUO_YOU_WGDDJNLPJZ.getCode().equals(detail.getIndexCode())) { | 
			
		
	
		
			
				
					|  |  |  |                 List<SubGridAvgResultDTO> subGridPartyAvgScore = factIndexGridScoreDao.selectSubGridAvgScoreByAreaCode(form.getMonthId(),IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(subGridPartyAvgScore)) { | 
			
		
	
		
			
				
					|  |  |  |                     log.warn(IndexCalConstant.GRID_PARTY_AVG_NULL); | 
			
		
	
		
			
				
					|  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
			
				
					|  |  |  |                     List<List<SubGridAvgResultDTO>> subPartyAvgList = ListUtils.partition(subGridPartyAvgScore, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                     subPartyAvgList.forEach(party -> { | 
			
		
	
		
			
				
					|  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                         party.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             pid.put(c.getAgencyId(), c.getParentId()); | 
			
		
	
		
			
				
					|  |  |  |                             SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); | 
			
		
	
		
			
				
					|  |  |  |                             index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                         BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                         IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc); | 
			
		
	
		
			
				
					|  |  |  |                         indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 // 社区名义发文数量
 | 
			
		
	
		
			
				
					|  |  |  |                 List<Map<String, Object>> publishArticleCountList = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMapbyAreaCode( form.getMonthId(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(publishArticleCountList)) { | 
			
		
	
		
			
				
					|  |  |  |                     log.warn(IndexCalConstant.COMMUNITY_PUBLISH_ARTICLE_LIST_NULL); | 
			
		
	
		
			
				
					|  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |                     String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); | 
			
		
	
		
			
				
					|  |  |  |                     if (StringUtils.isEmpty(fieldNameByIndexCode)) { | 
			
		
	
		
			
				
					|  |  |  |                         log.error(String.format(IndexCalConstant.INDEX_CODE_NULL, detail.getIndexCode())); | 
			
		
	
		
			
				
					|  |  |  |                         return; | 
			
		
	
		
			
				
					|  |  |  |                     } else { | 
			
		
	
		
			
				
					|  |  |  |                         List<BigDecimal> decimalList = publishArticleCountList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                         MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); | 
			
		
	
		
			
				
					|  |  |  |                         List<List<Map<String, Object>>> publishArticleList = ListUtils.partition(publishArticleCountList, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                         publishArticleList.forEach(publish -> { | 
			
		
	
		
			
				
					|  |  |  |                             ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                             List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                             publish.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                                 pid.put(c.get(IndexCalConstant.AGENCY_ID).toString(), c.get(IndexCalConstant.PARENT_ID).toString()); | 
			
		
	
		
			
				
					|  |  |  |                                 SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); | 
			
		
	
		
			
				
					|  |  |  |                                 index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                             }); | 
			
		
	
		
			
				
					|  |  |  |                             IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc1); | 
			
		
	
		
			
				
					|  |  |  |                             indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityPartyCalculateExistsSub getScoreCountOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
			
				
					|  |  |  |         HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityPartyCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
			
				
					|  |  |  |         CommunityCalResultDTO result = getResultB(scoreTotalOfSampleId, form.getCustomerId(), form.getMonthId(), NumConstant.ZERO_STR, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
			
				
					|  |  |  |         deleteOldRecord(form.getCustomerId(),form.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(result); | 
			
		
	
		
			
				
					|  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description  社区治理能力  存在下级客户 | 
			
		
	
		
			
				
					|  |  |  |      * @Param form | 
			
		
	
		
			
				
					|  |  |  |      * @author zxc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2021/1/15 上午10:56 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public Boolean communityGovernAbilityCalculateExistsSub(CalculateCommonFormDTO form) { | 
			
		
	
		
			
				
					|  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(form.getCustomerId(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(detailListByParentCode)) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); | 
			
		
	
		
			
				
					|  |  |  |             return true; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IndexInputVO> indexInputVOS = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> pid = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         detailListByParentCode.forEach(detail -> { | 
			
		
	
		
			
				
					|  |  |  |             // 社区下属所有网格治理能力汇总(平均值)
 | 
			
		
	
		
			
				
					|  |  |  |             if (IndexCodeEnum.SHE_QU_XIA_SHU_SYWGZLNLHZPJZ.getCode().equals(detail.getIndexCode())) { | 
			
		
	
		
			
				
					|  |  |  |                 List<SubGridAvgResultDTO> subGridGovernAvg = factIndexGridScoreDao.selectSubGridAvgScoreByAreaCode(form.getMonthId(),IndexCodeEnum.ZHI_LI_NENG_LI.getCode(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(subGridGovernAvg)){ | 
			
		
	
		
			
				
					|  |  |  |                     log.warn("社区下级治理能力平均分集合为空"); | 
			
		
	
		
			
				
					|  |  |  |                 }else{ | 
			
		
	
		
			
				
					|  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridGovernAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
			
				
					|  |  |  |                     List<List<SubGridAvgResultDTO>> governAvg = ListUtils.partition(subGridGovernAvg, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                     governAvg.forEach(avg -> { | 
			
		
	
		
			
				
					|  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                         avg.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             pid.put(c.getAgencyId(), c.getParentId()); | 
			
		
	
		
			
				
					|  |  |  |                             SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); | 
			
		
	
		
			
				
					|  |  |  |                             index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                         BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                         IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc); | 
			
		
	
		
			
				
					|  |  |  |                         indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 // 治理能力的六个五级指标
 | 
			
		
	
		
			
				
					|  |  |  |                 List<Map<String, Object>> communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao.selectCommunityGovernAbilityExistsSub(form.getMonthId(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(communityGovernAbility)){ | 
			
		
	
		
			
				
					|  |  |  |                     log.warn(IndexCalConstant.COMMUNITY_GOVERN_ABILITY_NULL); | 
			
		
	
		
			
				
					|  |  |  |                 }else{ | 
			
		
	
		
			
				
					|  |  |  |                     String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); | 
			
		
	
		
			
				
					|  |  |  |                     if (StringUtils.isEmpty(fieldNameByIndexCode)) { | 
			
		
	
		
			
				
					|  |  |  |                         log.error(String.format(IndexCalConstant.INDEX_CODE_NULL,detail.getIndexCode())); | 
			
		
	
		
			
				
					|  |  |  |                         return; | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                     List<BigDecimal> decimalList = communityGovernAbility.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); | 
			
		
	
		
			
				
					|  |  |  |                     List<List<Map<String, Object>>> governAbilityList = ListUtils.partition(communityGovernAbility, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                     governAbilityList.forEach(governAbility -> { | 
			
		
	
		
			
				
					|  |  |  |                         ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                         governAbility.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             pid.put(c.get(IndexCalConstant.AGENCY_ID).toString(), c.get(IndexCalConstant.PARENT_ID).toString()); | 
			
		
	
		
			
				
					|  |  |  |                             SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); | 
			
		
	
		
			
				
					|  |  |  |                             index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                         IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc1); | 
			
		
	
		
			
				
					|  |  |  |                         indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityGovernAbilityCalculateExistsSub getScoreCountOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
			
				
					|  |  |  |         HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityGovernAbilityCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
			
				
					|  |  |  |         CommunityCalResultDTO result = getResultB(scoreTotalOfSampleId, form.getCustomerId(), form.getMonthId(), NumConstant.ZERO_STR, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(result); | 
			
		
	
		
			
				
					|  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description  社区服务能力 存在下级客户 | 
			
		
	
		
			
				
					|  |  |  |      * @Param form | 
			
		
	
		
			
				
					|  |  |  |      * @author zxc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2021/1/15 下午1:42 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public Boolean communityServiceAbilityCalculateExistsSub(CalculateCommonFormDTO form) { | 
			
		
	
		
			
				
					|  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(form.getCustomerId(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.FU_WU_NENG_LI.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         if (CollectionUtils.isEmpty(detailListByParentCode)) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); | 
			
		
	
		
			
				
					|  |  |  |             return true; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         List<IndexInputVO> indexInputVOS = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> pid = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  |         detailListByParentCode.forEach(detail -> { | 
			
		
	
		
			
				
					|  |  |  |             String indexCode = detail.getIndexCode(); | 
			
		
	
		
			
				
					|  |  |  |             if (IndexCodeEnum.SHE_QU_XIA_JI_SYWGFWNLDFPJZ.getCode().equals(indexCode)) { | 
			
		
	
		
			
				
					|  |  |  |                 List<SubGridAvgResultDTO> subGridServiceAvg = factIndexGridScoreDao.selectSubGridAvgScoreByAreaCode(form.getMonthId(),IndexCodeEnum.FU_WU_NENG_LI.getCode(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(subGridServiceAvg)) { | 
			
		
	
		
			
				
					|  |  |  |                     log.warn("查询社区下级所有网格服务能力得分平均值集合为空"); | 
			
		
	
		
			
				
					|  |  |  |                 } else { | 
			
		
	
		
			
				
					|  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridServiceAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
			
				
					|  |  |  |                     List<List<SubGridAvgResultDTO>> serviceAvgList = ListUtils.partition(subGridServiceAvg, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                     serviceAvgList.forEach(serviceAvg -> { | 
			
		
	
		
			
				
					|  |  |  |                         BigDecimalScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                         serviceAvg.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             pid.put(c.getAgencyId(), c.getParentId()); | 
			
		
	
		
			
				
					|  |  |  |                             SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); | 
			
		
	
		
			
				
					|  |  |  |                             index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                         IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc1); | 
			
		
	
		
			
				
					|  |  |  |                         indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 List<Map<String, Object>> communityActivityCountList = factIndexServiceAblityOrgMonthlyDao.selectActivityCountMapExistsSub(form.getMonthId(),form.getCustomerAreaCode()); | 
			
		
	
		
			
				
					|  |  |  |                 if (CollectionUtils.isEmpty(communityActivityCountList)) { | 
			
		
	
		
			
				
					|  |  |  |                     log.warn(IndexCalConstant.COMMUNITY_SERVICE_ABILITY_NULL); | 
			
		
	
		
			
				
					|  |  |  |                 }else{ | 
			
		
	
		
			
				
					|  |  |  |                     String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); | 
			
		
	
		
			
				
					|  |  |  |                     if (StringUtils.isEmpty(fieldNameByIndexCode)) { | 
			
		
	
		
			
				
					|  |  |  |                         log.error(String.format(IndexCalConstant.INDEX_CODE_NULL,detail.getIndexCode())); | 
			
		
	
		
			
				
					|  |  |  |                         return; | 
			
		
	
		
			
				
					|  |  |  |                     } | 
			
		
	
		
			
				
					|  |  |  |                     List<BigDecimal> decimalList = communityActivityCountList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); | 
			
		
	
		
			
				
					|  |  |  |                     List<List<Map<String, Object>>> communityActivityList = ListUtils.partition(communityActivityCountList, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
			
				
					|  |  |  |                     communityActivityList.forEach(communityActivity -> { | 
			
		
	
		
			
				
					|  |  |  |                         ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); | 
			
		
	
		
			
				
					|  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |                         communityActivity.forEach(c -> { | 
			
		
	
		
			
				
					|  |  |  |                             pid.put(c.get(IndexCalConstant.AGENCY_ID).toString(), c.get(IndexCalConstant.PARENT_ID).toString()); | 
			
		
	
		
			
				
					|  |  |  |                             SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); | 
			
		
	
		
			
				
					|  |  |  |                             index1SampleValues.add(s); | 
			
		
	
		
			
				
					|  |  |  |                         }); | 
			
		
	
		
			
				
					|  |  |  |                         IndexInputVO index1VO = new IndexInputVO(detail.getIndexCode(), detail.getAllParentIndexCode(), index1SampleValues, detail.getThreshold(), detail.getWeight(), IndexCodeEnum.isAvgIndex(detail.getIndexCode()), sc1); | 
			
		
	
		
			
				
					|  |  |  |                         indexInputVOS.add(index1VO); | 
			
		
	
		
			
				
					|  |  |  |                     }); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityServiceAbilityCalculateExistsSub getScoreCountOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
			
				
					|  |  |  |         HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
			
				
					|  |  |  |         log.info("communityServiceAbilityCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
			
				
					|  |  |  |         CommunityCalResultDTO result = getResultB(scoreTotalOfSampleId, form.getCustomerId(), form.getMonthId(), NumConstant.ZERO_STR, IndexCodeEnum.FU_WU_NENG_LI.getCode(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
			
				
					|  |  |  |         deleteAndInsert(result); | 
			
		
	
		
			
				
					|  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
		
			
				
					|  |  |  |      * @Description  社区相关计算 存在下级客户 | 
			
		
	
		
			
				
					|  |  |  |      * @Param form | 
			
		
	
		
			
				
					|  |  |  |      * @author zxc | 
			
		
	
		
			
				
					|  |  |  |      * @date 2021/1/15 下午1:47 | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     public Boolean communityRelateExistsSub(CalculateCommonFormDTO form) { | 
			
		
	
		
			
				
					|  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
			
				
					|  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
			
				
					|  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(form.getCustomerId(), IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode()); | 
			
		
	
		
			
				
					|  |  |  |         List<FactIndexCommunityScoreDTO> factIndexCommunityScoreEntities = factIndexCommunityScoreDao.selectCommunityInfoExistsSub(form.getCustomerAreaCode(),form.getMonthId()); | 
			
		
	
		
			
				
					|  |  |  |         detailListByParentCode.forEach(detail -> { | 
			
		
	
		
			
				
					|  |  |  |             factIndexCommunityScoreEntities.forEach(community -> { | 
			
		
	
		
			
				
					|  |  |  |                 if (detail.getIndexCode().equals(community.getIndexCode())) { | 
			
		
	
		
			
				
					|  |  |  |                     community.setScore(community.getScore().multiply(detail.getWeight())); | 
			
		
	
		
			
				
					|  |  |  |                 } | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, List<FactIndexCommunityScoreDTO>> collect = factIndexCommunityScoreEntities.stream().collect(Collectors.groupingBy(FactIndexCommunityScoreDTO::getAgencyId)); | 
			
		
	
		
			
				
					|  |  |  |         List<FactIndexCommunityScoreDTO> result = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         collect.forEach((key, value) -> { | 
			
		
	
		
			
				
					|  |  |  |             FactIndexCommunityScoreDTO score = new FactIndexCommunityScoreDTO(); | 
			
		
	
		
			
				
					|  |  |  |             score.setIsTotal(NumConstant.ONE_STR); | 
			
		
	
		
			
				
					|  |  |  |             score.setCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  |             score.setAgencyId(key); | 
			
		
	
		
			
				
					|  |  |  |             score.setMonthId(monthId); | 
			
		
	
		
			
				
					|  |  |  |             score.setYearId(DateUtils.getYearId(monthId)); | 
			
		
	
		
			
				
					|  |  |  |             score.setQuarterId(DateUtils.getQuarterId(monthId)); | 
			
		
	
		
			
				
					|  |  |  |             score.setIndexCode(IndexCalConstant.COMMUNITY_RELATE); | 
			
		
	
		
			
				
					|  |  |  |             score.setAllParentIndexCode(NumConstant.ZERO_STR); | 
			
		
	
		
			
				
					|  |  |  |             score.setWeight(new BigDecimal(NumConstant.ONE_NEG)); | 
			
		
	
		
			
				
					|  |  |  |             value.forEach(community -> { | 
			
		
	
		
			
				
					|  |  |  |                 score.setScore(score.getScore().add(community.getScore())); | 
			
		
	
		
			
				
					|  |  |  |                 score.setParentAgencyId(community.getParentAgencyId()); | 
			
		
	
		
			
				
					|  |  |  |             }); | 
			
		
	
		
			
				
					|  |  |  |             result.add(score); | 
			
		
	
		
			
				
					|  |  |  |         }); | 
			
		
	
		
			
				
					|  |  |  |         if (!CollectionUtils.isEmpty(result)){ | 
			
		
	
		
			
				
					|  |  |  |             factIndexCommunityScoreDao.insertCommunityPartyRecord(result); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return true; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |