package com.ylcm.sys.task;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.ylcm.sys.service.SpecialAnalysisService;

import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

@Component
@Slf4j
public class SpecialTopTask {

	@Resource
	private SpecialAnalysisService specialAnalysisService;
	/**
	 * 一周的每天运行 产品专题广告投放排名
	 */
	@Scheduled(cron = "0 0 0/2 * * ?")
	public void topTaskWeek(){
		log.info("产品专题广告投放排名---start");
		LocalDate now = LocalDate.now();
		now = now.minusDays(1);
		LocalDate day7before = now.minusDays(7);
		specialAnalysisService.specialTop(0, now.format(DateTimeFormatter.ISO_DATE), day7before.format(DateTimeFormatter.ISO_DATE));
		specialAnalysisService.specialTop(1, now.format(DateTimeFormatter.ISO_DATE), day7before.format(DateTimeFormatter.ISO_DATE));
		log.info("产品专题广告投放排名---end");
	}
	
	/**
	 * 月的每天运行一次
	 */
	@Scheduled(cron = "0 0 1 * * ?")
	public void topTaskMonth(){
		log.info("产品专题广告投放排名---start");
		LocalDate now = LocalDate.now();
		now = now.minusDays(1);
		LocalDate day7before = now.minusDays(30);
		specialAnalysisService.specialTop(0, now.format(DateTimeFormatter.ISO_DATE), day7before.format(DateTimeFormatter.ISO_DATE));
		specialAnalysisService.specialTop(1, now.format(DateTimeFormatter.ISO_DATE), day7before.format(DateTimeFormatter.ISO_DATE));
		
		LocalDate day365before = now.minusDays(365);
		specialAnalysisService.specialTop(0, now.format(DateTimeFormatter.ISO_DATE), day365before.format(DateTimeFormatter.ISO_DATE));
		specialAnalysisService.specialTop(1, now.format(DateTimeFormatter.ISO_DATE), day365before.format(DateTimeFormatter.ISO_DATE));
		
		log.info("产品专题广告投放排名---end");
	}
	
	
	
	
}
