package com.chuanxia.mcp.sched;

import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson.JSON;
import com.chuanxia.mcp.bean.vo.UserSystemVideoVo;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@Component
@RequiredArgsConstructor
public class ScheduledService {

    private final M3U8Utils m3U8Utils;
    private final RestTemplate restTemplate;

    /**
     * 增量同步
     */
    //@Scheduled(cron = "0/5 * * * * *")
    public void scheduled() {
        log.info("执行定时任务");
    }

    public ArrayList<UserSystemVideoVo> getM3u8Vo(Date startTime, Date endTime) {
        String url = "";
        ResponseEntity<String> forEntity = restTemplate.getForEntity(url, String.class);
        String body = forEntity.getBody();
        if (StringUtils.isNotBlank(body)) {
            List<UserSystemVideoVo> voList = JSON.parseArray(body, UserSystemVideoVo.class);
            if (CollectionUtil.isNotEmpty(voList)) {
                for (UserSystemVideoVo userSystemVideoVo : voList) {

                }
            }
        }
        return null;
    }

    private void downLoad(String url) {
    }

}