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;
}
}
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);
}
});
});
}
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);
}
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());
}
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);
}
Aggregations