package com.goafanti.common.task;

import com.goafanti.common.model.TOrderNew;
import com.goafanti.common.utils.LoggerUtils;
import com.goafanti.order.service.OrderNewService;
import com.goafanti.order.service.OrderReportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class YearReportTask {
	@Resource
	private  OrderReportService	orderReportServiceImpl;
	@Resource
	private OrderNewService orderNewService;

	Logger	logger	= LoggerFactory.getLogger(YearReportTask.class);
	/**
     * 每年1月1日0点执行任务
     */
	//@Scheduled(cron = "0 10 14 * * ?")
    @Scheduled(cron = "0 0 0 1 1 ?")
    public void testTask(){
    	//新增年数据
    	int c = orderReportServiceImpl.saveLastYearReportData();
    	LoggerUtils.debug(logger, "统计去年订单【%s】条。", c);
		//处理订单年份金额计算
		pushOrderMaxDuration();
    }

	private void pushOrderMaxDuration() {
		List<TOrderNew> tOrderNews = orderNewService.selectGetAll();
		for (TOrderNew e : tOrderNews) {
			orderNewService.pushOrderPublicReleaseCount(e);
		}
	}
}
