public  class  ThreeUtils  { public  static  < T  extends  Three ,  E  extends  Three > void  treeListAncestral ( List < T > ,  E  threeResult,  Long  parentId,  ThreeFunctional < T ,  E > )  { if  ( ObjectUtil . isEmpty ( menuList) )  { return ; } Map < Long ,  List < T > > =  menuList. stream ( ) . filter ( menu ->  menu !=  null  &&  menu. getParentId ( )  !=  null ) . collect ( Collectors . groupingBy ( Three :: getParentId ) ) ; List < T > =  collect. get ( parentId) ; if  ( ObjectUtil . isEmpty ( threes) )  { return ; } ArrayList < T > =  threes. stream ( ) . collect ( Collectors . collectingAndThen ( Collectors . toCollection ( ( )  ->  new  TreeSet < > ( Comparator . comparing ( T :: getId ) ) ) ,  ArrayList :: new ) ) ; for  ( T  three :  groupT)  { List < T > =  menuList. stream ( ) . filter ( m ->  StringUtil . leftPad ( String . valueOf ( m. getId ( ) ) ,  String . valueOf ( m. getId ( ) ) . length ( ) ) . equals ( String . valueOf ( three. getId ( ) ) ) ) . collect ( Collectors . toList ( ) ) ; if  ( ObjectUtil . isEmpty ( ancestralThreeList) )  { continue ; } E  e =  dataTreating. dataTreating ( ancestralThreeList,  threeResult) ; if  ( null  ==  e)  { return ; } List < E > =  threeResult. getItemList ( ) ; if  ( null  ==  itemList)  { itemList =  new  ArrayList < > ( ) ; } itemList. add ( e) ; threeResult. setItemList ( itemList) ; treeListAncestral ( menuList,  e,  three. getId ( ) ,  dataTreating) ; } } public  static  < T  extends  Three ,  E  extends  Three > void  treeList ( List < T > ,  E  threeResult,  Long  parentId,  ThreeFunctional < T ,  E > )  { if  ( ObjectUtil . isEmpty ( menuList) )  { return ; } Map < Long ,  List < T > > =  menuList. stream ( ) . filter ( menu ->  menu !=  null  &&  menu. getParentId ( )  !=  null ) . collect ( Collectors . groupingBy ( Three :: getParentId ) ) ; List < T > =  collect. get ( parentId) ; if  ( ObjectUtil . isEmpty ( threes) )  { return ; } ArrayList < T > =  threes. stream ( ) . collect ( Collectors . collectingAndThen ( Collectors . toCollection ( ( )  ->  new  TreeSet < > ( Comparator . comparing ( T :: getId ) ) ) ,  ArrayList :: new ) ) ; for  ( T  three :  groupT)  { List < T > =  menuList. stream ( ) . filter ( menu ->  menu !=  null  &&  menu. getParentId ( )  !=  null  &&  menu. getParentId ( ) . equals ( three. getId ( ) ) ) . collect ( Collectors . toList ( ) ) ; if  ( ObjectUtil . isEmpty ( ancestralThreeList) )  { continue ; } E  e =  dataTreating. dataTreating ( ancestralThreeList,  threeResult) ; if  ( null  ==  e)  { return ; } List < E > =  threeResult. getItemList ( ) ; if  ( null  ==  itemList)  { itemList =  new  ArrayList < > ( ) ; } itemList. add ( e) ; threeResult. setItemList ( itemList) ; treeList ( menuList,  e,  three. getId ( ) ,  dataTreating) ; } } 
} 
@FunctionalInterface 
public  interface  ThreeFunctional < T ,  E > { E  dataTreating ( List < T > ,  E  data) ; 
} 
@Data 
public  class  Three < E > implements  Serializable  { private  static  final  long  serialVersionUID =  2883288479291688378L ; private  Long  id; private  String  name; private  Long  parentId; private  List < E > ItemList ; } @Data 
@ApiModel ( "返回VO" ) 
public  class  CoveredCountyEnteringVO  extends  Three < CoveredCountyEnteringVO > implements  Serializable  { private  static  final  long  serialVersionUID =  - 1571960669989120842L ; private  Integer  monitorBabyNumber; private  Integer  standardBabyNumber; private  BigDecimal  percentOfPass; } @Data 
@ApiModel ( "响应DTO" ) 
public  class  CoveredCountyEnteringDTO  extends  Three < CoveredCountyEnteringDTO > implements  Serializable  { private  static  final  long  serialVersionUID =  - 1571960669989120842L ; private  String  medicalQuestion1; private  String  medicalQuestion3; private  String  medicalQuestion7; } List < CoveredCountyEnteringDTO > =  cniQuestionnaireMapper. selectByAreaCode ( reportFormsDTO) ; CoveredCountyEnteringVO  countyEnteringVO =  new  CoveredCountyEnteringVO ( ) ; ThreeUtils . treeListAncestral ( questionnaireList,  countyEnteringVO,  reportFormsDTO. getAreaCode ( ) ,  ( threeList,  data)  ->  { if  ( ObjectUtil . isEmpty ( threeList) )  { return  null ; } Long  monitorBabyNumber =  threeList. stream ( ) . count ( ) ; Stream < CoveredCountyEnteringDTO > =  threeList. stream ( ) . filter ( coveredCountyEnteringDTO ->  null  !=  coveredCountyEnteringDTO&&  StringUtils . isNotBlank ( coveredCountyEnteringDTO. getMedicalQuestion1 ( ) ) &&  StringUtils . isNotBlank ( coveredCountyEnteringDTO. getMedicalQuestion3 ( ) ) &&  StringUtils . isNotBlank ( coveredCountyEnteringDTO. getMedicalQuestion7 ( ) ) ) ; CoveredCountyEnteringDTO  coveredCountyEnteringDTO =  threeList. get ( 0 ) ; CoveredCountyEnteringVO  resultCoveredCountVO =  new  CoveredCountyEnteringVO ( ) ; resultCoveredCountVO. setId ( coveredCountyEnteringDTO. getId ( ) ) ; resultCoveredCountVO. setName ( coveredCountyEnteringDTO. getName ( ) ) ; resultCoveredCountVO. setParentId ( coveredCountyEnteringDTO. getParentId ( ) ) ; resultCoveredCountVO. setMonitorBabyNumber ( null  !=  monitorBabyNumber ?  Integer . valueOf ( monitorBabyNumber +  "" )  :  0 ) ; resultCoveredCountVO. setStandardBabyNumber ( ObjectUtil . isNotEmpty ( standardBabyNumber)  ?  Integer . valueOf ( standardBabyNumber. count ( )  +  "" )  :  0 ) ; resultCoveredCountVO. setPercentOfPass ( BigDecimalUtils . rate ( resultCoveredCountVO. getStandardBabyNumber ( )  +  "" ,  resultCoveredCountVO. getMonitorBabyNumber ( )  +  "" ) ) ; return  resultCoveredCountVO; } ) ;