@ -3,14 +3,15 @@ package com.epmet.datareport.service.evaluationindex.screen.impl; 
			
		
	
		
			
				
					import  com.epmet.commons.dynamic.datasource.annotation.DataSource ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.constant.AppClientConstant ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.constant.NumConstant ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.dto.result.CustomerStaffInfoCacheResult ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.exception.RenException ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.redis.common.CustomerStaffRedis ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.security.dto.TokenDto ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.utils.ConvertUtils ;  
			
		
	
		
			
				
					import  com.epmet.commons.tools.utils.Result ;  
			
		
	
		
			
				
					import  com.epmet.constant.DataSourceConstant ;  
			
		
	
		
			
				
					import  com.epmet.datareport.dao.evaluationindex.screen.ScreenEventDataDao ;  
			
		
	
		
			
				
					import  com.epmet.datareport.dao.evaluationindex.screen.ScreenEventImgDataDao ;  
			
		
	
		
			
				
					import  com.epmet.datareport.dao.evaluationindex.screen.ScreenProjectCategoryOrgDailyDao ;  
			
		
	
		
			
				
					import  com.epmet.datareport.dao.evaluationindex.screen.ScreenProjectDataDao ;  
			
		
	
		
			
				
					import  com.epmet.datareport.constant.FactConstant ;  
			
		
	
		
			
				
					import  com.epmet.datareport.dao.evaluationindex.screen.* ;  
			
		
	
		
			
				
					import  com.epmet.datareport.service.evaluationindex.screen.ScreenProjectService ;  
			
		
	
		
			
				
					import  com.epmet.dto.UserDTO ;  
			
		
	
		
			
				
					import  com.epmet.dto.form.CustomerAgencyUserRoleFormDTO ;  
			
		
	
	
		
			
				
					
						
						
						
							
								 
						
					 
				
				@ -26,15 +27,21 @@ import com.epmet.evaluationindex.screen.dto.result.ScreenProjectDetailResultDTO; 
			
		
	
		
			
				
					import  com.epmet.evaluationindex.screen.dto.result.ScreenProjectDistributionResultDTO ;  
			
		
	
		
			
				
					import  com.epmet.feign.EpmetUserOpenFeignClient ;  
			
		
	
		
			
				
					import  com.epmet.project.CustomerProjectCategoryDTO ;  
			
		
	
		
			
				
					import  com.epmet.project.dto.form.CategoryProjectListFormDTO ;  
			
		
	
		
			
				
					import  com.epmet.project.dto.form.CategoryTopAppealFormDTO ;  
			
		
	
		
			
				
					import  com.epmet.project.dto.result.CategoryTopAppealResultDTO ;  
			
		
	
		
			
				
					import  com.epmet.project.dto.form.ProjectCategoryFormDTO ;  
			
		
	
		
			
				
					import  com.epmet.project.dto.result.* ;  
			
		
	
		
			
				
					import  com.github.pagehelper.PageHelper ;  
			
		
	
		
			
				
					import  com.github.pagehelper.PageInfo ;  
			
		
	
		
			
				
					import  lombok.extern.slf4j.Slf4j ;  
			
		
	
		
			
				
					import  org.apache.commons.lang3.StringUtils ;  
			
		
	
		
			
				
					import  org.springframework.beans.factory.annotation.Autowired ;  
			
		
	
		
			
				
					import  org.springframework.stereotype.Service ;  
			
		
	
		
			
				
					import  org.springframework.util.CollectionUtils ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					import  java.math.BigDecimal ;  
			
		
	
		
			
				
					import  java.util.ArrayList ;  
			
		
	
		
			
				
					import  java.util.Comparator ;  
			
		
	
		
			
				
					import  java.util.List ;  
			
		
	
		
			
				
					import  java.util.Map ;  
			
		
	
		
			
				
					import  java.util.stream.Collectors ;  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -63,6 +70,9 @@ public class ScreenProjectServiceImpl implements ScreenProjectService { 
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  EpmetUserOpenFeignClient  userOpenFeignClient ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    @Autowired  
			
		
	
		
			
				
					    private  ScreenProjectOrgDailyDao  screenProjectOrgDailyDao ;  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description   3 、 项目详情  
			
		
	
		
			
				
					     *  @param  projectDetailFormDTO  
			
		
	
	
		
			
				
					
						
							
								 
						
						
							
								 
						
						
					 
				
				@ -228,4 +238,147 @@ public class ScreenProjectServiceImpl implements ScreenProjectService { 
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        return  result ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description  【 项目分类 】 查询项目分类  
			
		
	
		
			
				
					     *  @param  formDTO  
			
		
	
		
			
				
					     *  @param  tokenDto  
			
		
	
		
			
				
					     *  @author  zxc  
			
		
	
		
			
				
					     *  @date  2021 / 11 / 4  3 : 38  下午  
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    @Override  
			
		
	
		
			
				
					    public  List < ProjectCategoryResultDTO >  selectProjectCategory ( ProjectCategoryFormDTO  formDTO ,  TokenDto  tokenDto )  {  
			
		
	
		
			
				
					        if  ( StringUtils . isBlank ( formDTO . getOrgId ( ) ) ) {  
			
		
	
		
			
				
					            CustomerStaffInfoCacheResult  staffInfo  =  CustomerStaffRedis . getStaffInfo ( tokenDto . getCustomerId ( ) ,  tokenDto . getUserId ( ) ) ;  
			
		
	
		
			
				
					            if  ( null  = =  staffInfo ) {  
			
		
	
		
			
				
					                throw  new  RenException ( "未查询到此工作人员的所属组织信息..." ) ;  
			
		
	
		
			
				
					            }  
			
		
	
		
			
				
					            formDTO . setOrgId ( staffInfo . getAgencyId ( ) ) ;  
			
		
	
		
			
				
					            formDTO . setOrgType ( FactConstant . AGENCY ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        String  customerId  =  tokenDto . getCustomerId ( ) ;  
			
		
	
		
			
				
					        String  endTime  =  formDTO . getEndTime ( ) ;  
			
		
	
		
			
				
					        String  startTime  =  formDTO . getStartTime ( ) ;  
			
		
	
		
			
				
					        String  orgId  =  formDTO . getOrgId ( ) ;  
			
		
	
		
			
				
					        // 查询客户下的所有分类
  
			
		
	
		
			
				
					        List < ProjectCategoryResultDTO >  result  =  screenProjectCategoryOrgDailyDao . selectCategoryByCustomerId ( tokenDto . getCustomerId ( ) ) ;  
			
		
	
		
			
				
					        List < ProjectCategoryResultDTO >  endCategoryList  =  new  ArrayList < > ( ) ;  
			
		
	
		
			
				
					        if  ( formDTO . getOrgType ( ) . equals ( FactConstant . AGENCY ) ) {  
			
		
	
		
			
				
					            Integer  endTotal  =  screenProjectOrgDailyDao . selectProjectTotalByAgency ( customerId ,  endTime ,  orgId ) ;  
			
		
	
		
			
				
					            endTotal  =  null  = =  endTotal  ?  NumConstant . ZERO  :  endTotal ;  
			
		
	
		
			
				
					            endCategoryList  =  screenProjectCategoryOrgDailyDao . selectProjectCategoryByAgency ( customerId , endTime , orgId ) ;  
			
		
	
		
			
				
					            Integer  total  =  endTotal ;  
			
		
	
		
			
				
					            if  ( StringUtils . isNotBlank ( startTime ) ) {  
			
		
	
		
			
				
					                Integer  startTotal  =  screenProjectOrgDailyDao . selectProjectTotalByAgency ( customerId ,  startTime ,  orgId ) ;  
			
		
	
		
			
				
					                startTotal  =  null  = =  startTotal  ?  NumConstant . ZERO  :  startTotal ;  
			
		
	
		
			
				
					                total  =  endTotal  -  startTotal ;  
			
		
	
		
			
				
					                List < ProjectCategoryResultDTO >  startCategoryList  =  screenProjectCategoryOrgDailyDao . selectProjectCategoryByAgency ( customerId , startTime , orgId ) ;  
			
		
	
		
			
				
					                endCategoryList . forEach ( e  - >  startCategoryList . stream ( ) . filter ( s  - >  e . getCategoryCode ( ) . equals ( s . getCategoryCode ( ) ) ) . forEach ( s  - >  e . setProjectTotal ( subtract ( e . getProjectTotal ( ) , s . getProjectTotal ( ) ) ) ) ) ;  
			
		
	
		
			
				
					                endCategoryList . forEach ( e  - >  startCategoryList . stream ( ) . filter ( s  - >  e . getCategoryCode ( ) . equals ( s . getCategoryCode ( ) ) ) . forEach ( s  - >  e . setClosedProjectTotal ( subtract ( e . getClosedProjectTotal ( ) , s . getClosedProjectTotal ( ) ) ) ) ) ;  
			
		
	
		
			
				
					            }  
			
		
	
		
			
				
					            Integer  finalTotal  =  total ;  
			
		
	
		
			
				
					            endCategoryList . forEach ( e  - >  {  
			
		
	
		
			
				
					                e . setTotalRatio ( ratio ( e . getProjectTotal ( ) ,  finalTotal ) ) ;  
			
		
	
		
			
				
					                e . setClosedRatio ( ratio ( e . getClosedProjectTotal ( ) , e . getProjectTotal ( ) ) ) ;  
			
		
	
		
			
				
					            } ) ;  
			
		
	
		
			
				
					        } else  {  
			
		
	
		
			
				
					            Integer  endTotal  =  screenProjectOrgDailyDao . selectProjectTotalByGrid ( customerId ,  endTime ,  orgId ) ;  
			
		
	
		
			
				
					            endTotal  =  null  = =  endTotal  ?  NumConstant . ZERO  :  endTotal ;  
			
		
	
		
			
				
					            endCategoryList  =  screenProjectCategoryOrgDailyDao . selectProjectCategoryByGrid ( customerId , endTime , orgId ) ;  
			
		
	
		
			
				
					            Integer  total  =  endTotal ;  
			
		
	
		
			
				
					            if  ( StringUtils . isNotBlank ( startTime ) ) {  
			
		
	
		
			
				
					                Integer  startTotal  =  screenProjectOrgDailyDao . selectProjectTotalByGrid ( customerId ,  startTime ,  orgId ) ;  
			
		
	
		
			
				
					                startTotal  =  null  = =  startTotal  ?  NumConstant . ZERO  :  startTotal ;  
			
		
	
		
			
				
					                total  =  endTotal  -  startTotal ;  
			
		
	
		
			
				
					                List < ProjectCategoryResultDTO >  startCategoryList  =  screenProjectCategoryOrgDailyDao . selectProjectCategoryByGrid ( customerId , startTime , orgId ) ;  
			
		
	
		
			
				
					                endCategoryList . forEach ( e  - >  startCategoryList . stream ( ) . filter ( s  - >  e . getCategoryCode ( ) . equals ( s . getCategoryCode ( ) ) ) . forEach ( s  - >  e . setProjectTotal ( subtract ( e . getProjectTotal ( ) , s . getProjectTotal ( ) ) ) ) ) ;  
			
		
	
		
			
				
					                endCategoryList . forEach ( e  - >  startCategoryList . stream ( ) . filter ( s  - >  e . getCategoryCode ( ) . equals ( s . getCategoryCode ( ) ) ) . forEach ( s  - >  e . setClosedProjectTotal ( subtract ( e . getClosedProjectTotal ( ) , s . getClosedProjectTotal ( ) ) ) ) ) ;  
			
		
	
		
			
				
					            }  
			
		
	
		
			
				
					            Integer  finalTotal  =  total ;  
			
		
	
		
			
				
					            endCategoryList . forEach ( e  - >  {  
			
		
	
		
			
				
					                e . setTotalRatio ( ratio ( e . getProjectTotal ( ) ,  finalTotal ) ) ;  
			
		
	
		
			
				
					                e . setClosedRatio ( ratio ( e . getClosedProjectTotal ( ) , e . getProjectTotal ( ) ) ) ;  
			
		
	
		
			
				
					            } ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        List < ProjectCategoryResultDTO >  finalEndCategoryList  =  endCategoryList ;  
			
		
	
		
			
				
					        result . forEach ( r  - >  {  
			
		
	
		
			
				
					            finalEndCategoryList . stream ( ) . filter ( e  - >  r . getCategoryCode ( ) . equals ( e . getCategoryCode ( ) ) ) . forEach ( e  - >  {  
			
		
	
		
			
				
					                r . setTotalRatio ( e . getTotalRatio ( ) ) ; r . setClosedRatio ( e . getClosedRatio ( ) ) ;  
			
		
	
		
			
				
					            } ) ;  
			
		
	
		
			
				
					            r . getChildren ( ) . forEach ( son  - >  finalEndCategoryList . stream ( ) . filter ( e  - >  son . getCategoryCode ( ) . equals ( e . getCategoryCode ( ) ) ) . forEach ( e  - >  {  
			
		
	
		
			
				
					                son . setTotalRatio ( e . getTotalRatio ( ) ) ; son . setClosedRatio ( e . getClosedRatio ( ) ) ;  
			
		
	
		
			
				
					            } ) ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        // 排序
  
			
		
	
		
			
				
					        List < ProjectCategoryResultDTO >  collect  =  result . stream ( ) . sorted ( Comparator . comparing ( ProjectCategoryResultDTO : : getProjectTotal ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ;  
			
		
	
		
			
				
					        collect . forEach ( c  - >  {  
			
		
	
		
			
				
					            c . setChildren ( c . getChildren ( ) . stream ( ) . sorted ( Comparator . comparing ( ProjectCategorySonResultDTO : : getProjectTotal ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ) ;  
			
		
	
		
			
				
					        } ) ;  
			
		
	
		
			
				
					        return  collect ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description   俩数相减 , 小于0就赋值为0  
			
		
	
		
			
				
					     *  @param  end  
			
		
	
		
			
				
					     *  @param  start  
			
		
	
		
			
				
					     *  @author  zxc  
			
		
	
		
			
				
					     *  @date  2021 / 11 / 5  9 : 18  上午  
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    public  Integer  subtract ( Integer  end , Integer  start ) {  
			
		
	
		
			
				
					        return  end  -  start  <  NumConstant . ZERO  ?  NumConstant . ZERO  :  end  -  start ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description   返回占比 , 保留小数点2位  
			
		
	
		
			
				
					     *  @param  molecule  分子  
			
		
	
		
			
				
					     *  @param  denominator  分母  
			
		
	
		
			
				
					     *  @author  zxc  
			
		
	
		
			
				
					     *  @date  2021 / 11 / 5  9 : 26  上午  
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    public  String  ratio ( Integer  molecule ,  Integer  denominator ) {  
			
		
	
		
			
				
					        if  ( denominator  = =  NumConstant . ZERO ) {  
			
		
	
		
			
				
					            return  "0.00%" ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        BigDecimal  bigDecimalMolecule  =  new  BigDecimal ( molecule ) ;  
			
		
	
		
			
				
					        BigDecimal  bigDecimalDenominator  =  new  BigDecimal ( denominator ) ;  
			
		
	
		
			
				
					        BigDecimal  divide  =  bigDecimalMolecule . divide ( bigDecimalDenominator ,  NumConstant . FOUR ,  BigDecimal . ROUND_HALF_UP ) ;  
			
		
	
		
			
				
					        return  divide . multiply ( NumConstant . ONE_HUNDRED_DECIMAL ) + "%" ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					    / * *  
			
		
	
		
			
				
					     *  @Description   【 项目分类 】 查询分类下的项目  
			
		
	
		
			
				
					     *  @param  formDTO  
			
		
	
		
			
				
					     *  @param  tokenDto  
			
		
	
		
			
				
					     *  @author  zxc  
			
		
	
		
			
				
					     *  @date  2021 / 11 / 4  3 : 39  下午  
			
		
	
		
			
				
					     * /  
			
		
	
		
			
				
					    @Override  
			
		
	
		
			
				
					    public  PageCategoryProjectListResultDTO  selectCategoryProjectList ( CategoryProjectListFormDTO  formDTO ,  TokenDto  tokenDto )  {  
			
		
	
		
			
				
					        if  ( StringUtils . isBlank ( formDTO . getOrgId ( ) ) ) {  
			
		
	
		
			
				
					            CustomerStaffInfoCacheResult  staffInfo  =  CustomerStaffRedis . getStaffInfo ( tokenDto . getCustomerId ( ) ,  tokenDto . getUserId ( ) ) ;  
			
		
	
		
			
				
					            if  ( null  = =  staffInfo ) {  
			
		
	
		
			
				
					                throw  new  RenException ( "未查询到此工作人员的所属组织信息..." ) ;  
			
		
	
		
			
				
					            }  
			
		
	
		
			
				
					            formDTO . setOrgId ( staffInfo . getAgencyId ( ) ) ;  
			
		
	
		
			
				
					            formDTO . setOrgType ( FactConstant . AGENCY ) ;  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        PageCategoryProjectListResultDTO  result  =  new  PageCategoryProjectListResultDTO ( ) ;  
			
		
	
		
			
				
					        if  ( formDTO . getIsPage ( ) ) {  
			
		
	
		
			
				
					            PageInfo < CategoryProjectListResultDTO >  objectPageInfo  =  PageHelper . startPage ( formDTO . getPageNo ( ) ,  formDTO . getPageSize ( ) ) . doSelectPageInfo ( ( )  - >  screenProjectDataDao . selectCategoryProjectList ( tokenDto . getCustomerId ( ) ,  formDTO . getOrgId ( ) ,  formDTO . getCategoryCode ( ) ,  formDTO . getStatus ( ) ) ) ;  
			
		
	
		
			
				
					            List < CategoryProjectListResultDTO >  list  =  objectPageInfo . getList ( ) ;  
			
		
	
		
			
				
					            result . setTotal ( Integer . valueOf ( String . valueOf ( objectPageInfo . getTotal ( ) ) ) ) ;  
			
		
	
		
			
				
					            if  ( ! CollectionUtils . isEmpty ( list ) ) {  
			
		
	
		
			
				
					                list . forEach ( l  - >  {  
			
		
	
		
			
				
					                    if  ( l . getOrgType ( ) . equals ( FactConstant . AGENCY ) ) {  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					                    } else  {  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					                    }  
			
		
	
		
			
				
					                } ) ;  
			
		
	
		
			
				
					            }  
			
		
	
		
			
				
					        }  
			
		
	
		
			
				
					        return  result ;  
			
		
	
		
			
				
					    }  
			
		
	
		
			
				
					
 
			
		
	
		
			
				
					}