mirror of
https://github.com/201206030/novel-plus.git
synced 2025-06-24 04:46:37 +00:00
实现小说内容多种存储方式(txt、db..)并存
This commit is contained in:
@ -37,10 +37,10 @@ public class BookController extends BaseController {
|
||||
|
||||
private final BookService bookService;
|
||||
|
||||
private final BookContentService bookContentService;
|
||||
|
||||
private final RabbitTemplate rabbitTemplate;
|
||||
|
||||
private final Map<String, BookContentService> bookContentServiceMap;
|
||||
|
||||
@Value("${spring.rabbitmq.enable}")
|
||||
private Integer enableMq;
|
||||
|
||||
@ -130,7 +130,8 @@ public class BookController extends BaseController {
|
||||
public ResultBean<Map<String, Object>> queryBookIndexAbout(Long bookId, Long lastBookIndexId) {
|
||||
Map<String, Object> data = new HashMap<>(2);
|
||||
data.put("bookIndexCount", bookService.queryIndexCount(bookId));
|
||||
String lastBookContent = bookContentService.queryBookContent(bookId,lastBookIndexId).getContent();
|
||||
BookIndex bookIndex = bookService.queryBookIndex(lastBookIndexId);
|
||||
String lastBookContent = bookContentServiceMap.get(bookIndex.getStorageType()).queryBookContent(bookId,lastBookIndexId).getContent();
|
||||
if (lastBookContent.length() > 42) {
|
||||
lastBookContent = lastBookContent.substring(0, 42);
|
||||
}
|
||||
|
@ -45,10 +45,9 @@ public class PageController extends BaseController {
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
private final BookContentService bookContentService;
|
||||
|
||||
private final ThreadPoolExecutor threadPoolExecutor;
|
||||
|
||||
private final Map<String, BookContentService> bookContentServiceMap;
|
||||
|
||||
@RequestMapping("{url}.html")
|
||||
public String module(@PathVariable("url") String url) {
|
||||
@ -210,10 +209,10 @@ public class PageController extends BaseController {
|
||||
return nextBookIndexId;
|
||||
}, threadPoolExecutor);
|
||||
|
||||
//加载小说内容信息线程
|
||||
CompletableFuture<BookContent> bookContentCompletableFuture = CompletableFuture.supplyAsync(() -> {
|
||||
//加载小说内容信息线程,该线程在加载小说章节信息线程执行完毕后才执行
|
||||
CompletableFuture<BookContent> bookContentCompletableFuture = bookIndexCompletableFuture.thenApplyAsync((bookIndex) -> {
|
||||
//查询内容
|
||||
BookContent bookContent = bookContentService.queryBookContent(bookId, bookIndexId);
|
||||
BookContent bookContent = bookContentServiceMap.get(bookIndex.getStorageType()).queryBookContent(bookId, bookIndexId);
|
||||
log.debug("加载小说内容信息线程结束");
|
||||
return bookContent;
|
||||
}, threadPoolExecutor);
|
||||
|
@ -262,7 +262,7 @@ public class BookServiceImpl implements BookService {
|
||||
|
||||
@Override
|
||||
public BookIndex queryBookIndex(Long bookIndexId) {
|
||||
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount,BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip)
|
||||
SelectStatementProvider selectStatement = select(BookIndexDynamicSqlSupport.id, BookIndexDynamicSqlSupport.bookId, BookIndexDynamicSqlSupport.indexNum, BookIndexDynamicSqlSupport.indexName, BookIndexDynamicSqlSupport.wordCount,BookIndexDynamicSqlSupport.bookPrice, BookIndexDynamicSqlSupport.updateTime, BookIndexDynamicSqlSupport.isVip,BookIndexDynamicSqlSupport.storageType)
|
||||
.from(bookIndex)
|
||||
.where(BookIndexDynamicSqlSupport.id, isEqualTo(bookIndexId))
|
||||
.build()
|
||||
|
@ -18,9 +18,8 @@ import static org.mybatis.dynamic.sql.SqlBuilder.update;
|
||||
import static org.mybatis.dynamic.sql.select.SelectDSL.select;
|
||||
|
||||
|
||||
@Service
|
||||
@Service(value = "db")
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "content.save", name = "storage", havingValue = "db")
|
||||
public class DbBookContentServiceImpl implements BookContentService {
|
||||
|
||||
private final BookContentMapper bookContentMapper;
|
||||
|
@ -1,21 +1,17 @@
|
||||
package com.java2nb.novel.service.impl;
|
||||
|
||||
import com.java2nb.novel.core.utils.FileUtil;
|
||||
import com.java2nb.novel.entity.BookContent;
|
||||
import com.java2nb.novel.service.BookContentService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.SneakyThrows;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.FileReader;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
@Service(value = "txt")
|
||||
@RequiredArgsConstructor
|
||||
@ConditionalOnProperty(prefix = "content.save", name = "storage", havingValue = "file")
|
||||
public class FileBookContentServiceImpl implements BookContentService {
|
||||
|
||||
@Value("${content.save.path}")
|
||||
|
Reference in New Issue
Block a user