use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class AmazonScheduler method startFullUpdate.
private void startFullUpdate() {
LOGGER.info("[开始更新Amazon(ALL)数据]");
updateFullUpdateTime();
LinkedHashSet<Disc> discs = new LinkedHashSet<>();
LinkedHashMap<String, Integer> results = new LinkedHashMap<>();
dao.execute(session -> {
findActiveSakura(session).forEach(sakura -> {
findAmazonDiscs(sakura).filter(needUpdate()).forEach(discs::add);
});
});
if (discs.size() > 0) {
AtomicInteger updateCount = new AtomicInteger(discs.size());
LOGGER.info("[正在更新Amazon(ALL)数据][共{}个]", discs.size());
discs.stream().sorted().forEach(disc -> {
service.createRankTask(disc.getAsin(), fullUpdateCB(discs, results, updateCount));
});
} else {
LOGGER.info("[结束更新Amazon(ALL)数据][未找到可以更新的Amazon(ALL)数据]");
amazonFetchStatus = AmazonFetchStatus.waitingForUpdate;
}
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class AmazonScheduler method finishTheUpdate.
private void finishTheUpdate(Set<Disc> discs, Map<String, Integer> results) {
LOGGER.info("[正在写入Amazon(ALL)数据]]");
dao.execute(session -> {
discs.forEach(disc -> {
Integer rank = results.get(disc.getAsin());
dao.refresh(disc);
disc.setPrevRank(disc.getThisRank());
if (rank != null) {
disc.setThisRank(rank);
disc.setUpdateTime(fullUpdateTime.get());
}
if (!Objects.equals(disc.getThisRank(), disc.getPrevRank())) {
disc.setModifyTime(fullUpdateTime.get());
}
});
dao.findAll(Sakura.class).stream().filter(sakura -> sakura.getViewType() != ViewType.SakuraList).forEach(sakura -> {
sakura.setModifyTime(fullUpdateTime.get());
});
});
LOGGER.info("[成功更新Amazon(ALL)数据]");
service.infoStatus();
amazonFetchStatus = AmazonFetchStatus.waitingForUpdate;
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class SakuraSpeedSpider method updateSakuraDiscs.
private void updateSakuraDiscs(Sakura sakura, Stream<Element> tableRows) {
Set<Disc> toAdd = new LinkedHashSet<>(sakura.getDiscs().size());
boolean isTop100 = "9999-99".equals(sakura.getKey());
tableRows.forEach(tr -> {
String href = tr.child(5).child(0).attr("href");
String asin = href.substring(href.length() - 10);
Disc disc = getOrCreateDisc(asin, tr);
if (disc.getUpdateType() == UpdateType.Both && !isTop100) {
disc.setUpdateType(UpdateType.Sakura);
}
if (disc.getUpdateType() == UpdateType.Sakura) {
String[] sakuraRank = tr.child(0).text().split("/");
disc.setThisRank(parseInteger(sakuraRank[0]));
disc.setPrevRank(parseInteger(sakuraRank[1]));
disc.setTotalPt(parseInteger(tr.child(2).text()));
disc.setNicoBook(parseInteger(tr.child(3).text()));
disc.setUpdateTime(sakura.getModifyTime());
if (!Objects.equals(disc.getThisRank(), disc.getPrevRank())) {
disc.setModifyTime(sakura.getModifyTime());
}
}
toAdd.add(disc);
});
if (isTop100) {
sakura.setDiscs(new LinkedList<>(toAdd));
} else {
boolean noExpiredSakura = noExpiredSakura(sakura);
sakura.getDiscs().stream().filter(disc -> {
return disc.getUpdateType() != UpdateType.Sakura || noExpiredSakura;
}).filter(disc -> !toAdd.contains(disc)).forEach(disc -> {
if (disc.getUpdateType() == UpdateType.Sakura) {
disc.setUpdateType(UpdateType.Both);
}
toAdd.add(disc);
});
sakura.setDiscs(toAdd.stream().sorted().collect(Collectors.toList()));
}
LOGGER.debug("成功更新[{}]列表", sakura.getTitle());
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class SakuraSpeedSpider method getOrCreateDisc.
private Disc getOrCreateDisc(String asin, Element tr) {
Disc disc = dao.lookup(Disc.class, "asin", asin);
if (disc == null) {
String title = titleOfDisc(tr.child(5).text());
String typeIcon = tr.child(1).text();
String dateText = tr.child(4).text();
LocalDate releaseDate = parseDate(fixYear(dateText));
disc = new Disc(asin, title, parseDiscType(typeIcon), UpdateType.Sakura, isAmazonLimit(title), releaseDate);
dao.save(disc);
LOGGER.info("发现了新的碟片, title={}", disc.getTitle());
}
return disc;
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class SakuraController method findDiscs.
@Transactional
@GetMapping(value = "/api/sakuras/key/{key}/discs", produces = MEDIA_TYPE)
public String findDiscs(@PathVariable String key, @RequestParam(defaultValue = DISC_COLUMNS) String discColumns, @RequestParam(name = "public", defaultValue = "true") boolean isPublic) {
Sakura sakura = dao.lookup(Sakura.class, "key", key);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[获取列表碟片失败][指定的列表索引不存在][key={}]", key);
}
return errorMessage("指定的列表索引不存在");
}
JSONObject result = sakura.toJSON();
JSONArray discs = new JSONArray();
sakura.getDiscs().stream().filter(disc -> !isPublic || disc.getUpdateType() != UpdateType.None).forEach(disc -> discs.put(disc.toJSON(getColumns(discColumns))));
result.put("discs", discs);
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取列表碟片成功][列表标题={}][碟片数量={}]", sakura.getTitle(), sakura.getDiscs().size());
}
return objectResult(result);
}
Aggregations