删除与该项目无关代码
This commit is contained in:
parent
0c6404829d
commit
1c6b2f75b6
|
@ -1,110 +0,0 @@
|
|||
package com.guwan.backend.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.common.Result;
|
||||
import com.guwan.backend.pojo.entity.Book;
|
||||
import com.guwan.backend.service.BookService;
|
||||
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/books")
|
||||
@RequiredArgsConstructor
|
||||
public class BookController {
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
@Operation(summary = "添加图书")
|
||||
@PostMapping("/add")
|
||||
public Result<Book> addBook(@RequestBody Book book) {
|
||||
try {
|
||||
return Result.success(bookService.addBook(book));
|
||||
} catch (Exception e) {
|
||||
log.error("添加图书失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "分页查询图书列表")
|
||||
@GetMapping
|
||||
public Result<IPage<Book>> getBookList(
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize,
|
||||
@RequestParam(required = false) String keyword) {
|
||||
try {
|
||||
return Result.success(bookService.getBookList(pageNum, pageSize, keyword));
|
||||
} catch (Exception e) {
|
||||
log.error("查询图书列表失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "更新图书信息")
|
||||
@PutMapping("/{id}")
|
||||
public Result<Book> updateBook(@PathVariable Long id, @RequestBody Book book) {
|
||||
try {
|
||||
book.setId(id);
|
||||
return Result.success(bookService.updateBook(book));
|
||||
} catch (Exception e) {
|
||||
log.error("更新图书失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "删除图书")
|
||||
@DeleteMapping("/{id}")
|
||||
public Result<Void> deleteBook(@PathVariable Long id) {
|
||||
try {
|
||||
bookService.deleteBook(id);
|
||||
return Result.success();
|
||||
} catch (Exception e) {
|
||||
log.error("删除图书失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取图书详情")
|
||||
@GetMapping("/{id}")
|
||||
public Result<Book> getBook(@PathVariable Long id) {
|
||||
try {
|
||||
return Result.success(bookService.getBookById(id));
|
||||
} catch (Exception e) {
|
||||
log.error("获取图书详情失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "根据ISBN获取图书")
|
||||
@GetMapping("/isbn/{isbn}")
|
||||
public Result<Book> getBookByIsbn(@PathVariable String isbn) {
|
||||
try {
|
||||
return Result.success(bookService.getBookByIsbn(isbn));
|
||||
} catch (Exception e) {
|
||||
log.error("根据ISBN获取图书失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Operation(summary = "根据分类获取图书")
|
||||
@GetMapping("/category/{category}")
|
||||
public Result<IPage<Book>> getBooksByCategory(
|
||||
@PathVariable String category,
|
||||
@RequestParam(defaultValue = "1") Integer pageNum,
|
||||
@RequestParam(defaultValue = "10") Integer pageSize) {
|
||||
try {
|
||||
return Result.success(bookService.getBooksByCategory(category, pageNum, pageSize));
|
||||
} catch (Exception e) {
|
||||
log.error("根据分类获取图书失败", e);
|
||||
return Result.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@ import com.guwan.backend.mongodb.EveryReadDetailOfMongodb;
|
|||
import com.guwan.backend.mongodb.EveryReadDetailOfMongodbService;
|
||||
import com.guwan.backend.mongodb.User;
|
||||
import com.guwan.backend.mongodb.MongodbUserService;
|
||||
import com.guwan.backend.service.BookContentService;
|
||||
import com.guwan.backend.util.MinioUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
@ -43,7 +42,7 @@ public class CommonController {
|
|||
|
||||
|
||||
|
||||
private final BookContentService bookContentService;
|
||||
//private final BookContentService bookContentService;
|
||||
|
||||
private final MongodbUserService mongodbUserService;
|
||||
|
||||
|
@ -55,29 +54,29 @@ public class CommonController {
|
|||
(bucketName, minioUtil.uploadFile(bucketName, file))));
|
||||
}
|
||||
|
||||
@PostMapping("/addBookComment")
|
||||
public Result<String> addBookComment(String url) {
|
||||
log.debug(url);
|
||||
// "http://localhost:9000/txt/8357cf6b-9637-4354-9ee6-2717141f665a.txt";
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
// 创建一个请求对象
|
||||
Request request = new Request.Builder()
|
||||
.url(url)
|
||||
.build();
|
||||
|
||||
// 发起同步请求
|
||||
try {
|
||||
String content = getTextUsingOkHttp(client, request);
|
||||
ArrayList<BookContent> bookContents = processContent(content);
|
||||
bookContentService.saveBatch(bookContents);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return Result.success("ok");
|
||||
}
|
||||
// @PostMapping("/addBookComment")
|
||||
// public Result<String> addBookComment(String url) {
|
||||
// log.debug(url);
|
||||
// // "http://localhost:9000/txt/8357cf6b-9637-4354-9ee6-2717141f665a.txt";
|
||||
// OkHttpClient client = new OkHttpClient();
|
||||
//
|
||||
// // 创建一个请求对象
|
||||
// Request request = new Request.Builder()
|
||||
// .url(url)
|
||||
// .build();
|
||||
//
|
||||
// // 发起同步请求
|
||||
// try {
|
||||
// String content = getTextUsingOkHttp(client, request);
|
||||
// ArrayList<BookContent> bookContents = processContent(content);
|
||||
// bookContentService.saveBatch(bookContents);
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// return Result.success("ok");
|
||||
// }
|
||||
|
||||
// 通过 OkHttpClient 发起同步请求获取文件内容
|
||||
public static String getTextUsingOkHttp(OkHttpClient client, Request request) throws IOException {
|
||||
|
@ -188,38 +187,38 @@ public class CommonController {
|
|||
}
|
||||
|
||||
|
||||
@GetMapping("/getBookComment")
|
||||
public Result<String> getBookComment(Long id) {
|
||||
BookContent bookContent = bookContentService.getById(id);
|
||||
return Result.success(bookContent.getSectionContent());
|
||||
}
|
||||
// @GetMapping("/getBookComment")
|
||||
// public Result<String> getBookComment(Long id) {
|
||||
// BookContent bookContent = bookContentService.getById(id);
|
||||
// return Result.success(bookContent.getSectionContent());
|
||||
// }
|
||||
|
||||
|
||||
@GetMapping("/getBookContent")
|
||||
public Result<String> getBookContent(String bookName, Long id) {
|
||||
BookContent bookContent = bookContentService.getBookContent(bookName, id);
|
||||
return Result.success(bookContent.getSectionContent());
|
||||
}
|
||||
// @GetMapping("/getBookContent")
|
||||
// public Result<String> getBookContent(String bookName, Long id) {
|
||||
// BookContent bookContent = bookContentService.getBookContent(bookName, id);
|
||||
// return Result.success(bookContent.getSectionContent());
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@GetMapping("/getBookCommentByPath")
|
||||
public ResponseEntity<Map<String, Object>> getBookCommentByPath(@RequestParam("id") Long id) {
|
||||
// 从数据库中获取评论内容
|
||||
//String comments = bookContentService.getById(id).getSectionContent();
|
||||
|
||||
BookContent byId = bookContentService.lambdaQuery()
|
||||
.eq(BookContent::getBookName, "大爱仙尊")
|
||||
.eq(BookContent::getSectionId, id).one();
|
||||
|
||||
// 构造返回数据
|
||||
Map<String, Object> response = new HashMap<>();
|
||||
response.put("data", byId);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
|
||||
}
|
||||
// @GetMapping("/getBookCommentByPath")
|
||||
// public ResponseEntity<Map<String, Object>> getBookCommentByPath(@RequestParam("id") Long id) {
|
||||
// // 从数据库中获取评论内容
|
||||
// //String comments = bookContentService.getById(id).getSectionContent();
|
||||
//
|
||||
// BookContent byId = bookContentService.lambdaQuery()
|
||||
// .eq(BookContent::getBookName, "大爱仙尊")
|
||||
// .eq(BookContent::getSectionId, id).one();
|
||||
//
|
||||
// // 构造返回数据
|
||||
// Map<String, Object> response = new HashMap<>();
|
||||
// response.put("data", byId);
|
||||
//
|
||||
// return ResponseEntity.ok(response);
|
||||
//
|
||||
// }
|
||||
|
||||
|
||||
@GetMapping("/testMongodb")
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.guwan.backend.pojo.entity.BookCategory;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
/**
|
||||
* @author 12455
|
||||
* @description 针对表【book_category】的数据库操作Mapper
|
||||
* @createDate 2024-12-20 17:04:09
|
||||
* @Entity com.guwan.backend.entity.BookCategory
|
||||
*/
|
||||
public interface BookCategoryMapper extends BaseMapper<BookCategory> {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guwan.backend.pojo.entity.BookContent;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BookContentMapper extends BaseMapper<BookContent> {
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guwan.backend.pojo.entity.Book;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface BookMapper extends BaseMapper<Book> {
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guwan.backend.pojo.entity.ReadingNote;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface ReadingNoteMapper extends BaseMapper<ReadingNote> {
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guwan.backend.pojo.entity.VideoLike;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface VideoLikeMapper extends BaseMapper<VideoLike> {
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.guwan.backend.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.guwan.backend.pojo.entity.Video;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
@Mapper
|
||||
public interface VideoMapper extends BaseMapper<Video> {
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.guwan.backend.pojo.entity.BookContent;
|
||||
|
||||
|
||||
public interface BookContentService extends IService<BookContent> {
|
||||
BookContent getBookContent(String bookName, Long id);
|
||||
// 添加书籍
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.pojo.entity.Book;
|
||||
|
||||
public interface BookService {
|
||||
// 添加书籍
|
||||
Book addBook(Book book);
|
||||
|
||||
// 更新书籍信息
|
||||
Book updateBook(Book book);
|
||||
|
||||
// 删除书籍
|
||||
void deleteBook(Long id);
|
||||
|
||||
// 获取书籍详情
|
||||
Book getBookById(Long id);
|
||||
|
||||
// 根据ISBN获取书籍
|
||||
Book getBookByIsbn(String isbn);
|
||||
|
||||
// 分页查询书籍列表
|
||||
IPage<Book> getBookList(Integer pageNum, Integer pageSize, String keyword);
|
||||
|
||||
// 根据分类获取书籍
|
||||
IPage<Book> getBooksByCategory(String category, Integer pageNum, Integer pageSize);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.pojo.entity.ReadingNote;
|
||||
|
||||
public interface ReadingNoteService {
|
||||
// 添加笔记
|
||||
ReadingNote addNote(ReadingNote note);
|
||||
|
||||
// 更新笔记
|
||||
ReadingNote updateNote(ReadingNote note);
|
||||
|
||||
// 删除笔记
|
||||
void deleteNote(Long id);
|
||||
|
||||
// 获取笔记详情
|
||||
ReadingNote getNoteById(Long id);
|
||||
|
||||
// 获取用户的所有笔记
|
||||
IPage<ReadingNote> getUserNotes(Long userId, Integer pageNum, Integer pageSize);
|
||||
|
||||
// 获取书籍的所有笔记
|
||||
IPage<ReadingNote> getBookNotes(Long bookId, Integer pageNum, Integer pageSize);
|
||||
|
||||
// 获取用户在特定书籍上的笔记
|
||||
IPage<ReadingNote> getUserBookNotes(Long userId, Long bookId, Integer pageNum, Integer pageSize);
|
||||
|
||||
// 获取公开的笔记
|
||||
IPage<ReadingNote> getPublicNotes(Integer pageNum, Integer pageSize);
|
||||
}
|
|
@ -1,25 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.pojo.dto.ReadingStatistics;
|
||||
import com.guwan.backend.pojo.entity.ReadingProgress;
|
||||
|
||||
public interface ReadingProgressService {
|
||||
// 创建或更新阅读进度
|
||||
ReadingProgress updateProgress(ReadingProgress progress);
|
||||
|
||||
// 获取用户的阅读进度
|
||||
ReadingProgress getProgress(Long userId, Long bookId);
|
||||
|
||||
// 获取用户的所有阅读进度
|
||||
IPage<ReadingProgress> getUserProgress(Long userId, Integer pageNum, Integer pageSize);
|
||||
|
||||
// 获取用户特定状态的书籍
|
||||
IPage<ReadingProgress> getProgressByStatus(Long userId, String status, Integer pageNum, Integer pageSize);
|
||||
|
||||
// 更新阅读时长
|
||||
void updateReadingTime(Long userId, Long bookId, Integer minutes);
|
||||
|
||||
// 获取用户的阅读统计
|
||||
ReadingStatistics getReadingStatistics(Long userId);
|
||||
}
|
|
@ -1,135 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import cn.easyes.core.conditions.LambdaEsQueryWrapper;
|
||||
import cn.easyes.core.conditions.LambdaEsUpdateWrapper;
|
||||
import com.guwan.backend.pojo.dto.video.VideoDTO;
|
||||
import com.guwan.backend.pojo.entity.Video;
|
||||
import com.guwan.backend.elasticsearch.document.VideoDocument;
|
||||
import com.guwan.backend.elasticsearch.mapper.VideoEsMapper;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@ConditionalOnProperty(name = "easy-es.enable", havingValue = "true")
|
||||
@RequiredArgsConstructor
|
||||
public class VideoSearchService {
|
||||
|
||||
private final VideoEsMapper videoEsMapper;
|
||||
|
||||
/**
|
||||
* 保存或更新视频文档
|
||||
*/
|
||||
public void saveOrUpdate(Video video) {
|
||||
VideoDocument document = convertToDocument(video);
|
||||
videoEsMapper.insert(document);
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除视频文档
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
videoEsMapper.deleteById(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新视频观看次数
|
||||
*/
|
||||
public void updateViewCount(Long id, Integer viewCount) {
|
||||
LambdaEsUpdateWrapper<VideoDocument> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
wrapper.eq(VideoDocument::getId, id)
|
||||
.set(VideoDocument::getViewCount, viewCount);
|
||||
videoEsMapper.update(null, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新视频点赞次数
|
||||
*/
|
||||
public void updateLikeCount(Long id, Integer likeCount) {
|
||||
LambdaEsUpdateWrapper<VideoDocument> wrapper = new LambdaEsUpdateWrapper<>();
|
||||
wrapper.eq(VideoDocument::getId, id)
|
||||
.set(VideoDocument::getLikeCount, likeCount);
|
||||
videoEsMapper.update(null, wrapper);
|
||||
}
|
||||
|
||||
/**
|
||||
* 搜索视频
|
||||
*/
|
||||
public List<VideoDTO> search(String keyword) {
|
||||
// 构建查询条件
|
||||
LambdaEsQueryWrapper<VideoDocument> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.and(w -> w
|
||||
.match(VideoDocument::getTitle, keyword)
|
||||
.or()
|
||||
.match(VideoDocument::getDescription, keyword)
|
||||
.or()
|
||||
.match(VideoDocument::getTags, keyword)
|
||||
);
|
||||
|
||||
// 设置排序
|
||||
wrapper.orderByDesc(VideoDocument::getScore)
|
||||
.orderByDesc(VideoDocument::getCreatedTime);
|
||||
|
||||
// 执行查询
|
||||
List<VideoDocument> documents = videoEsMapper.selectList(wrapper);
|
||||
|
||||
// 转换结果
|
||||
return documents.stream()
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 推荐相似视频
|
||||
*/
|
||||
public List<VideoDTO> findSimilar(Long id, int limit) {
|
||||
// 获取当前视频
|
||||
VideoDocument current = videoEsMapper.selectById(id);
|
||||
if (current == null) {
|
||||
return List.of();
|
||||
}
|
||||
|
||||
// 构建查询条件
|
||||
LambdaEsQueryWrapper<VideoDocument> wrapper = new LambdaEsQueryWrapper<>();
|
||||
wrapper.and(w -> w
|
||||
.match(VideoDocument::getTags, current.getTags())
|
||||
.or()
|
||||
.match(VideoDocument::getTitle, current.getTitle())
|
||||
.or()
|
||||
.match(VideoDocument::getDescription, current.getDescription())
|
||||
);
|
||||
|
||||
// 排除当前视频
|
||||
wrapper.ne(VideoDocument::getId, id);
|
||||
|
||||
// 设置排序和限制
|
||||
wrapper.orderByDesc(VideoDocument::getScore)
|
||||
.limit(limit);
|
||||
|
||||
// 执行查询
|
||||
List<VideoDocument> documents = videoEsMapper.selectList(wrapper);
|
||||
|
||||
// 转换结果
|
||||
return documents.stream()
|
||||
.map(this::convertToDTO)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private VideoDocument convertToDocument(Video video) {
|
||||
VideoDocument document = new VideoDocument();
|
||||
BeanUtils.copyProperties(video, document);
|
||||
return document;
|
||||
}
|
||||
|
||||
private VideoDTO convertToDTO(VideoDocument document) {
|
||||
VideoDTO dto = new VideoDTO();
|
||||
BeanUtils.copyProperties(document, dto);
|
||||
return dto;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.guwan.backend.pojo.dto.video.VideoDTO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface VideoService {
|
||||
// 上传视频
|
||||
VideoDTO uploadVideo(String fileUrl, String title, String description, String tags);
|
||||
|
||||
// 更新视频信息
|
||||
VideoDTO updateVideo(VideoDTO videoDTO);
|
||||
|
||||
// 删除视频
|
||||
void deleteVideo(Long id);
|
||||
|
||||
// 获取视频详情
|
||||
VideoDTO getVideoById(Long id);
|
||||
|
||||
// 分页查询视频列表
|
||||
IPage<VideoDTO> getVideoList(Integer pageNum, Integer pageSize, String keyword);
|
||||
|
||||
// 增加观看次数
|
||||
void incrementViewCount(Long id);
|
||||
|
||||
// 点赞/取消点赞
|
||||
void toggleLike(Long id);
|
||||
|
||||
public List<VideoDTO> getSimilarVideosByEs(Long id, int limit);
|
||||
|
||||
public List<VideoDTO> searchVideosByEs(String keyword);
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package com.guwan.backend.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.pojo.entity.BookContent;
|
||||
import com.guwan.backend.mapper.BookContentMapper;
|
||||
import com.guwan.backend.service.BookContentService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BookContentServiceImpl extends ServiceImpl<BookContentMapper, BookContent> implements BookContentService {
|
||||
|
||||
|
||||
private final BookContentMapper bookContentMapper;
|
||||
|
||||
@Override
|
||||
public BookContent getBookContent(String bookName, Long id) {
|
||||
return bookContentMapper.selectOne(new LambdaQueryWrapper<BookContent>()
|
||||
.eq(BookContent::getBookName, bookName)
|
||||
.eq(BookContent::getSectionId, id));
|
||||
}
|
||||
}
|
|
@ -1,137 +0,0 @@
|
|||
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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.guwan.backend.annotation.OperationLog;
|
||||
import com.guwan.backend.common.BusinessException;
|
||||
import com.guwan.backend.pojo.entity.Book;
|
||||
import com.guwan.backend.pojo.entity.BookContent;
|
||||
import com.guwan.backend.mapper.BookMapper;
|
||||
import com.guwan.backend.service.BookContentService;
|
||||
import com.guwan.backend.service.BookService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import static com.guwan.backend.util.BookContentUtil.getTextUsingOkHttp;
|
||||
import static com.guwan.backend.util.BookContentUtil.processContent;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class BookServiceImpl extends ServiceImpl<BookMapper, Book> implements BookService {
|
||||
|
||||
|
||||
private final BookContentService bookContentService;
|
||||
|
||||
private final BookMapper bookMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "添加图书")
|
||||
public Book addBook(Book book) {
|
||||
|
||||
Book one = this.getOne(new LambdaQueryWrapper<Book>().eq(Book::getBookUrl, book.getBookUrl()));
|
||||
|
||||
|
||||
if (one != null){
|
||||
//复制处理
|
||||
|
||||
|
||||
//不允许
|
||||
throw new BusinessException("此图书url已被使用");
|
||||
|
||||
}
|
||||
|
||||
|
||||
// new LambdaQueryWrapper<>()
|
||||
|
||||
// new LambdaQueryChainWrapper<>()
|
||||
|
||||
bookMapper.insert(book);
|
||||
|
||||
log.debug(book.getBookUrl());
|
||||
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
|
||||
// 创建一个请求对象
|
||||
Request request = new Request.Builder()
|
||||
.url(book.getBookUrl())
|
||||
.build();
|
||||
|
||||
// 发起同步请求
|
||||
try {
|
||||
String content = getTextUsingOkHttp(client, request);
|
||||
ArrayList<BookContent> bookContents = processContent(content, book.getName());
|
||||
bookContentService.saveBatch(bookContents);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
|
||||
return book;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Book updateBook(Book book) {
|
||||
bookMapper.updateById(book);
|
||||
|
||||
|
||||
Book book1 = bookMapper.selectOne(new LambdaQueryWrapper<Book>()
|
||||
.eq(Book::getBookUrl, book.getBookUrl()));
|
||||
|
||||
|
||||
|
||||
|
||||
return book;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteBook(Long id) {
|
||||
bookMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book getBookById(Long id) {
|
||||
return bookMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Book getBookByIsbn(String isbn) {
|
||||
return bookMapper.selectOne(
|
||||
new LambdaQueryWrapper<Book>()
|
||||
.eq(Book::getIsbn, isbn)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Book> getBookList(Integer pageNum, Integer pageSize, String keyword) {
|
||||
LambdaQueryWrapper<Book> wrapper = new LambdaQueryWrapper<>();
|
||||
if (keyword != null && !keyword.isEmpty()) {
|
||||
wrapper.like(Book::getName, keyword)
|
||||
.or()
|
||||
.like(Book::getAuthor, keyword)
|
||||
.or()
|
||||
.like(Book::getDescription, keyword);
|
||||
}
|
||||
return bookMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<Book> getBooksByCategory(String category, Integer pageNum, Integer pageSize) {
|
||||
LambdaQueryWrapper<Book> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(Book::getCategory, category);
|
||||
return bookMapper.selectPage(new Page<>(pageNum, pageSize), wrapper);
|
||||
}
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
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.pojo.entity.ReadingNote;
|
||||
import com.guwan.backend.mapper.ReadingNoteMapper;
|
||||
import com.guwan.backend.service.ReadingNoteService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ReadingNoteServiceImpl implements ReadingNoteService {
|
||||
|
||||
private final ReadingNoteMapper noteMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ReadingNote addNote(ReadingNote note) {
|
||||
noteMapper.insert(note);
|
||||
return note;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ReadingNote updateNote(ReadingNote note) {
|
||||
noteMapper.updateById(note);
|
||||
return note;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void deleteNote(Long id) {
|
||||
noteMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadingNote getNoteById(Long id) {
|
||||
return noteMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingNote> getUserNotes(Long userId, Integer pageNum, Integer pageSize) {
|
||||
return noteMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingNote>()
|
||||
.eq(ReadingNote::getUserId, userId)
|
||||
.orderByDesc(ReadingNote::getCreatedTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingNote> getBookNotes(Long bookId, Integer pageNum, Integer pageSize) {
|
||||
return noteMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingNote>()
|
||||
.eq(ReadingNote::getBookId, bookId)
|
||||
.eq(ReadingNote::getIsPublic, true)
|
||||
.orderByDesc(ReadingNote::getCreatedTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingNote> getUserBookNotes(Long userId, Long bookId, Integer pageNum, Integer pageSize) {
|
||||
return noteMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingNote>()
|
||||
.eq(ReadingNote::getUserId, userId)
|
||||
.eq(ReadingNote::getBookId, bookId)
|
||||
.orderByDesc(ReadingNote::getCreatedTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingNote> getPublicNotes(Integer pageNum, Integer pageSize) {
|
||||
return noteMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingNote>()
|
||||
.eq(ReadingNote::getIsPublic, true)
|
||||
.orderByDesc(ReadingNote::getCreatedTime)
|
||||
);
|
||||
}
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
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.pojo.dto.ReadingStatistics;
|
||||
import com.guwan.backend.pojo.entity.ReadingProgress;
|
||||
import com.guwan.backend.mapper.ReadingProgressMapper;
|
||||
import com.guwan.backend.service.ReadingProgressService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class ReadingProgressServiceImpl implements ReadingProgressService {
|
||||
|
||||
private final ReadingProgressMapper progressMapper;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public ReadingProgress updateProgress(ReadingProgress progress) {
|
||||
progress.setLastReadTime(LocalDateTime.now());
|
||||
|
||||
// 检查是否存在记录
|
||||
ReadingProgress existing = getProgress(progress.getUserId(), progress.getBookId());
|
||||
if (existing != null) {
|
||||
progress.setId(existing.getId());
|
||||
progressMapper.updateById(progress);
|
||||
} else {
|
||||
progressMapper.insert(progress);
|
||||
}
|
||||
return progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadingProgress getProgress(Long userId, Long bookId) {
|
||||
return progressMapper.selectOne(
|
||||
new LambdaQueryWrapper<ReadingProgress>()
|
||||
.eq(ReadingProgress::getUserId, userId)
|
||||
.eq(ReadingProgress::getBookId, bookId)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingProgress> getUserProgress(Long userId, Integer pageNum, Integer pageSize) {
|
||||
return progressMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingProgress>()
|
||||
.eq(ReadingProgress::getUserId, userId)
|
||||
.orderByDesc(ReadingProgress::getLastReadTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<ReadingProgress> getProgressByStatus(Long userId, String status, Integer pageNum, Integer pageSize) {
|
||||
return progressMapper.selectPage(
|
||||
new Page<>(pageNum, pageSize),
|
||||
new LambdaQueryWrapper<ReadingProgress>()
|
||||
.eq(ReadingProgress::getUserId, userId)
|
||||
.eq(ReadingProgress::getStatus, status)
|
||||
.orderByDesc(ReadingProgress::getLastReadTime)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void updateReadingTime(Long userId, Long bookId, Integer minutes) {
|
||||
ReadingProgress progress = getProgress(userId, bookId);
|
||||
if (progress != null) {
|
||||
progress.setReadingTime(progress.getReadingTime() + minutes);
|
||||
progress.setLastReadTime(LocalDateTime.now());
|
||||
progressMapper.updateById(progress);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ReadingStatistics getReadingStatistics(Long userId) {
|
||||
// TODO: 实现阅读统计逻辑
|
||||
return new ReadingStatistics();
|
||||
}
|
||||
}
|
|
@ -11,7 +11,6 @@ import com.guwan.backend.pojo.dto.user.RegisterDTO;
|
|||
import com.guwan.backend.pojo.dto.user.UserDTO;
|
||||
import com.guwan.backend.pojo.entity.User;
|
||||
import com.guwan.backend.pojo.enums.UserEnums;
|
||||
import com.guwan.backend.mapper.BookMapper;
|
||||
import com.guwan.backend.mapper.UserMapper;
|
||||
import com.guwan.backend.mybatis.query.LambdaQueryWrapperX;
|
||||
import com.guwan.backend.service.EmailService;
|
||||
|
@ -43,7 +42,6 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements Us
|
|||
private final RedisUtils redisUtil;
|
||||
private final EmailService emailService;
|
||||
private final SecurityUtil securityUtil;
|
||||
private final BookMapper bookMapper;
|
||||
|
||||
private static final String USER_CACHE_KEY = "user:";
|
||||
private static final long USER_CACHE_DURATION = 3600L; // 1小时
|
||||
|
|
|
@ -1,276 +0,0 @@
|
|||
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.annotation.OperationLog;
|
||||
import com.guwan.backend.pojo.dto.video.VideoDTO;
|
||||
import com.guwan.backend.pojo.entity.Video;
|
||||
import com.guwan.backend.pojo.entity.VideoLike;
|
||||
import com.guwan.backend.mapper.VideoLikeMapper;
|
||||
import com.guwan.backend.mapper.VideoMapper;
|
||||
import com.guwan.backend.service.VideoService;
|
||||
import com.guwan.backend.service.VideoSearchService;
|
||||
import com.guwan.backend.util.MinioUtil;
|
||||
import com.guwan.backend.util.SecurityUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class VideoServiceImpl implements VideoService {
|
||||
|
||||
private final VideoMapper videoMapper;
|
||||
private final MinioUtil minioUtil;
|
||||
private final SecurityUtil securityUtil;
|
||||
private final VideoLikeMapper videoLikeMapper;
|
||||
|
||||
@Autowired(required = false)
|
||||
private VideoSearchService videoSearchService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "上传视频", operationType = "上传")
|
||||
public VideoDTO uploadVideo(String fileUrl, String title, String description, String tags) {
|
||||
// 获取当前用户
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new IllegalStateException("用户未登录");
|
||||
}
|
||||
|
||||
try {
|
||||
// 上传视频文件到MinIO
|
||||
|
||||
String url = fileUrl;
|
||||
|
||||
// 创建视频记录
|
||||
Video video = new Video();
|
||||
video.setTitle(title);
|
||||
video.setDescription(description);
|
||||
video.setUrl(url);
|
||||
// video.setSize(file.getSize());
|
||||
video.setUserId(userId);
|
||||
video.setStatus("PUBLISHED");
|
||||
video.setTags(tags);
|
||||
video.setViewCount(0);
|
||||
video.setLikeCount(0);
|
||||
|
||||
videoMapper.insert(video);
|
||||
|
||||
// 保存到ES
|
||||
updateEs(video);
|
||||
|
||||
return convertToDTO(video);
|
||||
} catch (Exception e) {
|
||||
log.error("上传视频失败", e);
|
||||
throw new RuntimeException("上传视频失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "更新视频信息", operationType = "更新")
|
||||
public VideoDTO updateVideo(VideoDTO videoDTO) {
|
||||
Video video = videoMapper.selectById(videoDTO.getId());
|
||||
if (video == null) {
|
||||
throw new IllegalArgumentException("视频不存在");
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
Long currentUserId = securityUtil.getCurrentUserId();
|
||||
if (!video.getUserId().equals(currentUserId)) {
|
||||
throw new IllegalStateException("无权修改此视频");
|
||||
}
|
||||
|
||||
BeanUtils.copyProperties(videoDTO, video, "id", "userId", "url", "createdTime");
|
||||
videoMapper.updateById(video);
|
||||
|
||||
return convertToDTO(video);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "删除视频", operationType = "删除")
|
||||
public void deleteVideo(Long id) {
|
||||
Video video = videoMapper.selectById(id);
|
||||
if (video == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 检查权限
|
||||
Long currentUserId = securityUtil.getCurrentUserId();
|
||||
if (!video.getUserId().equals(currentUserId)) {
|
||||
throw new IllegalStateException("无权删除此视频");
|
||||
}
|
||||
|
||||
// 从MinIO中删除视频文件
|
||||
String fileName = video.getUrl().substring(video.getUrl().lastIndexOf("/") + 1);
|
||||
minioUtil.deleteFile("videos", fileName);
|
||||
|
||||
// 删除数据库记录
|
||||
videoMapper.deleteById(id);
|
||||
|
||||
// 从ES中删除
|
||||
deleteFromEs(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OperationLog(description = "获取视频详情", operationType = "查询")
|
||||
public VideoDTO getVideoById(Long id) {
|
||||
Video video = videoMapper.selectById(id);
|
||||
return convertToDTO(video);
|
||||
}
|
||||
|
||||
@Override
|
||||
@OperationLog(description = "获取视频列表", operationType = "查询")
|
||||
public IPage<VideoDTO> getVideoList(Integer pageNum, Integer pageSize, String keyword) {
|
||||
Page<Video> page = new Page<>(pageNum, pageSize);
|
||||
|
||||
LambdaQueryWrapper<Video> wrapper = new LambdaQueryWrapper<Video>()
|
||||
.eq(Video::getStatus, "PUBLISHED")
|
||||
.like(keyword != null, Video::getTitle, keyword)
|
||||
.or()
|
||||
.like(keyword != null, Video::getDescription, keyword)
|
||||
.orderByDesc(Video::getCreatedTime);
|
||||
|
||||
IPage<Video> videoPage = videoMapper.selectPage(page, wrapper);
|
||||
|
||||
return videoPage.convert(this::convertToDTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "增加视频观看次数", operationType = "更新")
|
||||
public void incrementViewCount(Long id) {
|
||||
Video video = videoMapper.selectById(id);
|
||||
if (video != null) {
|
||||
video.setViewCount(video.getViewCount() + 1);
|
||||
videoMapper.updateById(video);
|
||||
|
||||
// 更新ES中的观看次数
|
||||
updateEsViewCount(id, video.getViewCount());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@OperationLog(description = "视频点赞/取消点赞", operationType = "更新")
|
||||
public void toggleLike(Long id) {
|
||||
// 获取当前用户
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
throw new IllegalStateException("用户未登录");
|
||||
}
|
||||
|
||||
// 检查视频是否存在
|
||||
Video video = videoMapper.selectById(id);
|
||||
if (video == null) {
|
||||
throw new IllegalArgumentException("视频不存在");
|
||||
}
|
||||
|
||||
// 检查是否已点赞
|
||||
LambdaQueryWrapper<VideoLike> wrapper = new LambdaQueryWrapper<VideoLike>()
|
||||
.eq(VideoLike::getVideoId, id)
|
||||
.eq(VideoLike::getUserId, userId);
|
||||
|
||||
VideoLike like = videoLikeMapper.selectOne(wrapper);
|
||||
|
||||
if (like == null) {
|
||||
// 未点赞,添加点赞记录
|
||||
like = new VideoLike();
|
||||
like.setVideoId(id);
|
||||
like.setUserId(userId);
|
||||
videoLikeMapper.insert(like);
|
||||
|
||||
// 更新视频点赞数
|
||||
video.setLikeCount(video.getLikeCount() + 1);
|
||||
} else {
|
||||
// 已点赞,取消点赞
|
||||
videoLikeMapper.deleteById(like.getId());
|
||||
|
||||
// 更新视频点赞数
|
||||
video.setLikeCount(video.getLikeCount() - 1);
|
||||
}
|
||||
|
||||
videoMapper.updateById(video);
|
||||
|
||||
// 更新ES中的点赞次数
|
||||
updateEsLikeCount(id, video.getLikeCount());
|
||||
}
|
||||
|
||||
// 添加新方法:检查用户是否已点赞
|
||||
public boolean hasLiked(Long videoId) {
|
||||
Long userId = securityUtil.getCurrentUserId();
|
||||
if (userId == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
LambdaQueryWrapper<VideoLike> wrapper = new LambdaQueryWrapper<VideoLike>()
|
||||
.eq(VideoLike::getVideoId, videoId)
|
||||
.eq(VideoLike::getUserId, userId);
|
||||
|
||||
return videoLikeMapper.selectCount(wrapper) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VideoDTO> searchVideosByEs(String keyword) {
|
||||
if (videoSearchService != null) {
|
||||
return videoSearchService.search(keyword);
|
||||
}
|
||||
// 降级到数据库搜索
|
||||
return getVideoList(1, 10, keyword).getRecords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<VideoDTO> getSimilarVideosByEs(Long id, int limit) {
|
||||
if (videoSearchService != null) {
|
||||
return videoSearchService.findSimilar(id, limit);
|
||||
}
|
||||
// 降级到随机推荐
|
||||
return getVideoList(1, limit, null).getRecords();
|
||||
}
|
||||
|
||||
private VideoDTO convertToDTO(Video video) {
|
||||
if (video == null) {
|
||||
return null;
|
||||
}
|
||||
VideoDTO dto = new VideoDTO();
|
||||
BeanUtils.copyProperties(video, dto);
|
||||
|
||||
// 设置是否已点赞
|
||||
// dto.setHasLiked(hasLiked(video.getId()));
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
private void updateEs(Video video) {
|
||||
if (videoSearchService != null) {
|
||||
videoSearchService.saveOrUpdate(video);
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteFromEs(Long id) {
|
||||
if (videoSearchService != null) {
|
||||
videoSearchService.delete(id);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEsViewCount(Long id, Integer viewCount) {
|
||||
if (videoSearchService != null) {
|
||||
videoSearchService.updateViewCount(id, viewCount);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateEsLikeCount(Long id, Integer likeCount) {
|
||||
if (videoSearchService != null) {
|
||||
videoSearchService.updateLikeCount(id, likeCount);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.guwan.backend.mapper.BookCategoryMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="com.guwan.backend.pojo.entity.BookCategory">
|
||||
<id property="id" column="id" jdbcType="TINYINT"/>
|
||||
<result property="categoryName" column="category_name" jdbcType="VARCHAR"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,category_name
|
||||
</sql>
|
||||
</mapper>
|
|
@ -1,8 +1,6 @@
|
|||
package com.guwan.backend.service;
|
||||
|
||||
import com.guwan.backend.pojo.entity.Book;
|
||||
import com.guwan.backend.mapper.BookMapper;
|
||||
import com.guwan.backend.service.impl.BookServiceImpl;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.InjectMocks;
|
||||
|
|
Loading…
Reference in New Issue