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