|  |  | @ -1,5 +1,6 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.DateUtils; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.RobotConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.org.result.CustomerAreaCodeResultDTO; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.entity.crm.CustomerEntity; | 
			
		
	
	
		
			
				
					|  |  | @ -78,10 +79,10 @@ public class StatsDimServiceImpl implements StatsDimService { | 
			
		
	
		
			
				
					|  |  |  |         Date now = new Date(); | 
			
		
	
		
			
				
					|  |  |  |         if (lastDimEntity == null) { | 
			
		
	
		
			
				
					|  |  |  |             // 首次初始化
 | 
			
		
	
		
			
				
					|  |  |  |             grids = customerGridService.listGridsByCreateTime(null, now); | 
			
		
	
		
			
				
					|  |  |  |             grids = customerGridService.listGridsByCreateTime(null, null, now); | 
			
		
	
		
			
				
					|  |  |  |         } else { | 
			
		
	
		
			
				
					|  |  |  |             Date lastInitTime = lastDimEntity.getCreatedTime(); | 
			
		
	
		
			
				
					|  |  |  |             grids = customerGridService.listGridsByCreateTime(lastInitTime, now); | 
			
		
	
		
			
				
					|  |  |  |             grids = customerGridService.listGridsByCreateTime(null, lastInitTime, now); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return convertCustomerGrid2GridDim(grids, now); | 
			
		
	
	
		
			
				
					|  |  | @ -127,7 +128,7 @@ public class StatsDimServiceImpl implements StatsDimService { | 
			
		
	
		
			
				
					|  |  |  |      * @param initTime 创建时间会用来作为下一次查询的输入条件,因此必须和本次初始化查询的endTime一致 | 
			
		
	
		
			
				
					|  |  |  |      * @return | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     private List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids, Date initTime) { | 
			
		
	
		
			
				
					|  |  |  |     public List<DimGridEntity> convertCustomerGrid2GridDim(List<CustomerGridEntity> grids, Date initTime) { | 
			
		
	
		
			
				
					|  |  |  |         return grids.stream().map(grid -> { | 
			
		
	
		
			
				
					|  |  |  |             DimGridEntity dimGrid = new DimGridEntity(); | 
			
		
	
		
			
				
					|  |  |  |             dimGrid.setAgencyId(grid.getPid()); | 
			
		
	
	
		
			
				
					|  |  | @ -168,7 +169,7 @@ public class StatsDimServiceImpl implements StatsDimService { | 
			
		
	
		
			
				
					|  |  |  |             lastInitTime = latestCreatedAgencyDim.getCreatedTime(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         return customerAgencyService.listAgenciesByCreateTime(lastInitTime, endDate); | 
			
		
	
		
			
				
					|  |  |  |         return customerAgencyService.listAgenciesByCreateTime(null, lastInitTime, endDate); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -268,7 +269,7 @@ public class StatsDimServiceImpl implements StatsDimService { | 
			
		
	
		
			
				
					|  |  |  |         if (lastCreatedDeptDim != null) { | 
			
		
	
		
			
				
					|  |  |  |             lastInitTime = lastCreatedDeptDim.getCreatedTime(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return departmentService.listDepartmentsByCreatedTime(lastInitTime, now); | 
			
		
	
		
			
				
					|  |  |  |         return departmentService.listDepartmentsByCreatedTime(null, lastInitTime, now); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     public List<CustomerDepartmentEntity> listUpdatedDepartments(Date initTime) { | 
			
		
	
	
		
			
				
					|  |  | @ -321,4 +322,55 @@ public class StatsDimServiceImpl implements StatsDimService { | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         return new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void syncCustomerAgencyDims(String customerId) { | 
			
		
	
		
			
				
					|  |  |  |         // 1.列出现有的agency 维度id列表
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> dimAgencyIds = dimAgencyService.listAgencyIds(customerId); | 
			
		
	
		
			
				
					|  |  |  |          | 
			
		
	
		
			
				
					|  |  |  |         // 2.查询业务表的agency列表
 | 
			
		
	
		
			
				
					|  |  |  |         Date endDate = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerAgencyEntity> bizAgencies = customerAgencyService.listAgenciesByCreateTime(customerId, null, endDate); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 3.将没有同步过来的插入到dim表。创建和更新时间存为今天凌晨
 | 
			
		
	
		
			
				
					|  |  |  |         for (CustomerAgencyEntity bizAgency : bizAgencies) { | 
			
		
	
		
			
				
					|  |  |  |             if (!dimAgencyIds.contains(bizAgency.getId())) { | 
			
		
	
		
			
				
					|  |  |  |                 dimAgencyService.initAgencyAllDim(bizAgency, endDate); | 
			
		
	
		
			
				
					|  |  |  |                 dimAgencyService.initAgencySelfDim(bizAgency, endDate); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void syncCustomerGridDims(String customerId) { | 
			
		
	
		
			
				
					|  |  |  |         // 1.列出现有的grid维度id列表
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> dimGridIds = dimGridService.listGridIds(customerId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 2.查询业务表的grid列表
 | 
			
		
	
		
			
				
					|  |  |  |         // 时间截止到今天凌晨,防止把今天的数据同步过来,影响定时任务查询,漏掉其他客户的数据
 | 
			
		
	
		
			
				
					|  |  |  |         Date endDate = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerGridEntity> bizGrids = customerGridService.listGridsByCreateTime(customerId, null, endDate); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 3.将没有同步过来的插入到dim表。创建和更新时间存为今天凌晨
 | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerGridEntity> grids2insert = bizGrids.stream().filter(bg -> !dimGridIds.contains(bg.getId())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  |         List<DimGridEntity> dimGridEntities = convertCustomerGrid2GridDim(grids2insert, endDate); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         dimGridEntities.forEach(g -> dimGridService.insert(g)); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void syncCustomerDepartmentDims(String customerId) { | 
			
		
	
		
			
				
					|  |  |  |         // 1.列出现有的grid维度id列表
 | 
			
		
	
		
			
				
					|  |  |  |         List<String> dimDeptIds = dimDepartmentService.listDepartmentIds(customerId); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 2.查询业务表的grid列表
 | 
			
		
	
		
			
				
					|  |  |  |         // 时间截止到今天凌晨,防止把今天的数据同步过来,影响定时任务查询,漏掉其他客户的数据
 | 
			
		
	
		
			
				
					|  |  |  |         Date endDate = DateUtils.integrate(new Date(), DateUtils.DATE_PATTERN); | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerDepartmentEntity> bizDepts = departmentService.listDepartmentsByCreatedTime(customerId, null, endDate); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         List<CustomerDepartmentEntity> depts2insert = bizDepts.stream().filter(bd -> !dimDeptIds.contains(bd.getId())).collect(Collectors.toList()); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |         // 3.将没有同步过来的插入到dim表。创建和更新时间存为今天凌晨
 | 
			
		
	
		
			
				
					|  |  |  |         dimDepartmentService.initDepartmentDims(depts2insert, new ArrayList<>(), endDate); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | } | 
			
		
	
	
		
			
				
					|  |  | 
 |