| 
						
						
							
								
							
						
						
					 | 
					@ -24,12 +24,17 @@ import com.epmet.commons.tools.page.PageData; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.ConvertUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.constant.FieldConstant; | 
					 | 
					 | 
					import com.epmet.commons.tools.constant.FieldConstant; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.commons.tools.utils.DateUtils; | 
					 | 
					 | 
					import com.epmet.commons.tools.utils.DateUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.epmet.constant.StatsSubject; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dao.stats.DimDateDao; | 
					 | 
					 | 
					import com.epmet.dao.stats.DimDateDao; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.dto.stats.DimDateDTO; | 
					 | 
					 | 
					import com.epmet.dto.stats.DimDateDTO; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.entity.stats.DimDateEntity; | 
					 | 
					 | 
					import com.epmet.entity.stats.DimDateEntity; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.epmet.entity.stats.LastExecRecordEntity; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.service.stats.DimDateService; | 
					 | 
					 | 
					import com.epmet.service.stats.DimDateService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import com.epmet.service.stats.LastExecRecordService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import com.epmet.util.DimIdGenerator; | 
					 | 
					 | 
					import com.epmet.util.DimIdGenerator; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.apache.commons.lang3.StringUtils; | 
					 | 
					 | 
					import org.apache.commons.lang3.StringUtils; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import org.joda.time.LocalDate; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					import org.springframework.beans.factory.annotation.Autowired; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.stereotype.Service; | 
					 | 
					 | 
					import org.springframework.stereotype.Service; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					import org.springframework.transaction.annotation.Transactional; | 
					 | 
					 | 
					import org.springframework.transaction.annotation.Transactional; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -44,6 +49,9 @@ import java.util.*; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					@Service | 
					 | 
					 | 
					@Service | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntity> implements DimDateService { | 
					 | 
					 | 
					public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntity> implements DimDateService { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    @Autowired | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					    private LastExecRecordService lastExecRecordService; | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    @Override | 
					 | 
					 | 
					    @Override | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public PageData<DimDateDTO> page(Map<String, Object> params) { | 
					 | 
					 | 
					    public PageData<DimDateDTO> page(Map<String, Object> params) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        IPage<DimDateEntity> page = baseDao.selectPage( | 
					 | 
					 | 
					        IPage<DimDateEntity> page = baseDao.selectPage( | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -109,32 +117,44 @@ public class DimDateServiceImpl extends BaseServiceImpl<DimDateDao, DimDateEntit | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    @Override | 
					 | 
					 | 
					    @Override | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    public void initDimDate() { | 
					 | 
					 | 
					    public void initDimDate() { | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        DimDateDTO latestDimDateDto = baseDao.getLatestDimDate(); | 
					 | 
					 | 
					        LastExecRecordEntity lastExecRecord = lastExecRecordService.getLastExecRecord(StatsSubject.DIM_DATE); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        if (lastExecRecord == null) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            lastExecRecord = lastExecRecordService.createLastExecRecord(StatsSubject.DIM_DATE); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        Date now = new Date(); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        Date targetDate = DateUtils.addDateDays(DateUtils.parse( | 
					 | 
					 | 
					        Date targetDate = DateUtils.addDateDays(DateUtils.parse( | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                DateUtils.format(new Date(), DateUtils.DATE_PATTERN_YYYYMMDD), | 
					 | 
					 | 
					                DateUtils.format(now, DateUtils.DATE_PATTERN_YYYYMMDD), | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                DateUtils.DATE_PATTERN_YYYYMMDD), -1); | 
					 | 
					 | 
					                DateUtils.DATE_PATTERN_YYYYMMDD), -1); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        Date lastDimDate; | 
					 | 
					 | 
					        Date lastDimDate = null; | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        if (latestDimDateDto == null) { | 
					 | 
					 | 
					        if ((lastDimDate = lastExecRecord.getExecTime()) == null) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            // 没有维度数据
 | 
					 | 
					 | 
					            // 首次初始化按日维度
 | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            initDimDate(targetDate); | 
					 | 
					 | 
					            initDimDate(targetDate); | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        } else if(targetDate.after(lastDimDate = DateUtils.parse(latestDimDateDto.getId(), DateUtils.DATE_PATTERN_YYYYMMDD))) { | 
					 | 
					 | 
					            lastExecRecord.setExecTime(now); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            // 有维度数据,并且当前日期大于最大按日维度数据的id,需要连续生成至少一天的维度数据(补缺)
 | 
					 | 
					 | 
					            lastExecRecordService.updateById(lastExecRecord); | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        } else { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            if (targetDate.equals(lastDimDate) || targetDate.after(lastDimDate)) { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                initDimDate(lastDimDate, targetDate); | 
					 | 
					 | 
					                initDimDate(lastDimDate, targetDate); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                lastExecRecord.setExecTime(now); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                lastExecRecordService.updateById(lastExecRecord); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    /** | 
					 | 
					 | 
					    /** | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     * 连续初始化 | 
					 | 
					 | 
					     * 连续初始化 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					     * @param lastDimDate | 
					 | 
					 | 
					     * @param startDate | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					     * @param targetDate | 
					 | 
					 | 
					     * @param targetDate | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					     */ | 
					 | 
					 | 
					     */ | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    private void initDimDate(Date lastDimDate, Date targetDate) { | 
					 | 
					 | 
					    private void initDimDate(Date startDate, Date targetDate) { | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        while (lastDimDate.before(targetDate)) { | 
					 | 
					 | 
					        LocalDate localStartDate = new LocalDate(startDate); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            lastDimDate = DateUtils.addDateDays(lastDimDate, 1); | 
					 | 
					 | 
					        LocalDate localTargetDate = new LocalDate(targetDate); | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            initDimDate(lastDimDate); | 
					 | 
					 | 
					        while (localTargetDate.isEqual(localStartDate) || localTargetDate.isAfter(localStartDate)) { | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            initDimDate(localStartDate.toDate()); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            localStartDate = localStartDate.plusDays(1); | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        } | 
					 | 
					 | 
					        } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    } | 
					 | 
					 | 
					    } | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |