@ -2,15 +2,17 @@ package com.epmet.service.indexcal.impl;
import com.epmet.commons.tools.constant.NumConstant ;
import com.epmet.commons.tools.constant.StrConstant ;
import com.epmet.commons.tools.utils.DateUtils ;
import com.epmet.constant.IndexCalConstant ;
import com.epmet.dao.indexcoll.FactIndexGovrnAblityGridMonthlyDao ;
import com.epmet.dao.indexcoll.FactIndexPartyAblityGridMonthlyDao ;
import com.epmet.dao.indexcoll.FactIndexServiceAblityGridMonthlyDao ;
import com.epmet.dao.indexscore.CpcScoreDao ;
import com.epmet.dao.indexscore.GridScoreDao ;
import com.epmet.dao.screen.ScreenCustomerGridDao ;
import com.epmet.dto.ScreenCustomerGridDTO ;
import com.epmet.dto.indexcal.CalculateCommonFormDTO ;
import com.epmet.dto.indexcal.CustomerGridInfoDTO ;
import com.epmet.dto.indexcal.PageQueryGridFormDTO ;
import com.epmet.dto.indexcal.* ;
import com.epmet.entity.indexscore.GridScoreEntity ;
import com.epmet.entity.screen.IndexGroupDetailEntity ;
import com.epmet.eum.IndexCodeEnum ;
import com.epmet.service.indexcal.GridCorreLationService ;
@ -23,6 +25,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger ;
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 ;
@ -51,6 +54,11 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
private IndexGroupDetailService indexGroupDetailService ;
@Autowired
private IndexCodeFieldReService indexCodeFieldReService ;
@Autowired
private CpcScoreDao cpcScoreDao ;
@Autowired
private GridScoreDao gridScoreDao ;
/ * *
* @param formDTO
@ -67,28 +75,28 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) ) ;
if ( ! CollectionUtils . isEmpty ( dangJianNengLiList ) ) {
//1、计算网格相关-党建能力
calculateGridCorreLation DangJian ( formDTO , dangJianNengLiList ) ;
calculateGridDangJian ( formDTO , dangJianNengLiList ) ;
}
/ * List < IndexGroupDetailEntity > zhiLiNengLiList = indexGroupDetailService . getDetailListByParentCode ( formDTO . getCustomerId ( ) ,
List < IndexGroupDetailEntity > zhiLiNengLiList = indexGroupDetailService . getDetailListByParentCode ( formDTO . getCustomerId ( ) ,
IndexCodeEnum . WANG_GE_XIANG_GUAN . getCode ( ) ,
IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) ) ;
if ( ! CollectionUtils . isEmpty ( zhiLiNengLiList ) ) {
//2、计算网格相关-治理能力
calculateGridCorreLation ZhiLi ( formDTO , zhiLiNengLiList ) ;
calculateGridZhiLi ( formDTO , zhiLiNengLiList ) ;
}
List < IndexGroupDetailEntity > fuWuNengLiList = indexGroupDetailService . getDetailListByParentCode ( formDTO . getCustomerId ( ) ,
IndexCodeEnum . WANG_GE_XIANG_GUAN . getCode ( ) ,
IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) ) ;
if ( ! CollectionUtils . isEmpty ( fuWuNengLiList ) ) {
//3、计算网格相关-服务能力
calculateGridCorreLation FuWu ( formDTO , fuWuNengLiList ) ;
calculateGridFuWu ( formDTO , fuWuNengLiList ) ;
}
//计算网格相关总分
List < IndexGroupDetailEntity > wgxgList = indexGroupDetailService . getDetailListByParentCode ( formDTO . getCustomerId ( ) ,
IndexCodeEnum . WANG_GE_XIANG_GUAN . getCode ( ) ) ;
if ( ! CollectionUtils . isEmpty ( wgxgList ) ) {
calculateGridCorreLation Total ( formDTO , wgxgList ) ;
} * /
calculateGridTotal ( formDTO , wgxgList , IndexCodeEnum . WANG_GE_XIANG_GUAN . getCode ( ) ) ;
}
resultFlag = true ;
return resultFlag ;
}
@ -101,7 +109,8 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @description 计算网格相关 - 党建能力
* @Date 2020 / 8 / 26 16 : 47
* * /
private void calculateGridCorreLationDangJian ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
@Transactional ( rollbackFor = Exception . class )
public void calculateGridDangJian ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
//查询总记录数
int total = factIndexPartyAblityGridMonthlyDao . selectCount ( formDTO ) ;
if ( NumConstant . ZERO = = total ) {
@ -115,6 +124,7 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
Map < String , Object > minAndMaxMap = queryPartyAblityGridMinAndMax ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = getIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
@ -136,47 +146,140 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
SampleValue < BigDecimal > currentGridIndexValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , new BigDecimal ( sampleValueStr ) ) ;
value . getIndexValueVOs ( ) . add ( currentGridIndexValue ) ;
} else if ( IndexCodeEnum . ZUZHINEIDANGYDLXQZNLKPFPJZ . getCode ( ) . equals ( key ) ) {
//组织内党员的联系群众能力考评分(平均值) TODO
logger . info ( "组织内党员的联系群众能力考评分(平均值) TODO " ) ;
//组织内党员的联系群众能力考评分(平均值)
logger . info ( "组织内党员的联系群众能力考评分(平均值) 单独处理 " ) ;
//网格内党员的联系群众能力考评分(平均值)
/ * BigDecimal contactResiAblity = null ;
SampleValue < BigDecimal > contactResiAblityValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , contactResiAblity ) ;
value . getIndexValueVOs ( ) . add ( contactResiAblityValue ) ; * /
String gridId = ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) ;
BigDecimal contactMassesAvgValue = getGridContactMassesAvgValue ( formDTO , gridId ) ;
SampleValue < BigDecimal > contactMassesAblityValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , contactMassesAvgValue ) ;
value . getIndexValueVOs ( ) . add ( contactMassesAblityValue ) ;
}
} ) ;
} ) ;
List < IndexOutputVO > result = calculate ( indexMap ) ;
// TODO 处理结果
saveGridCorreLationDangJian ( formDTO , indexList , result ) ;
try {
for ( IndexOutputVO m : result ) {
logger . info ( "indexId=" + m . getIndexId ( ) ) ;
for ( SampleScore sampleScore : m . getIndexScoreVOs ( ) ) {
logger . info ( String . format ( "网格id:%s,得分:%s" , sampleScore . getSampleId ( ) , sampleScore . getSampleScore ( ) ) ) ;
}
}
} catch ( Exception e ) {
}
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationDangJian ( formDTO , resultMapList , IndexCodeEnum . DANG_JIAN_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
}
/ * *
* @return java . util . Map < java . lang . String , java . math . BigDecimal >
* @param calculateCommonFormDTO
* @author yinzuomei
* @description 获取网格内党员的联系群众能力考评分 ( 平均值 ) 的最大值 , 最小值
* @Date 2020 / 8 / 31 9 : 51
* * /
private Map < String , BigDecimal > getContactMassesAblityMap ( CalculateCommonFormDTO calculateCommonFormDTO ) {
Map < String , BigDecimal > map = new HashMap < > ( ) ;
List < BigDecimal > list = cpcScoreDao . selectListGridContactMassesAvgValue ( calculateCommonFormDTO ) ;
if ( ! CollectionUtils . isEmpty ( list ) ) {
BigDecimal minValue = Collections . min ( list ) ;
BigDecimal maxValue = Collections . max ( list ) ;
map . put ( StrConstant . MIN , minValue ) ;
map . put ( StrConstant . MAX , maxValue ) ;
return map ;
}
map . put ( StrConstant . MIN , new BigDecimal ( NumConstant . ZERO_STR ) ) ;
map . put ( StrConstant . MAX , new BigDecimal ( NumConstant . ZERO_STR ) ) ;
return map ;
}
/ * *
* @return java . math . BigDecimal
* @param calculateCommonFormDTO
* @param gridId 网格id
* @author yinzuomei
* @description 获取网格 ( 组织 ) 内党员的联系群众能力考评分 ( 平均值 )
* @Date 2020 / 8 / 31 9 : 50
* * /
private BigDecimal getGridContactMassesAvgValue ( CalculateCommonFormDTO calculateCommonFormDTO , String gridId ) {
BigDecimal result = cpcScoreDao . selectGridContactMassesAvgValue ( calculateCommonFormDTO . getCustomerId ( ) , calculateCommonFormDTO . getMonthId ( ) , gridId ) ;
if ( null = = result ) {
return new BigDecimal ( NumConstant . ZERO_STR ) ;
}
return result ;
}
/ * *
* @param formDTO 客户id 月份id : yyyyMM
* @param indexList 指标集合
* @param indexOutputVOList
* @return java . math . BigDecimal
* @param formDTO
* @param gridId
* @author yinzuomei
* @description 组织内党员的参与议事能力考评分 ( 平均值 )
* @Date 2020 / 8 / 31 15 : 51
* * /
private BigDecimal getGridJoinIssueAvgValue ( CalculateCommonFormDTO formDTO , String gridId ) {
BigDecimal result = cpcScoreDao . selectGridJoinIssueAvgValue ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , gridId ) ;
if ( null = = result ) {
return new BigDecimal ( NumConstant . ZERO_STR ) ;
}
return result ;
}
/ * *
* @return java . util . Map < java . lang . String , java . math . BigDecimal >
* @param calculateCommonFormDTO
* @author yinzuomei
* @description 网格内党员的参与议事能力考评分 ( 平均值 ) 最大值最小值
* @Date 2020 / 8 / 31 14 : 41
* * /
private Map < String , BigDecimal > getJoinIssueAblityMap ( CalculateCommonFormDTO calculateCommonFormDTO ) {
Map < String , BigDecimal > map = new HashMap < > ( ) ;
List < BigDecimal > list = cpcScoreDao . selectListJoinIssueAvgValue ( calculateCommonFormDTO ) ;
if ( ! CollectionUtils . isEmpty ( list ) ) {
BigDecimal minValue = Collections . min ( list ) ;
BigDecimal maxValue = Collections . max ( list ) ;
map . put ( StrConstant . MIN , minValue ) ;
map . put ( StrConstant . MAX , maxValue ) ;
return map ;
}
map . put ( StrConstant . MIN , new BigDecimal ( NumConstant . ZERO_STR ) ) ;
map . put ( StrConstant . MAX , new BigDecimal ( NumConstant . ZERO_STR ) ) ;
return map ;
}
/ * *
* @param formDTO 客户id 月份id : yyyyMM
* @param resultMapList
* @param indexCode 指标编码
* @param isTotal 1 : 总分 ; 0不是
* @return void
* @author yinzuomei
* @description 保存网格相关五级指标分值
* @description 保存网格相关三大能力 值
* @Date 2020 / 8 / 30 22 : 50
* * /
private void saveGridCorreLationDangJian ( CalculateCommonFormDTO formDTO ,
List < IndexGroupDetailEntity > indexList ,
List < IndexOutputVO > indexOutputVOList ) {
Map < String , IndexGroupDetailEntity > indexMap = indexList . stream ( ) . collect ( Collectors . toMap ( IndexGroupDetailEntity : : getIndexCode , Function . identity ( ) ) ) ;
List < HashMap < String , BigDecimal > > resultMapList ,
String indexCode ,
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 ) - > {
logger . info ( "网格id:" + gridId + ";分值:" + partyAblityScore ) ;
GridScoreEntity gridScoreEntity = new GridScoreEntity ( ) ;
gridScoreEntity . setCustomerId ( formDTO . getCustomerId ( ) ) ;
gridScoreEntity . setGridId ( gridId ) ;
gridScoreEntity . setIsTotal ( isTotal ) ;
gridScoreEntity . setIndexCode ( indexCode ) ;
ScreenCustomerGridDTO screenCustomerGridDTO = screenCustomerGridDao . selectParentAgencyId ( formDTO . getCustomerId ( ) , gridId ) ;
if ( null ! = screenCustomerGridDTO ) {
gridScoreEntity . setAgencyId ( screenCustomerGridDTO . getParentAgencyId ( ) ) ;
gridScoreEntity . setAllParentIds ( screenCustomerGridDTO . getAllParentIds ( ) ) ;
}
gridScoreEntity . setQuarterId ( quarterId ) ;
gridScoreEntity . setYearId ( yearId ) ;
gridScoreEntity . setMonthId ( formDTO . getMonthId ( ) ) ;
gridScoreEntity . setScore ( partyAblityScore ) ;
gridScoreEntityList . add ( gridScoreEntity ) ;
} ) ;
}
if ( ! CollectionUtils . isEmpty ( gridScoreEntityList ) ) {
gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , indexCode , isTotal ) ;
gridScoreDao . insertBatches ( gridScoreEntityList ) ;
}
}
/ * *
@ -186,11 +289,11 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @description
* @Date 2020 / 8 / 30 21 : 40
* * /
private List < IndexOutputVO > calculate ( Map < String , IndexInputVO < BigDecimal > > indexMap ) {
private HashMap < String , BigDecimal > calculate ( Map < String , IndexInputVO < BigDecimal > > indexMap ) {
//构造入参
List < IndexInputVO > indexInputVOS = this . getIndexInputVOList ( indexMap ) ;
BatchScoreCalculator batchScoreCalculator = new BatchScoreCalculator ( ) ;
return batchScoreCalculator . getScoreDetailOfIndex Id ( indexInputVOS ) ;
return batchScoreCalculator . getScoreCountOfSample Id ( indexInputVOS ) ;
}
/ * *
@ -230,26 +333,31 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
BigDecimal minValue = null ;
BigDecimal maxValue = null ;
if ( IndexCodeEnum . ZUZHINEIDANGYDLXQZNLKPFPJZ . getCode ( ) . equals ( index . getIndexCode ( ) ) ) {
//组织内党员的联系群众能力考评分(平均值) TODO 获取最大值,最小值
logger . info ( "组织内党员的联系群众能力考评分(平均值) TODO" ) ;
/ * Map < String , BigDecimal > contactResiAblityMap = ;
minValue = contactResiAblityMap . get ( StrConstant . MIN ) ;
maxValue = contactResiAblityMap . get ( StrConstant . MAX ) ; * /
continue ;
//组织内党员的联系群众能力考评分(平均值) 获取最大值,最小值
logger . info ( "组织内党员的联系群众能力考评分(平均值) 单独处理" ) ;
Map < String , BigDecimal > contactMassesAblityMap = this . getContactMassesAblityMap ( formDTO ) ;
minValue = contactMassesAblityMap . get ( StrConstant . MIN ) ;
maxValue = contactMassesAblityMap . get ( StrConstant . MAX ) ;
} else if ( IndexCodeEnum . ZUZHINEIDANGYDSYYSNLKPFPJZ . getCode ( ) . equals ( index . getIndexCode ( ) ) ) {
logger . info ( "组织内党员的参与议事能力考评分(平均值) 单独处理" ) ;
Map < String , BigDecimal > joinIssueAblityMap = this . getJoinIssueAblityMap ( formDTO ) ;
minValue = joinIssueAblityMap . get ( StrConstant . MIN ) ;
maxValue = joinIssueAblityMap . get ( StrConstant . MAX ) ;
} else {
//获取指标对应的列名
String fieldName = indexCodeFieldReService . getFieldNameByIndexCode ( index . getIndexCode ( ) ) ;
// logger.info("fieldName=" + fieldName + ";index.getIndexCode()=" + index.getIndexCode());
//最小值key
if ( StringUtils . isBlank ( fieldName ) ) {
logger . error ( "index_code:" + index . getIndexCode ( ) + "not find field_name" ) ;
continue ;
}
logger . info ( "INDEX_CODE=" + index . getIndexCode ( ) + ";FIELD_ID=" + fieldName ) ;
String minValueKey = fieldName . concat ( StrConstant . UNDER_LINE ) . concat ( StrConstant . MIN ) ;
//最大值key
String maxValueKey = fieldName . concat ( StrConstant . UNDER_LINE ) . concat ( StrConstant . MAX ) ;
minValue = new BigDecimal ( String . valueOf ( minAndMaxMap . get ( minValueKey ) ) ) ;
maxValue = new BigDecimal ( String . valueOf ( minAndMaxMap . get ( maxValueKey ) ) ) ;
}
// logger.info("minValue="+minValue+";maxValue="+maxValue);
//分值计算器
ScoreCalculator < Integer > scoreCalculator = new BigDecimalScoreCalculator ( minValue ,
ScoreCalculator scoreCalculator = new BigDecimalScoreCalculator ( minValue ,
maxValue ,
ScoreConstants . MIN_SCORE ,
ScoreConstants . MAX_SCORE ,
@ -272,10 +380,58 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @description 计算网格相关 - 治理能力
* @Date 2020 / 8 / 26 16 : 47
* * /
private void calculateGridCorreLationZhiLi ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
private void calculateGridZhiLi ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
//查询总记录数
int total = factIndexGovrnAblityGridMonthlyDao . selectCount ( formDTO ) ;
if ( NumConstant . ZERO = = total ) {
logger . info ( String . format ( "customerId:%s,monthId:%s,没有上传网格相关-治理能力-五级指标数据" ) , formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
return ;
}
//总页数,进行批量查询,批量计算
int totalPage = ( int ) Math . ceil ( ( double ) total / IndexCalConstant . PAGE_SIZE ) ;
logger . info ( String . format ( "共%s条数据,分%s次计算" , total , totalPage ) ) ;
//每一组指标的最大值,key:code_MIN/MAX
Map < String , Object > minAndMaxMap = queryGovrnAblityGridMinAndMax ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = getIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
//前10条
List < Map < String , Object > > recordList = queryListGovrnAblityGrid ( new PageQueryGridFormDTO ( formDTO . getCustomerId ( ) ,
formDTO . getMonthId ( ) ,
pageIndex ,
pageNo ,
IndexCalConstant . PAGE_SIZE ) ) ;
//遍历每一个网格的记录
recordList . forEach ( recordMap - > {
//遍历所有的指标
indexMap . forEach ( ( key , value ) - > {
//列名不为空
if ( StringUtils . isNotBlank ( indexCodeFieldReService . getFieldNameByIndexCode ( key ) ) ) {
//对应的数值
String sampleValueStr = String . valueOf ( recordMap . get ( indexCodeFieldReService . getFieldNameByIndexCode ( key ) ) ) ;
//构造样本值对象
SampleValue < BigDecimal > currentGridIndexValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , new BigDecimal ( sampleValueStr ) ) ;
value . getIndexValueVOs ( ) . add ( currentGridIndexValue ) ;
} else if ( IndexCodeEnum . ZUZHINEIDANGYDSYYSNLKPFPJZ . getCode ( ) . equals ( key ) ) {
logger . info ( "组织内党员的参与议事能力考评分(平均值) 单独处理" ) ;
String gridId = ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) ;
BigDecimal joinAvgValue = getGridJoinIssueAvgValue ( formDTO , gridId ) ;
SampleValue < BigDecimal > contactMassesAblityValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , joinAvgValue ) ;
value . getIndexValueVOs ( ) . add ( contactMassesAblityValue ) ;
}
} ) ;
} ) ;
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationDangJian ( formDTO , resultMapList , IndexCodeEnum . ZHI_LI_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
}
/ * *
* @param formDTO
* @param indexList
@ -284,8 +440,51 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @description 计算网格相关 - 服务能力
* @Date 2020 / 8 / 26 16 : 48
* * /
private void calculateGridCorreLationFuWu ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
private void calculateGridFuWu ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
//查询总记录数
int total = factIndexGovrnAblityGridMonthlyDao . selectCount ( formDTO ) ;
if ( NumConstant . ZERO = = total ) {
logger . info ( String . format ( "customerId:%s,monthId:%s,没有上传网格相关-服务能力-五级指标数据" ) , formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
return ;
}
//总页数,进行批量查询,批量计算
int totalPage = ( int ) Math . ceil ( ( double ) total / IndexCalConstant . PAGE_SIZE ) ;
logger . info ( String . format ( "共%s条数据,分%s次计算" , total , totalPage ) ) ;
//每一组指标的最大值,key:code_MIN/MAX
Map < String , Object > minAndMaxMap = queryServiceAblityGridMinAndMax ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
//指标集合
Map < String , IndexInputVO < BigDecimal > > indexMap = getIndexInputVO ( formDTO , indexList , minAndMaxMap ) ;
List < HashMap < String , BigDecimal > > resultMapList = new ArrayList < > ( ) ;
//分页查询采集记录
for ( int pageNo = 1 ; pageNo < = totalPage ; pageNo + + ) {
int pageIndex = ( pageNo - NumConstant . ONE ) * IndexCalConstant . PAGE_SIZE ;
//前10条
List < Map < String , Object > > recordList = queryListServiceAblityGrid ( new PageQueryGridFormDTO ( formDTO . getCustomerId ( ) ,
formDTO . getMonthId ( ) ,
pageIndex ,
pageNo ,
IndexCalConstant . PAGE_SIZE ) ) ;
//遍历每一个网格的记录
recordList . forEach ( recordMap - > {
//遍历所有的指标
indexMap . forEach ( ( key , value ) - > {
//列名不为空
if ( StringUtils . isNotBlank ( indexCodeFieldReService . getFieldNameByIndexCode ( key ) ) ) {
//对应的数值
String sampleValueStr = String . valueOf ( recordMap . get ( indexCodeFieldReService . getFieldNameByIndexCode ( key ) ) ) ;
//构造样本值对象
SampleValue < BigDecimal > currentGridIndexValue = new SampleValue ( ( String ) recordMap . get ( IndexCalConstant . GRID_ID ) , new BigDecimal ( sampleValueStr ) ) ;
value . getIndexValueVOs ( ) . add ( currentGridIndexValue ) ;
} else {
logger . error ( "index_code:" + key + " not find field_name" ) ;
}
} ) ;
} ) ;
HashMap < String , BigDecimal > resultMap = calculate ( indexMap ) ;
resultMapList . add ( resultMap ) ;
}
// 保存中间表
saveGridCorreLationDangJian ( formDTO , resultMapList , IndexCodeEnum . FU_WU_NENG_LI . getCode ( ) , NumConstant . ZERO_STR ) ;
}
/ * *
@ -296,11 +495,42 @@ public class GridCorreLationServiceImpl implements GridCorreLationService {
* @description 计算网格相关总分
* @Date 2020 / 8 / 26 16 : 50
* * /
private void calculateGridCorreLationTotal ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList ) {
private void calculateGridTotal ( CalculateCommonFormDTO formDTO , List < IndexGroupDetailEntity > indexList , String indexCode ) {
//查询总记录数
List < GridScoreDTO > gridScoreDTOList = gridScoreDao . selectList ( formDTO ) ;
Map < String , IndexGroupDetailEntity > indexMap = indexList . stream ( ) . collect ( Collectors . toMap ( IndexGroupDetailEntity : : getIndexCode , Function . identity ( ) ) ) ;
List < GridScoreEntity > gridScoreEntityList = new ArrayList < > ( ) ;
gridScoreDTOList . forEach ( gridScoreDTO - > {
GridScoreEntity gridScoreEntity = new GridScoreEntity ( ) ;
gridScoreEntity . setCustomerId ( gridScoreDTO . getCustomerId ( ) ) ;
gridScoreEntity . setGridId ( gridScoreDTO . getGridId ( ) ) ;
gridScoreEntity . setIsTotal ( NumConstant . ONE_STR ) ;
gridScoreEntity . setIndexCode ( indexCode ) ;
gridScoreEntity . setAgencyId ( gridScoreDTO . getAgencyId ( ) ) ;
gridScoreEntity . setAllParentIds ( gridScoreDTO . getAllParentIds ( ) ) ;
gridScoreEntity . setQuarterId ( gridScoreDTO . getQuarterId ( ) ) ;
gridScoreEntity . setYearId ( gridScoreDTO . getYearId ( ) ) ;
gridScoreEntity . setMonthId ( gridScoreDTO . getMonthId ( ) ) ;
gridScoreEntity . setScore ( BigDecimal . ZERO ) ;
for ( GridScoreDetailDTO gridScoreDetailDTO : gridScoreDTO . getDetailList ( ) ) {
BigDecimal indexScore = gridScoreDetailDTO . getScore ( ) . multiply ( indexMap . get ( gridScoreDetailDTO . getIndexCode ( ) ) . getWeight ( ) ) ;
gridScoreEntity . setScore ( gridScoreEntity . getScore ( ) . add ( indexScore ) ) ;
}
gridScoreEntityList . add ( gridScoreEntity ) ;
} ) ;
if ( ! CollectionUtils . isEmpty ( gridScoreEntityList ) ) {
gridScoreDao . deleteByCusAndMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , indexCode , NumConstant . ONE_STR ) ;
gridScoreDao . insertBatches ( gridScoreEntityList ) ;
}
}
public static void main ( String [ ] args ) {
BigDecimal totalScore = BigDecimal . ZERO ;
for ( int i = 1 ; i < 5 ; i + + ) {
totalScore = totalScore . add ( new BigDecimal ( "1.00" ) ) ;
}
System . out . println ( totalScore ) ;
}
/ * *
* @param customerId
* @return com . epmet . dto . indexcal . CustomerGridInfoDTO