package com.yijia.station.task;


import com.yijia.station.domain.StationOilPrice;
import com.yijia.station.domain.StationOilPriceAdjust;
import com.yijia.station.service.IStationOilPriceAdjustService;
import com.yijia.station.service.IStationOilPriceService;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

@Configuration      //1.主要用于标记配置类，兼备Component的效果。
@EnableScheduling   // 2.开启定时任务
public class SaticScheduleTask {

//    private IStationOilPriceAdjustService stationOilPriceAdjustService;
//    private IStationOilPriceService stationOilPriceService;
//    //3.添加定时任务
//    @Scheduled(cron = "0/5 * * * * ?")
//    //或直接指定时间间隔，例如：5秒
//    //@Scheduled(fixedRate=5000)
//    private void configureTasks() {
//        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
//        //查询油品调价列表 查询出未调价的信息
////        StationOilPriceAdjust stationOilPriceAdjust =new StationOilPriceAdjust();
////        stationOilPriceAdjust.setTakeEffectStatus("1");
////        List<StationOilPriceAdjust>  oilPriceAdjustList=stationOilPriceAdjustService.selectStationOilPriceAdjustList(stationOilPriceAdjust);
////        //循环查看 调价的生效时间是否和当前时间相符
////        for(StationOilPriceAdjust adjust: oilPriceAdjustList ){
////            //判断当前时间是否符合调价生效时间
////            if(adjust.getAdjustDate().equals(new Date()) ){
////                //根据查询油品价格id
////                StationOilPrice oilPrice=new StationOilPrice();
////                oilPrice.setOilName(adjust.getOilName());
////                oilPrice.setStationId(adjust.getStationId());
////               List<StationOilPrice> list = stationOilPriceService.selectStationOilPriceList(oilPrice);
////               if(list!=null && list.size()==1){
////                   //修改调价状态
////                   adjust.setTakeEffectStatus("2");
////                   stationOilPriceAdjustService.updateStationOilPriceAdjust(adjust);
////                   //修改油站对应的价格
////                   StationOilPrice stationOilPrice=new StationOilPrice();
////                   stationOilPrice.setOilPriceId(list.get(0).getOilPriceId());
////                   stationOilPrice.setOilPrice(adjust.getOilAdjustPrice());
////                   stationOilPriceService.updateStationOilPrice(stationOilPrice);
////               }
////            }
//      //  }
//    }
}
