From ae8b8d47a9effdcab23ad14b29e207c088c2a1af Mon Sep 17 00:00:00 2001 From: xiongxiaoyang <773861846@qq.com> Date: Mon, 6 Jan 2020 10:06:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=97=A0=E6=95=88=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=B8=85=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/ClearInvilidDataSchedule.java | 19 ++++++++++++++++++- .../books/service/BookService.java | 9 +++++++++ .../src/main/resources/logback-boot.xml | 2 +- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/novel-front/src/main/java/xyz/zinglizingli/books/core/schedule/ClearInvilidDataSchedule.java b/novel-front/src/main/java/xyz/zinglizingli/books/core/schedule/ClearInvilidDataSchedule.java index 7174e8a..a67a761 100644 --- a/novel-front/src/main/java/xyz/zinglizingli/books/core/schedule/ClearInvilidDataSchedule.java +++ b/novel-front/src/main/java/xyz/zinglizingli/books/core/schedule/ClearInvilidDataSchedule.java @@ -8,6 +8,8 @@ import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Service; import xyz.zinglizingli.books.service.BookService; +import java.io.File; + /** * 清理数据库中无效数据 * @@ -32,8 +34,23 @@ public class ClearInvilidDataSchedule { bookService.clearInvilidData(); - + clearInvilidFile(new File(picSavePath)); } + + private void clearInvilidFile(File directory) { + for(File file : directory.listFiles()){ + if(file.isDirectory()){ + clearInvilidFile(file); + }else{ + String fileName = file.getName(); + int count = bookService.countByPicName(fileName); + if(count == 0){ + file.deleteOnExit(); + } + } + } + + } } 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 de6ef47..0d9d090 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 @@ -433,4 +433,13 @@ public class BookService { public List queryNetworkPicBooks(Integer limit, Integer offset) { return bookMapper.queryNetworkPicBooks(limit,offset); } + + /** + * 通过图片名查询小说数量 + * */ + public int countByPicName(String fileName) { + BookExample bookExample = new BookExample(); + bookExample.createCriteria().andPicUrlLike('%'+fileName+'%'); + return bookMapper.countByExample(bookExample); + } } diff --git a/novel-front/src/main/resources/logback-boot.xml b/novel-front/src/main/resources/logback-boot.xml index d3bdf39..d185bae 100644 --- a/novel-front/src/main/resources/logback-boot.xml +++ b/novel-front/src/main/resources/logback-boot.xml @@ -57,7 +57,7 @@ - +