From 53caf7dc2dc148670e79f28eac33485198630a30 Mon Sep 17 00:00:00 2001 From: zxc <1272811460@qq.com> Date: Wed, 2 Sep 2020 13:39:42 +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=203?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/epmet/constant/IndexCalConstant.java | 4 +- .../java/com/epmet/eum/IndexCodeEnum.java | 5 +- .../IndexCalculateCommunityServiceImpl.java | 439 +++++++----------- 3 files changed, 178 insertions(+), 270 deletions(-) diff --git a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java index e89cc969b3..d56ae32d54 100644 --- a/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java +++ b/epmet-module/data-statistical/data-statistical-client/src/main/java/com/epmet/constant/IndexCalConstant.java @@ -29,9 +29,9 @@ public interface IndexCalConstant { String COMMUNITY_SERVICE_AVG = "shequxiajisywgfwnldfpjz"; - String COMMUNITY_GOVERN_AVG = "shequxiashusywgzlnlhzpyz"; + String COMMUNITY_GOVERN_AVG = "shequxiashusywgzlnlhzpjz"; - String COMMUNITY_PARTY_AVG = "xiazhusuoyouwgddjnlpjz"; + String COMMUNITY_PARTY_AVG = "xiashusuoyouwgddjnlpjz"; String COMMUNITY_RELATE = "shequxiangguan"; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/eum/IndexCodeEnum.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/eum/IndexCodeEnum.java index 9697e84fcf..88e759af17 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/eum/IndexCodeEnum.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/eum/IndexCodeEnum.java @@ -24,7 +24,10 @@ public enum IndexCodeEnum { DANG_WU_HUO_DONG("dangwuhuodong", "党务活动", 4), LIAN_XI_QUN_ZHONG("lianxiqunzhong", "联系群众", 4), ZUZHINEIDANGYDLXQZNLKPFPJZ("zuzhineidangydlxqznlkpfpjz","组织内党员的联系群众能力考评分(平均值)",5), - ZUZHINEIDANGYDSYYSNLKPFPJZ("zuzhineidangydcyysnlkpfpjz","组织内党员的参与议事能力考评分(平均值)",5), + ZUZHINEIDANGYDSYYSNLKPFPJZ("zuzhineidangydsyysnlkpfpjz","组织内党员的参与议事能力考评分(平均值)",5), + XIA_SHU_SUO_YOU_WGDDJNLPJZ("xiashusuoyouwgddjnlpjz","下属所有网格的党建能力(平均值)",5), + SHE_QU_XIA_SHU_SYWGZLNLHZPJZ("shequxiashusywgzlnlhzpjz","社区下属所有网格治理能力汇总(平均值)",5), + SHE_QU_XIA_JI_SYWGFWNLDFPJZ("shequxiajisywgfwnldfpjz","社区下级所有网格服务能力得分(平均值) ",5), ; private String code; diff --git a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateCommunityServiceImpl.java b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateCommunityServiceImpl.java index 072c6c6e36..0e778ae49f 100644 --- a/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateCommunityServiceImpl.java +++ b/epmet-module/data-statistical/data-statistical-server/src/main/java/com/epmet/service/screen/impl/IndexCalculateCommunityServiceImpl.java @@ -19,13 +19,13 @@ import com.epmet.service.screen.IndexGroupDetailService; import com.epmet.support.normalizing.*; import com.epmet.support.normalizing.batch.BatchScoreCalculator; import com.epmet.support.normalizing.batch.IndexInputVO; -import com.epmet.support.normalizing.batch.IndexOutputVO; import com.epmet.support.normalizing.batch.SampleValue; import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeanUtils; +import org.apache.commons.collections4.ListUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.CollectionUtils; import java.math.BigDecimal; import java.util.*; @@ -55,8 +55,8 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni private FactIndexGridScoreDao factIndexGridScoreDao; /** - * @Description 社区名义发文数量计算【党建能力】 * @param customerId + * @Description 社区名义发文数量计算【党建能力】 * @author zxc * @date 2020/8/26 10:46 上午 */ @@ -64,314 +64,210 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni public Boolean communityPartyCalculate(String customerId, String monthId) { // 党建能力 // 根据all_parent_index_code 获取指标明细 - List detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(),IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); - List subAllGridList = new ArrayList<>(); - List communityPublishArticle = new ArrayList<>(); + List detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); + if (CollectionUtils.isEmpty(detailListByParentCode)) { + log.error("指标明细查询集合为空"); + return false; + } + List indexInputVOS = new ArrayList<>(); //下属所有网格的党建能力平均值 - detailListByParentCode.forEach(indexGroup -> { - if (indexGroup.getIndexCode().equals(IndexCalConstant.COMMUNITY_PARTY_AVG)){ + detailListByParentCode.forEach(detail -> { + if (IndexCodeEnum.XIA_SHU_SUO_YOU_WGDDJNLPJZ.getCode().equals(detail.getIndexCode())) { List subGridPartyAvgScore = factIndexGridScoreDao.selectSubGridPartyAvgScore(customerId, monthId); - if (subGridPartyAvgScore.size() != NumConstant.ZERO){ - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridPartyAvgScore.stream().map(o -> o.getScore()).collect(Collectors.toList())); - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List collect; - do { - collect = subGridPartyAvgScore.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); - List index1SampleValues = new ArrayList<>(); - collect.forEach(c -> { - SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); - index1SampleValues.add(s); - FactIndexCommunityScoreDTO dto = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,dto); - subAllGridList.add(dto); - }); - HashMap result = this.getCalResult(maxAndMinBigDecimal, index1SampleValues, indexGroup); - result.forEach((key,value) -> { - subAllGridList.forEach(grid -> { - if (grid.getAgencyId().equals(key)){ - grid.setScore(value); - } - }); - }); - indexStart++; - }while (collect.size() == NumConstant.TEN); - } - }else { - List indexInputVOS = new ArrayList<>(); - List> maps = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMap(customerId, monthId); - String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(indexGroup.getIndexCode()); - if (!StringUtils.isEmpty(fieldNameByIndexCode)) { - if (maps.get(NumConstant.ZERO).containsKey(fieldNameByIndexCode)) { - List decimalList = maps.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List> collect; - do { - collect = maps.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); - ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); - List index1SampleValues = new ArrayList<>(); - collect.forEach(c -> { - SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); - index1SampleValues.add(s); - FactIndexCommunityScoreDTO publishArticle = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,publishArticle); - communityPublishArticle.add(publishArticle); - }); - IndexInputVO index1VO = new IndexInputVO(indexGroup.getIndexId(), index1SampleValues, indexGroup.getThreshold(), indexGroup.getWeight(), sc1); - indexInputVOS.add(index1VO); - } while (collect.size() == NumConstant.TEN); - } + if (CollectionUtils.isEmpty(subGridPartyAvgScore)) { + log.error("查询下属所有网格的党建能力平均值集合为空"); + return; } - BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); - HashMap scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); - scoreCountOfSampleId.forEach((key,value) -> { - communityPublishArticle.forEach(grid -> { - if (key.equals(grid.getAgencyId())) { - grid.setCustomerId(customerId); - grid.setIndexCode(IndexCalConstant.COMMUNITY_GOVERN); - grid.setScore(grid.getScore().add(value)); - } + 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); }); - } - }); - // 社区名义发文数量 - /*List publishArticleCounts = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCount(customerId, monthId); - detailListByParentCode.forEach(indexGroup -> { - if (indexGroup.getIndexCode().equals("shequmingyifwsl")) { - if (publishArticleCounts.size() == NumConstant.ONE) { - //TODO 结果为一条时 - } else if (publishArticleCounts.size() > NumConstant.ONE) { - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List collect; - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(publishArticleCounts.stream().map(o -> new BigDecimal(o.getPublishArticleCount())).collect(Collectors.toList())); - do { - collect = publishArticleCounts.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); - List ll = new ArrayList<>(); - collect.forEach(c -> { - SampleValue s = new SampleValue(c.getAgencyId(), c.getPublishArticleCount()); - ll.add(s); - FactIndexCommunityScoreDTO publishArticle = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,publishArticle); - communityPublishArticle.add(publishArticle); - }); - HashMap result = this.getCalResult(maxAndMinBigDecimal, ll, indexGroup); - result.forEach((key,value) -> { - communityPublishArticle.forEach(publish -> { - if (publish.getAgencyId().equals(key)){ - publish.setIndexCode(indexGroup.getIndexCode()); - publish.setScore(value); - } - }); - }); - indexStart++; - } while (collect.size() == NumConstant.TEN); + } else { + // 社区名义发文数量 + List> mapList = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMap(customerId, monthId); + if (CollectionUtils.isEmpty(mapList)) { + log.error("查询社区名义发文数量集合为空"); + return; } - } - });*/ - subAllGridList.forEach(grid -> { - communityPublishArticle.forEach(publish -> { - if (grid.getAgencyId().equals(publish.getAgencyId())){ - grid.setScore(grid.getScore().add(publish.getScore())); - grid.setIndexCode(IndexCalConstant.COMMUNITY_PARTY); + String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); + 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); + }); + IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); + indexInputVOS.add(index1VO); + }); + } }); - deleteAndInsert(customerId,monthId,IndexCalConstant.COMMUNITY_PARTY,subAllGridList); + BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); + HashMap scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); + List result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); + deleteAndInsert(customerId, monthId, IndexCodeEnum.DANG_JIAN_NENG_LI.getCode(), result); return true; } /** - * @Description 社区治理能力 * @param customerId * @param monthId + * @Description 社区治理能力 * @author zxc * @date 2020/8/26 1:40 下午 */ @Transactional(rollbackFor = Exception.class) public Boolean communityGovernAbilityCalculate(String customerId, String monthId) { - List subAllGridList = new ArrayList<>(); List detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); + if (CollectionUtils.isEmpty(detailListByParentCode)) { + log.error("指标明细查询集合为空"); + return false; + } + List indexInputVOS = new ArrayList<>(); detailListByParentCode.forEach(detail -> { - if (detail.getIndexCode().equals(IndexCalConstant.COMMUNITY_GOVERN_AVG)){ + if (IndexCodeEnum.SHE_QU_XIA_SHU_SYWGZLNLHZPJZ.getCode().equals(detail.getIndexCode())) { List subGridGovernAvg = factIndexGridScoreDao.selectSubGridGovernAvgScore(customerId, monthId); - if (subGridGovernAvg.size() == NumConstant.ONE){ - + if (subGridGovernAvg.size() == NumConstant.ONE) { // TODO - - }else if (subGridGovernAvg.size() > NumConstant.ONE){ + } else if (subGridGovernAvg.size() > NumConstant.ONE) { MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridGovernAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List collect; - do { - collect = subGridGovernAvg.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); + List> governAvg = ListUtils.partition(subGridGovernAvg, 10); + governAvg.forEach(avg -> { List index1SampleValues = new ArrayList<>(); - collect.forEach(c -> { + avg.forEach(c -> { SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); index1SampleValues.add(s); - FactIndexCommunityScoreDTO dto = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,dto); - subAllGridList.add(dto); }); - HashMap result = this.getCalResult(maxAndMinBigDecimal, index1SampleValues, detail); - result.forEach((key,value) -> { - subAllGridList.forEach(grid -> { - if (grid.getAgencyId().equals(key)){ - grid.setScore(value); - } - }); + 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> communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao.selectCommunityGovernAbility(customerId, monthId); + if (communityGovernAbility.size() == NumConstant.ONE) { + // TODO + } else if (communityGovernAbility.size() > NumConstant.ONE) { + String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); + if (StringUtils.isEmpty(fieldNameByIndexCode)) { + log.error("指标Code未查询出对应字段 【" + detail.getIndexCode() + "】"); + return; + } + List decimalList = communityGovernAbility.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); + MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); + List>> governAbilityList = ListUtils.partition(communityGovernAbility, 10); + governAbilityList.forEach(governAbility -> { + ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); + List index1SampleValues = new ArrayList<>(); + governAbility.forEach(c -> { + SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); + index1SampleValues.add(s); }); - indexStart++; - }while (collect.size() == NumConstant.TEN); + IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); + indexInputVOS.add(index1VO); + }); } } }); - - List> communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao.selectCommunityGovernAbility(customerId, monthId); - if (communityGovernAbility.size() == NumConstant.ONE){ - // TODO - }else if (communityGovernAbility.size() > NumConstant.ONE){ - List indexInputVOS = new ArrayList<>(); - detailListByParentCode.forEach(detail -> { - String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); - if (!StringUtils.isEmpty(fieldNameByIndexCode)){ - if (communityGovernAbility.get(NumConstant.ZERO).containsKey(fieldNameByIndexCode)) { - List decimalList = communityGovernAbility.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List> collect; - do { - collect = communityGovernAbility.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); - ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); - List index1SampleValues = new ArrayList<>(); - collect.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); - } while (collect.size() == NumConstant.TEN); - } - } - }); - BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); - HashMap scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); - scoreCountOfSampleId.forEach((key,value) -> { - subAllGridList.forEach(grid -> { - if (key.equals(grid.getAgencyId())) { - grid.setCustomerId(customerId); - grid.setIndexCode(IndexCalConstant.COMMUNITY_GOVERN); - grid.setScore(grid.getScore().add(value)); - } - }); - }); - } - deleteAndInsert(customerId,monthId,IndexCalConstant.COMMUNITY_GOVERN,subAllGridList); + BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); + HashMap scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); + List result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.ZHI_LI_NENG_LI.getCode()); + deleteAndInsert(customerId, monthId, IndexCodeEnum.ZHI_LI_NENG_LI.getCode(), result); return true; } /** - * @Description 社区服务能力 * @param customerId * @param monthId + * @Description 社区服务能力 * @author zxc * @date 2020/8/31 1:38 下午 */ @Transactional(rollbackFor = Exception.class) public Boolean communityServiceAbilityCalculate(String customerId, String monthId) { - List subAllGridList = new ArrayList<>(); - List communityPublishArticle = new ArrayList<>(); List detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(), IndexCodeEnum.FU_WU_NENG_LI.getCode()); + if (CollectionUtils.isEmpty(detailListByParentCode)) { + log.error("指标明细查询集合为空"); + return false; + } + List indexInputVOS = new ArrayList<>(); detailListByParentCode.forEach(detail -> { String indexCode = detail.getIndexCode(); - if (indexCode.equals(IndexCalConstant.COMMUNITY_SERVICE_AVG)){ + if (IndexCodeEnum.SHE_QU_XIA_JI_SYWGFWNLDFPJZ.getCode().equals(indexCode)) { List subGridServiceAvg = factIndexGridScoreDao.selectSubGridServiceAvgScore(customerId, monthId); - if (subGridServiceAvg.size() == NumConstant.ONE){ + if (subGridServiceAvg.size() == NumConstant.ONE) { // TODO 只有一条记录时 - }else if (subGridServiceAvg.size() > NumConstant.ONE ){ + } else if (subGridServiceAvg.size() > NumConstant.ONE) { MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(subGridServiceAvg.stream().map(o -> o.getScore()).collect(Collectors.toList())); - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List collect; - do { - collect = subGridServiceAvg.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); + List> serviceAvgList = ListUtils.partition(subGridServiceAvg, 10); + serviceAvgList.forEach(serviceAvg -> { BigDecimalScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); List index1SampleValues = new ArrayList<>(); - collect.forEach(c -> { + serviceAvg.forEach(c -> { SampleValue s = new SampleValue(c.getAgencyId(), c.getScore()); index1SampleValues.add(s); - FactIndexCommunityScoreDTO dto = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,dto); - subAllGridList.add(dto); }); - IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues,detail.getThreshold(), detail.getWeight(), sc1); - List indexInputVOS = Arrays.asList(index1VO); - BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); - List result = batchScoreCalculator.getScoreDetailOfIndexId(indexInputVOS); - result.get(NumConstant.ZERO).getIndexScoreVOs().forEach(agency -> { - subAllGridList.forEach(grid -> { - if (grid.getAgencyId().equals(agency.getSampleId())){ - grid.setScore(agency.getSampleScore()); - } - }); - }); - indexStart++; - }while (collect.size() == NumConstant.TEN); + IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); + indexInputVOS.add(index1VO); + }); } - }else{ - List communityActivityCount = factIndexServiceAblityOrgMonthlyDao.selectActivityCount(customerId, monthId); - if (communityActivityCount.size() == NumConstant.ONE){ + } else { + List> communityActivityCountList = factIndexServiceAblityOrgMonthlyDao.selectActivityCountMap(customerId, monthId); + if (CollectionUtils.isEmpty(communityActivityCountList)) { + log.error(""); + return; + } + if (communityActivityCountList.size() == NumConstant.ONE) { // TODO - }else if (communityActivityCount.size() > NumConstant.ONE){ - Integer indexStart = NumConstant.ZERO; - Integer indexEnd = NumConstant.TEN; - List collect; - MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(communityActivityCount.stream().map(o -> new BigDecimal(o.getActivityCount())).collect(Collectors.toList())); - do { - collect = communityActivityCount.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); - List ll = new ArrayList<>(); - collect.forEach(c -> { - SampleValue s = new SampleValue(c.getAgencyId(), c.getActivityCount()); - ll.add(s); - FactIndexCommunityScoreDTO publishArticle = new FactIndexCommunityScoreDTO(); - BeanUtils.copyProperties(c,publishArticle); - communityPublishArticle.add(publishArticle); - }); - HashMap result = this.getCalResult(maxAndMinBigDecimal, ll, detail); - result.forEach((k,v) -> { - communityPublishArticle.forEach(publish -> { - if (publish.getAgencyId().equals(k)){ - publish.setScore(v); - } - }); + } else if (communityActivityCountList.size() > NumConstant.ONE) { + String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); + if (StringUtils.isEmpty(fieldNameByIndexCode)) { + log.error("指标Code未查询出对应字段 【" + detail.getIndexCode() + "】"); + return; + } + List decimalList = communityActivityCountList.stream().map(m -> new BigDecimal(m.get(fieldNameByIndexCode).toString())).collect(Collectors.toList()); + MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this.getMaxAndMinBigDecimal(decimalList); + List>> communityActivityList = ListUtils.partition(communityActivityCountList, 10); + communityActivityList.forEach(communityActivity -> { + ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); + List index1SampleValues = new ArrayList<>(); + communityActivity.forEach(c -> { + SampleValue s = new SampleValue((String) c.get(IndexCalConstant.AGENCY_ID), new BigDecimal(String.valueOf(c.get(fieldNameByIndexCode)))); + index1SampleValues.add(s); }); - indexStart++; - } while (collect.size() == NumConstant.TEN); + IndexInputVO index1VO = new IndexInputVO(detail.getIndexId(), index1SampleValues, detail.getThreshold(), detail.getWeight(), sc1); + indexInputVOS.add(index1VO); + }); } } }); - subAllGridList.forEach(grid -> { - grid.setIndexCode(IndexCalConstant.COMMUNITY_SERVICE); - communityPublishArticle.forEach(publish -> { - if (grid.getAgencyId().equals(publish.getAgencyId())){ - grid.setScore(grid.getScore().add(publish.getScore())); - grid.setCustomerId(customerId); - } - }); - }); - deleteAndInsert(customerId,monthId,IndexCalConstant.COMMUNITY_SERVICE,subAllGridList); + BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); + HashMap scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); + List result = getResult(scoreCountOfSampleId, customerId, monthId, NumConstant.ZERO_STR, IndexCodeEnum.FU_WU_NENG_LI.getCode()); + deleteAndInsert(customerId, monthId, IndexCodeEnum.FU_WU_NENG_LI.getCode(), result); return true; } /** - * @Description 社区相关计算 * @param customerId * @param monthId + * @Description 社区相关计算 * @author zxc * @date 2020/9/1 9:21 上午 */ @@ -380,14 +276,14 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni List factIndexCommunityScoreEntities = factIndexCommunityScoreDao.selectCommunityInfo(customerId, monthId); detailListByParentCode.forEach(detail -> { factIndexCommunityScoreEntities.forEach(community -> { - if (detail.getIndexCode().equals(community.getIndexCode())){ + if (detail.getIndexCode().equals(community.getIndexCode())) { community.setScore(community.getScore().multiply(detail.getWeight())); } }); }); Map> collect = factIndexCommunityScoreEntities.stream().collect(Collectors.groupingBy(FactIndexCommunityScoreDTO::getAgencyId)); List result = new ArrayList<>(); - collect.forEach((key,value) -> { + collect.forEach((key, value) -> { FactIndexCommunityScoreDTO score = new FactIndexCommunityScoreDTO(); score.setIsTotal(NumConstant.ONE_STR); score.setCustomerId(customerId); @@ -401,44 +297,44 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni }); result.add(score); }); - deleteAndInsert(customerId,monthId,IndexCalConstant.COMMUNITY_RELATE,result); + deleteAndInsert(customerId, monthId, IndexCalConstant.COMMUNITY_RELATE, result); return true; } /** - * @Description 计算社区相关总分 * @param customerId * @param monthId + * @Description 计算社区相关总分 * @author zxc * @date 2020/9/1 4:12 下午 */ - public Boolean calCommunityAll(String customerId,String monthId){ + public Boolean calCommunityAll(String customerId, String monthId) { Boolean aBoolean = communityPartyCalculate(customerId, monthId);//党建能力 - if (!aBoolean.equals(true)){ + if (!aBoolean.equals(true)) { throw new RenException("calculate community-party-ability failure ......"); } Boolean bBoolean = communityGovernAbilityCalculate(customerId, monthId);// 治理能力 - if (!bBoolean.equals(true)){ + if (!bBoolean.equals(true)) { throw new RenException("calculate community-govern-ability failure ......"); } Boolean cBoolean = communityServiceAbilityCalculate(customerId, monthId);// 服务能力 - if (!cBoolean.equals(true)){ + if (!cBoolean.equals(true)) { throw new RenException("calculate community-service-ability failure ......"); } Boolean dBoolean = communityRelate(customerId, monthId); - if (!dBoolean.equals(true)){ + if (!dBoolean.equals(true)) { throw new RenException("calculate community-all insert failure ......"); } return true; } /** - * @Description BigDecimal类型获取最大数和最小数 * @param list + * @Description BigDecimal类型获取最大数和最小数 * @author zxc * @date 2020/8/27 1:30 下午 */ - public MaxAndMinBigDecimalResultDTO getMaxAndMinBigDecimal(List list){ + public MaxAndMinBigDecimalResultDTO getMaxAndMinBigDecimal(List list) { BigDecimal max = Collections.max(list); BigDecimal min = Collections.min(list); MaxAndMinBigDecimalResultDTO result = new MaxAndMinBigDecimalResultDTO(); @@ -447,25 +343,34 @@ public class IndexCalculateCommunityServiceImpl implements IndexCalculateCommuni return result; } - public HashMap getCalResult(MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal,List ll, IndexGroupDetailEntity indexGroup){ - BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); - IndexInputVO index1VO = new IndexInputVO(indexGroup.getIndexId(), ll,indexGroup.getThreshold(), indexGroup.getWeight(), sc); - List indexInputVOS = Arrays.asList(index1VO); - BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); - return batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); - } - /** - * @Description 先删除记录,在插入 * @param customerId * @param monthId * @param indexCode * @param subAllGridList + * @Description 先删除记录,在插入 * @author zxc * @date 2020/9/1 4:24 下午 */ - public void deleteAndInsert(String customerId,String monthId,String indexCode,List subAllGridList){ - factIndexCommunityScoreDao.deleteOldRecord(customerId,monthId,indexCode); + public void deleteAndInsert(String customerId, String monthId, String indexCode, List subAllGridList) { + factIndexCommunityScoreDao.deleteOldRecord(customerId, monthId, indexCode); factIndexCommunityScoreDao.insertCommunityPartyRecord(subAllGridList); } + + public List getResult(HashMap scoreCountOfSampleId, String customerId, String monthId, String isTotal, String indexCode) { + List result = new ArrayList<>(); + scoreCountOfSampleId.forEach((k, v) -> { + FactIndexCommunityScoreDTO score = new FactIndexCommunityScoreDTO(); + score.setCustomerId(customerId); + score.setAgencyId(k); + score.setMonthId(monthId); + score.setQuarterId(DateUtils.getQuarterId(monthId)); + score.setYearId(DateUtils.getYearId(monthId)); + score.setIsTotal(isTotal); + score.setIndexCode(indexCode); + score.setScore(v); + result.add(score); + }); + return result; + } }