From 378c4cbdf8243bf753856ff42a4d6f5cba397322 Mon Sep 17 00:00:00 2001 From: ovo Date: Fri, 13 Dec 2024 18:00:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=9B=BE=E4=B9=A6=E5=88=9D=E6=AD=A5):=20?= =?UTF-8?q?=E5=9B=BE=E4=B9=A6=E5=88=9D=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 图书初步 --- .../controller/LiveStreamController.java | 80 ----------- .../backend/controller/VideoController.java | 130 ----------------- .../guwan/backend/service/LiveService.java | 132 ------------------ .../service/ReadingProgressService.java | 1 + .../impl/ReadingProgressServiceImpl.java | 1 + 5 files changed, 2 insertions(+), 342 deletions(-) delete mode 100644 src/main/java/com/guwan/backend/controller/LiveStreamController.java delete mode 100644 src/main/java/com/guwan/backend/controller/VideoController.java delete mode 100644 src/main/java/com/guwan/backend/service/LiveService.java diff --git a/src/main/java/com/guwan/backend/controller/LiveStreamController.java b/src/main/java/com/guwan/backend/controller/LiveStreamController.java deleted file mode 100644 index 62b81c6..0000000 --- a/src/main/java/com/guwan/backend/controller/LiveStreamController.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.guwan.backend.controller; - -import com.guwan.backend.common.Result; -import com.guwan.backend.dto.live.CreateRoomRequest; -import com.guwan.backend.dto.live.StartLiveRequest; -import com.guwan.backend.dto.live.WebRTCRequest; -import com.guwan.backend.dto.live.WebRTCResponse; -import com.guwan.backend.entity.LiveRoom; -import com.guwan.backend.service.LiveStreamService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; - -@Slf4j -@Tag(name = "直播管理", description = "直播相关接口") -@RestController -@RequestMapping("/api/live") -@RequiredArgsConstructor -public class LiveStreamController { - - private final LiveStreamService liveStreamService; - - @Operation(summary = "创建直播间") - @PostMapping("/room") - public Result createLiveRoom(@RequestBody CreateRoomRequest request) { - try { - LiveRoom room = liveStreamService.createLiveRoom( - request.getTitle(), - request.getDescription(), - request.getUserId() - ); - return Result.success(room); - } catch (Exception e) { - log.error("创建直播间失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "开始直播") - @PostMapping("/room/{id}/start") - public Result startLive( - @PathVariable Long id, - @RequestBody StartLiveRequest request) { - try { - liveStreamService.startLive(id, request.getSourceUrl()); - return Result.success(); - } catch (Exception e) { - log.error("开始直播失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "结束直播") - @PostMapping("/room/{id}/end") - public Result endLive(@PathVariable Long id) { - try { - liveStreamService.endLive(id); - return Result.success(); - } catch (Exception e) { - log.error("结束直播失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取WebRTC Offer") - @PostMapping("/room/{id}/webrtc") - public Result getWebRTCOffer( - @PathVariable Long id, - @RequestBody WebRTCRequest request) { - try { - String sdp = liveStreamService.getWebRTCOffer(id, request.getSdp()); - return Result.success(new WebRTCResponse(sdp)); - } catch (Exception e) { - log.error("获取WebRTC Offer失败", e); - return Result.error(e.getMessage()); - } - } -} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/controller/VideoController.java b/src/main/java/com/guwan/backend/controller/VideoController.java deleted file mode 100644 index 7e4b136..0000000 --- a/src/main/java/com/guwan/backend/controller/VideoController.java +++ /dev/null @@ -1,130 +0,0 @@ -package com.guwan.backend.controller; - -import com.baomidou.mybatisplus.core.metadata.IPage; -import com.guwan.backend.common.Result; -import com.guwan.backend.dto.video.VideoDTO; -import com.guwan.backend.dto.video.VideoUploadDTO; -import com.guwan.backend.service.VideoService; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.security.SecurityRequirement; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.multipart.MultipartFile; - -@Slf4j -@Tag(name = "视频管理", description = "视频相关接口") -@RestController -@RequestMapping("/api/videos") -@RequiredArgsConstructor -public class VideoController { - - private final VideoService videoService; - - - @Operation(summary = "上传视频", description = "上传视频文件并返回视频信息") - // @SecurityRequirement(name = "bearer-jwt") - @PostMapping("/upload") - public Result uploadVideo(@RequestBody VideoUploadDTO videoUploadDTO) { - try { - VideoDTO video = videoService.uploadVideo(videoUploadDTO.getFileUrl(), - videoUploadDTO.getTitle(), videoUploadDTO.getDescription(), videoUploadDTO.getTags()); - return Result.success(video); - } catch (Exception e) { - log.error("上传视频失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "更新视频信息") - @SecurityRequirement(name = "bearer-jwt") - @PutMapping("/{id}") - public Result updateVideo( - @Parameter(description = "视频ID") @PathVariable Long id, - @RequestBody VideoDTO videoDTO) { - try { - videoDTO.setId(id); - return Result.success(videoService.updateVideo(videoDTO)); - } catch (Exception e) { - log.error("更新视频失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "删除视频") - @SecurityRequirement(name = "bearer-jwt") - @DeleteMapping("/{id}") - public Result deleteVideo( - @Parameter(description = "视频ID") @PathVariable Long id) { - try { - videoService.deleteVideo(id); - return Result.success(); - } catch (Exception e) { - log.error("删除视频失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取视频详情") - @GetMapping("/{id}") - public Result getVideo( - @Parameter(description = "视频ID") @PathVariable Long id) { - try { - VideoDTO video = videoService.getVideoById(id); - if (video == null) { - return Result.notFound("视频不存在"); - } - return Result.success(video); - } catch (Exception e) { - log.error("获取视频失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "获取视频列表", description = "支持分页和关键词搜索") - @GetMapping - public Result> getVideoList( - @Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer pageNum, - @Parameter(description = "每页条数") @RequestParam(defaultValue = "10") Integer pageSize, - @Parameter(description = "搜索关键词") @RequestParam(required = false) String keyword) { - try { - return Result.success(videoService.getVideoList(pageNum, pageSize, keyword)); - } catch (Exception e) { - log.error("获取视频列表失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "增加视频观看次数") - @PostMapping("/{id}/view") - public Result incrementViewCount( - @Parameter(description = "视频ID") @PathVariable Long id) { - try { - videoService.incrementViewCount(id); - return Result.success(); - } catch (Exception e) { - log.error("增加观看次数失败", e); - return Result.error(e.getMessage()); - } - } - - @Operation(summary = "视频点赞/取消点赞") - @SecurityRequirement(name = "bearer-jwt") - @PostMapping("/{id}/like") - public Result toggleLike( - @Parameter(description = "视频ID") @PathVariable Long id) { - try { - videoService.toggleLike(id); - return Result.success(); - } catch (Exception e) { - log.error("点赞失败", e); - return Result.error(e.getMessage()); - } - } - - - - -} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/service/LiveService.java b/src/main/java/com/guwan/backend/service/LiveService.java deleted file mode 100644 index bbcaa57..0000000 --- a/src/main/java/com/guwan/backend/service/LiveService.java +++ /dev/null @@ -1,132 +0,0 @@ -//package com.guwan.backend.service; -// -//import com.guwan.backend.client.SrsClient; -//import com.guwan.backend.dto.live.LiveRoomDTO; -//import com.guwan.backend.entity.LiveRoom; -//import com.guwan.backend.mapper.LiveRoomMapper; -//import com.guwan.backend.util.SecurityUtil; -//import lombok.RequiredArgsConstructor; -//import lombok.extern.slf4j.Slf4j; -//import org.springframework.beans.BeanUtils; -//import org.springframework.stereotype.Service; -// -//@Slf4j -//@Service -//@RequiredArgsConstructor -//public class LiveService { -// -// private final LiveRoomMapper liveRoomMapper; -// private final SrsClient srsClient; -// private final SecurityUtil securityUtil; -// -// /** -// * 创建直播间 -// */ -// public LiveRoom createLiveRoom(LiveRoomDTO dto) { -// // 获取当前用户 -// Long userId = securityUtil.getCurrentUserId(); -// String username = securityUtil.getCurrentUsername(); -// if (userId == null) { -// throw new IllegalStateException("用户未登录"); -// } -// -// LiveRoom room = new LiveRoom(); -// BeanUtils.copyProperties(dto, room); -// -// // 设置用户信息 -// room.setUserId(userId); -// room.setUsername(username); -// -// // 生成推流密钥 -// String streamKey = generateStreamKey(); -// room.setStreamKey(streamKey); -// -// // 生成推流地址 -// String rtmpUrl = generateRtmpUrl(streamKey); -// room.setRtmpUrl(rtmpUrl); -// -// // 生成播放地址 -// String hlsUrl = generateHlsUrl(streamKey); -// room.setHlsUrl(hlsUrl); -// -// room.setStatus("PREPARING"); -// room.setOnlineCount(0); -// room.setLikeCount(0); -// -// liveRoomMapper.insert(room); -// return room; -// } -// -// /** -// * 开始直播 -// */ -// public void startLive(Long roomId) { -// LiveRoom room = liveRoomMapper.selectById(roomId); -// room.setStatus("LIVING"); -// liveRoomMapper.updateById(room); -// -// // 开始录制 -// startRecording(room.getStreamKey()); -// } -// -// /** -// * 结束直播 -// */ -// public void endLive(Long roomId) { -// LiveRoom room = liveRoomMapper.selectById(roomId); -// room.setStatus("ENDED"); -// liveRoomMapper.updateById(room); -// -// // 停止录制 -// stopRecording(room.getStreamKey()); -// -// // 生成回放地址 -// String replayUrl = generateReplayUrl(room.getStreamKey()); -// room.setReplayUrl(replayUrl); -// liveRoomMapper.updateById(room); -// } -// -// /** -// * 开始录制 -// */ -// private void startRecording(String streamKey) { -// SrsClient.RecordConfig config = new SrsClient.RecordConfig(); -// config.setFilePath("/recordings/" + streamKey + ".flv"); -// srsClient.startRecord(streamKey, config); -// } -// -// /** -// * 停止录制 -// */ -// private void stopRecording(String streamKey) { -// srsClient.stopRecord(streamKey); -// } -// -// /** -// * 生成推流密钥 -// */ -// private String generateStreamKey() { -// return UUID.randomUUID().toString(); -// } -// -// /** -// * 生成推流地址 -// */ -// private String generateRtmpUrl(String streamKey) { -// return "rtmp://localhost:1935/live/" + streamKey; -// } -// -// /** -// * 生成播放地址 -// */ -// private String generateHlsUrl(String streamKey) { -// return "http://localhost:8088/live/" + streamKey + ".m3u8"; -// } -// -// /** -// * 生成回放地址 -// */ -// private String generateReplayUrl(String streamKey) { -// return "http://localhost:8080/recordings/" + streamKey + ".flv"; -// } -//} \ No newline at end of file diff --git a/src/main/java/com/guwan/backend/service/ReadingProgressService.java b/src/main/java/com/guwan/backend/service/ReadingProgressService.java index 5277c77..40572ae 100644 --- a/src/main/java/com/guwan/backend/service/ReadingProgressService.java +++ b/src/main/java/com/guwan/backend/service/ReadingProgressService.java @@ -1,6 +1,7 @@ package com.guwan.backend.service; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.guwan.backend.dto.ReadingStatistics; import com.guwan.backend.entity.ReadingProgress; public interface ReadingProgressService { diff --git a/src/main/java/com/guwan/backend/service/impl/ReadingProgressServiceImpl.java b/src/main/java/com/guwan/backend/service/impl/ReadingProgressServiceImpl.java index 6ee9094..6ca6475 100644 --- a/src/main/java/com/guwan/backend/service/impl/ReadingProgressServiceImpl.java +++ b/src/main/java/com/guwan/backend/service/impl/ReadingProgressServiceImpl.java @@ -3,6 +3,7 @@ package com.guwan.backend.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; +import com.guwan.backend.dto.ReadingStatistics; import com.guwan.backend.entity.ReadingProgress; import com.guwan.backend.mapper.ReadingProgressMapper; import com.guwan.backend.service.ReadingProgressService;