From 2b907596aaeab321796f4e78e552a7de0345c605 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 2 Sep 2020 15:04:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E7=9B=B8=E5=85=B3=E4=BC=98?= =?UTF-8?q?=E5=8C=96=207?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../IndexCalculateCommunityServiceImpl.java | 112 ++++++++++++------ 1 file changed, 77 insertions(+), 35 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCalculateCommunityServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCalculateCommunityServiceImpl.java index bea808f8be..70b539beae 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCalculateCommunityServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/indexcal/impl/IndexCalculateCommunityServiceImpl.java @@ -77,20 +77,24 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (CollectionUtils.isEmpty(subGridPartyAvgScore)) { log.error("查询下属所有网格的党建能力平均值集合为空"); return; - } - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); - Integer indexEnd = NumConstant.TEN; - List> partition = ListUtils.partition(subGridPartyAvgScore, indexEnd); - partition.forEach(publish -> { - List index1SampleValues = new ArrayList<>(); - publish.forEach(c -> { - SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); - index1SampleValues.add(s); + }else if (subGridPartyAvgScore.size() == NumConstant.ONE){ + sizeOne(subGridPartyAvgScore.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); + return; + }else if (subGridPartyAvgScore.size() > NumConstant.ONE) { + MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); + Integer indexEnd = NumConstant.TEN; + List> partition = ListUtils.partition(subGridPartyAvgScore, indexEnd); + partition.forEach(publish -> { + List index1SampleValues = new ArrayList<>(); + publish.forEach(c -> { + 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.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc); + indexInputVOS.add(index1VO); }); - BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.getCorrelation(detail.getCorrelation())); - IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc); - indexInputVOS.add(index1VO); - }); + } } else { // 社区名义发文数量 List> mapList = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMap(customerId, monthId,IndexCalConstant.COMMUNITY_LEVEL); @@ -102,20 +106,24 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (StringUtils.isEmpty(fieldNameByIndexCode)) { log.error("指标Code未查询出对应字段 【" + detail.getIndexCode() + "】"); return; - } - List decimalList = mapList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); - List>> publishArticleList = ListUtils.partition(mapList, 10); - publishArticleList.forEach(publish -> { - ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); - List index1SampleValues = new ArrayList<>(); - publish.forEach(c -> { - SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); - index1SampleValues.add(s); + }else if (mapList.size() == NumConstant.ONE){ + sizeOne(mapList.get(NumConstant.ZERO).get(IndexCalConstant.AGENCY_ID).toString(),customerId,monthId,IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); + return; + }else if (mapList.size() > NumConstant.ONE) { + List decimalList = mapList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); + MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); + List>> publishArticleList = ListUtils.partition(mapList, 10); + publishArticleList.forEach(publish -> { + ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); + List index1SampleValues = new ArrayList<>(); + publish.forEach(c -> { + 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.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); + indexInputVOS.add(index1VO); }); - IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); - indexInputVOS.add(index1VO); - }); + } } }); BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); @@ -144,7 +152,8 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (IndexCodeEnum.SHE_QU_XIA_SHU_SYWGZLNLHZPJZ.getCode().equals(detail.getIndexCode())) { List subGridGovernAvg = factIndexGridScoreDao.selectSubGridGovernAvgScore(customerId, monthId); if (subGridGovernAvg.size() == NumConstant.ONE) { - // TODO + sizeOne(subGridGovernAvg.get(NumConstant.ZERO).getAgencyId(),customerId,monthId,IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); + return; } else if (subGridGovernAvg.size() > NumConstant.ONE) { MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridGovernAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); List> governAvg = ListUtils.partition(subGridGovernAvg, 10); @@ -160,9 +169,14 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni }); } } else { + // 治理能力的六个五级指标 List> communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao.selectCommunityGovernAbility(customerId, monthId,IndexCalConstant.COMMUNITY_LEVEL); - if (communityGovernAbility.size() == NumConstant.ONE) { - // TODO + if (CollectionUtils.isEmpty(communityGovernAbility)){ + log.error("查询治理能力的六个五级指标集合为空"); + return; + }else if (communityGovernAbility.size() == NumConstant.ONE) { + sizeOne(communityGovernAbility.get(NumConstant.ZERO).get(IndexCalConstant.AGENCY_ID).toString(),customerId,monthId,IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); + return; } else if (communityGovernAbility.size() > NumConstant.ONE) { String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); if (StringUtils.isEmpty(fieldNameByIndexCode)) { @@ -212,7 +226,8 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (IndexCodeEnum.SHE_QU_XIA_JI_SYWGFWNLDFPJZ.getCode().equals(indexCode)) { List subGridServiceAvg = factIndexGridScoreDao.selectSubGridServiceAvgScore(customerId, monthId); if (subGridServiceAvg.size() == NumConstant.ONE) { - // TODO 只有一条记录时 + sizeOne(subGridServiceAvg.get(NumConstant.ZERO).getAgencyId().toString(),customerId,monthId,IndexCodeEnum.FU_WU_NENG_LI.getCode()); + return; } else if (subGridServiceAvg.size() > NumConstant.ONE) { MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridServiceAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); List> serviceAvgList = ListUtils.partition(subGridServiceAvg, 10); @@ -232,9 +247,9 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni if (CollectionUtils.isEmpty(communityActivityCountList)) { log.error("查询社区活动组织次数集合为空"); return; - } - if (communityActivityCountList.size() == NumConstant.ONE) { - // TODO + }else if (communityActivityCountList.size() == NumConstant.ONE) { + sizeOne(communityActivityCountList.get(NumConstant.ZERO).get(IndexCalConstant.AGENCY_ID).toString(),customerId,monthId,IndexCodeEnum.FU_WU_NENG_LI.getCode()); + return; } else if (communityActivityCountList.size() > NumConstant.ONE) { String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); if (StringUtils.isEmpty(fieldNameByIndexCode)) { @@ -353,10 +368,22 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni * @date 2020/9/1 4:24 下午 */ public void deleteAndInsert(String customerId, String monthId, String indexCode, List subAllGridList) { - factIndexCommunityScoreDao.deleteOldRecord(customerId, monthId, indexCode); - factIndexCommunityScoreDao.insertCommunityPartyRecord(subAllGridList); + if (!CollectionUtils.isEmpty(subAllGridList)) { + factIndexCommunityScoreDao.deleteOldRecord(customerId, monthId, indexCode); + factIndexCommunityScoreDao.insertCommunityPartyRecord(subAllGridList); + } } + /** + * @Description + * @param scoreCountOfSampleId 指标计算结果 + * @param customerId 客户ID + * @param monthId 月份ID + * @param isTotal 是否 总分【党建+治理+服务】 + * @param indexCode 党建能力:dangjiannengli,治理能力:zhilinengli,服务能力:fuwunengli,xx相关:xx相关 + * @author zxc + * @date 2020/9/2 2:37 下午 + */ public List getResult(HashMap scoreCountOfSampleId, String customerId, String monthId, String isTotal, String indexCode) { List result = new ArrayList<>(); scoreCountOfSampleId.forEach((k, v) -> { @@ -373,4 +400,19 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni }); return result; } + + /** + * @Description 当查询结果为一条时,调用此方法 + * @param agencyId + * @param customerId + * @param monthId + * @author zxc + * @date 2020/9/2 2:40 下午 + */ + public void sizeOne(String agencyId,String customerId,String monthId,String indexCode){ + HashMap scoreCountOfSampleId = new HashMap<>(); + scoreCountOfSampleId.put(agencyId,new BigDecimal(NumConstant.FIFTY)); + List result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, indexCode); + deleteAndInsert(customerId, monthId, indexCode, result); + } }