增加无效图片清理

This commit is contained in:
xiongxiaoyang 2020-01-06 10:06:47 +08:00
parent 1555c5b170
commit ae8b8d47a9
3 changed files with 28 additions and 2 deletions

View File

@ -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();
}
}
}
}
}

View File

@ -433,4 +433,13 @@ public class BookService {
public List<Book> 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);
}
}

View File

@ -57,7 +57,7 @@
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
<!-- com.maijinjie.springboot 为根包也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
<!-- 级别依次为【从高到低】FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
<logger name="xyz.zinglizingli" level="INFO">
<logger name="xyz.zinglizingli" level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="FILE" />
</logger>