package com.gyee.generation.service;

import com.gyee.generation.GenerationMain;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.concurrent.TimeUnit;

@Service
public class ReCalSevice {

    @Resource
    private EquipmentInfo1Service equipmentInfo1Service;

    @Resource
    private EquipmentInfo2Service equipmentInfo2Service;
    @Resource
    private EquipmentInfo3Service equipmentInfo3Service;

    @Resource
    private EquipmentInfoDayTopService equipmentInfoDayTopService;
    @Resource
    private EquipmentInfo5Service equipmentInfo5Service;
    @Resource
    private WtAlysisDayService wtAlysisDayService;
    @Resource
    private EquipmentInfo4Service equipmentInfo4Service;

    public void calWt(Date recordDate) throws Exception {

        Calendar c = Calendar.getInstance();
        Logger logger = LoggerFactory.getLogger(GenerationMain.class);


        c.setTime(recordDate);
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        Date begin = c.getTime();
        Date end = null;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        logger.info(df.format(c.getTime()).toString());


        equipmentInfo1Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo1Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);
        equipmentInfo2Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo2Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);
        equipmentInfo3Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo3Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);
        logger.info("equipmentInfo5Service开始!。。。。。。");

        TimeUnit.SECONDS.sleep(3);
        equipmentInfo5Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo5Service完成一次!。。。。。。");
        logger.info("equipmentInfo4Service开始!。。。。。。");
        equipmentInfo4Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo4Service完成一次!。。。。。。");


        equipmentInfoDayTopService.calEquipmentInfoDayTop(begin);
        equipmentInfoDayTopService.calEquipmentInfoMonthTop(begin);
        equipmentInfoDayTopService.calEquipmentInfoYearTop(begin);

        TimeUnit.SECONDS.sleep(3);
        logger.info("wtAlysisyService开始!。。。。。。");
        wtAlysisDayService.calEquipmentInfoDay(begin);
        logger.info("wtAlysisyService完成!。。。。。。");
        end = new Date();
        logger.info(df.format(end).toString());
        logger.info("完成一次!。。。。。。");
        logger.info("执行用时" + com.gyee.generation.util.DateUtils.secondsDiff(begin, end) + "秒");
    }


    public void calIn(Date recordDate) throws Exception {

        Calendar c = Calendar.getInstance();
        Logger logger = LoggerFactory.getLogger(GenerationMain.class);


        c.setTime(recordDate);
        c.set(Calendar.HOUR_OF_DAY, 23);
        c.set(Calendar.MINUTE, 59);
        c.set(Calendar.SECOND, 59);
        Date begin = c.getTime();
        Date end = null;
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        logger.info(df.format(c.getTime()).toString());


        equipmentInfo1Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo1Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);
        equipmentInfo2Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo2Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);
        equipmentInfo3Service.calEquipmentInfoDay(begin);
        logger.info("equipmentInfo3Service完成一次!。。。。。。");
        TimeUnit.SECONDS.sleep(3);

        end = new Date();
        logger.info(df.format(end).toString());
        logger.info("完成一次!。。。。。。");
        logger.info("执行用时" + com.gyee.generation.util.DateUtils.secondsDiff(begin, end) + "秒");
    }
}
