mirror of
https://github.com/201206030/novel-plus.git
synced 2025-04-26 17:20:52 +00:00
bug修复
This commit is contained in:
parent
ca798314e3
commit
4d5cd12b92
@ -46,8 +46,4 @@ public interface CacheKey {
|
|||||||
* */
|
* */
|
||||||
String RUNNING_CRAWL_THREAD_KEY_PREFIX = "runningCrawlTreadDataKeyPrefix";
|
String RUNNING_CRAWL_THREAD_KEY_PREFIX = "runningCrawlTreadDataKeyPrefix";
|
||||||
|
|
||||||
/**
|
|
||||||
* 标记小说是否正在入库
|
|
||||||
* */
|
|
||||||
String NEW_BOOK_IN_SAVE = "newBookInSave";
|
|
||||||
}
|
}
|
@ -26,7 +26,6 @@ public class CrawlParser {
|
|||||||
public static final Integer BOOK_INDEX_LIST_KEY = 1;
|
public static final Integer BOOK_INDEX_LIST_KEY = 1;
|
||||||
|
|
||||||
public static final Integer BOOK_CONTENT_LIST_KEY = 2;
|
public static final Integer BOOK_CONTENT_LIST_KEY = 2;
|
||||||
private static final Integer BOOK_KEY = 3;
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public static Book parseBook(RuleBean ruleBean, String bookId) {
|
public static Book parseBook(RuleBean ruleBean, String bookId) {
|
||||||
|
@ -5,7 +5,6 @@ import com.java2nb.novel.entity.BookContent;
|
|||||||
import com.java2nb.novel.entity.BookIndex;
|
import com.java2nb.novel.entity.BookIndex;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -25,10 +24,10 @@ public interface BookService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 更新书籍的爬虫属性
|
* 更新书籍的爬虫属性
|
||||||
|
* @param id 本站小说ID
|
||||||
* @param sourceId 爬虫源ID
|
* @param sourceId 爬虫源ID
|
||||||
* @param bookId 源站小说ID
|
* @param bookId 源站小说ID */
|
||||||
* */
|
void updateCrawlProperties(Long id, Integer sourceId, String bookId);
|
||||||
void updateCrawlProperties(Integer sourceId, String bookId);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过分类ID查询分类名
|
* 通过分类ID查询分类名
|
||||||
@ -74,4 +73,12 @@ public interface BookService {
|
|||||||
* @param bookId 小说ID
|
* @param bookId 小说ID
|
||||||
* */
|
* */
|
||||||
void updateCrawlLastTime(Long bookId);
|
void updateCrawlLastTime(Long bookId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过小说名和作者名查询已存在的书籍
|
||||||
|
* @param bookName 小说名
|
||||||
|
* @param authorName 作者名
|
||||||
|
* @return 小说对象
|
||||||
|
* */
|
||||||
|
Book queryBookByBookNameAndAuthorName(String bookName, String authorName);
|
||||||
}
|
}
|
||||||
|
@ -51,12 +51,13 @@ public class BookServiceImpl implements BookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateCrawlProperties(Integer sourceId, String bookId) {
|
public void updateCrawlProperties(Long id, Integer sourceId, String bookId) {
|
||||||
bookMapper.update(update(BookDynamicSqlSupport.book)
|
bookMapper.update(update(BookDynamicSqlSupport.book)
|
||||||
.set(crawlSourceId)
|
.set(crawlSourceId)
|
||||||
.equalTo(sourceId)
|
.equalTo(sourceId)
|
||||||
.set(crawlBookId)
|
.set(crawlBookId)
|
||||||
.equalTo(bookId)
|
.equalTo(bookId)
|
||||||
|
.where(BookDynamicSqlSupport.id,isEqualTo(id))
|
||||||
.build()
|
.build()
|
||||||
.render(RenderingStrategies.MYBATIS3));
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
}
|
}
|
||||||
@ -176,6 +177,22 @@ public class BookServiceImpl implements BookService {
|
|||||||
bookMapper.updateByPrimaryKeySelective(book);
|
bookMapper.updateByPrimaryKeySelective(book);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Book queryBookByBookNameAndAuthorName(String bookName, String authorName) {
|
||||||
|
List<Book> books = bookMapper.selectMany(select(BookDynamicSqlSupport.id).from(BookDynamicSqlSupport.book)
|
||||||
|
.where(BookDynamicSqlSupport.bookName, isEqualTo(bookName))
|
||||||
|
.and(BookDynamicSqlSupport.authorName, isEqualTo(authorName))
|
||||||
|
.build()
|
||||||
|
.render(RenderingStrategies.MYBATIS3));
|
||||||
|
|
||||||
|
if(books.size()>0){
|
||||||
|
return books.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询最后的章节
|
* 查询最后的章节
|
||||||
* */
|
* */
|
||||||
|
@ -168,11 +168,10 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
String bookId = bookIdMatcher.group(1);
|
String bookId = bookIdMatcher.group(1);
|
||||||
Book book = CrawlParser.parseBook(ruleBean, bookId);
|
Book book = CrawlParser.parseBook(ruleBean, bookId);
|
||||||
//这里只做新书入库,查询是否存在这本书
|
//这里只做新书入库,查询是否存在这本书
|
||||||
boolean isExist = bookService.queryIsExistByBookNameAndAuthorName(book.getBookName(), book.getAuthorName());
|
Book existBook = bookService.queryBookByBookNameAndAuthorName(book.getBookName(), book.getAuthorName());
|
||||||
//如果该小说不存在,则可以解析入库,但是标记该小说正在入库,30分钟之后才允许再次入库
|
//如果该小说不存在,则可以解析入库,但是标记该小说正在入库,30分钟之后才允许再次入库
|
||||||
if (!isExist && StringUtils.isBlank(cacheService.get(CacheKey.NEW_BOOK_IN_SAVE + book.getBookName() + "-" + book.getAuthorName()))) {
|
if (existBook == null) {
|
||||||
//没有该书,可以入库
|
//没有该书,可以入库
|
||||||
cacheService.set(CacheKey.NEW_BOOK_IN_SAVE + book.getBookName() + "-" + book.getAuthorName(), "true", 60 * 30);
|
|
||||||
book.setCatId(catId);
|
book.setCatId(catId);
|
||||||
//根据分类ID查询分类
|
//根据分类ID查询分类
|
||||||
book.setCatName(bookService.queryCatNameByCatId(catId));
|
book.setCatName(bookService.queryCatNameByCatId(catId));
|
||||||
@ -194,7 +193,7 @@ public class CrawlServiceImpl implements CrawlService {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
//只更新书籍的爬虫相关字段
|
//只更新书籍的爬虫相关字段
|
||||||
bookService.updateCrawlProperties(sourceId, bookId);
|
bookService.updateCrawlProperties(existBook.getId(),sourceId, bookId);
|
||||||
}
|
}
|
||||||
}catch (Exception e){
|
}catch (Exception e){
|
||||||
log.error(e.getMessage(),e);
|
log.error(e.getMessage(),e);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user