use of me.zhyd.hunter.util.HunterPrintWriter in project OneBlog by zhangyd-c.
the class RemoverServiceImpl method run.
@Transactional(rollbackFor = Exception.class)
@Override
public void run(Long typeId, @Validated HunterConfig config, PrintWriter writer) {
HunterPrintWriter writerUtil = new HunterPrintWriter(writer);
long start = System.currentTimeMillis();
if (null == typeId) {
writerUtil.print("校验不通过!请选择文章分类......", String.format("共耗时 %s ms.", (System.currentTimeMillis() - start)));
writerUtil.shutdown();
return;
}
HunterProcessor hunter = new BlogHunterProcessor(config, writerUtil, String.valueOf(SessionUtil.getUser().getId()));
CopyOnWriteArrayList<VirtualArticle> list = hunter.execute();
if (CollectionUtils.isEmpty(list)) {
writerUtil.print(String.format("未抓取到任何内容,请确保连接[<a href=\"%s\" target=\"_blank\">%s</a>]是否正确并能正常访问!共耗时 %s ms.", config.getEntryUrls().get(0), config.getEntryUrls().get(0), (System.currentTimeMillis() - start))).shutdown();
return;
}
writerUtil.print("Congratulation ! 此次共整理到" + list.size() + "篇文章");
saveArticles(typeId, config, writerUtil, list);
writerUtil.print(String.format("搬家完成!耗时 %s ms.", (System.currentTimeMillis() - start)));
writerUtil.shutdown();
}
use of me.zhyd.hunter.util.HunterPrintWriter in project OneBlog by zhangyd-c.
the class RemoverServiceImpl method crawlSingle.
@Transactional(rollbackFor = Exception.class)
@Override
public void crawlSingle(Long typeId, String[] urls, boolean convertImg, PrintWriter writer) {
HunterPrintWriter writerUtil = new HunterPrintWriter(writer);
for (String url : urls) {
HunterProcessor hunter = new BlogHunterProcessor(url, convertImg, writerUtil);
CopyOnWriteArrayList<VirtualArticle> list = hunter.execute();
this.saveArticles(typeId, hunter.getConfig(), writerUtil, list);
}
writerUtil.shutdown();
}
use of me.zhyd.hunter.util.HunterPrintWriter in project OneBlog by zhangyd-c.
the class RemoverServiceImpl method saveArticles.
private void saveArticles(Long typeId, HunterConfig config, HunterPrintWriter writerUtil, CopyOnWriteArrayList<VirtualArticle> list) {
// 获取数据库中的标签列表
List<Tags> tags = tagsService.listAll();
Map<String, Long> originalTags = tags.stream().collect(Collectors.toMap(tag -> tag.getName().toUpperCase(), Tags::getId));
User user = SessionUtil.getUser();
// 添加文章到数据库
Article article = null;
for (VirtualArticle spiderVirtualArticle : list) {
article = this.saveArticle(typeId, config.isConvertImg(), writerUtil, user, spiderVirtualArticle);
this.saveTags(writerUtil, originalTags, article, spiderVirtualArticle);
}
}
Aggregations