use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class SakuraController method pushDiscs.
@Transactional
@PreAuthorize("hasRole('BASIC')")
@PostMapping(value = "/api/sakuras/{id}/discs/{discId}", produces = MEDIA_TYPE)
public String pushDiscs(@PathVariable("id") Long id, @PathVariable("discId") Long discId, @RequestParam(name = "discColumns", defaultValue = DISC_COLUMNS) String discColumns) {
Sakura sakura = dao.get(Sakura.class, id);
if (sakura == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[添加碟片到列表失败][指定的列表Id不存在][Id={}]", id);
}
return errorMessage("指定的列表Id不存在");
}
Disc disc = dao.get(Disc.class, discId);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[添加碟片到列表失败][指定的碟片Id不存在][Id={}]", discId);
}
return errorMessage("指定的碟片Id不存在");
}
if (sakura.getDiscs().stream().anyMatch(d -> d.getId().equals(discId))) {
if (LOGGER.isInfoEnabled()) {
infoRequest("[添加碟片到列表失败][指定的碟片已存在于列表][ASIN={}][列表={}]", disc.getAsin(), sakura.getTitle());
}
return errorMessage("指定的碟片已存在于列表");
}
sakura.getDiscs().add(disc);
if (LOGGER.isInfoEnabled()) {
infoRequest("[添加碟片到列表成功][ASIN={}][列表={}]", disc.getAsin(), sakura.getTitle());
}
return objectResult(disc.toJSON(getColumns(discColumns)));
}
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();
if (LOGGER.isDebugEnabled()) {
debugRequest("[获取碟片排名成功][碟片信息={}]", result);
}
result.put("records", buildRecords(dao, disc));
return objectResult(result);
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method searchFromAmazon.
private void searchFromAmazon(String asin, AtomicReference<Disc> disc, StringBuffer error) {
Instant instant = Instant.now();
if (LOGGER.isInfoEnabled()) {
infoRequest("[查找碟片][从Amazon查询开始][asin={}]", asin);
}
service.createDiscTask(asin, task -> {
if (task.isDone()) {
Node node = getNode(task.getDocument(), "Items", "Item", "ItemAttributes");
String rankText = getText(task.getDocument(), "Items", "Item", "SalesRank");
if (node != null) {
Document itemAttributes = node.getOwnerDocument();
String title = getText(itemAttributes, "Title");
String group = getText(itemAttributes, "ProductGroup");
String release = getText(itemAttributes, "ReleaseDate");
Objects.requireNonNull(title);
Objects.requireNonNull(group);
DiscType type = getType(group, title);
boolean amazon = title.startsWith("【Amazon.co.jp限定】");
LocalDate releaseDate;
if (release != null) {
releaseDate = LocalDate.parse(release, formatter);
} else {
releaseDate = LocalDate.now();
}
Disc newDisc = new Disc(asin, title, type, UpdateType.Both, amazon, releaseDate);
if (rankText != null) {
newDisc.setThisRank(new Integer(rankText));
}
dao.save(newDisc);
disc.set(newDisc);
} else {
error.append(task.getErrorMessage());
}
}
if (LOGGER.isInfoEnabled()) {
LOGGER.info("[查找碟片][从Amazon查询成功][asin={}][耗时={}ms]", asin, Instant.now().toEpochMilli() - instant.toEpochMilli());
}
synchronized (disc) {
disc.notify();
}
});
}
use of mingzuozhibi.persist.disc.Disc in project mzzb-server by mingzuozhibi.
the class DiscController method mergePts.
@Transactional
@PutMapping(value = "/api/discs/{id}/pts", produces = MEDIA_TYPE)
public String mergePts(@PathVariable Long id, @JsonArg String text) {
Disc disc = dao.get(Disc.class, id);
if (disc == null) {
if (LOGGER.isWarnEnabled()) {
warnRequest("[提交PT失败][指定的碟片Id不存在][Id={}]", id);
}
return errorMessage("指定的碟片Id不存在");
}
int matchLine = mergePtText(dao, disc, text);
computeAndUpdateSakuraPt(dao, disc);
JSONObject result = disc.toJSON();
if (LOGGER.isDebugEnabled()) {
debugRequest("[提交PT成功][提交记录数={}][碟片信息={}]", matchLine, result);
}
result.put("records", buildRecords(dao, disc));
return objectResult(result);
}
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;
}
}
Aggregations