|  | @ -88,21 +88,43 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict | 
			
		
	
		
		
			
				
					|  |  |     public Boolean calDistrictAll(CalculateCommonFormDTO form) { |  |  |     public Boolean calDistrictAll(CalculateCommonFormDTO form) { | 
			
		
	
		
		
			
				
					|  |  |         String customerId = form.getCustomerId(); |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |         String monthId = form.getMonthId(); |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
		
			
				
					
					|  |  |         Boolean aBoolean = districtPartyCalculate(customerId, monthId);//党建能力
 |  |  |         if (StringUtils.isEmpty(form.getCustomerAreaCode())) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if (!aBoolean.equals(true)) { |  |  |             Boolean aBoolean = districtPartyCalculate(customerId, monthId);//党建能力
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             throw new RenException("calculate district-party-ability failure ......"); |  |  |             if (!aBoolean.equals(true)) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         } |  |  |                 throw new RenException("calculate district-party-ability failure ......"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         Boolean bBoolean = districtGovernAbilityCalculate(customerId, monthId);// 治理能力
 |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if (!bBoolean.equals(true)) { |  |  |             Boolean bBoolean = districtGovernAbilityCalculate(customerId, monthId);// 治理能力
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             throw new RenException("calculate district-govern-ability failure ......"); |  |  |             if (!bBoolean.equals(true)) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         } |  |  |                 throw new RenException("calculate district-govern-ability failure ......"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         Boolean cBoolean = districtServiceAbilityCalculate(customerId, monthId);// 服务能力
 |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if (!cBoolean.equals(true)) { |  |  |             Boolean cBoolean = districtServiceAbilityCalculate(customerId, monthId);// 服务能力
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             throw new RenException("calculate district-service-ability failure ......"); |  |  |             if (!cBoolean.equals(true)) { | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         } |  |  |                 throw new RenException("calculate district-service-ability failure ......"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         Boolean dBoolean = districtRelate(customerId, monthId); |  |  |             } | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if (!dBoolean.equals(true)) { |  |  |             Boolean dBoolean = districtRelate(customerId, monthId); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             throw new RenException("calculate district-all insert failure ......"); |  |  |             if (!dBoolean.equals(true)) { | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |                 throw new RenException("calculate district-all insert failure ......"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         }else { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             //党建能力
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             Boolean aBoolean = districtPartyCalculateExistSub(form); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!aBoolean.equals(true)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 throw new RenException("calculate district-party-ability-exists-sub failure ......"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 治理能力
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             Boolean bBoolean = districtGovernAbilityCalculateExistSub(form); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!bBoolean.equals(true)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 throw new RenException("calculate district-govern-ability-exists-sub failure ......"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             // 服务能力
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             Boolean cBoolean = districtServiceAbilityCalculateExistSub(form); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!cBoolean.equals(true)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 throw new RenException("calculate district-service-ability-exists-sub failure ......"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             Boolean dBoolean = districtRelateExistSub(form); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (!dBoolean.equals(true)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 throw new RenException("calculate district-all-exists-sub insert failure ......"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |         //计算自身和下级
 |  |  |         //计算自身和下级
 | 
			
		
	
		
		
			
				
					|  |  |         CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); |  |  |         CalculateCommonFormDTO formDTO = new CalculateCommonFormDTO(); | 
			
		
	
	
		
		
			
				
					|  | @ -563,4 +585,269 @@ public class IndexCalculateDistrictServiceImpl implements IndexCalculateDistrict | 
			
		
	
		
		
			
				
					|  |  |         return result; |  |  |         return result; | 
			
		
	
		
		
			
				
					|  |  |     } |  |  |     } | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param form | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 全区名义发文数量计算【党建能力】 存在下级客户 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020/8/26 10:46 上午 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public Boolean districtPartyCalculateExistSub(CalculateCommonFormDTO form) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // 党建能力
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         // 根据all_parent_index_code  获取指标明细
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<IndexGroupDetailEntity> indexDetailList = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (CollectionUtils.isEmpty(indexDetailList)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             log.error(IndexCalConstant.INDEX_DETAIL_LIST_NULL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             return true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<IndexInputVO> indexInputVOS = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map<String, String> pid = new HashMap<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         //党建能力平均值
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         indexDetailList.forEach(detail -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             if (IndexCodeEnum.QU_XIA_JI_JIE_DDJNLHZPJZ.getCode().equals(detail.getIndexCode())) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<SubAgencyScoreAvgResultDTO> subGridPartyAvgScore = agencyScoreDao.selectAgencyScoreAvgExistsSub(monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(),IndexCalConstant.STREET_LEVEL,form.getCustomerAreaCode(),NumConstant.SIX); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (CollectionUtils.isEmpty(subGridPartyAvgScore)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.warn(IndexCalConstant.DISTRICT_PARTY_AVG_NULL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } else if (subGridPartyAvgScore.size() > NumConstant.ZERO) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     List<List<SubAgencyScoreAvgResultDTO>> subPartyAvgList = ListUtils.partition(subGridPartyAvgScore, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     subPartyAvgList.forEach(party -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         party.forEach(c -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             if (!c.getParentId().equals(NumConstant.ZERO_STR)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 pid.put(c.getParentId(), customerAgencyDao.selectPid(c.getParentId())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 SampleValue s = new SampleValue(c.getParentId(), 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.selectPublishArticleCountMapExistSub(monthId,form.getCustomerAreaCode(),NumConstant.SIX); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (CollectionUtils.isEmpty(publishArticleCountList)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.warn(IndexCalConstant.DISTRICT_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(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         log.info("districtPartyAbilityCalculateExistsSub getScoreTotalOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         log.info("districtPartyAbilityCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         AgencyCalResultDTO result = getResultB(scoreTotalOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         deleteOldRecord(customerId,monthId,IndexCalConstant.DISTRICT_LEVEL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         insertDetail(result); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param form | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 全区治理能力  存在下级客户 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020/8/26 1:40 下午 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public Boolean districtGovernAbilityCalculateExistSub(CalculateCommonFormDTO form) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_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.SUO_YOU_JIE_DAO_ZLNLPJZ.getCode().equals(detail.getIndexCode())) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<SubAgencyScoreAvgResultDTO> districtGovernAvgList = agencyScoreDao.selectAgencyScoreAvgExistsSub(monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(),IndexCalConstant.STREET_LEVEL,form.getCustomerAreaCode(),NumConstant.SIX); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 for (int i = 0; i < districtGovernAvgList.size(); i++) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     if (districtGovernAvgList.get(i).getAgencyId().equals(NumConstant.ZERO_STR)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         districtGovernAvgList.remove(districtGovernAvgList.get(i)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (CollectionUtils.isEmpty(districtGovernAvgList)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.warn("查询所有街道治理能力平均值集合为空"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } else{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(districtGovernAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     List<List<SubAgencyScoreAvgResultDTO>> governAvg = ListUtils.partition(districtGovernAvgList, IndexCalConstant.PAGE_SIZE); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     governAvg.forEach(avg -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         List<SampleValue> index1SampleValues = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         avg.forEach(c -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             if (!c.getParentId().equals(NumConstant.ZERO_STR)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 pid.put(c.getParentId(), customerAgencyDao.selectPid(c.getParentId())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 SampleValue s = new SampleValue(c.getParentId(), 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 if (IndexCodeEnum.SUO_YOU_ZHI_SHU_BMZLNLPJZ.getCode().equals(detail.getIndexCode())){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<SubAgencyScoreAvgResultDTO> deptScoreAvgList = deptScoreDao.selectGovernDeptScoreAvgExistsSub(monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(),form.getCustomerAreaCode()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 for (int i = 0; i < deptScoreAvgList.size(); i++) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     if (deptScoreAvgList.get(i).getAgencyId().equals(NumConstant.ZERO_STR)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         deptScoreAvgList.remove(deptScoreAvgList.get(i)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (CollectionUtils.isEmpty(deptScoreAvgList)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.warn("查询所有直属部门治理能力平均值集合为空"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } else{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(deptScoreAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     List<List<SubAgencyScoreAvgResultDTO>> governAvg = ListUtils.partition(deptScoreAvgList, 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{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // TODO 治理能力暂无自身级别
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         log.info("districtGovernAbilityCalculateExistsSub getScoreTotalOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         log.info("districtGovernAbilityCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         AgencyCalResultDTO result = getResultB(scoreTotalOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         insertDetail(result); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param form | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 全区服务能力  存在下级客户 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020/8/31 1:38 下午 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public Boolean districtServiceAbilityCalculateExistSub(CalculateCommonFormDTO form) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.QUAN_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.QU_XIA_SHU_JIE_DFWNLHZPJZ.getCode().equals(indexCode)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 List<SubAgencyScoreAvgResultDTO> subStreetAvgList = agencyScoreDao.selectAgencyScoreAvgExistsSub(monthId,IndexCodeEnum.FU_WU_NENG_LI.getCode(),IndexCalConstant.STREET_LEVEL,form.getCustomerAreaCode(),NumConstant.SIX); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 for (int i = 0; i < subStreetAvgList.size(); i++) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     if (subStreetAvgList.get(i).getAgencyId().equals(NumConstant.ZERO_STR)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                         subStreetAvgList.remove(subStreetAvgList.get(i)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (CollectionUtils.isEmpty(subStreetAvgList)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     log.warn("查询区下属街道服务能力汇总平均值集合为空"); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } else{ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subStreetAvgList.stream().map(o -> o.getScore()).collect(Collectors.toList())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     List<List<SubAgencyScoreAvgResultDTO>> serviceAvgList = ListUtils.partition(subStreetAvgList, 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 -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                             if (!c.getParentId().equals(NumConstant.ZERO_STR)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 pid.put(c.getParentId(), customerAgencyDao.selectPid(c.getParentId())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                                 SampleValue s = new SampleValue(c.getParentId(), 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 { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 // todo 暂时没有自身级别
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (!CollectionUtils.isEmpty(indexInputVOS)) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             HashMap<String, CalculateResult> scoreTotalOfSampleId = batchScoreCalculator.getScoreTotalOfSampleId(indexInputVOS); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             log.info("districtServiceAbilityCalculateExistsSub getScoreTotalOfSampleId param:{}", JSON.toJSONString(indexInputVOS)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             log.info("districtServiceAbilityCalculateExistsSub getScoreCountOfSampleId result:{}", JSON.toJSONString(scoreTotalOfSampleId)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             AgencyCalResultDTO result = getResultB(scoreTotalOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.FU_WU_NENG_LI.getCode(), IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode(), pid); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             insertDetail(result); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     /** | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @param form | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @Description 区相关计算  存在下级客户 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @author zxc | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      * @date 2020/9/1 9:21 上午 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |      */ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     public Boolean districtRelateExistSub(CalculateCommonFormDTO form) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String customerId = form.getCustomerId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         String monthId = form.getMonthId(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<AgencyScoreDTO> agencyScoreList = agencyScoreDao.selectAgencyScoreInfoExistsSub(form.getCustomerAreaCode(),NumConstant.SIX,monthId, IndexCalConstant.DISTRICT_LEVEL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         detailListByParentCode.forEach(detail -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             agencyScoreList.forEach(community -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 if (detail.getIndexCode().equals(community.getIndexCode())) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                     community.setScore(community.getScore().multiply(detail.getWeight())); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |                 } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         Map<String, List<AgencyScoreDTO>> collect = agencyScoreList.stream().collect(Collectors.groupingBy(AgencyScoreDTO::getAgencyId)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         List<AgencyScoreDTO> result = new ArrayList<>(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         collect.forEach((key, value) -> { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             AgencyScoreDTO score = new AgencyScoreDTO(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             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.setDataType(IndexCalConstant.DISTRICT_LEVEL); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             score.setIndexCode(IndexCodeEnum.QUAN_QU_XIANG_GUAN.getCode()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             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)){ | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             agencyScoreDao.insertStreetRecord(result); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         return true; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | } |  |  | } | 
			
		
	
	
		
		
			
				
					|  | 
 |