@ -12,12 +12,13 @@ import com.epmet.dto.voice.ArticleViewedSummaryDTO;
import com.epmet.entity.stats.* ;
import com.epmet.entity.voice.ArticleEntity ;
import com.epmet.entity.voice.ArticleTagsEntity ;
import com.epmet.entity.voice.TagCustomerEntity ;
import com.epmet.service.StatsPublicityService ;
import com.epmet.service.stats.* ;
import com.epmet.service.voice.ArticleOperateRecordService ;
import com.epmet.service.voice.ArticleService ;
import com.epmet.service.voice.ArticleTagsService ;
import com.epmet.service.voice.ArticleVisitRecordService ;
import com.epmet.service.voice.TagCustomerService ;
import com.epmet.util.DimIdGenerator ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -56,7 +57,7 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
@Autowired
private ArticleVisitRecordService articleVisitRecordService ;
@Autowired
private ArticleOperateRecordService articleOperateRecord Service;
private TagCustomerService tagCustomer Service;
@Autowired
private FactArticlePublishedGridDailyService factArticlePublishedGridDailyService ;
@Autowired
@ -528,38 +529,45 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
//获取所有网格
List < DimAgencyEntity > agencyDTOList = dimAgencyService . getAgencyListByCustomerId ( customerId ) ;
if ( CollectionUtils . isEmpty ( agencyDTOList ) ) {
log . warn ( "publicitySummar y getAgencyListByCustomerId return empty,customerId:{}" , customerId ) ;
log . warn ( "statsTagUsedDail y getAgencyListByCustomerId return empty,customerId:{}" , customerId ) ;
return ;
}
//转换为 需要插入的Entity
Map < String , DimAgencyEntity > dimAgencyEntityMap = agencyDTOList . stream ( ) . collect ( Collectors . toMap ( DimAgencyEntity : : getId , o - > o ) ) ;
List < DimGridEntity > gridDTOList = dimGridService . getGridListByCustomerId ( customerId ) ;
if ( CollectionUtils . isEmpty ( gridDTOList ) ) {
log . warn ( "statsTagUsedDaily getGridListByCustomerId return empty,customerId:{}" , customerId ) ;
}
List < DimDepartmentEntity > departmentDTOList = dimDepartmentService . getDepartmentListByCustomerId ( customerId ) ;
if ( CollectionUtils . isEmpty ( departmentDTOList ) ) {
log . warn ( "statsTagUsedDaily getDepartmentListByCustomerId return empty,customerId:{}" , customerId ) ;
}
//转换为 需要插入的Entity key gridId_tagId
Map < String , FactTagUsedGridDailyEntity > tagUsedGridDailyMap = new HashMap < > ( ) ;
Map < String , FactTagUsedDepartmentDailyEntity > tagUsedDeptDailyMap = new HashMap < > ( ) ;
Map < String , FactTagUsedAgencyDailyEntity > tagUsedAgencyDailyMap = new HashMap < > ( ) ;
Map < String , FactTagUsedAgencyDailyEntity > tagUsedAgencyDailySelfMap = new HashMap < > ( ) ;
//默认标签
buildDefaultUsedTag ( dimIdBean , customerId , agencyDTOList , gridDTOList , departmentDTOList , tagUsedGridDailyMap , tagUsedDeptDailyMap , tagUsedAgencyDailyMap , tagUsedAgencyDailySelfMap ) ;
//转换为 需要插入的Entity
Map < String , DimAgencyEntity > dimAgencyEntityMap = agencyDTOList . stream ( ) . collect ( Collectors . toMap ( DimAgencyEntity : : getId , o - > o ) ) ;
//获取当天的业务数据
//1获取文章及机关id,网格Id
List < ArticleEntity > publishedArticleList = articleService . getPublishedArticleByPublishTime ( customerId , DateUtils . format ( statsDate ) ) ;
if ( CollectionUtils . isEmpty ( publishedArticleList ) ) {
return ;
}
if ( ! CollectionUtils . isEmpty ( publishedArticleList ) ) {
//KEY 文章Id
Map < String , ArticleEntity > articleMap = publishedArticleList . stream ( ) . collect ( Collectors . toMap ( ArticleEntity : : getId , o - > o ) ) ;
Date startTime = DateUtils . integrate ( statsDate , DateUtils . DATE_PATTERN ) ;
Date endTime = DateUtils . integrate ( DateUtils . addDateDays ( statsDate , 1 ) , DateUtils . DATE_PATTERN ) ;
//2 获取文章标签
List < ArticleTagsEntity > articleTagsList = articleTagsService . getArticleTagsByCreateTime ( customerId , startTime , endTime ) ;
if ( CollectionUtils . isEmpty ( articleTagsList ) ) {
log . error ( "publicitySummary getArticleTagsByCreateTime customerId:{} have not articleTags,publishedArticleList:{}" , customerId , JSON . toJSONString ( publishedArticleList ) ) ;
return ;
}
if ( ! CollectionUtils . isEmpty ( articleTagsList ) ) {
//tagId
for ( ArticleTagsEntity tagEntity : articleTagsList ) {
ArticleEntity articleEntity = articleMap . get ( tagEntity . getArticleId ( ) ) ;
if ( articleEntity = = null ) {
log . error ( "publicitySummary articleMap articleId:{} " , tagEntity . getArticleId ( ) ) ;
return ;
continue ;
}
DimAgencyEntity dimAgencyEntity = dimAgencyEntityMap . get ( articleEntity . getOrgId ( ) ) ;
convertTagUsedAgencyDailyEntity ( dimAgencyEntity . getPid ( ) , tagUsedAgencyDailyMap , articleEntity , tagEntity , dimIdBean ) ;
@ -571,10 +579,13 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
convertTagUsedDepartmentDailyEntity ( tagUsedDeptDailyMap , articleEntity , tagEntity , dimIdBean ) ;
break ;
case ProjectConstant . PUBLISHER_TYPE_AGENCY :
convertTagUsedAgencyDailySelfEntity ( tagUsedAgencyDailySelfMap , articleEntity , tagEntity , dimIdBean ) ;
convertTagUsedAgencyDailySelfEntity ( tagUsedAgencyDailySelfMap , articleEntity , tagEntity , dimIdBean ) ;
break ;
}
}
}
}
factTagUsedGridDailyService . deleteAndInsertBatch ( customerId , dimIdBean . getDateId ( ) , tagUsedGridDailyMap . values ( ) ) ;
factTagUsedDepartmentDailyService . deleteAndInsertBatch ( customerId , dimIdBean . getDateId ( ) , tagUsedDeptDailyMap . values ( ) ) ;
@ -598,6 +609,64 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
}
private void buildDefaultUsedTag ( DimIdGenerator . DimIdBean dimIdBean , String customerId , List < DimAgencyEntity > agencyDTOList , List < DimGridEntity > gridDTOList , List < DimDepartmentEntity > departmentDTOList , Map < String , FactTagUsedGridDailyEntity > tagUsedGridDailyMap , Map < String , FactTagUsedDepartmentDailyEntity > tagUsedDeptDailyMap , Map < String , FactTagUsedAgencyDailyEntity > tagUsedAgencyDailyMap , Map < String , FactTagUsedAgencyDailyEntity > tagUsedAgencyDailySelfMap ) {
List < TagCustomerEntity > tagDefaultList = tagCustomerService . getTagDefaultList ( customerId ) ;
if ( ! CollectionUtils . isEmpty ( tagDefaultList ) ) {
agencyDTOList . forEach ( agency - > {
if ( ! CollectionUtils . isEmpty ( gridDTOList ) ) {
gridDTOList . forEach ( grid - > {
tagDefaultList . forEach ( tag - > {
FactTagUsedGridDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagUsedGridDailyEntity . class ) ;
entity . setCustomerId ( customerId ) ;
entity . setAgencyId ( agency . getId ( ) ) ;
entity . setGridId ( grid . getId ( ) ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setUsedCount ( 0 ) ;
tagUsedGridDailyMap . put ( grid . getId ( ) . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
} ) ;
}
if ( ! CollectionUtils . isEmpty ( departmentDTOList ) ) {
departmentDTOList . forEach ( dept - > {
tagDefaultList . forEach ( tag - > {
FactTagUsedDepartmentDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagUsedDepartmentDailyEntity . class ) ;
entity . setCustomerId ( customerId ) ;
entity . setAgencyId ( agency . getId ( ) ) ;
entity . setDepartmentId ( dept . getId ( ) ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setUsedCount ( 0 ) ;
tagUsedDeptDailyMap . put ( dept . getId ( ) . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
} ) ;
}
tagDefaultList . forEach ( tag - > {
FactTagUsedAgencyDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagUsedAgencyDailyEntity . class ) ;
entity . setPid ( agency . getPid ( ) ) ;
entity . setCustomerId ( customerId ) ;
entity . setAgencyId ( agency . getId ( ) ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setUsedCount ( 0 ) ;
tagUsedAgencyDailyMap . put ( agency . getId ( ) . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
tagDefaultList . forEach ( tag - > {
FactTagUsedAgencyDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagUsedAgencyDailyEntity . class ) ;
entity . setPid ( agency . getId ( ) ) ;
entity . setCustomerId ( customerId ) ;
String agencyId = agency . getId ( ) . concat ( DimAgencyConstant . TYPE_SELF_ID_SUFFIX ) ;
entity . setAgencyId ( agencyId ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setUsedCount ( 0 ) ;
tagUsedAgencyDailySelfMap . put ( agencyId . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
} ) ;
}
}
/ * *
* desc : 按日统计 标签被阅读的次数
*
@ -621,24 +690,25 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
List < DimGridEntity > dimGridList = dimGridService . getGridListByCustomerId ( customerId ) ;
if ( CollectionUtils . isEmpty ( dimGridList ) ) {
log . debug ( "statsTagViewedDaily customerId:{} have any grid" , customerId ) ;
return ;
}
Map < String , DimGridEntity > dimGridEntityMap = dimGridList . stream ( ) . collect ( Collectors . toMap ( DimGridEntity : : getId , o - > o ) ) ;
//转换为 需要插入的Entity
Map < String , DimAgencyEntity > dimAgencyEntityMap = agencyDTOList . stream ( ) . collect ( Collectors . toMap ( DimAgencyEntity : : getId , o - > o ) ) ;
//转换为 需要插入的Entity key gridId_tagId
Map < String , FactTagViewedGridDailyEntity > tagViewedGridDailyMap = new HashMap < > ( ) ;
Map < String , FactTagViewedAgencyDailyEntity > tagViewedAgencyDailyMap = new HashMap < > ( ) ;
Map < String , FactTagViewedAgencyDailyEntity > tagViewedAgencyDailySelfMap = new HashMap < > ( ) ;
//默认标签
buildDefaultViewedTag ( dimIdBean , customerId , agencyDTOList , dimGridList , tagViewedGridDailyMap , tagViewedAgencyDailyMap , tagViewedAgencyDailySelfMap ) ;
Map < String , DimGridEntity > dimGridEntityMap = dimGridList . stream ( ) . collect ( Collectors . toMap ( DimGridEntity : : getId , o - > o ) ) ;
//转换为 需要插入的Entity
Map < String , DimAgencyEntity > dimAgencyEntityMap = agencyDTOList . stream ( ) . collect ( Collectors . toMap ( DimAgencyEntity : : getId , o - > o ) ) ;
//获取当天的业务数据
//1获取今天文章的阅读记录数
Date startTime = DateUtils . integrate ( statsDate , DateUtils . DATE_PATTERN ) ;
Date endTime = DateUtils . integrate ( DateUtils . addDateDays ( statsDate , 1 ) , DateUtils . DATE_PATTERN ) ;
List < ArticleViewedSummaryDTO > visitRecordList = articleVisitRecordService . getArticleVisitByCreateTime ( customerId , startTime , endTime ) ;
if ( CollectionUtils . isEmpty ( visitRecordList ) ) {
return ;
}
if ( ! CollectionUtils . isEmpty ( visitRecordList ) ) {
for ( ArticleViewedSummaryDTO viewedSummaryDTO : visitRecordList ) {
List < ArticleTagsEntity > articleTagsList = articleTagsService . getArticleTagsByArticleId ( customerId , viewedSummaryDTO . getArticleId ( ) ) ;
if ( CollectionUtils . isEmpty ( articleTagsList ) ) {
@ -668,6 +738,7 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
}
}
}
}
factTagViewedGridDailyService . deleteAndInsertBatch ( customerId , dimIdBean . getDateId ( ) , tagViewedGridDailyMap . values ( ) ) ;
@ -679,7 +750,6 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
FactTagViewedAgencyDailyEntity currentEntity = entry . getValue ( ) ;
DimAgencyEntity dimAgencyEntity = dimAgencyEntityMap . get ( currentEntity . getAgencyId ( ) ) ;
if ( dimAgencyEntity = = null ) {
log . error ( "dimAgencyEntityMap bizData agencyId:{} not exist in dimAgency" , agencyId ) ;
continue ;
}
@ -691,6 +761,50 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
factTagViewedAgencyDailyService . deleteAndInsertBatch ( customerId , dimIdBean . getDateId ( ) , finalTagUsedAgencyDailyMap . values ( ) ) ;
}
private void buildDefaultViewedTag ( DimIdGenerator . DimIdBean dimIdBean , String customerId , List < DimAgencyEntity > agencyDTOList , List < DimGridEntity > dimGridList , Map < String , FactTagViewedGridDailyEntity > tagViewedGridDailyMap , Map < String , FactTagViewedAgencyDailyEntity > tagViewedAgencyDailyMap , Map < String , FactTagViewedAgencyDailyEntity > tagViewedAgencyDailySelfMap ) {
List < TagCustomerEntity > tagDefaultList = tagCustomerService . getTagDefaultList ( customerId ) ;
if ( ! CollectionUtils . isEmpty ( tagDefaultList ) ) {
agencyDTOList . forEach ( agency - > {
if ( ! CollectionUtils . isEmpty ( dimGridList ) ) {
dimGridList . forEach ( grid - > {
tagDefaultList . forEach ( tag - > {
FactTagViewedGridDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagViewedGridDailyEntity . class ) ;
entity . setCustomerId ( customerId ) ;
entity . setAgencyId ( agency . getId ( ) ) ;
entity . setGridId ( grid . getId ( ) ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setTagReadCount ( 0 ) ;
tagViewedGridDailyMap . put ( grid . getId ( ) . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
} ) ;
}
tagDefaultList . forEach ( tag - > {
FactTagViewedAgencyDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagViewedAgencyDailyEntity . class ) ;
entity . setPid ( agency . getPid ( ) ) ;
entity . setCustomerId ( customerId ) ;
entity . setAgencyId ( agency . getId ( ) ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setTagReadCount ( 0 ) ;
tagViewedAgencyDailyMap . put ( agency . getId ( ) . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
tagDefaultList . forEach ( tag - > {
FactTagViewedAgencyDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagViewedAgencyDailyEntity . class ) ;
entity . setPid ( agency . getId ( ) ) ;
entity . setCustomerId ( customerId ) ;
String agencyId = agency . getId ( ) . concat ( DimAgencyConstant . TYPE_SELF_ID_SUFFIX ) ;
entity . setAgencyId ( agencyId ) ;
entity . setTagId ( tag . getId ( ) ) ;
entity . setTagName ( tag . getTagName ( ) ) ;
entity . setTagReadCount ( 0 ) ;
tagViewedAgencyDailySelfMap . put ( agencyId . concat ( StrConstant . UNDER_LINE ) . concat ( tag . getId ( ) ) , entity ) ;
} ) ;
} ) ;
}
}
/ * *
* desc : 按月统计 标签使用数
*
@ -972,25 +1086,9 @@ public class StatsPublicityServiceImpl implements StatsPublicityService {
/ * *
* desc : 将网格对象构建为 tagUsedGridDaily 对象
*
* @param dimGridEntities
* @param dimIdBean
* @return
* /
private Map < String , FactTagUsedGridDailyEntity > convertTagUsedGridDailyEntity ( List < DimGridEntity > dimGridEntities , DimIdGenerator . DimIdBean dimIdBean ) {
Map < String , FactTagUsedGridDailyEntity > result = new HashMap < > ( ) ;
dimGridEntities . forEach ( dimGridEntity - > {
FactTagUsedGridDailyEntity entity = ConvertUtils . sourceToTarget ( dimIdBean , FactTagUsedGridDailyEntity . class ) ;
entity . setCustomerId ( dimGridEntity . getCustomerId ( ) ) ;
entity . setAgencyId ( dimGridEntity . getAgencyId ( ) ) ;
entity . setGridId ( dimGridEntity . getId ( ) ) ;
entity . setTagId ( "" ) ;
entity . setTagName ( "" ) ;
entity . setUsedCount ( 0 ) ;
result . put ( dimGridEntity . getId ( ) , entity ) ;
} ) ;
return result ;
}
private void convertTagUsedGridDailyEntity ( Map < String , FactTagUsedGridDailyEntity > result , ArticleEntity articleEntity , ArticleTagsEntity tagEntity , DimIdGenerator . DimIdBean dimIdBean ) {
String gridId = articleEntity . getPublisherId ( ) ;
String tagId = tagEntity . getTagId ( ) ;