@ -11,13 +11,16 @@ import com.epmet.constant.DataSourceConstant;
import com.epmet.constant.IndexCalConstant ;
import com.epmet.dao.evaluationindex.indexcal.CpcScoreDao ;
import com.epmet.dao.evaluationindex.indexcal.GridScoreDao ;
import com.epmet.dao.evaluationindex.indexcal.GridSubScoreDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexGovrnAblityGridMonthlyDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexPartyAblityGridMonthlyDao ;
import com.epmet.dao.evaluationindex.indexcoll.FactIndexServiceAblityGridMonthlyDao ;
import com.epmet.dao.evaluationindex.screen.ScreenCustomerGridDao ;
import com.epmet.dto.ScreenCustomerGridDTO ;
import com.epmet.dto.indexcal.* ;
import com.epmet.entity.evaluationindex.indexcal.DeptSubScoreEntity ;
import com.epmet.entity.evaluationindex.indexcal.GridScoreEntity ;
import com.epmet.entity.evaluationindex.indexcal.GridSubScoreEntity ;
import com.epmet.entity.evaluationindex.screen.IndexGroupDetailEntity ;
import com.epmet.eum.IndexCodeEnum ;
import com.epmet.service.evaluationindex.indexcal.GridCorreLationService ;
@ -27,11 +30,9 @@ 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.IndexOutputVO ;
import com.epmet.support.normalizing.batch.SampleValue ;
import com.epmet.support.normalizing.batch.* ;
import lombok.extern.slf4j.Slf4j ;
import org.apache.commons.collections4.ListUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@ -69,6 +70,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
private CpcScoreDao cpcScoreDao ;
@Autowired
private GridScoreDao gridScoreDao ;
@Autowired
private GridSubScoreDao gridSubScoreDao ;
/ * *
@ -154,7 +157,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = buildGridCorrelationIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
List < HashMap < String , CalculateResult > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
@ -186,11 +189,16 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
} ) ;
} ) ;
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
HashMap < String , CalculateResult > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationResult ( formDTO , resultMapList , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
deleteBeforeDataList ( formDTO , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , IndexCalConstant . GRID_DJ_ALL_PARENT_INDEX_CODE ) ;
saveGridCorreLationResult ( formDTO ,
resultMapList ,
IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) ,
IndexCalConstant . GRID_DJ_ALL_PARENT_INDEX_CODE ,
NumConstant . ZERO_STR ) ;
}
/ * *
@ -318,6 +326,36 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
return map ;
}
/ * *
* @return void
* @param formDTO
* @param indexCode 当前计算的指标 ( 党建能力 , 治理能力 , 服务能力 )
* @param allParentIndexCode
* @author yinzuomei
* @description
* @Date 2020 / 9 / 10 13 : 58
* * /
private void deleteBeforeDataList ( CalculateCommonFormDTO formDTO , String indexCode , String allParentIndexCode ) {
//先删除
int masterDeleteNum ;
do {
//一次删除50条
masterDeleteNum = gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) ,
formDTO . getMonthId ( ) ,
indexCode ,
IndexCalConstant . DELETE_SIZE ) ;
} while ( masterDeleteNum ! = NumConstant . ZERO ) ;
//删除明细时,需要根据分组删,比方说当前计算的是网格相关-党建能力,主表需要删除indexCode=dangjiannengli的,明细需要删除网格相关:党建能力 下面所有的指标明细
int detailDelteNum ;
do {
detailDelteNum = gridSubScoreDao . deleteByDeptIdAndMonthId ( formDTO . getCustomerId ( ) ,
formDTO . getMonthId ( ) ,
allParentIndexCode ,
IndexCalConstant . DELETE_SIZE ) ;
} while ( detailDelteNum ! = NumConstant . ZERO ) ;
log . info ( "delete fact_index_grid_score and fact_index_grid_sub_score complete" ) ;
}
/ * *
* @param formDTO 客户id 月份id : yyyyMM
* @param resultMapList
@ -329,15 +367,18 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @Date 2020 / 8 / 30 22 : 50
* * /
private void saveGridCorreLationResult ( CalculateCommonFormDTO formDTO ,
List < HashMap < String , BigDecimal > > resultMapList ,
List < HashMap < String , CalculateResult > > resultMapList ,
String indexCode ,
String allParentIndexCode ,
String isTotal ) {
List < GridScoreEntity > gridScoreEntityList = new ArrayList < > ( ) ;
String quarterId = DateUtils . getQuarterId ( formDTO . getMonthId ( ) ) ;
String yearId = DateUtils . getYearId ( formDTO . getMonthId ( ) ) ;
for ( HashMap < String , BigDecimal > resultMap : resultMapList ) {
resultMap . forEach ( ( gridId , partyAblityScore ) - > {
log . info ( "网格id:" + gridId + ";index_Code:" + indexCode + ";分值:" + partyAblityScore ) ;
//三大能力结果表
List < GridScoreEntity > gridScoreEntityList = new ArrayList < > ( ) ;
//五级指标分值明细
List < GridSubScoreEntity > gridSubScoreList = new ArrayList < > ( ) ;
for ( HashMap < String , CalculateResult > resultMap : resultMapList ) {
resultMap . forEach ( ( gridId , calculateResult ) - > {
GridScoreEntity gridScoreEntity = new GridScoreEntity ( ) ;
gridScoreEntity . setCustomerId ( formDTO . getCustomerId ( ) ) ;
gridScoreEntity . setGridId ( gridId ) ;
@ -355,18 +396,36 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
gridScoreEntity . setQuarterId ( quarterId ) ;
gridScoreEntity . setYearId ( yearId ) ;
gridScoreEntity . setMonthId ( formDTO . getMonthId ( ) ) ;
gridScoreEntity . setScore ( partyAblityScore ) ;
gridScoreEntity . setScore ( calculateResult . getTotalScore ( ) ) ;
//新增ALL_PARENT_INDEX_CODE 所有指标code拼接的字符串 冒号隔开
gridScoreEntity . setAllParentIndexCode ( IndexCodeEnum . WANG_GE_XIANG_GUAN . getCode ( ) ) ;
gridScoreEntityList . add ( gridScoreEntity ) ;
for ( IndexScoreVo detail : calculateResult . getDetails ( ) ) {
GridSubScoreEntity gridSubScoreEntity = ConvertUtils . sourceToTarget ( gridScoreEntity , GridSubScoreEntity . class ) ;
//重新赋值
gridSubScoreEntity . setIndexCode ( detail . getIndexCode ( ) ) ;
gridSubScoreEntity . setAllParentIndexCode ( detail . getAllParentIndexCode ( ) ) ;
gridSubScoreEntity . setScore ( detail . getScore ( ) ) ;
gridSubScoreList . add ( gridSubScoreEntity ) ;
}
} ) ;
}
//后新增
if ( ! CollectionUtils . isEmpty ( gridScoreEntityList ) ) {
gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , indexCode , isTotal ) ;
//批量插入
List < List < GridScoreEntity > > partition = ListUtils . partition ( gridScoreEntityList , 100 ) ;
List < List < GridScoreEntity > > partition = ListUtils . partition ( gridScoreEntityList , IndexCalConstant . INSERT_SIZE ) ;
partition . forEach ( list - > {
gridScoreDao . insertBatches ( list ) ;
} ) ;
}
if ( ! CollectionUtils . isEmpty ( gridSubScoreList ) ) {
//批量插入
List < List < GridSubScoreEntity > > subPartition = ListUtils . partition ( gridSubScoreList , IndexCalConstant . INSERT_SIZE ) ;
subPartition . forEach ( subList - > {
gridSubScoreDao . insertBatches ( subList ) ;
} ) ;
}
log . info ( "insert fact_index_grid_score and fact_index_grid_sub_score complete" ) ;
}
/ * *
@ -377,7 +436,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @Date 2020 / 8 / 30 21 : 40
* * /
@Override
public HashMap < String , BigDecimal > calculate ( Map < String , IndexInputVO < BigDecimal > > indexMap ) {
public HashMap < String , CalculateResult > calculate ( Map < String , IndexInputVO < BigDecimal > > indexMap ) {
//构造入参
List < IndexInputVO > indexInputVOS = this . getIndexInputVOList ( indexMap ) ;
log . info ( "计算的参数" + JSON . toJSONString ( indexInputVOS ) ) ;
@ -387,7 +446,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
List < IndexOutputVO > listTemp = batchScoreCalculator . getScoreDetailOfIndexId ( indexInputVOS ) ;
log . info ( "计算的结果(List)" + JSON . toJSONString ( listTemp ) ) ;
HashMap < String , BigDecimal > resultMap = batchScoreCalculator . getScoreCount OfSampleId ( indexInputVOS ) ;
HashMap < String , CalculateResult > resultMap = batchScoreCalculator . getScoreTotal OfSampleId ( indexInputVOS ) ;
log . info ( "计算的结果{}" , resultMap ) ;
return resultMap ;
}
@ -503,7 +562,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = buildGridCorrelationIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
List < HashMap < String , CalculateResult > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
@ -532,11 +591,16 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
} ) ;
} ) ;
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
HashMap < String , CalculateResult > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationResult ( formDTO , resultMapList , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
deleteBeforeDataList ( formDTO , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , IndexCalConstant . GRID_ZL_ALL_PARENT_INDEX_CODE ) ;
saveGridCorreLationResult ( formDTO ,
resultMapList ,
IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) ,
IndexCalConstant . GRID_ZL_ALL_PARENT_INDEX_CODE ,
NumConstant . ZERO_STR ) ;
}
@ -572,7 +636,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = buildGridCorrelationIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
List < HashMap < String , CalculateResult > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
@ -597,11 +661,16 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
}
} ) ;
} ) ;
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
HashMap < String , CalculateResult > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationResult ( formDTO , resultMapList , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
deleteBeforeDataList ( formDTO , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , IndexCalConstant . GRID_FW_ALL_PARENT_INDEX_CODE ) ;
saveGridCorreLationResult ( formDTO ,
resultMapList ,
IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) ,
IndexCalConstant . GRID_FW_ALL_PARENT_INDEX_CODE ,
NumConstant . ZERO_STR ) ;
}
/ * *
@ -637,9 +706,9 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
gridScoreEntityList . add ( gridScoreEntity ) ;
}
if ( ! CollectionUtils . isEmpty ( gridScoreEntityList ) ) {
gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , indexCode , NumConstant . ONE_STR ) ;
gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , indexCode , IndexCalConstant . DELETE_SIZE ) ;
//批量插入
List < List < GridScoreEntity > > partition = ListUtils . partition ( gridScoreEntityList , 100 ) ;
List < List < GridScoreEntity > > partition = ListUtils . partition ( gridScoreEntityList , IndexCalConstant . INSERT_SIZE ) ;
partition . forEach ( list - > {
gridScoreDao . insertBatches ( list ) ;
} ) ;