This commit is contained in:
xxy 2020-05-05 07:45:36 +08:00
parent 7c3fb654bb
commit bc445548ce
3 changed files with 78 additions and 72 deletions

View File

@ -43,15 +43,7 @@ public class Network2LocalPicSchedule {
log.info("Network2LocalPicSchedule。。。。。。。。。。。。"); log.info("Network2LocalPicSchedule。。。。。。。。。。。。");
Integer offset = 0, limit = 100; bookService.networkPicToLocal();
List<Book> networkPicBooks;
do {
networkPicBooks = bookService.queryNetworkPicBooks(limit, offset);
for (Book book : networkPicBooks) {
bookService.updateBook(book, book.getId());
}
offset += limit;
} while (networkPicBooks.size() > 0);
} }

View File

@ -54,10 +54,9 @@ public class BookService {
private String picSavePath; private String picSavePath;
/** /**
* 保存章节目录和内容 * 保存章节目录和内容
* */ */
public void saveBookAndIndexAndContent(Book book, List<BookIndex> bookIndex, List<BookContent> bookContent) { public void saveBookAndIndexAndContent(Book book, List<BookIndex> bookIndex, List<BookContent> bookContent) {
//解决内部调用事物不生效的问题 //解决内部调用事物不生效的问题
BookService bookService = SpringUtil.getBean(BookService.class); BookService bookService = SpringUtil.getBean(BookService.class);
@ -126,7 +125,6 @@ public class BookService {
} }
} }
@ -134,7 +132,7 @@ public class BookService {
/** /**
* 更新书籍 * 更新书籍
* */ */
public void updateBook(Book book, Long bookId) { public void updateBook(Book book, Long bookId) {
book.setId(bookId); book.setId(bookId);
String picSrc = book.getPicUrl(); String picSrc = book.getPicUrl();
@ -150,11 +148,31 @@ public class BookService {
bookMapper.updateByPrimaryKeySelective(book); bookMapper.updateByPrimaryKeySelective(book);
} }
/**
* 网络图片转本地
*/
public void networkPicToLocal() {
Integer offset = 0, limit = 100;
List<Book> networkPicBooks;
do {
networkPicBooks = queryNetworkPicBooks(limit, offset);
for (Book book : networkPicBooks) {
try {
book.setPicUrl(FileUtil.network2Local(book.getPicUrl(), picSavePath));
bookMapper.updateByPrimaryKeySelective(book);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
offset += limit;
} while (networkPicBooks.size() > 0);
}
/** /**
* 批量插入章节目录表和章节内容表自动修复错误章节 * 批量插入章节目录表和章节内容表自动修复错误章节
* */ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void insertIndexListAndContentList(List<BookIndex> newBookIndexList, List<BookContent> newContentList) { public void insertIndexListAndContentList(List<BookIndex> newBookIndexList, List<BookContent> newContentList) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@ -179,7 +197,7 @@ public class BookService {
/** /**
* 生成随机访问次数 * 生成随机访问次数
* */ */
private Long generateVisitCount(Float score) { private Long generateVisitCount(Float score) {
int baseNum = (int) (score * 100); int baseNum = (int) (score * 100);
return Long.parseLong(baseNum + new Random().nextInt(1000) + ""); return Long.parseLong(baseNum + new Random().nextInt(1000) + "");
@ -206,10 +224,9 @@ public class BookService {
} }
/** /**
* 查询书籍的基础数据 * 查询书籍的基础数据
* */ */
public Book queryBaseInfo(Long bookId) { public Book queryBaseInfo(Long bookId) {
return bookMapper.selectByPrimaryKey(bookId); return bookMapper.selectByPrimaryKey(bookId);
@ -217,7 +234,7 @@ public class BookService {
/** /**
* 查询最新更新的书籍列表 * 查询最新更新的书籍列表
* */ */
public List<BookIndex> queryNewIndexList(Long bookId) { public List<BookIndex> queryNewIndexList(Long bookId) {
PageHelper.startPage(1, 15); PageHelper.startPage(1, 15);
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
@ -229,7 +246,7 @@ public class BookService {
/** /**
* 查询书籍目录列表 * 查询书籍目录列表
* */ */
public List<BookIndex> queryAllIndexList(Long bookId) { public List<BookIndex> queryAllIndexList(Long bookId) {
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
example.createCriteria().andBookIdEqualTo(bookId); example.createCriteria().andBookIdEqualTo(bookId);
@ -239,7 +256,7 @@ public class BookService {
/** /**
* 查询书籍章节内容 * 查询书籍章节内容
* */ */
public BookContent queryBookContent(Long bookId, Integer indexNum) { public BookContent queryBookContent(Long bookId, Integer indexNum) {
BookContent content = (BookContent) cacheUtil.getObject(CacheKeyConstans.BOOK_CONTENT_KEY_PREFIX + "_" + bookId + "_" + indexNum); BookContent content = (BookContent) cacheUtil.getObject(CacheKeyConstans.BOOK_CONTENT_KEY_PREFIX + "_" + bookId + "_" + indexNum);
if (content == null) { if (content == null) {
@ -256,7 +273,7 @@ public class BookService {
/** /**
* 增加访问次数 * 增加访问次数
* */ */
public void addVisitCount(Long bookId, String userId, Integer indexNum) { public void addVisitCount(Long bookId, String userId, Integer indexNum) {
bookMapper.addVisitCount(bookId); bookMapper.addVisitCount(bookId);
@ -269,7 +286,7 @@ public class BookService {
/** /**
* 查询章节名 * 查询章节名
* */ */
public String queryIndexNameByBookIdAndIndexNum(Long bookId, Integer indexNum) { public String queryIndexNameByBookIdAndIndexNum(Long bookId, Integer indexNum) {
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
@ -283,7 +300,7 @@ public class BookService {
/** /**
* 查询最大和最小章节号 * 查询最大和最小章节号
* */ */
public List<Integer> queryMaxAndMinIndexNum(Long bookId) { public List<Integer> queryMaxAndMinIndexNum(Long bookId) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
@ -321,11 +338,9 @@ public class BookService {
} }
/** /**
* 保存弹幕 * 保存弹幕
* */ */
public void sendBullet(Long contentId, String bullet) { public void sendBullet(Long contentId, String bullet) {
ScreenBullet screenBullet = new ScreenBullet(); ScreenBullet screenBullet = new ScreenBullet();
@ -338,7 +353,7 @@ public class BookService {
/** /**
* 查询弹幕 * 查询弹幕
* */ */
public List<ScreenBullet> queryBullet(Long contentId) { public List<ScreenBullet> queryBullet(Long contentId) {
ScreenBulletExample example = new ScreenBulletExample(); ScreenBulletExample example = new ScreenBulletExample();
@ -351,7 +366,7 @@ public class BookService {
/** /**
* 查询章节内容 * 查询章节内容
* */ */
public String queryContentList(Long bookId, int count) { public String queryContentList(Long bookId, int count) {
BookContentExample example = new BookContentExample(); BookContentExample example = new BookContentExample();
example.createCriteria().andBookIdEqualTo(bookId).andIndexNumEqualTo(count); example.createCriteria().andBookIdEqualTo(bookId).andIndexNumEqualTo(count);
@ -360,7 +375,7 @@ public class BookService {
/** /**
* 查询章节数 * 查询章节数
* */ */
public int countIndex(Long bookId) { public int countIndex(Long bookId) {
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
example.createCriteria().andBookIdEqualTo(bookId); example.createCriteria().andBookIdEqualTo(bookId);
@ -368,11 +383,9 @@ public class BookService {
} }
/** /**
* 查询前一章节和后一章节号 * 查询前一章节和后一章节号
* */ */
public List<Integer> queryPreAndNextIndexNum(Long bookId, Integer indexNum) { public List<Integer> queryPreAndNextIndexNum(Long bookId, Integer indexNum) {
List<Integer> result = new ArrayList<>(); List<Integer> result = new ArrayList<>();
BookIndexExample example = new BookIndexExample(); BookIndexExample example = new BookIndexExample();
@ -399,14 +412,14 @@ public class BookService {
/** /**
* 查询推荐书籍数据 * 查询推荐书籍数据
* */ */
public List<Book> queryRecBooks(List<Map<String, String>> configMap) { public List<Book> queryRecBooks(List<Map<String, String>> configMap) {
return bookMapper.queryRecBooks(configMap); return bookMapper.queryRecBooks(configMap);
} }
/** /**
* 清理数据库中无效数据 * 清理数据库中无效数据
* */ */
public void clearInvilidData() { public void clearInvilidData() {
//清除无效内容 //清除无效内容
@ -423,14 +436,15 @@ public class BookService {
* 查询网络图片的小说 * 查询网络图片的小说
* *
* @param limit * @param limit
* @param offset*/ * @param offset
*/
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) { public int countByPicName(String fileName) {
BookExample bookExample = new BookExample(); BookExample bookExample = new BookExample();
bookExample.createCriteria().andPicUrlLike('%' + fileName + '%'); bookExample.createCriteria().andPicUrlLike('%' + fileName + '%');
@ -439,7 +453,7 @@ public class BookService {
/** /**
* 添加解析日志 * 添加解析日志
* */ */
public void addBookParseLog(String bookUrl, String bookName, Float score, Byte priority) { public void addBookParseLog(String bookUrl, String bookName, Float score, Byte priority) {
BookParseLogExample example = new BookParseLogExample(); BookParseLogExample example = new BookParseLogExample();
example.createCriteria().andBookUrlEqualTo(bookUrl).andCreateTimeGreaterThan(new Date(System.currentTimeMillis() - 1000 * 60 * 60)); example.createCriteria().andBookUrlEqualTo(bookUrl).andCreateTimeGreaterThan(new Date(System.currentTimeMillis() - 1000 * 60 * 60));
@ -456,7 +470,7 @@ public class BookService {
/** /**
* 查询解析日志 * 查询解析日志
* */ */
public List<BookParseLog> queryBookParseLogs() { public List<BookParseLog> queryBookParseLogs() {
List<BookParseLog> logs = bookParseLogMapper.queryBookParseLogs(); List<BookParseLog> logs = bookParseLogMapper.queryBookParseLogs();
SpringUtil.getBean(BookService.class).addBookUpdateCount(logs); SpringUtil.getBean(BookService.class).addBookUpdateCount(logs);
@ -465,7 +479,7 @@ public class BookService {
/** /**
* 增加小说更新次数 * 增加小说更新次数
* */ */
@Async @Async
public void addBookUpdateCount(List<BookParseLog> logs) { public void addBookUpdateCount(List<BookParseLog> logs) {
bookParseLogMapper.addBookUpdateCount(logs); bookParseLogMapper.addBookUpdateCount(logs);
@ -473,7 +487,7 @@ public class BookService {
/** /**
* 删除已经成功更新的解析日志 * 删除已经成功更新的解析日志
* */ */
public void deleteBookParseLogs(List<Long> successLogIds) { public void deleteBookParseLogs(List<Long> successLogIds) {
if (successLogIds.size() > 0) { if (successLogIds.size() > 0) {
BookParseLogExample example = new BookParseLogExample(); BookParseLogExample example = new BookParseLogExample();
@ -484,7 +498,7 @@ public class BookService {
/** /**
* 查询书籍是否存在 * 查询书籍是否存在
* */ */
public Boolean hasBook(String bookName, String author) { public Boolean hasBook(String bookName, String author) {
BookExample example = new BookExample(); BookExample example = new BookExample();
example.createCriteria().andBookNameEqualTo(bookName).andAuthorEqualTo(author); example.createCriteria().andBookNameEqualTo(bookName).andAuthorEqualTo(author);
@ -493,7 +507,7 @@ public class BookService {
/** /**
* 查询分类更新时间映射信息 * 查询分类更新时间映射信息
* */ */
public Map<Integer, Date> queryLastUpdateTime() { public Map<Integer, Date> queryLastUpdateTime() {
List<BookUpdateTimeLog> list = bookUpdateTimeLogMapper.selectByExample(new BookUpdateTimeLogExample()); List<BookUpdateTimeLog> list = bookUpdateTimeLogMapper.selectByExample(new BookUpdateTimeLogExample());
@ -503,7 +517,7 @@ public class BookService {
/** /**
* 更新分类时间日志 * 更新分类时间日志
* */ */
public void updateBookUpdateTimeLog(Map<Integer, Date> cat2Date) { public void updateBookUpdateTimeLog(Map<Integer, Date> cat2Date) {
if (cat2Date.size() > 0) { if (cat2Date.size() > 0) {
Set<Map.Entry<Integer, Date>> entries = cat2Date.entrySet(); Set<Map.Entry<Integer, Date>> entries = cat2Date.entrySet();
@ -520,7 +534,7 @@ public class BookService {
/** /**
* 删除已经成功更新的解析日志 * 删除已经成功更新的解析日志
* */ */
public void deleteBookParseLog(Long id) { public void deleteBookParseLog(Long id) {
bookParseLogMapper.deleteByPrimaryKey(id); bookParseLogMapper.deleteByPrimaryKey(id);
@ -528,7 +542,7 @@ public class BookService {
/** /**
* 查询数据库书籍数量 * 查询数据库书籍数量
* */ */
public int queryBookNumber() { public int queryBookNumber() {
Integer bookNumber = (Integer) cacheUtil.getObject(CacheKeyConstans.BOOK_NUMBER_KEY); Integer bookNumber = (Integer) cacheUtil.getObject(CacheKeyConstans.BOOK_NUMBER_KEY);

View File

@ -5,7 +5,7 @@ spring:
datasource: datasource:
url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf-8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
username: root username: root
password: test123456 password:
# url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai # url: jdbc:mysql://127.0.0.1:3306/books?useUnicode=true&characterEncoding=utf8&useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=Asia/Shanghai
# username: root # username: root
# password: test123456 # password: test123456
@ -96,7 +96,7 @@ crawl:
pic: pic:
save: save:
type: 1 #图片保存方式, 1不保存使用网络图片 2本地保存 type: 2 #图片保存方式, 1不保存使用网络图片 2本地保存
path: /var/pic #图片保存路径 path: /var/pic #图片保存路径