use of mingzuozhibi.persist.disc.Disc.DiscType 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();
}
});
}
Aggregations