@ -1,6 +1,8 @@
package com.epmet.service.indexcal.impl ;
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.constant.StrConstant ;
import com.epmet.commons.tools.utils.ConvertUtils ;
import com.epmet.commons.tools.utils.DateUtils ;
import com.epmet.commons.tools.utils.DateUtils ;
import com.epmet.constant.IndexCalConstant ;
import com.epmet.constant.IndexCalConstant ;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao ;
import com.epmet.dao.indexcoll.FactIndexPartyAblityCpcMonthlyDao ;
@ -53,12 +55,12 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
calculatePartScore ( formDTO ) ;
calculatePartScore ( formDTO ) ;
calculateTotalScore ( formDTO ) ;
calculateTotalScore ( formDTO ) ;
return true ;
return null ;
}
}
/ * *
/ * *
* desc : 计算总分
* desc : 计算总分
*
* @param formDTO
* @param formDTO
* /
* /
private void calculateTotalScore ( CalculateCommonFormDTO formDTO ) {
private void calculateTotalScore ( CalculateCommonFormDTO formDTO ) {
@ -70,19 +72,35 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
}
}
//获取数据
//获取数据
List < CpcScoreEntity > list = null ;
List < CpcScoreEntity > list = null ;
int pageNo = 1 ;
Map < String , CpcScoreEntity > cpcScoreTotalMap = new HashMap < > ( ) ;
int pageSize = 10 ;
Map < String , IndexGroupDetailEntity > indexWeightMap = parentIndexDetails . stream ( ) . collect ( Collectors . toMap ( IndexGroupDetailEntity : : getIndexCode , o - > o ) ) ;
do {
list = cpcScoreDao . getPartScore ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) ) ;
if ( ! CollectionUtils . isEmpty ( list ) ) {
Map < String , List < CpcScoreEntity > > userGroupMap = list . stream ( ) . collect ( Collectors . groupingBy ( CpcScoreEntity : : getUserId ) ) ;
userGroupMap . forEach ( ( userId , partScoreList ) - > {
CpcScoreEntity totalEntity = null ;
for ( CpcScoreEntity part : partScoreList ) {
IndexGroupDetailEntity indexGroupDetailEntity = indexWeightMap . get ( part . getIndexCode ( ) ) ;
if ( totalEntity = = null ) {
totalEntity = ConvertUtils . sourceToTarget ( part , CpcScoreEntity . class ) ;
totalEntity . setIsTotal ( NumConstant . ONE_STR ) ;
totalEntity . setIndexCode ( indexGroupDetailEntity . getIndexCode ( ) ) ;
cpcScoreTotalMap . put ( userId , totalEntity ) ;
}
BigDecimal total = part . getScore ( ) . multiply ( indexGroupDetailEntity . getWeight ( ) ) ;
totalEntity . setScore ( totalEntity . getScore ( ) . add ( total ) ) ;
}
} ) ;
}
list = cpcScoreDao . getPartScoreByPage ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , ( pageNo - 1 ) * pageSize , pageSize ) ;
insertBatch ( cpcScoreTotalMap . values ( ) . stream ( ) . collect ( Collectors . toList ( ) ) ) ;
if ( ! CollectionUtils . isEmpty ( list ) ) {
list . forEach ( partScore - > {
} ) ;
}
}
} while ( ! CollectionUtils . isEmpty ( list ) & & pageNo + + > 0 ) ;
private void insertBatch ( Collection < CpcScoreEntity > values ) {
cpcScoreDao . insertBatch ( values ) ;
}
}
private void calculatePartScore ( CalculateCommonFormDTO formDTO ) {
private void calculatePartScore ( CalculateCommonFormDTO formDTO ) {
@ -165,6 +183,7 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
cpcScoreEntity . setAgencyId ( String . valueOf ( cpcCount . get ( IndexCalConstant . AGENCY_ID ) ) ) ;
cpcScoreEntity . setAgencyId ( String . valueOf ( cpcCount . get ( IndexCalConstant . AGENCY_ID ) ) ) ;
cpcScoreEntity . setGridId ( String . valueOf ( cpcCount . get ( IndexCalConstant . GRID_ID ) ) ) ;
cpcScoreEntity . setGridId ( String . valueOf ( cpcCount . get ( IndexCalConstant . GRID_ID ) ) ) ;
cpcScoreEntity . setUserId ( userId ) ;
cpcScoreEntity . setUserId ( userId ) ;
cpcScoreEntity . setIsTotal ( NumConstant . ZERO_STR ) ;
cpcScoreEntity . setMonthId ( formDTO . getMonthId ( ) ) ;
cpcScoreEntity . setMonthId ( formDTO . getMonthId ( ) ) ;
cpcScoreEntity . setScore ( new BigDecimal ( 0 ) ) ;
cpcScoreEntity . setScore ( new BigDecimal ( 0 ) ) ;
cpcScoreEntity . setIndexCode ( parentIndexCode ) ;
cpcScoreEntity . setIndexCode ( parentIndexCode ) ;
@ -186,11 +205,13 @@ public class CpcIndexCalculateServiceImpl implements CpcIndexCalculateService {
@Transactional ( rollbackFor = Exception . class )
@Transactional ( rollbackFor = Exception . class )
public void saveCpcScore ( CalculateCommonFormDTO formDTO , Map < String , CpcScoreEntity > indexDetails , String parentIndexCode , HashMap < String , BigDecimal > result ) {
public void saveCpcScore ( CalculateCommonFormDTO formDTO , Map < String , CpcScoreEntity > indexDetails , String parentIndexCode , HashMap < String , BigDecimal > result ) {
cpcScoreDao . deleteByMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , parentIndexCode ) ;
cpcScoreDao . deleteByMonthId ( formDTO . getCustomerId ( ) , formDTO . getMonthId ( ) , parentIndexCode ) ;
List < CpcScoreEntity > list = new ArrayList < > ( ) ;
result . forEach ( ( userId , score ) - > {
result . forEach ( ( userId , score ) - > {
CpcScoreEntity cpcScoreEntity = indexDetails . get ( userId ) ;
CpcScoreEntity cpcScoreEntity = indexDetails . get ( userId ) ;
cpcScoreEntity . setScore ( score ) ;
cpcScoreEntity . setScore ( score ) ;
cpcScoreDao . insert ( cpcScoreEntity ) ;
list . add ( cpcScoreEntity ) ;
} ) ;
} ) ;
this . insertBatch ( list ) ;
}
}
/ * *
/ * *