mirror of
https://github.com/201206030/novel.git
synced 2025-04-27 07:30:50 +00:00
增加无效图片清理
This commit is contained in:
parent
1555c5b170
commit
ae8b8d47a9
@ -8,6 +8,8 @@ import org.springframework.scheduling.annotation.Scheduled;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import xyz.zinglizingli.books.service.BookService;
|
import xyz.zinglizingli.books.service.BookService;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 清理数据库中无效数据
|
* 清理数据库中无效数据
|
||||||
*
|
*
|
||||||
@ -32,8 +34,23 @@ public class ClearInvilidDataSchedule {
|
|||||||
|
|
||||||
bookService.clearInvilidData();
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -433,4 +433,13 @@ public class BookService {
|
|||||||
public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) {
|
public List<Book> queryNetworkPicBooks(Integer limit, Integer offset) {
|
||||||
return bookMapper.queryNetworkPicBooks(limit,offset);
|
return bookMapper.queryNetworkPicBooks(limit,offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过图片名查询小说数量
|
||||||
|
* */
|
||||||
|
public int countByPicName(String fileName) {
|
||||||
|
BookExample bookExample = new BookExample();
|
||||||
|
bookExample.createCriteria().andPicUrlLike('%'+fileName+'%');
|
||||||
|
return bookMapper.countByExample(bookExample);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@
|
|||||||
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
<!-- 指定项目中某个包,当有日志操作行为时的日志记录级别 -->
|
||||||
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
<!-- com.maijinjie.springboot 为根包,也就是只要是发生在这个根包下面的所有日志操作行为的权限都是DEBUG -->
|
||||||
<!-- 级别依次为【从高到低】:FATAL > ERROR > WARN > INFO > DEBUG > TRACE -->
|
<!-- 级别依次为【从高到低】: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="STDOUT" />
|
||||||
<appender-ref ref="FILE" />
|
<appender-ref ref="FILE" />
|
||||||
</logger>
|
</logger>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user