完善项目

This commit is contained in:
2025-04-20 15:02:38 +08:00
parent d60df6d712
commit 11a207a10a
10 changed files with 68 additions and 9 deletions

View File

@@ -1,7 +1,9 @@
package com.ping.study.controller; package com.ping.study.controller;
import com.ping.study.model.dto.addUrls; 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.pojo.Games;
import com.ping.study.service.GamesService; import com.ping.study.service.GamesService;
import com.ping.study.service.UrlsService; import com.ping.study.service.UrlsService;
@@ -37,6 +39,12 @@ public class NbaController {
@Scheduled(cron = "0 0 0 * * ?") @Scheduled(cron = "0 0 0 * * ?")
@RequestMapping("/add") @RequestMapping("/add")
public List<Games> addGames() { public List<Games> addGames() {
//先删除数据库中所有赛程
log.info("执行定时方法删除数据库中所有赛程");
gamesService.deleteAllGames();
//再删除数据库中所有直播链接
log.info("执行定时方法删除数据库中所有直播链接");
urlsService.deleteAllUrls();
log.info("执行定时方法添加当天赛程"); log.info("执行定时方法添加当天赛程");
return nbaApi.addGames(); return nbaApi.addGames();
} }
@@ -47,7 +55,7 @@ public class NbaController {
} }
@RequestMapping("/urls") @RequestMapping("/urls")
public List<HashMap<String, List<HashMap<String, String>>>> getUrls() { public List<HashMap<String, List<LiveUrl>>> getUrls() {
log.info("获取所有赛程直播链接"); log.info("获取所有赛程直播链接");
return urlsService.getUrls(); return urlsService.getUrls();
} }
@@ -61,4 +69,10 @@ public class NbaController {
log.info("添加所有赛程直播链接"); log.info("添加所有赛程直播链接");
urlsService.addUrls(addUrls); urlsService.addUrls(addUrls);
} }
//删除直播链接根据id
@RequestMapping("/delete/{id}")
public void deleteUrlById(@PathVariable("id") Integer id){
urlsService.deleteUrlById(id);
}
} }

View File

@@ -27,4 +27,7 @@ public interface GamesMapper {
Games selectByGameId(String gameId); Games selectByGameId(String gameId);
List<Games> selectAll(); List<Games> selectAll();
//删除所有赛程
void deleteAllGames();
} }

View File

@@ -28,7 +28,12 @@ public interface UrlsMapper {
int updateByPrimaryKey(Urls record); int updateByPrimaryKey(Urls record);
List<String> selectGameIds(); List<String> selectGameIds();
List<HashMap<String, String>> selectUrlsListByGameId(String gameId); List<LiveUrl> selectUrlsListByGameId(String gameId);
void insertUrlsWithGameId(@Param("gameId") String gameId, @Param("list") List<LiveUrl> urls); void insertUrlsWithGameId(@Param("gameId") String gameId, @Param("list") List<LiveUrl> urls);
//删除url
void deleteUrlById(Integer id);
//删除所有url
void deleteAllUrls();
} }

View File

@@ -13,6 +13,7 @@ import lombok.NoArgsConstructor;
public class LiveUrl { public class LiveUrl {
// private Integer gameId; // private Integer gameId;
private Integer id;
private String type; private String type;
private String url; private String url;

View File

@@ -10,4 +10,6 @@ public interface GamesService {
//获取当时比赛赛程 //获取当时比赛赛程
List<Games> getGames(); List<Games> getGames();
void deleteAllGames();
} }

View File

@@ -11,8 +11,12 @@ public interface UrlsService {
//查询当天的直播地址 //查询当天的直播地址
public List<HashMap<String, List<HashMap<String, String>>>> getUrls(); public List<HashMap<String, List<LiveUrl>>> getUrls();
//添加直播地址到对应赛事 //添加直播地址到对应赛事
public void addUrls(addUrls addUrls); public void addUrls(addUrls addUrls);
public void deleteUrlById(Integer id);
void deleteAllUrls();
} }

View File

@@ -31,4 +31,9 @@ public class GamesServiceImpl implements GamesService {
return gamesMapper.selectAll(); return gamesMapper.selectAll();
} }
@Override
public void deleteAllGames() {
gamesMapper.deleteAllGames();
}
} }

View File

@@ -17,12 +17,12 @@ public class UrlsServiceImpl implements UrlsService {
@Autowired @Autowired
private UrlsMapper urlsMapper; private UrlsMapper urlsMapper;
@Override @Override
public List<HashMap<String, List<HashMap<String, String>>>> getUrls() { public List<HashMap<String, List<LiveUrl>>> getUrls() {
List<HashMap<String,List<HashMap<String, String>>>> urlsList = new ArrayList<>(); List<HashMap<String,List<LiveUrl>>> urlsList = new ArrayList<>();
List<String> gameIds = urlsMapper.selectGameIds(); List<String> gameIds = urlsMapper.selectGameIds();
gameIds.forEach(gameId -> { gameIds.forEach(gameId -> {
List<HashMap<String, String>> maps = urlsMapper.selectUrlsListByGameId(gameId); List<LiveUrl> maps = urlsMapper.selectUrlsListByGameId(gameId);
HashMap<String, List<HashMap<String, String>>> map = new HashMap<>(); HashMap<String, List<LiveUrl>> map = new HashMap<>();
map.put(gameId,maps); map.put(gameId,maps);
urlsList.add(map); urlsList.add(map);
}); // 添加右括号和分号 }); // 添加右括号和分号
@@ -34,4 +34,20 @@ public class UrlsServiceImpl implements UrlsService {
urlsMapper.insertUrlsWithGameId(addUrls.getGameId(), addUrls.getUrls()); urlsMapper.insertUrlsWithGameId(addUrls.getGameId(), addUrls.getUrls());
} }
@Override
public void deleteUrlById(Integer id) {
try {
urlsMapper.deleteUrlById(id);
}
catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void deleteAllUrls() {
urlsMapper.deleteAllUrls();
}
} }

View File

@@ -117,4 +117,7 @@
<include refid="Base_Column_List" /> <include refid="Base_Column_List" />
from games from games
</select> </select>
<delete id="deleteAllGames" >
delete from games
</delete>
</mapper> </mapper>

View File

@@ -77,7 +77,7 @@
</select> </select>
<select id="selectUrlsListByGameId" resultType="map"> <select id="selectUrlsListByGameId" resultType="map">
select urls.type,urls.url from urls where game_id = #{gameId} select urls.id,urls.type,urls.url from urls where game_id = #{gameId}
</select> </select>
<insert id="insertUrlsWithGameId"> <insert id="insertUrlsWithGameId">
@@ -88,4 +88,10 @@
(#{gameId}, #{item.url}, #{item.type}) (#{gameId}, #{item.url}, #{item.type})
</foreach> </foreach>
</insert> </insert>
<delete id="deleteUrlById" parameterType="java.lang.Integer">
delete from urls where id = #{id}
</delete>
<delete id="deleteAllUrls">
delete from urls
</delete>
</mapper> </mapper>