Files
NBA/src/main/java/com/ping/study/controller/NbaController.java
2025-04-21 11:17:19 +08:00

85 lines
2.4 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.ping.study.controller;
import com.ping.study.model.dto.addUrls;
import com.ping.study.model.vo.live.LiveUrl;
import com.ping.study.pojo.Games;
import com.ping.study.service.GamesService;
import com.ping.study.service.UrlsService;
import com.ping.study.utils.NbaApi;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.List;
@RequestMapping("/api")
@RestController
@Data
@Slf4j
//@CrossOrigin(origins = "http://nba.new9.me")
@CrossOrigin
public class NbaController {
@Autowired
private NbaApi nbaApi;
@Autowired
private GamesService gamesService;
@Autowired
private UrlsService urlsService;
//添加定时任务每日凌晨0点执行一次
// 每天 00:00:00 执行
@Scheduled(cron = "0 0 0 * * ?")
@RequestMapping("/add")
public List<Games> addGames() {
//先删除数据库中所有赛程
log.info("执行定时方法删除数据库中所有赛程");
gamesService.deleteAllGames();
//再删除数据库中所有直播链接
log.info("执行定时方法删除数据库中所有直播链接");
urlsService.deleteAllUrls();
log.info("执行定时方法添加当天赛程");
return nbaApi.addGames();
}
@Scheduled(cron = "0 0 0 * * ?")
@RequestMapping("/updateLive")
public void updateLive() {
log.info("执行定时方法更新当天赛程直播链接");
}
@RequestMapping("/games")
public List<Games> getGames() {
log.info("获取所有赛程");
return gamesService.getGames();
}
@RequestMapping("/urls")
public List<HashMap<String, List<LiveUrl>>> getUrls() {
log.info("获取所有赛程直播链接");
return urlsService.getUrls();
}
@RequestMapping("/go")
public Boolean go(@RequestParam("pwd") String pwd) {
return pwd.equals("inspur123");
}
@RequestMapping(value = "/addUrls",method = RequestMethod.POST)
public void addUrls(@RequestBody addUrls addUrls) {
log.info("添加所有赛程直播链接");
urlsService.addUrls(addUrls);
}
//删除直播链接根据id
@RequestMapping("/delete/{id}")
public void deleteUrlById(@PathVariable("id") Integer id){
urlsService.deleteUrlById(id);
}
}