|
|
@ -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<IndexGroupDetailEntity> detailListByParentCode = indexGroupDetailService.getDetailListByParentCode(customerId, IndexCodeEnum.SHE_QU_XIANG_GUAN.getCode(),IndexCodeEnum.DANG_JIAN_NENG_LI.getCode()); |
|
|
|
List<FactIndexCommunityScoreDTO> subAllGridList = new ArrayList<>(); |
|
|
|
List<FactIndexCommunityScoreDTO> communityPublishArticle = new ArrayList<>(); |
|
|
|
List<IndexGroupDetailEntity> 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<IndexInputVO> 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<SubGridPartyAvgResultDTO> 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<SubGridPartyAvgResultDTO> collect; |
|
|
|
do { |
|
|
|
collect = subGridPartyAvgScore.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); |
|
|
|
List<SampleValue> 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<String, BigDecimal> 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<IndexInputVO> indexInputVOS = new ArrayList<>(); |
|
|
|
List<Map<String, Object>> maps = factIndexPartyAblityOrgMonthlyDao.selectPublishArticleCountMap(customerId, monthId); |
|
|
|
String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(indexGroup.getIndexCode()); |
|
|
|
if (!StringUtils.isEmpty(fieldNameByIndexCode)) { |
|
|
|
if (maps.get(NumConstant.ZERO).containsKey(fieldNameByIndexCode)) { |
|
|
|
List<BigDecimal> 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<Map<String, Object>> collect; |
|
|
|
do { |
|
|
|
collect = maps.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); |
|
|
|
ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
|
|
|
List<SampleValue> 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<String, BigDecimal> 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<List<SubGridPartyAvgResultDTO>> partition = ListUtils.partition(subGridPartyAvgScore, indexEnd); |
|
|
|
partition.forEach(publish -> { |
|
|
|
List<SampleValue> 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<CommunityPublishArticleCountResultDTO> 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<CommunityPublishArticleCountResultDTO> 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<SampleValue> 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<String, BigDecimal> 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<Map<String, Object>> 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<BigDecimal> decimalList = mapList.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(mapList, 10); |
|
|
|
publishArticleList.forEach(publish -> { |
|
|
|
ScoreCalculator sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
|
|
|
List<SampleValue> 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<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
|
|
|
List<FactIndexCommunityScoreDTO> 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<FactIndexCommunityScoreDTO> subAllGridList = new ArrayList<>(); |
|
|
|
List<IndexGroupDetailEntity> 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<IndexInputVO> 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<SubGridGovernAvgResultDTO> 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<SubGridGovernAvgResultDTO> collect; |
|
|
|
do { |
|
|
|
collect = subGridGovernAvg.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); |
|
|
|
List<List<SubGridGovernAvgResultDTO>> governAvg = ListUtils.partition(subGridGovernAvg, 10); |
|
|
|
governAvg.forEach(avg -> { |
|
|
|
List<SampleValue> 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<String, BigDecimal> 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<Map<String, Object>> 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<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, 10); |
|
|
|
governAbilityList.forEach(governAbility -> { |
|
|
|
ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
|
|
|
List<SampleValue> 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<Map<String,Object>> communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao.selectCommunityGovernAbility(customerId, monthId); |
|
|
|
if (communityGovernAbility.size() == NumConstant.ONE){ |
|
|
|
// TODO
|
|
|
|
}else if (communityGovernAbility.size() > NumConstant.ONE){ |
|
|
|
List<IndexInputVO> indexInputVOS = new ArrayList<>(); |
|
|
|
detailListByParentCode.forEach(detail -> { |
|
|
|
String fieldNameByIndexCode = indexCodeFieldReService.getFieldNameByIndexCode(detail.getIndexCode()); |
|
|
|
if (!StringUtils.isEmpty(fieldNameByIndexCode)){ |
|
|
|
if (communityGovernAbility.get(NumConstant.ZERO).containsKey(fieldNameByIndexCode)) { |
|
|
|
List<BigDecimal> 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<Map<String, Object>> collect; |
|
|
|
do { |
|
|
|
collect = communityGovernAbility.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); |
|
|
|
ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
|
|
|
List<SampleValue> 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<String, BigDecimal> 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<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
|
|
|
List<FactIndexCommunityScoreDTO> 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<FactIndexCommunityScoreDTO> subAllGridList = new ArrayList<>(); |
|
|
|
List<FactIndexCommunityScoreDTO> communityPublishArticle = new ArrayList<>(); |
|
|
|
List<IndexGroupDetailEntity> 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<IndexInputVO> 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<SubGridServiceAvgResultDTO> 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<SubGridServiceAvgResultDTO> collect; |
|
|
|
do { |
|
|
|
collect = subGridServiceAvg.stream().skip(indexEnd * indexStart).limit(indexEnd).collect(Collectors.toList()); |
|
|
|
List<List<SubGridServiceAvgResultDTO>> 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<SampleValue> 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<IndexInputVO> indexInputVOS = Arrays.asList(index1VO); |
|
|
|
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator(); |
|
|
|
List<IndexOutputVO> 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<CommunityActivityCountResultDTO> communityActivityCount = factIndexServiceAblityOrgMonthlyDao.selectActivityCount(customerId, monthId); |
|
|
|
if (communityActivityCount.size() == NumConstant.ONE){ |
|
|
|
} else { |
|
|
|
List<Map<String, Object>> 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<CommunityActivityCountResultDTO> 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<SampleValue> 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<String, BigDecimal> 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<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, 10); |
|
|
|
communityActivityList.forEach(communityActivity -> { |
|
|
|
ScoreCalculator<Integer> sc1 = new BigDecimalScoreCalculator(maxAndMinBigDecimal.getMin(), maxAndMinBigDecimal.getMax(), ScoreConstants.MIN_SCORE, ScoreConstants.MAX_SCORE, Correlation.POSITIVE); |
|
|
|
List<SampleValue> 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<String, BigDecimal> scoreCountOfSampleId = batchScoreCalculator.getScoreCountOfSampleId(indexInputVOS); |
|
|
|
List<FactIndexCommunityScoreDTO> 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<FactIndexCommunityScoreDTO> 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<String, List<FactIndexCommunityScoreDTO>> collect = factIndexCommunityScoreEntities.stream().collect(Collectors.groupingBy(FactIndexCommunityScoreDTO::getAgencyId)); |
|
|
|
List<FactIndexCommunityScoreDTO> 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<BigDecimal> list){ |
|
|
|
public MaxAndMinBigDecimalResultDTO getMaxAndMinBigDecimal(List<BigDecimal> 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<String, BigDecimal> getCalResult(MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal,List<SampleValue> 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<IndexInputVO> 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<FactIndexCommunityScoreDTO> subAllGridList){ |
|
|
|
factIndexCommunityScoreDao.deleteOldRecord(customerId,monthId,indexCode); |
|
|
|
public void deleteAndInsert(String customerId, String monthId, String indexCode, List<FactIndexCommunityScoreDTO> subAllGridList) { |
|
|
|
factIndexCommunityScoreDao.deleteOldRecord(customerId, monthId, indexCode); |
|
|
|
factIndexCommunityScoreDao.insertCommunityPartyRecord(subAllGridList); |
|
|
|
} |
|
|
|
|
|
|
|
public List<FactIndexCommunityScoreDTO> getResult(HashMap<String, BigDecimal> scoreCountOfSampleId, String customerId, String monthId, String isTotal, String indexCode) { |
|
|
|
List<FactIndexCommunityScoreDTO> 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; |
|
|
|
} |
|
|
|
} |
|
|
|