package com.hzjt.config;

import com.hzjt.domain.*;
import com.hzjt.handler.WebSocket;
import com.hzjt.service.TraffFlowService;
import com.hzjt.service.TraffalarmrecordService;
import com.hzjt.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.net.URI;
import java.util.Calendar;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@Slf4j

@Configuration
@EnableScheduling
public class ScheduleTaskConfig {
    @Autowired
    TraffFlowService traffFlowService;

    @Autowired
    TraffalarmrecordService traffalarmrecordService;
    @Autowired
    private RestTemplate restTemplate;



    @Scheduled(cron = "0 */1 * * * ?")//每天凌晨2点执行
    private void statis() {
//        //取帧
//        HttpHeaders headers = new HttpHeaders();
//        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
//        RTSPFrame result = restTemplate.getForObject(rtspformUrl, RTSPFrame.class);
//      if(result.getRet()==0)
//      {
//          //获取成功
//
//          result.getUrl();
//
//
//
//      }

        //查询监控是否存在


        //查询rtsp 多线程进行图片抽取，并记录表中，ftp  上传到服务器，路径返回表中








    }

    @Scheduled(cron = "0 */1 * * * ?")//每一个月执行一次
    private void reconnectWebsocket() {

        final Calendar c = Calendar.getInstance();
        if (c.get(Calendar.DATE) == c.getActualMaximum(Calendar.DATE)) {
//            log.info("每个月最后一天执行删除前2个月车流量数据操作start");
            //删除2个月之前车流量详情的数据
            traffFlowService.deleteBeforeTwoMonthVehicles();
        }
    }

//    @Scheduled(cron = "0 30/5 6-19 * * ?")//每隔5分钟统计当天目前为止的数据
//    private void statistoday() {
//        //判断是否为空表
//        //执行查询存在更新，不存在新增
//        log.info("每隔5分钟");
//       Integer result= traffFlowService.insertOrUpdatevehicleTodaystatistic();
//        log.info("today"+result);
//
//    }

}
