Search in sources :

Example 16 with Disc

use of mingzuozhibi.persist.disc.Disc 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

Disc (mingzuozhibi.persist.disc.Disc)16 Transactional (org.springframework.transaction.annotation.Transactional)9 JSONObject (org.json.JSONObject)7 Sakura (mingzuozhibi.persist.disc.Sakura)6 LocalDate (java.time.LocalDate)5 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)5 LocalDateTime (java.time.LocalDateTime)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 UpdateType (mingzuozhibi.persist.disc.Disc.UpdateType)3 ViewType (mingzuozhibi.persist.disc.Sakura.ViewType)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 PutMapping (org.springframework.web.bind.annotation.PutMapping)3 java.util (java.util)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Collectors (java.util.stream.Collectors)2 Stream (java.util.stream.Stream)2 DiscType (mingzuozhibi.persist.disc.Disc.DiscType)2 Dao (mingzuozhibi.support.Dao)2 Restrictions (org.hibernate.criterion.Restrictions)2 JSONArray (org.json.JSONArray)2