Search in sources :

Example 11 with Sakura

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));
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) SakuraHelper.noExpiredSakura(mingzuozhibi.support.SakuraHelper.noExpiredSakura) Sakura(mingzuozhibi.persist.disc.Sakura)

Example 12 with Sakura

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;
}
Also used : SakuraHelper.noExpiredSakura(mingzuozhibi.support.SakuraHelper.noExpiredSakura) Sakura(mingzuozhibi.persist.disc.Sakura)

Example 13 with 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);
            }
        });
    });
}
Also used : LocalDateTime(java.time.LocalDateTime) LinkedHashSet(java.util.LinkedHashSet) Disc(mingzuozhibi.persist.disc.Disc) Record(mingzuozhibi.persist.disc.Record) Sakura(mingzuozhibi.persist.disc.Sakura) LocalDate(java.time.LocalDate)

Aggregations

Sakura (mingzuozhibi.persist.disc.Sakura)13 Transactional (org.springframework.transaction.annotation.Transactional)8 Disc (mingzuozhibi.persist.disc.Disc)6 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 JSONObject (org.json.JSONObject)5 LocalDateTime (java.time.LocalDateTime)4 UpdateType (mingzuozhibi.persist.disc.Disc.UpdateType)3 ViewType (mingzuozhibi.persist.disc.Sakura.ViewType)3 SakuraHelper.noExpiredSakura (mingzuozhibi.support.SakuraHelper.noExpiredSakura)3 LocalDate (java.time.LocalDate)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 Dao (mingzuozhibi.support.Dao)2 Criteria (org.hibernate.Criteria)2 Restrictions (org.hibernate.criterion.Restrictions)2 JSONArray (org.json.JSONArray)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2