use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraSpeedSpider method updateSakura.
private void updateSakura(Element table, String timeText) {
dao.execute(session -> {
Sakura sakura = getOrCreateSakura(findSakuraKey(table));
if (timeText.equals("更新中")) {
LOGGER.info("发现sakura网站更新中");
return;
}
LocalDateTime time = parseTime(timeText);
if (time.equals(sakura.getModifyTime())) {
LOGGER.debug("不需要更新[{}]列表", sakura.getTitle());
return;
}
sakura.setEnabled(true);
sakura.setViewType(ViewType.SakuraList);
sakura.setModifyTime(time);
updateSakuraDiscs(sakura, table.select("tr").stream().skip(1));
});
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class SakuraSpeedSpider method getOrCreateSakura.
private Sakura getOrCreateSakura(String key) {
Sakura sakura = dao.lookup(Sakura.class, "key", key);
if (sakura == null) {
sakura = new Sakura(key, null, true, ViewType.SakuraList);
dao.save(sakura);
LOGGER.info("发现新的Sakura列表, title={}", sakura.getTitle());
}
return sakura;
}
use of mingzuozhibi.persist.disc.Sakura in project mzzb-server by mingzuozhibi.
the class HourlyMission method recordDiscsRankAndComputePt.
public void recordDiscsRankAndComputePt() {
// +9 timezone and prev hour, so +1h -1h = +0h
LocalDateTime recordTime = LocalDateTime.now();
LocalDate date = recordTime.toLocalDate();
int hour = recordTime.getHour();
dao.execute(session -> {
@SuppressWarnings("unchecked") List<Sakura> sakuras = session.createCriteria(Sakura.class).add(Restrictions.ne("key", "9999-99")).add(Restrictions.eq("enabled", true)).list();
Set<Disc> discs = new LinkedHashSet<>();
sakuras.forEach(sakura -> {
sakura.getDiscs().stream().filter(disc -> disc.getUpdateType() != UpdateType.None).filter(SakuraHelper::noExpiredDisc).forEach(discs::add);
});
LOGGER.info("[定时任务][记录碟片排名][碟片数量为:{}]", discs.size());
discs.forEach(disc -> {
Record record = getOrCreateRecord(dao, disc, date);
record.setRank(hour, disc.getThisRank());
record.setTotalPt(disc.getTotalPt());
});
LOGGER.info("[定时任务][计算碟片PT][碟片数量为:{}]", discs.size());
discs.forEach(disc -> {
if (disc.getUpdateType() != UpdateType.Sakura) {
computeAndUpdateAmazonPt(dao, disc);
} else {
computeAndUpdateSakuraPt(dao, disc);
}
});
});
}
Aggregations