Search in sources :

Example 1 with DiscType

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();
        }
    });
}
Also used : Disc(mingzuozhibi.persist.disc.Disc) Instant(java.time.Instant) Node(org.w3c.dom.Node) DocumentReader.getNode(mingzuozhibi.service.amazon.DocumentReader.getNode) DiscType(mingzuozhibi.persist.disc.Disc.DiscType) Document(org.w3c.dom.Document) LocalDate(java.time.LocalDate)

Aggregations

Instant (java.time.Instant)1 LocalDate (java.time.LocalDate)1 Disc (mingzuozhibi.persist.disc.Disc)1 DiscType (mingzuozhibi.persist.disc.Disc.DiscType)1 DocumentReader.getNode (mingzuozhibi.service.amazon.DocumentReader.getNode)1 Document (org.w3c.dom.Document)1 Node (org.w3c.dom.Node)1