|  |  | @ -1,12 +1,10 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | 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.DimDepartmentEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.stats.DimGridEntity; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.stats.FactArticlePublishedDepartmentDailyEntity; | 
			
		
	
		
			
				
					|  |  |  | 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; | 
			
		
	
	
		
			
				
					|  |  | @ -60,6 +58,9 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 	private FactArticlePublishedGridDailyService factArticlePublishedGridDailyService; | 
			
		
	
		
			
				
					|  |  |  | 	@Autowired | 
			
		
	
		
			
				
					|  |  |  | 	private FactArticlePublishedDepartmentDailyService factArticlePublishedDepartmentDailyService; | 
			
		
	
		
			
				
					|  |  |  | 	@Autowired | 
			
		
	
		
			
				
					|  |  |  | 	private FactArticlePublishedAgencyDailyService factArticlePublishedAgencyDailyService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	@Autowired | 
			
		
	
		
			
				
					|  |  |  | 	private ExecutorService executorService; | 
			
		
	
	
		
			
				
					|  |  | @ -101,7 +102,7 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 		//转换为 需要插入的Entity
 | 
			
		
	
		
			
				
					|  |  |  | 		Map<String, FactArticlePublishedDepartmentDailyEntity> departmentDailyEntityMap = convertDepartmentDailyEntity(departmentDTOList, dimIdBean); | 
			
		
	
		
			
				
					|  |  |  | 		//获取当天的业务数据
 | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllDepartmentPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		if (!CollectionUtils.isEmpty(publishedArticleCount)) { | 
			
		
	
		
			
				
					|  |  |  | 			for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) { | 
			
		
	
	
		
			
				
					|  |  | @ -162,12 +163,12 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 		//转换为 需要插入的Entity
 | 
			
		
	
		
			
				
					|  |  |  | 		Map<String, FactArticlePublishedGridDailyEntity> gridDailyEntityMap = convertGridDailyEntity(gridDTOList, dimIdBean); | 
			
		
	
		
			
				
					|  |  |  | 		//获取当天的业务数据
 | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articlePublishRangeService.getAllPublishedCount(customerId, statsDate); | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllGridPublishedCount(customerId, statsDate); | 
			
		
	
		
			
				
					|  |  |  | 		if (!CollectionUtils.isEmpty(publishedArticleCount)) { | 
			
		
	
		
			
				
					|  |  |  | 			for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) { | 
			
		
	
		
			
				
					|  |  |  | 				FactArticlePublishedGridDailyEntity gridDailyEntities = gridDailyEntityMap.get(summaryDTO.getGridId()); | 
			
		
	
		
			
				
					|  |  |  | 				if (gridDailyEntities == null) { | 
			
		
	
		
			
				
					|  |  |  | 					log.error("publicitySummary bizData gridId:{} not exist in dimGrid", summaryDTO.getGridId()); | 
			
		
	
		
			
				
					|  |  |  | 					log.error("publicitySummary getAllGridPublishedCount gridId:{} not exist in dimGrid", summaryDTO.getGridId()); | 
			
		
	
		
			
				
					|  |  |  | 					continue; | 
			
		
	
		
			
				
					|  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  | 				gridDailyEntities.setArticleTotalCount(summaryDTO.getArticleTotalCount()); | 
			
		
	
	
		
			
				
					|  |  | @ -180,20 +181,20 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	private void statsPublishedAgencyDaily(Date statsDate, DimIdGenerator.DimIdBean dimIdBean, String customerId, Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap) { | 
			
		
	
		
			
				
					|  |  |  | 		//获取所有客户
 | 
			
		
	
		
			
				
					|  |  |  | 		List<DimDepartmentEntity> departmentDTOList = null;//dimAgencyService.getAgencyListByCustomerId(customerId);
 | 
			
		
	
		
			
				
					|  |  |  | 		if (CollectionUtils.isEmpty(departmentDTOList)) { | 
			
		
	
		
			
				
					|  |  |  | 		//获取所有机关
 | 
			
		
	
		
			
				
					|  |  |  | 		List<DimAgencyEntity> agencyDTOList = dimAgencyService.getAgencyListByCustomerId(customerId); | 
			
		
	
		
			
				
					|  |  |  | 		if (CollectionUtils.isEmpty(agencyDTOList)) { | 
			
		
	
		
			
				
					|  |  |  | 			log.warn("publicitySummary getAgencyListByCustomerId return empty,customerId:{}", customerId); | 
			
		
	
		
			
				
					|  |  |  | 			return; | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 		//转换为 需要插入的Entity
 | 
			
		
	
		
			
				
					|  |  |  | 		Map<String, FactArticlePublishedDepartmentDailyEntity> departmentDailyEntityMap = convertDepartmentDailyEntity(departmentDTOList, dimIdBean); | 
			
		
	
		
			
				
					|  |  |  | 		Map<String, FactArticlePublishedAgencyDailyEntity> agencyDailyEntityMap = convertAgencyDailyEntity(agencyDTOList, dimIdBean); | 
			
		
	
		
			
				
					|  |  |  | 		//获取当天的业务数据
 | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); | 
			
		
	
		
			
				
					|  |  |  | 		List<ArticleGridPublishedSummaryDTO> publishedArticleCount = articleService.getAllAgencyPublishedCount(customerId,DateUtils.integrate(statsDate,DateUtils.DATE_PATTERN)); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		if (!CollectionUtils.isEmpty(publishedArticleCount)) { | 
			
		
	
		
			
				
					|  |  |  | 			for (ArticleGridPublishedSummaryDTO summaryDTO : publishedArticleCount) { | 
			
		
	
		
			
				
					|  |  |  | 				FactArticlePublishedDepartmentDailyEntity gridDailyEntities = departmentDailyEntityMap.get(summaryDTO.getPublisherId()); | 
			
		
	
		
			
				
					|  |  |  | 				FactArticlePublishedAgencyDailyEntity gridDailyEntities = agencyDailyEntityMap.get(summaryDTO.getPublisherId()); | 
			
		
	
		
			
				
					|  |  |  | 				if (gridDailyEntities == null) { | 
			
		
	
		
			
				
					|  |  |  | 					log.error("publicitySummary bizData departmentId:{} not exist in dimDepartment", summaryDTO.getGridId()); | 
			
		
	
		
			
				
					|  |  |  | 					continue; | 
			
		
	
	
		
			
				
					|  |  | @ -204,7 +205,32 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 				buildAgencySummaryData(agencySummaryMap, summaryDTO); | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 		boolean b = factArticlePublishedDepartmentDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), departmentDailyEntityMap.values()); | 
			
		
	
		
			
				
					|  |  |  | 		//数据向上级机关添加
 | 
			
		
	
		
			
				
					|  |  |  | 		if (!CollectionUtils.isEmpty(agencySummaryMap)){ | 
			
		
	
		
			
				
					|  |  |  | 			for (Map.Entry<String, ArticleGridPublishedSummaryDTO> entry : agencySummaryMap.entrySet()) { | 
			
		
	
		
			
				
					|  |  |  | 				String agencyId = entry.getKey(); | 
			
		
	
		
			
				
					|  |  |  | 				ArticleGridPublishedSummaryDTO summary = entry.getValue(); | 
			
		
	
		
			
				
					|  |  |  | 				FactArticlePublishedAgencyDailyEntity dailyEntity = agencyDailyEntityMap.get(agencyId); | 
			
		
	
		
			
				
					|  |  |  | 				if (dailyEntity == null) { | 
			
		
	
		
			
				
					|  |  |  | 					log.error("publicitySummary bizData agencyId:{} not exist in dimAgency", agencyId); | 
			
		
	
		
			
				
					|  |  |  | 					continue; | 
			
		
	
		
			
				
					|  |  |  | 				} | 
			
		
	
		
			
				
					|  |  |  | 				setData2ParentAgency(agencySummaryMap, summary); | 
			
		
	
		
			
				
					|  |  |  | 			} | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		boolean b = factArticlePublishedAgencyDailyService.deleteAndInsertBatch(customerId, dimIdBean.getDateId(), agencyDailyEntityMap.values()); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	private void setData2ParentAgency(Map<String, ArticleGridPublishedSummaryDTO> agencySummaryMap, ArticleGridPublishedSummaryDTO summary) { | 
			
		
	
		
			
				
					|  |  |  | 		String pid = summary.getPid(); | 
			
		
	
		
			
				
					|  |  |  | 		ArticleGridPublishedSummaryDTO parentAgency = agencySummaryMap.get(pid); | 
			
		
	
		
			
				
					|  |  |  | 		parentAgency.setArticleTotalCount(parentAgency.getArticleTotalCount()+summary.getArticleTotalCount()); | 
			
		
	
		
			
				
					|  |  |  | 		parentAgency.setArticlePublishedCount(parentAgency.getArticlePublishedCount()+summary.getArticlePublishedCount()); | 
			
		
	
		
			
				
					|  |  |  | 		pid = parentAgency.getPid(); | 
			
		
	
		
			
				
					|  |  |  | 		if (!NumConstant.ZERO_STR.equals(pid)){ | 
			
		
	
		
			
				
					|  |  |  | 			setData2ParentAgency(agencySummaryMap,parentAgency); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
	
		
			
				
					|  |  | @ -248,4 +274,25 @@ public class StatsPublicityServiceImpl implements StatsPublicityService { | 
			
		
	
		
			
				
					|  |  |  | 		}); | 
			
		
	
		
			
				
					|  |  |  | 		return result; | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	/** | 
			
		
	
		
			
				
					|  |  |  | 	 * desc:将机关卫队对象构建为 agencyDaily 对象 | 
			
		
	
		
			
				
					|  |  |  | 	 * | 
			
		
	
		
			
				
					|  |  |  | 	 * @param dimDepartmentEntities | 
			
		
	
		
			
				
					|  |  |  | 	 * @param dimIdBean | 
			
		
	
		
			
				
					|  |  |  | 	 * @return | 
			
		
	
		
			
				
					|  |  |  | 	 */ | 
			
		
	
		
			
				
					|  |  |  | 	private Map<String, FactArticlePublishedAgencyDailyEntity> convertAgencyDailyEntity(List<DimAgencyEntity> dimDepartmentEntities, DimIdGenerator.DimIdBean dimIdBean) { | 
			
		
	
		
			
				
					|  |  |  | 		Map<String, FactArticlePublishedAgencyDailyEntity> result = new HashMap<>(); | 
			
		
	
		
			
				
					|  |  |  | 		dimDepartmentEntities.forEach(dimGridEntity -> { | 
			
		
	
		
			
				
					|  |  |  | 			FactArticlePublishedAgencyDailyEntity entity = ConvertUtils.sourceToTarget(dimIdBean, FactArticlePublishedAgencyDailyEntity.class); | 
			
		
	
		
			
				
					|  |  |  | 			entity.setCustomerId(dimGridEntity.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  | 			entity.setPid(dimGridEntity.getPid()); | 
			
		
	
		
			
				
					|  |  |  | 			entity.setAgencyId(dimGridEntity.getId()); | 
			
		
	
		
			
				
					|  |  |  | 			entity.setArticleTotalCount(0); | 
			
		
	
		
			
				
					|  |  |  | 			entity.setArticlePublishedCount(0); | 
			
		
	
		
			
				
					|  |  |  | 			result.put(dimGridEntity.getId(), entity); | 
			
		
	
		
			
				
					|  |  |  | 		}); | 
			
		
	
		
			
				
					|  |  |  | 		return result; | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |