From f403870d48ad3d62039b29823ad7ab062b9052d0 Mon Sep 17 00:00:00 2001
From: xiongxiaoyang <773861846@qq.com>
Date: Mon, 13 Jan 2020 11:53:38 +0800
Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=AD=96=E7=95=A5=E8=B0=83?=
 =?UTF-8?q?=E6=95=B4?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../books/core/crawl/BiquCrawlSource.java         | 15 +++++++++++++--
 .../zinglizingli/books/service/BookService.java   |  9 +++++++++
 novel-front/src/main/resources/application.yml    |  6 +++---
 3 files changed, 25 insertions(+), 5 deletions(-)

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