|
|
|
@ -3,11 +3,11 @@ package com.epmet.service.impl; |
|
|
|
import com.epmet.commons.tools.utils.ConvertUtils; |
|
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
import com.epmet.dto.stats.ArticleGridPublishedSummaryDTO; |
|
|
|
import com.epmet.entity.stats.DimGridEntity; |
|
|
|
import com.epmet.entity.stats.FactArticlePublishedGridDailyEntity; |
|
|
|
import com.epmet.entity.stats.*; |
|
|
|
import com.epmet.service.StatsPublicityService; |
|
|
|
import com.epmet.service.stats.*; |
|
|
|
import com.epmet.service.voice.ArticlePublishRangeService; |
|
|
|
import com.epmet.service.voice.ArticleService; |
|
|
|
import com.epmet.util.DimIdGenerator; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
@ -46,11 +46,17 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { |
|
|
|
private DimCustomerService dimCustomerService; |
|
|
|
@Autowired |
|
|
|
private DimGridService dimGridService; |
|
|
|
@Autowired |
|
|
|
private DimDepartmentService dimDepartmentService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ArticleService articleService; |
|
|
|
@Autowired |
|
|
|
private ArticlePublishRangeService articlePublishRangeService; |
|
|
|
@Autowired |
|
|
|
private FactArticlePublishedGridDailyService factArticlePublishedGridDailyService; |
|
|
|
@Autowired |
|
|
|
private FactArticlePublishedDepartmentDailyService factArticlePublishedDepartmentDailyService; |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private ExecutorService executorService; |
|
|
|
@ -71,21 +77,78 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { |
|
|
|
/*executorService.submit(()->{ |
|
|
|
|
|
|
|
});*/ |
|
|
|
statsPublishedGridDaily(statsDate, dimIdBean, customerId); |
|
|
|
//key:所在机关Id
|
|
|
|
Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap = new HashMap<>(); |
|
|
|
statsPublishedGridDaily(statsDate, dimIdBean, customerId,agencySummaryMap); |
|
|
|
statsPublishedDepartmentDaily(statsDate, dimIdBean, customerId,agencySummaryMap); |
|
|
|
statsPublishedAgencyDaily(statsDate, dimIdBean, customerId,agencySummaryMap); |
|
|
|
} |
|
|
|
} |
|
|
|
} while (!CollectionUtils.isEmpty(customerIdList) && customerIdList.size() >= pageSize); |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
private void statsPublishedDepartmentDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId, Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap) { |
|
|
|
//获取所有客户
|
|
|
|
List<DimDepartmentEntity> departmentDTOList = dimDepartmentService.getDepartmentListByCustomerId(customerId); |
|
|
|
if (CollectionUtils.isEmpty(departmentDTOList)) { |
|
|
|
log.warn("publicitySummary getDepartmentListByCustomerId return empty,customerId:{}", customerId); |
|
|
|
return; |
|
|
|
} |
|
|
|
//转换为 需要插入的Entity
|
|
|
|
Map<String, FactArticlePublishedDepartmentDailyEntity> departmentDailyEntityMap = convertDepartmentDailyEntity(departmentDTOList, dimIdBean); |
|
|
|
//获取当天的业务数据
|
|
|
|
List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(publishedArticleCount)) { |
|
|
|
for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) { |
|
|
|
FactArticlePublishedDepartmentDailyEntity gridDailyEntities = departmentDailyEntityMap.get(summaryDTO.getPublisherId()); |
|
|
|
if (gridDailyEntities == null) { |
|
|
|
log.error("publicitySummary bizData departmentId:{} not exist in dimDepartment", summaryDTO.getGridId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
gridDailyEntities.setArticleTotalCount(summaryDTO.getArticleTotalCount()); |
|
|
|
gridDailyEntities.setArticlePublishedCount(summaryDTO.getArticlePublishedCount()); |
|
|
|
//同一个机关下数据累加
|
|
|
|
buildAgencySummaryData(agencySummaryMap, summaryDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean b = factArticlePublishedDepartmentDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), departmentDailyEntityMap.values()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:同一个机关下的数据进行类型处理 |
|
|
|
* @param result |
|
|
|
* @param summaryDTO |
|
|
|
*/ |
|
|
|
private void buildAgencySummaryData(Map<String, ArticleGridPublishedSummaryDTO> result, ArticleGridPublishedSummaryDTO summaryDTO) { |
|
|
|
//同一个机关下数据累加
|
|
|
|
ArticleGridPublishedSummaryDTO publishedSummaryDTO = result.get(summaryDTO.getAgencyId()); |
|
|
|
if (publishedSummaryDTO == null) { |
|
|
|
ArticleGridPublishedSummaryDTO summary = new ArticleGridPublishedSummaryDTO(); |
|
|
|
summary.setCustomerId(summaryDTO.getCustomerId()); |
|
|
|
summary.setAgencyId(summaryDTO.getAgencyId()); |
|
|
|
summary.setGridId(summaryDTO.getGridId()); |
|
|
|
summary.setPublisherId(summaryDTO.getPublisherId()); |
|
|
|
summary.setArticleTotalCount(summaryDTO.getArticleTotalCount()); |
|
|
|
summary.setArticlePublishedCount(summaryDTO.getArticlePublishedCount()); |
|
|
|
result.put(summaryDTO.getPublisherId(),summaryDTO); |
|
|
|
}else{ |
|
|
|
publishedSummaryDTO.setArticlePublishedCount(publishedSummaryDTO.getArticlePublishedCount()+summaryDTO.getArticlePublishedCount()); |
|
|
|
publishedSummaryDTO.setArticleTotalCount(publishedSummaryDTO.getArticleTotalCount()+summaryDTO.getArticlePublishedCount()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:按日统计 网格纬度的 文章总数数据 |
|
|
|
* |
|
|
|
* @param statsDate |
|
|
|
* @param statsDate |
|
|
|
* @param dimIdBean |
|
|
|
* @param customerId |
|
|
|
* @param agencySummaryMap |
|
|
|
*/ |
|
|
|
private void statsPublishedGridDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId) { |
|
|
|
private void statsPublishedGridDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId, Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap) { |
|
|
|
//key:所在机关Id
|
|
|
|
Map<String,ArticleGridPublishedSummaryDTO> result = new HashMap<>(); |
|
|
|
//获取所有网格
|
|
|
|
List<DimGridEntity> gridDTOList = dimGridService.getGridListByCustomerId(customerId); |
|
|
|
if (CollectionUtils.isEmpty(gridDTOList)) { |
|
|
|
@ -106,11 +169,41 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { |
|
|
|
} |
|
|
|
gridDailyEntities.setArticleTotalCount(summaryDTO.getArticleTotalCount()); |
|
|
|
gridDailyEntities.setArticlePublishedCount(summaryDTO.getArticlePublishedCount()); |
|
|
|
//同一个机关下数据累加
|
|
|
|
buildAgencySummaryData(agencySummaryMap, summaryDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean b = factArticlePublishedGridDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), gridDailyEntityMap.values()); |
|
|
|
} |
|
|
|
|
|
|
|
private void statsPublishedAgencyDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId, Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap) { |
|
|
|
//获取所有客户
|
|
|
|
List<DimAgencyEntity> departmentDTOList = dimAgencyService.getAgencyListByCustomerId(customerId); |
|
|
|
if (CollectionUtils.isEmpty(departmentDTOList)) { |
|
|
|
log.warn("publicitySummary getAgencyListByCustomerId return empty,customerId:{}", customerId); |
|
|
|
return; |
|
|
|
} |
|
|
|
//转换为 需要插入的Entity
|
|
|
|
Map<String, FactArticlePublishedDepartmentDailyEntity> departmentDailyEntityMap = convertDepartmentDailyEntity(departmentDTOList, dimIdBean); |
|
|
|
//获取当天的业务数据
|
|
|
|
List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); |
|
|
|
|
|
|
|
if (!CollectionUtils.isEmpty(publishedArticleCount)) { |
|
|
|
for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) { |
|
|
|
FactArticlePublishedDepartmentDailyEntity gridDailyEntities = departmentDailyEntityMap.get(summaryDTO.getPublisherId()); |
|
|
|
if (gridDailyEntities == null) { |
|
|
|
log.error("publicitySummary bizData departmentId:{} not exist in dimDepartment", summaryDTO.getGridId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
gridDailyEntities.setArticleTotalCount(summaryDTO.getArticleTotalCount()); |
|
|
|
gridDailyEntities.setArticlePublishedCount(summaryDTO.getArticlePublishedCount()); |
|
|
|
//同一个机关下数据累加
|
|
|
|
buildAgencySummaryData(agencySummaryMap, summaryDTO); |
|
|
|
} |
|
|
|
} |
|
|
|
boolean b = factArticlePublishedDepartmentDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), departmentDailyEntityMap.values()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:将网格对象构建为 gridDaily 对象 |
|
|
|
* |
|
|
|
@ -131,4 +224,25 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* desc:将网格对象构建为 gridDaily 对象 |
|
|
|
* |
|
|
|
* @param dimDepartmentEntities |
|
|
|
* @param dimIdBean |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
private Map<String, FactArticlePublishedDepartmentDailyEntity> convertDepartmentDailyEntity(List<DimDepartmentEntity> dimDepartmentEntities, DimIdGenerator.DimIdBean dimIdBean) { |
|
|
|
Map<String, FactArticlePublishedDepartmentDailyEntity> result = new HashMap<>(); |
|
|
|
dimDepartmentEntities.forEach(dimGridEntity -> { |
|
|
|
FactArticlePublishedDepartmentDailyEntity entity = ConvertUtils.sourceToTarget(dimIdBean, FactArticlePublishedDepartmentDailyEntity.class); |
|
|
|
entity.setCustomerId(dimGridEntity.getCustomerId()); |
|
|
|
entity.setAgencyId(dimGridEntity.getAgencyId()); |
|
|
|
entity.setDepartmentId(dimGridEntity.getId()); |
|
|
|
entity.setArticleTotalCount(0); |
|
|
|
entity.setArticlePublishedCount(0); |
|
|
|
result.put(dimGridEntity.getId(), entity); |
|
|
|
}); |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|