@ -1,10 +1,42 @@
package com.epmet.service.evaluationindex.indexcal.impl ;
import com.alibaba.druid.util.StringUtils ;
import com.epmet.commons.dynamic.datasource.annotation.DataSource ;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.exception.RenException ;
import com.epmet.commons.tools.utils.DateUtils ;
import com.epmet.constant.DataSourceConstant ;
import com.epmet.constant.IndexCalConstant ;
import com.epmet.dao.evaluationindex.indexcal.AgencyScoreDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityOrgMonthlyDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityOrgMonthlyDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexServiceAblityOrgMonthlyDao ;
import com.epmet.dao.evaluationindex.screen.FactIndexCommunityScoreDao ;
import com.epmet.dto.indexcal.AgencyScoreDTO ;
import com.epmet.dto.indexcal.SubCommunityAvgResultDTO ;
import com.epmet.dto.screen.result.MaxAndMinBigDecimalResultDTO ;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity ;
import com.epmet.eum.IndexCodeEnum ;
import com.epmet.service.evaluationindex.indexcal.IndexCalculateStreetService ;
import com.epmet.service.evaluationindex.indexcal.IndexCodeFieldReService ;
import com.epmet.service.evaluationindex.screen.IndexGroupDetailService ;
import com.epmet.support.normalizing.BigDecimalScoreCalculator ;
import com.epmet.support.normalizing.Correlation ;
import com.epmet.support.normalizing.ScoreCalculator ;
import com.epmet.support.normalizing.ScoreConstants ;
import com.epmet.support.normalizing.batch.BatchScoreCalculator ;
import com.epmet.support.normalizing.batch.IndexInputVO ;
import com.epmet.support.normalizing.batch.SampleValue ;
import lombok.extern.slf4j.Slf4j ;
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.* ;
import java.util.stream.Collectors ;
/ * *
* @Author zxc
@ -15,6 +47,21 @@ import org.springframework.stereotype.Service;
@DataSource ( DataSourceConstant . EVALUATION_INDEX )
public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetService {
@Autowired
private FactIndexPartyAblityOrgMonthlyDao factIndexPartyAblityOrgMonthlyDao ;
@Autowired
private FactIndexGovrnAblityOrgMonthlyDao factIndexGovrnAblityOrgMonthlyDao ;
@Autowired
private FactIndexServiceAblityOrgMonthlyDao factIndexServiceAblityOrgMonthlyDao ;
@Autowired
private IndexGroupDetailService indexGroupDetailService ;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService ;
@Autowired
private FactIndexCommunityScoreDao communityScoreDao ;
@Autowired
private AgencyScoreDao agencyScoreDao ;
/ * *
* @Description 计算街道相关总分
* @param customerId
@ -24,6 +71,379 @@ public class IndexCalculateStreetServiceImpl implements IndexCalculateStreetServ
* /
@Override
public Boolean calStreetAll ( String customerId , String monthId ) {
return null ;
Boolean aBoolean = streetPartyCalculate ( customerId , monthId ) ; //党建能力
if ( ! aBoolean . equals ( true ) ) {
throw new RenException ( "calculate street-party-ability failure ......" ) ;
}
Boolean bBoolean = streetGovernAbilityCalculate ( customerId , monthId ) ; // 治理能力
if ( ! bBoolean . equals ( true ) ) {
throw new RenException ( "calculate street-govern-ability failure ......" ) ;
}
Boolean cBoolean = streetServiceAbilityCalculate ( customerId , monthId ) ; // 服务能力
if ( ! cBoolean . equals ( true ) ) {
throw new RenException ( "calculate street-service-ability failure ......" ) ;
}
Boolean dBoolean = streetRelate ( customerId , monthId ) ;
if ( ! dBoolean . equals ( true ) ) {
throw new RenException ( "calculate street-all insert failure ......" ) ;
}
return true ;
}
/ * *
* @param customerId
* @Description 社区名义发文数量计算 【 党建能力 】
* @author zxc
* @date 2020 / 8 / 26 10 : 46 上午
* /
public Boolean streetPartyCalculate ( String customerId , String monthId ) {
// 党建能力
// 根据all_parent_index_code 获取指标明细
List < IndexGroupDetailEntity > detailListByParentCode = indexGroupDetailService . getDetailListByParentCode ( customerId , IndexCodeEnum . JIE_DAO_XIANG_GUAN . getCode ( ) , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) ) ;
if ( CollectionUtils . isEmpty ( detailListByParentCode ) ) {
log . error ( IndexCalConstant . INDEX_DETAIL_LIST_NULL ) ;
return false ;
}
List < IndexInputVO > indexInputVOS = new ArrayList < > ( ) ;
Map < String , String > pid = new HashMap < > ( ) ;
//下属所有社区的党建能力平均值
detailListByParentCode . forEach ( detail - > {
if ( IndexCodeEnum . JIE_DAO_XIA_SHU_SYSQDJNLHZPJZ . getCode ( ) . equals ( detail . getIndexCode ( ) ) ) {
List < SubCommunityAvgResultDTO > subCommPartyAvgScore = communityScoreDao . selectSubCommAvgScore ( customerId , monthId , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) ) ;
if ( CollectionUtils . isEmpty ( subCommPartyAvgScore ) ) {
log . error ( IndexCalConstant . COMMUNITY_PARTY_AVG_NULL ) ;
return ;
} else if ( subCommPartyAvgScore . size ( ) = = NumConstant . ONE ) {
pid . put ( subCommPartyAvgScore . get ( NumConstant . ZERO ) . getAgencyId ( ) , subCommPartyAvgScore . get ( NumConstant . ZERO ) . getParentId ( ) ) ;
sizeOne ( subCommPartyAvgScore . get ( NumConstant . ZERO ) . getAgencyId ( ) , customerId , monthId , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( subCommPartyAvgScore . size ( ) > NumConstant . ONE ) {
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( subCommPartyAvgScore . stream ( ) . map ( o - > o . getScore ( ) ) . collect ( Collectors . toList ( ) ) ) ;
Integer indexEnd = NumConstant . TEN ;
List < List < SubCommunityAvgResultDTO > > partition = ListUtils . partition ( subCommPartyAvgScore , indexEnd ) ;
partition . forEach ( publish - > {
List < SampleValue > index1SampleValues = new ArrayList < > ( ) ;
publish . 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 . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
} else {
// 街道名义发文数量
List < Map < String , Object > > mapList = factIndexPartyAblityOrgMonthlyDao . selectPublishArticleCountMap ( customerId , monthId , IndexCalConstant . STREET_LEVEL ) ;
if ( CollectionUtils . isEmpty ( mapList ) ) {
log . error ( IndexCalConstant . STREET_PUBLISH_ARTICLE_LIST_NULL ) ;
return ;
}
String fieldName = indexCodeFieldReService . getFieldNameByIndexCode ( detail . getIndexCode ( ) ) ;
if ( StringUtils . isEmpty ( fieldName ) ) {
log . error ( String . format ( IndexCalConstant . INDEX_CODE_NULL , detail . getIndexCode ( ) ) ) ;
return ;
} else if ( mapList . size ( ) = = NumConstant . ONE ) {
pid . put ( mapList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , mapList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . PARENT_ID ) . toString ( ) ) ;
sizeOne ( mapList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , customerId , monthId , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( mapList . size ( ) > NumConstant . ONE ) {
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( mapList . stream ( ) . map ( m - > new BigDecimal ( m . get ( fieldName ) . toString ( ) ) ) . collect ( Collectors . toList ( ) ) ) ;
List < List < Map < String , Object > > > publishArticleList = ListUtils . partition ( mapList , IndexCalConstant . PAGE_SIZE ) ;
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 - > {
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 ( fieldName ) ) ) ) ;
index1SampleValues . add ( s ) ;
} ) ;
IndexInputVO index1VO = new IndexInputVO ( detail . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc1 ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
}
} ) ;
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator ( ) ;
HashMap < String , BigDecimal > scoreCountOfSampleId = batchScoreCalculator . getScoreCountOfSampleId ( indexInputVOS ) ;
List < AgencyScoreDTO > result = getResult ( scoreCountOfSampleId , customerId , monthId , NumConstant . ZERO_STR , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , pid ) ;
deleteAndInsert ( customerId , monthId , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , result ) ;
return true ;
}
/ * *
* @Description 街道治理能力
* @param customerId
* @param monthId
* @author zxc
* @date 2020 / 8 / 26 1 : 40 下午
* /
public Boolean streetGovernAbilityCalculate ( String customerId , String monthId ) {
List < IndexGroupDetailEntity > detailListByParentCode = indexGroupDetailService . getDetailListByParentCode ( customerId , IndexCodeEnum . JIE_DAO_XIANG_GUAN . getCode ( ) , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) ) ;
if ( CollectionUtils . isEmpty ( detailListByParentCode ) ) {
log . error ( IndexCalConstant . INDEX_DETAIL_LIST_NULL ) ;
return false ;
}
List < IndexInputVO > indexInputVOS = new ArrayList < > ( ) ;
Map < String , String > pid = new HashMap < > ( ) ;
detailListByParentCode . forEach ( detail - > {
if ( IndexCodeEnum . JIE_DAO_XIA_SHU_SYSQZLNLHZ . getCode ( ) . equals ( detail . getIndexCode ( ) ) ) {
List < SubCommunityAvgResultDTO > subGridGovernAvg = communityScoreDao . selectSubCommAvgScore ( customerId , monthId , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) ) ;
if ( subGridGovernAvg . size ( ) = = NumConstant . ONE ) {
pid . put ( subGridGovernAvg . get ( NumConstant . ZERO ) . getAgencyId ( ) , subGridGovernAvg . get ( NumConstant . ZERO ) . getParentId ( ) ) ;
sizeOne ( subGridGovernAvg . get ( NumConstant . ZERO ) . getAgencyId ( ) , customerId , monthId , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( subGridGovernAvg . size ( ) > NumConstant . ONE ) {
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( subGridGovernAvg . stream ( ) . map ( o - > o . getScore ( ) ) . collect ( Collectors . toList ( ) ) ) ;
List < List < SubCommunityAvgResultDTO > > governAvg = ListUtils . partition ( subGridGovernAvg , IndexCalConstant . PAGE_SIZE ) ;
governAvg . forEach ( avg - > {
List < SampleValue > index1SampleValues = new ArrayList < > ( ) ;
avg . forEach ( c - > {
pid . put ( c . getAgencyId ( ) , c . getParentId ( ) ) ;
SampleValue s = new SampleValue ( c . getAgencyId ( ) , c . getScore ( ) ) ;
index1SampleValues . add ( s ) ;
} ) ;
BigDecimalScoreCalculator sc = new BigDecimalScoreCalculator ( maxAndMinBigDecimal . getMin ( ) , maxAndMinBigDecimal . getMax ( ) , ScoreConstants . MIN_SCORE , ScoreConstants . MAX_SCORE , Correlation . getCorrelation ( detail . getCorrelation ( ) ) ) ;
IndexInputVO index1VO = new IndexInputVO ( detail . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
} else {
// 治理能力的六个五级指标
List < Map < String , Object > > communityGovernAbility = factIndexGovrnAblityOrgMonthlyDao . selectCommunityGovernAbility ( customerId , monthId , IndexCalConstant . STREET_LEVEL ) ;
if ( CollectionUtils . isEmpty ( communityGovernAbility ) ) {
log . error ( IndexCalConstant . STREET_GOVERN_ABILITY_NULL ) ;
return ;
} else if ( communityGovernAbility . size ( ) = = NumConstant . ONE ) {
pid . put ( communityGovernAbility . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , communityGovernAbility . get ( NumConstant . ZERO ) . get ( IndexCalConstant . PARENT_ID ) . toString ( ) ) ;
sizeOne ( communityGovernAbility . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , customerId , monthId , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( communityGovernAbility . size ( ) > NumConstant . ONE ) {
String fieldNameByIndexCode = indexCodeFieldReService . getFieldNameByIndexCode ( detail . getIndexCode ( ) ) ;
System . err . println ( fieldNameByIndexCode ) ;
System . err . println ( detail . getIndexCode ( ) ) ;
if ( StringUtils . isEmpty ( fieldNameByIndexCode ) ) {
log . error ( String . format ( IndexCalConstant . INDEX_CODE_NULL , detail . getIndexCode ( ) ) ) ;
return ;
}
List < BigDecimal > decimalList = communityGovernAbility . stream ( ) . map ( m - > new BigDecimal ( m . get ( fieldNameByIndexCode ) . toString ( ) ) ) . collect ( Collectors . toList ( ) ) ;
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( decimalList ) ;
List < List < Map < String , Object > > > governAbilityList = ListUtils . partition ( communityGovernAbility , IndexCalConstant . PAGE_SIZE ) ;
governAbilityList . forEach ( governAbility - > {
ScoreCalculator < Integer > sc1 = new BigDecimalScoreCalculator ( maxAndMinBigDecimal . getMin ( ) , maxAndMinBigDecimal . getMax ( ) , ScoreConstants . MIN_SCORE , ScoreConstants . MAX_SCORE , Correlation . POSITIVE ) ;
List < SampleValue > index1SampleValues = new ArrayList < > ( ) ;
governAbility . forEach ( c - > {
pid . put ( c . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , c . get ( IndexCalConstant . PARENT_ID ) . toString ( ) ) ;
SampleValue s = new SampleValue ( ( String ) c . get ( IndexCalConstant . AGENCY_ID ) , new BigDecimal ( String . valueOf ( c . get ( fieldNameByIndexCode ) ) ) ) ;
index1SampleValues . add ( s ) ;
} ) ;
IndexInputVO index1VO = new IndexInputVO ( detail . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc1 ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
}
} ) ;
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator ( ) ;
HashMap < String , BigDecimal > scoreCountOfSampleId = batchScoreCalculator . getScoreCountOfSampleId ( indexInputVOS ) ;
List < AgencyScoreDTO > result = getResult ( scoreCountOfSampleId , customerId , monthId , NumConstant . ZERO_STR , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , pid ) ;
deleteAndInsert ( customerId , monthId , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , result ) ;
return true ;
}
/ * *
* @Description 街道服务能力
* @param customerId
* @param monthId
* @author zxc
* @date 2020 / 8 / 31 1 : 38 下午
* /
public Boolean streetServiceAbilityCalculate ( String customerId , String monthId ) {
List < IndexGroupDetailEntity > detailListByParentCode = indexGroupDetailService . getDetailListByParentCode ( customerId , IndexCodeEnum . JIE_DAO_XIANG_GUAN . getCode ( ) , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) ) ;
if ( CollectionUtils . isEmpty ( detailListByParentCode ) ) {
log . error ( IndexCalConstant . INDEX_DETAIL_LIST_NULL ) ;
return false ;
}
List < IndexInputVO > indexInputVOS = new ArrayList < > ( ) ;
Map < String , String > pid = new HashMap < > ( ) ;
detailListByParentCode . forEach ( detail - > {
String indexCode = detail . getIndexCode ( ) ;
if ( IndexCodeEnum . JIE_DAO_XIA_SHU_SQFWNLDFPYZ . getCode ( ) . equals ( indexCode ) ) {
List < SubCommunityAvgResultDTO > subCommServiceAvg = communityScoreDao . selectSubCommAvgScore ( customerId , monthId , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) ) ;
if ( subCommServiceAvg . size ( ) = = NumConstant . ONE ) {
pid . put ( subCommServiceAvg . get ( NumConstant . ZERO ) . getAgencyId ( ) , subCommServiceAvg . get ( NumConstant . ZERO ) . getParentId ( ) ) ;
sizeOne ( subCommServiceAvg . get ( NumConstant . ZERO ) . getAgencyId ( ) , customerId , monthId , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( subCommServiceAvg . size ( ) > NumConstant . ONE ) {
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( subCommServiceAvg . stream ( ) . map ( o - > o . getScore ( ) ) . collect ( Collectors . toList ( ) ) ) ;
List < List < SubCommunityAvgResultDTO > > serviceAvgList = ListUtils . partition ( subCommServiceAvg , IndexCalConstant . PAGE_SIZE ) ;
serviceAvgList . forEach ( serviceAvg - > {
BigDecimalScoreCalculator sc1 = new BigDecimalScoreCalculator ( maxAndMinBigDecimal . getMin ( ) , maxAndMinBigDecimal . getMax ( ) , ScoreConstants . MIN_SCORE , ScoreConstants . MAX_SCORE , Correlation . POSITIVE ) ;
List < SampleValue > index1SampleValues = new ArrayList < > ( ) ;
serviceAvg . forEach ( c - > {
pid . put ( c . getAgencyId ( ) , c . getParentId ( ) ) ;
SampleValue s = new SampleValue ( c . getAgencyId ( ) , c . getScore ( ) ) ;
index1SampleValues . add ( s ) ;
} ) ;
IndexInputVO index1VO = new IndexInputVO ( detail . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc1 ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
} else {
List < Map < String , Object > > communityActivityCountList = factIndexServiceAblityOrgMonthlyDao . selectActivityCountMap ( customerId , monthId , IndexCalConstant . STREET_LEVEL ) ;
if ( CollectionUtils . isEmpty ( communityActivityCountList ) ) {
log . error ( IndexCalConstant . STREET_SERVICE_ABILITY_NULL ) ;
return ;
} else if ( communityActivityCountList . size ( ) = = NumConstant . ONE ) {
pid . put ( communityActivityCountList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , communityActivityCountList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . PARENT_ID ) . toString ( ) ) ;
sizeOne ( communityActivityCountList . get ( NumConstant . ZERO ) . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , customerId , monthId , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , pid ) ;
return ;
} else if ( communityActivityCountList . size ( ) > NumConstant . ONE ) {
String fieldNameByIndexCode = indexCodeFieldReService . getFieldNameByIndexCode ( detail . getIndexCode ( ) ) ;
if ( StringUtils . isEmpty ( fieldNameByIndexCode ) ) {
log . error ( String . format ( IndexCalConstant . INDEX_CODE_NULL , detail . getIndexCode ( ) ) ) ;
return ;
}
List < BigDecimal > decimalList = communityActivityCountList . stream ( ) . map ( m - > new BigDecimal ( m . get ( fieldNameByIndexCode ) . toString ( ) ) ) . collect ( Collectors . toList ( ) ) ;
MaxAndMinBigDecimalResultDTO maxAndMinBigDecimal = this . getMaxAndMinBigDecimal ( decimalList ) ;
List < List < Map < String , Object > > > communityActivityList = ListUtils . partition ( communityActivityCountList , IndexCalConstant . PAGE_SIZE ) ;
communityActivityList . forEach ( communityActivity - > {
ScoreCalculator < Integer > sc1 = new BigDecimalScoreCalculator ( maxAndMinBigDecimal . getMin ( ) , maxAndMinBigDecimal . getMax ( ) , ScoreConstants . MIN_SCORE , ScoreConstants . MAX_SCORE , Correlation . POSITIVE ) ;
List < SampleValue > index1SampleValues = new ArrayList < > ( ) ;
communityActivity . forEach ( c - > {
pid . put ( c . get ( IndexCalConstant . AGENCY_ID ) . toString ( ) , c . get ( IndexCalConstant . PARENT_ID ) . toString ( ) ) ;
SampleValue s = new SampleValue ( ( String ) c . get ( IndexCalConstant . AGENCY_ID ) , new BigDecimal ( String . valueOf ( c . get ( fieldNameByIndexCode ) ) ) ) ;
index1SampleValues . add ( s ) ;
} ) ;
IndexInputVO index1VO = new IndexInputVO ( detail . getIndexId ( ) , index1SampleValues , detail . getThreshold ( ) , detail . getWeight ( ) , sc1 ) ;
indexInputVOS . add ( index1VO ) ;
} ) ;
}
}
} ) ;
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator ( ) ;
HashMap < String , BigDecimal > scoreCountOfSampleId = batchScoreCalculator . getScoreCountOfSampleId ( indexInputVOS ) ;
List < AgencyScoreDTO > result = getResult ( scoreCountOfSampleId , customerId , monthId , NumConstant . ZERO_STR , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , pid
) ;
deleteAndInsert ( customerId , monthId , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , result ) ;
return true ;
}
/ * *
* @Description 街道相关计算
* @param customerId
* @param monthId
* @author zxc
* @date 2020 / 9 / 3 9 : 21 上午
* /
public Boolean streetRelate ( String customerId , String monthId ) {
List < IndexGroupDetailEntity > detailListByParentCode = indexGroupDetailService . getDetailListByParentCode ( customerId , IndexCodeEnum . SHE_QU_XIANG_GUAN . getCode ( ) ) ;
List < AgencyScoreDTO > agencyScoreList = agencyScoreDao . selectStreetInfo ( customerId , monthId , IndexCalConstant . STREET_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 . setIndexCode ( IndexCodeEnum . JIE_DAO_XIANG_GUAN . getCode ( ) ) ;
score . setDataType ( IndexCalConstant . STREET_LEVEL ) ;
value . forEach ( street - > {
score . setScore ( score . getScore ( ) . add ( street . getScore ( ) ) ) ;
score . setParentAgencyId ( street . getParentAgencyId ( ) ) ;
} ) ;
result . add ( score ) ;
} ) ;
deleteAndInsert ( customerId , monthId , IndexCodeEnum . JIE_DAO_XIANG_GUAN . getCode ( ) , result ) ;
return true ;
}
/ * *
* @param list
* @Description BigDecimal类型获取最大数和最小数
* @author zxc
* @date 2020 / 8 / 27 1 : 30 下午
* /
public MaxAndMinBigDecimalResultDTO getMaxAndMinBigDecimal ( List < BigDecimal > list ) {
BigDecimal max = Collections . max ( list ) ;
BigDecimal min = Collections . min ( list ) ;
MaxAndMinBigDecimalResultDTO result = new MaxAndMinBigDecimalResultDTO ( ) ;
result . setMax ( max ) ;
result . setMin ( min ) ;
return result ;
}
/ * *
* @param customerId
* @param monthId
* @param indexCode
* @param subAllCommunityList
* @Description 先删除记录 , 在插入
* @author zxc
* @date 2020 / 9 / 1 4 : 24 下午
* /
@Transactional ( rollbackFor = Exception . class )
public void deleteAndInsert ( String customerId , String monthId , String indexCode , List < AgencyScoreDTO > subAllCommunityList ) {
if ( ! CollectionUtils . isEmpty ( subAllCommunityList ) ) {
agencyScoreDao . deleteOldRecord ( customerId , monthId , indexCode , IndexCalConstant . STREET_LEVEL ) ;
agencyScoreDao . insertStreetRecord ( subAllCommunityList ) ;
}
}
/ * *
* @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 < AgencyScoreDTO > getResult ( HashMap < String , BigDecimal > scoreCountOfSampleId , String customerId , String monthId , String isTotal , String indexCode , Map < String , String > pid ) {
List < AgencyScoreDTO > result = new ArrayList < > ( ) ;
scoreCountOfSampleId . forEach ( ( k , v ) - > {
AgencyScoreDTO score = new AgencyScoreDTO ( ) ;
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 ) ;
pid . forEach ( ( agency , parentAgency ) - > {
if ( k . equals ( agency ) ) {
score . setParentAgencyId ( parentAgency ) ;
}
} ) ;
result . add ( score ) ;
} ) ;
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 , Map < String , String > pid ) {
HashMap < String , BigDecimal > scoreCountOfSample = new HashMap < > ( ) ;
scoreCountOfSample . put ( agencyId , new BigDecimal ( NumConstant . FIFTY ) ) ;
List < AgencyScoreDTO > result = getResult ( scoreCountOfSample , customerId , monthId , NumConstant . ZERO_STR , indexCode , pid ) ;
deleteAndInsert ( customerId , monthId , indexCode , result ) ;
}
}