@ -52,61 +52,73 @@ public class StatsGroupServiceImpl implements StatsGroupService {
private CustomerGridService customerGridService ;
/ * *
* @Description 统计 【 网格 - 日 】
* @param
* @Description 统计 【 网格 - 日 】
* @author zxc
* /
@Override
public void groupGridDaily ( GroupStatsFormDTO formDTO ) {
Integer pageNo = NumConstant . ONE ;
Integer pageSize = NumConstant . ONE_HUNDRED ;
List < String > customerIds ;
List < String > customerIds = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( formDTO . getCustomerId ( ) ) ) {
customerIds . add ( formDTO . getCustomerId ( ) ) ;
} else {
customerIds = dimCustomerService . selectCustomerIdPage ( pageNo + + , pageSize ) ;
}
do {
customerIds = dimCustomerService . selectCustomerIdPage ( pageNo + + , pageSize ) ;
DimIdGenerator . DimIdBean dimIdBean = this . getDimIdBean ( formDTO ) ;
if ( customerIds . size ( ) ! = NumConstant . ZERO ) {
if ( customerIds . size ( ) ! = NumConstant . ZERO ) {
customerIds . forEach ( customerId - > {
try {
List < GridIdListByCustomerResultDTO > gridsInfo = customerGridService . getCustomerGridIdList ( customerId , dimIdBean . getDateId ( ) ) ;
List < GroupGridDailyResultDTO > resultDTOS = groupDataService . groupGridDaily ( customerId , dimIdBean , gridsInfo ) ;
factGroupGridDailyService . statisticsGroupGridDaily ( resultDTOS , customerId ) ;
List < GroupGridDailyResultDTO > resultDTOS = groupDataService . groupGridDaily ( customerId , dimIdBean , gridsInfo ) ;
factGroupGridDailyService . statisticsGroupGridDaily ( resultDTOS , customerId ) ;
} catch ( Exception e ) {
log . error ( String . format ( GroupConstant . STATS_FAILED_GRID_DAILY , customerId , LocalDate . now ( ) , e ) ) ;
log . error ( String . format ( GroupConstant . STATS_FAILED_GRID_DAILY , customerId , LocalDate . now ( ) , e ) ) ;
}
} ) ;
}
} while ( customerIds . size ( ) ! = NumConstant . ZERO & & customerIds . size ( ) = = pageSize ) ;
} while ( customerIds . size ( ) ! = NumConstant . ZERO & & customerIds . size ( ) = = pageSize ) ;
}
/ * *
* @Description 统计 “ 小组 ” 有关数据 , dim : 【 机关 - 日 】
* @Description 统计 “ 小组 ” 有关数据 , dim : 【 机关 - 日 】
* @author zxc
* /
@Override
public void groupAgencyDaily ( GroupStatsFormDTO formDTO ) {
Integer pageNo = NumConstant . ONE ;
Integer pageSize = NumConstant . ONE_HUNDRED ;
List < String > customerIds ;
List < String > customerIds = new ArrayList < > ( ) ;
if ( StringUtils . isNotBlank ( formDTO . getCustomerId ( ) ) ) {
customerIds . add ( formDTO . getCustomerId ( ) ) ;
} else {
customerIds = dimCustomerService . selectCustomerIdPage ( pageNo + + , pageSize ) ;
}
do {
customerIds = dimCustomerService . selectCustomerIdPage ( pageNo + + , pageSize ) ;
if ( customerIds . size ( ) ! = NumConstant . ZERO ) {
if ( customerIds . size ( ) ! = NumConstant . ZERO ) {
DimIdGenerator . DimIdBean dimIdBean = this . getDimIdBean ( formDTO ) ;
customerIds . forEach ( customerId - > {
try {
List < DimAgencyDTO > customerAgencyInfos = dimAgencyService . getAgencyInfoByCustomerId ( customerId ) ;
List < AgencyGroupDailyResultDTO > agencyGroupDaily = this . getAgencyGroupDaily ( customerAgencyInfos , dimIdBean , customerId ) ;
factGroupAgencyDailyService . insertGroupAgencyDaily ( agencyGroupDaily , customerId ) ;
factGroupAgencyDailyService . insertGroupAgencyDaily ( agencyGroupDaily , customerId ) ;
} catch ( Exception e ) {
log . error ( String . format ( GroupConstant . STATS_FAILED_AGENCY_DAILY , customerId , LocalDate . now ( ) , e ) ) ;
log . error ( String . format ( GroupConstant . STATS_FAILED_AGENCY_DAILY , customerId , LocalDate . now ( ) , e ) ) ;
}
} ) ;
}
} while ( customerIds . size ( ) ! = NumConstant . ZERO & & customerIds . size ( ) = = pageSize ) ;
} while ( customerIds . size ( ) ! = NumConstant . ZERO & & customerIds . size ( ) = = pageSize ) ;
}
/ * *
* @Description 统计 “ 小组 ” 有关数据 , dim : 【 机关 - 月 】
* @Description 统计 “ 小组 ” 有关数据 , dim : 【 机关 - 月 】
* @author zxc String customerId
* /
@Override
@ -114,16 +126,16 @@ public class StatsGroupServiceImpl implements StatsGroupService {
DimIdGenerator . DimIdBean dimIdBean = this . getDimIdBean ( formDTO ) ;
String monthId = dimIdBean . getMonthId ( ) ;
String dateId = dimIdBean . getDateId ( ) ;
List < AgencyMonthlyFormDTO > lastDayAgency = factGroupAgencyDailyService . getLastDayAgency ( dateId ) ;
List < AgencyGroupMonthlyResultDTO > monthGroupIncr = factGroupAgencyDailyService . getMonthGroupIncr ( monthId ) ;
if ( monthGroupIncr . size ( ) = = NumConstant . ZERO ) {
List < AgencyMonthlyFormDTO > lastDayAgency = factGroupAgencyDailyService . getLastDayAgency ( formDTO . getCustomerId ( ) , dateId ) ;
List < AgencyGroupMonthlyResultDTO > monthGroupIncr = factGroupAgencyDailyService . getMonthGroupIncr ( formDTO . getCustomerId ( ) , monthId ) ;
if ( monthGroupIncr . size ( ) = = NumConstant . ZERO ) {
lastDayAgency . forEach ( agency - > {
agency . setGroupIncr ( NumConstant . ZERO ) ;
} ) ;
} else {
} else {
lastDayAgency . forEach ( agency - > {
monthGroupIncr . forEach ( monthIncr - > {
if ( agency . getAgencyId ( ) . equals ( monthIncr . getAgencyId ( ) ) ) {
if ( agency . getAgencyId ( ) . equals ( monthIncr . getAgencyId ( ) ) ) {
agency . setGroupIncr ( monthIncr . getMonthGroupIncr ( ) ) ;
}
} ) ;
@ -133,14 +145,14 @@ public class StatsGroupServiceImpl implements StatsGroupService {
}
/ * *
* @Description 网格小组 【 机关 - 日 】 数据统计处理
* @param customerAgencyInfos
* @param timeDim
* @param customerId
* @Description 网格小组 【 机关 - 日 】 数据统计处理
* @author zxc
* /
public List < AgencyGroupDailyResultDTO > getAgencyGroupDaily ( List < DimAgencyDTO > customerAgencyInfos , DimIdGenerator . DimIdBean timeDim , String customerId ) {
if ( customerAgencyInfos . size ( ) = = NumConstant . ZERO ) {
public List < AgencyGroupDailyResultDTO > getAgencyGroupDaily ( List < DimAgencyDTO > customerAgencyInfos , DimIdGenerator . DimIdBean timeDim , String customerId ) {
if ( customerAgencyInfos . size ( ) = = NumConstant . ZERO ) {
return new ArrayList < > ( ) ;
}
List < AgencyGroupDailyResultDTO > result = new ArrayList < > ( ) ;
@ -152,9 +164,9 @@ public class StatsGroupServiceImpl implements StatsGroupService {
agencyResult . setAgencyId ( agencyId ) ;
agencyResult . setCustomerId ( customerId ) ;
agencyResult . setPid ( agency . getPid ( ) ) ;
BeanUtils . copyProperties ( timeDim , agencyResult ) ;
BeanUtils . copyProperties ( timeDim , agencyResult ) ;
//机关下的所有网格(包括直属网格)
List < String > allGrid = this . getAllGrid ( agencyId , customerId ) ;
List < String > allGrid = this . getAllGrid ( agencyId , customerId ) ;
if ( allGrid . size ( ) ! = NumConstant . ZERO ) {
// 1. 机关下有多少网格 (this.getAllGrid拿的是当前机关下所有网格,以下方法是根据“dateId”来拿的,两者过滤)
List < GridIdListByCustomerResultDTO > customerGridIdList = customerGridService . getCustomerGridIdList ( customerId , dateId ) ;
@ -246,23 +258,23 @@ public class StatsGroupServiceImpl implements StatsGroupService {
}
/ * *
* @Description 根据当前机关ID , 查询出直属网格和所有下级机关的网格
* @param agencyId
* @Description 根据当前机关ID , 查询出直属网格和所有下级机关的网格
* @author zxc
* /
public List < String > getAllGrid ( String agencyId , String customerId ) {
public List < String > getAllGrid ( String agencyId , String customerId ) {
List < String > result = new ArrayList < > ( ) ;
List < AgencySubTreeDto > allAgency = dimAgencyService . getAllAgency ( customerId ) ;
Map < String , Set < String > > subGridOfAgency = new HashMap < > ( ) ;
Map < String , Set < String > > subGridOfAgency = new HashMap < > ( ) ;
allAgency . forEach ( agency - > {
this . initAgencyGridMap ( agency . getAgencyId ( ) , agency , subGridOfAgency ) ;
this . initAgencyGridMap ( agency . getAgencyId ( ) , agency , subGridOfAgency ) ;
} ) ;
Set < Map . Entry < String , Set < String > > > entries = subGridOfAgency . entrySet ( ) ;
entries . forEach ( entry - > {
String key = entry . getKey ( ) ;
Set < String > value = entry . getValue ( ) ;
if ( key . equals ( agencyId ) ) {
if ( key . equals ( agencyId ) ) {
result . addAll ( value ) ;
}
} ) ;
@ -270,49 +282,49 @@ public class StatsGroupServiceImpl implements StatsGroupService {
}
/ * *
* @Description 递归获取机关下的网格id 【 包括直属机关 】
* @param pid
* @param agency
* @param subGridOfAgency
* @Description 递归获取机关下的网格id 【 包括直属机关 】
* @author zxc
* /
void initAgencyGridMap ( String pid , AgencySubTreeDto agency , Map < String , Set < String > > subGridOfAgency ) {
void initAgencyGridMap ( String pid , AgencySubTreeDto agency , Map < String , Set < String > > subGridOfAgency ) {
//向map中放入数据
if ( subGridOfAgency . containsKey ( pid ) ) {
if ( subGridOfAgency . containsKey ( pid ) ) {
//包含key
Set < String > grids = subGridOfAgency . get ( pid ) ;
if ( null = = grids ) {
if ( null = = grids ) {
grids = new HashSet < > ( ) ;
subGridOfAgency . put ( pid , grids ) ;
subGridOfAgency . put ( pid , grids ) ;
}
if ( null ! = agency . getGridIds ( ) & & agency . getGridIds ( ) . size ( ) > NumConstant . ZERO ) {
if ( null ! = agency . getGridIds ( ) & & agency . getGridIds ( ) . size ( ) > NumConstant . ZERO ) {
grids . addAll ( agency . getGridIds ( ) ) ;
}
} else {
} else {
//不包含key
Set < String > grids = new HashSet < > ( agency . getGridIds ( ) ) ;
subGridOfAgency . put ( pid , grids ) ;
subGridOfAgency . put ( pid , grids ) ;
}
//定义递归出口
if ( StringUtils . equals ( ModuleConstant . AGENCY_LEVEL_COMMUNITY , agency . getLevel ( ) ) | | null = = agency . getSubAgencies ( ) | | agency . getSubAgencies ( ) . size ( ) = = NumConstant . ZERO ) {
return ;
if ( StringUtils . equals ( ModuleConstant . AGENCY_LEVEL_COMMUNITY , agency . getLevel ( ) ) | | null = = agency . getSubAgencies ( ) | | agency . getSubAgencies ( ) . size ( ) = = NumConstant . ZERO ) {
return ;
}
//定义递归入口
agency . getSubAgencies ( ) . forEach ( obj - > {
initAgencyGridMap ( pid , obj , subGridOfAgency ) ;
initAgencyGridMap ( pid , obj , subGridOfAgency ) ;
} ) ;
}
/ * *
* @Description 获取时间维度 dateId - - weekId - - monthId - - quarterId - - yearId
* @param
* @Description 获取时间维度 dateId - - weekId - - monthId - - quarterId - - yearId
* 如果有自定义时间 , 根据自定义时间获取时间维度
* 没有自定义时间 , 默认获取前一天的时间维度
* @param
* @author zxc
* /
public DimIdGenerator . DimIdBean getDimIdBean ( GroupStatsFormDTO formDTO ) {
if ( StringUtils . isNotBlank ( formDTO . getDate ( ) ) ) {
return DimIdGenerator . getDimIdBean ( DateUtils . parse ( formDTO . getDate ( ) , DateUtils . DATE_PATTERN ) ) ;
public DimIdGenerator . DimIdBean getDimIdBean ( GroupStatsFormDTO formDTO ) {
if ( StringUtils . isNotBlank ( formDTO . getDate ( ) ) ) {
return DimIdGenerator . getDimIdBean ( DateUtils . parse ( formDTO . getDate ( ) , DateUtils . DATE_PATTERN ) ) ;
}
ZoneId zoneId = ZoneId . systemDefault ( ) ;
LocalDate localDate = LocalDate . now ( ) . minusDays ( NumConstant . ONE ) ;