Search in sources :

Example 21 with Disc

use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.

the class AmazonScheduler method checkAmazonHotData.

private void checkAmazonHotData() {
    LOGGER.info("[开始检测Amazon(Hot)数据]");
    Set<Disc> discs = new LinkedHashSet<>();
    dao.execute(session -> {
        findActiveSakura(session).forEach(sakura -> {
            findAmazonDiscs(sakura).filter(needUpdate()).forEach(discs::add);
        });
    });
    Set<Disc> hotDiscs = discs.stream().unordered().limit(10).collect(Collectors.toSet());
    if (hotDiscs.size() > 0) {
        LOGGER.debug("[开始检测Amazon(Hot)数据][共{}个]", hotDiscs.size());
        AtomicInteger updateCount = new AtomicInteger(hotDiscs.size());
        hotDiscs.forEach(disc -> {
            service.createRankTask(disc.getAsin(), checkHotCB(updateCount, disc));
        });
    } else {
        LOGGER.info("[结束检测Amazon(Hot)数据][未找到可以检测的Amazon(Hot)数据]]");
        amazonFetchStatus = AmazonFetchStatus.waitingForUpdate;
    }
}
Also used : Disc(mingzuozhibi.persist.disc.Disc) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 22 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)

Example 23 with Disc

use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.

the class DiscController method findRecords.

@Transactional
@GetMapping(value = "/api/discs/{id}/records", produces = MEDIA_TYPE)
public String findRecords(@PathVariable Long id) {
    Disc disc = dao.get(Disc.class, id);
    if (disc == null) {
        if (LOGGER.isWarnEnabled()) {
            warnRequest("[获取碟片排名失败][指定的碟片Id不存在][Id={}]", id);
        }
        return errorMessage("指定的碟片Id不存在");
    }
    JSONObject result = disc.toJSON();
    result.put("records", buildRecords(dao, disc));
    return objectResult(result);
}
Also used : JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc) GetMapping(org.springframework.web.bind.annotation.GetMapping) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with Disc

use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.

the class DiscGroupItemsController method dropDiscs.

@Transactional
@PreAuthorize("hasRole('BASIC')")
@DeleteMapping(value = "/api/discGroups/{id}/discs/{discId}", produces = MEDIA_TYPE)
public synchronized String dropDiscs(@PathVariable("id") Long id, @PathVariable("discId") Long discId) {
    DiscGroup discGroup = dao.get(DiscGroup.class, id);
    if (discGroup == null) {
        if (LOGGER.isWarnEnabled()) {
            warnRequest("[从列表移除碟片失败][指定的列表Id不存在][Id={}]", id);
        }
        return errorMessage("指定的列表Id不存在");
    }
    Disc disc = discGroup.getDiscs().stream().filter(t -> t.getId().equals(discId)).findFirst().orElse(null);
    if (disc == null) {
        if (LOGGER.isWarnEnabled()) {
            warnRequest("[从列表移除碟片失败][指定的碟片Id不存在于列表][Id={}]", discId);
        }
        return errorMessage("指定的碟片Id不存在于列表");
    }
    discGroup.getDiscs().remove(disc);
    jmsMessage.info("[用户=%s][移除碟片成功][列表=%s][碟片=%s]", getUserName(), discGroup.getTitle(), disc.getLogName());
    return objectResult(disc.toJSON());
}
Also used : Disc(mingzuozhibi.persist.disc.Disc) DiscGroup(mingzuozhibi.persist.disc.DiscGroup) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) Transactional(org.springframework.transaction.annotation.Transactional)

Example 25 with Disc

use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.

the class DiscSpiderController method searchDiscFromAmazon.

private String searchDiscFromAmazon(@PathVariable String asin) {
    if (LOGGER.isInfoEnabled()) {
        infoRequest("[申请查询碟片][开始从日亚查询][ASIN={}]", asin);
    }
    JSONObject result = discInfosSpider.fetchDisc(asin);
    if (!result.getBoolean("success")) {
        return result.toString();
    }
    JSONObject discJson = result.getJSONObject("data");
    if (discJson.getBoolean("offTheShelf")) {
        return errorMessage("可能该碟片已下架");
    }
    Disc disc = createDisc(asin, discJson);
    jmsHelper.sendDiscTrack(disc.getAsin(), disc.getTitle());
    jmsMessage.success("[用户=%s][查询碟片成功][标题=%s][%s]", getUserName(), disc.getTitle(), asin);
    JSONObject data = disc.toJSON();
    if (LOGGER.isInfoEnabled()) {
        infoRequest("[申请查询碟片][成功从日亚查询][ASIN={}][JSON={}]", asin, data);
    }
    return objectResult(data);
}
Also used : JSONObject(org.json.JSONObject) Disc(mingzuozhibi.persist.disc.Disc)

Aggregations

Disc (mingzuozhibi.persist.disc.Disc)27 Transactional (org.springframework.transaction.annotation.Transactional)14 JSONObject (org.json.JSONObject)9 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)9 LocalDate (java.time.LocalDate)8 Sakura (mingzuozhibi.persist.disc.Sakura)6 LocalDateTime (java.time.LocalDateTime)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 PutMapping (org.springframework.web.bind.annotation.PutMapping)4 LinkedHashSet (java.util.LinkedHashSet)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 UpdateType (mingzuozhibi.persist.disc.Disc.UpdateType)3 DiscGroup (mingzuozhibi.persist.disc.DiscGroup)3 ViewType (mingzuozhibi.persist.disc.Sakura.ViewType)3 DateTimeFormatter (java.time.format.DateTimeFormatter)2 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