diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/core/crawl/BiquCrawlSource.java b/novel-front/src/main/java/xyz/zinglizingli/books/core/crawl/BiquCrawlSource.java index 95b7272..7fe3ec6 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/core/crawl/BiquCrawlSource.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/core/crawl/BiquCrawlSource.java @@ -55,9 +55,13 @@ public class BiquCrawlSource extends BaseHtmlCrawlSource { Matcher bookNameMatch = bookNamePatten.matcher(forObject); + Pattern authorPatten = compile(getAuthorPattern()); + + Matcher authorMatch = authorPatten.matcher(forObject); + boolean isBookNameMatch = bookNameMatch.find(); - while (isFind && scoreFind && isBookNameMatch) { + while (isFind && scoreFind && isBookNameMatch && authorMatch.find()) { try { Float score = Float.parseFloat(scoreMatch.group(1)); @@ -71,7 +75,14 @@ public class BiquCrawlSource extends BaseHtmlCrawlSource { String bookName = bookNameMatch.group(1); - bookService.addBookParseLog(bookUrl, bookName, score); + String author = authorMatch.group(1); + + Boolean hasBook = bookService.hasBook(bookName, author); + + if(hasBook) { + + bookService.addBookParseLog(bookUrl, bookName, score); + } } catch (Exception e) { diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java b/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java index 8bfe558..072ac5f 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/service/BookService.java @@ -482,4 +482,13 @@ public class BookService { bookParseLogMapper.deleteByExample(example); } } + + /** + * 查询书籍是否存在 + * */ + public Boolean hasBook(String bookName, String author) { + BookExample example = new BookExample(); + example.createCriteria().andBookNameEqualTo(bookName).andAuthorEqualTo(author); + return bookMapper.countByExample(example)>0; + } } diff --git a/novel-front/src/main/resources/application.yml b/novel-front/src/main/resources/application.yml index 5bfbc8d..1d3681b 100644 --- a/novel-front/src/main/resources/application.yml +++ b/novel-front/src/main/resources/application.yml @@ -3,9 +3,9 @@ server: spring: datasource: - url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai - username: root - password: test123456 + url: jdbc:mysql://47.106.243.172:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai + username: books + password: books!8888 # url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai # username: root # password: test123456