diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/UserNotifyModel.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/UserNotifyModel.java index bc1bcd7..0b9dfb0 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/UserNotifyModel.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/UserNotifyModel.java @@ -24,19 +24,15 @@ public class UserNotifyModel { } public String toCompositedMessage() { - String compositedMessage = wrapUserId() + "\n" + + return wrapUserId() + "\n" + articles.stream() - .map(this::convertArticletoMessage) + .map(ArticleModel::convertArticletoMessage) .collect(Collectors.joining("\n")); - // article -> builder.append(convertArticletoMessage.toMessage()).append("\n");i - return compositedMessage; } private String wrapUserId() { return "<@" + slackId + ">"; } - private String convertArticletoMessage(ArticleModel article) { - return "<" + article.getArticleUrl() + "|" + article.getTitle() + ">"; - } + } diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/v2/ArticleModel.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/v2/ArticleModel.java index ec7626b..5d9a42f 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/v2/ArticleModel.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/domain/model/v2/ArticleModel.java @@ -22,4 +22,7 @@ public class ArticleModel { private Integer recommended; private ZonedDateTime registeredAt; + public String convertArticletoMessage() { + return "- <" + this.getArticleUrl() + "|" + this.getTitle() + ">"; + } } diff --git a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java index b49f828..bf6c027 100644 --- a/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java +++ b/shopping-crawler/src/main/java/com/myoa/engineering/crawl/shopping/event/handler/ArticleUpsertEventListener.java @@ -38,6 +38,8 @@ public class ArticleUpsertEventListener { Map> articleMap = ((List) event.getSource()).stream() .collect(Collectors.groupingBy(ArticleModel::getCrawlTarget)); + articleMap.forEach(this::notifyMessage); + List appUsers = appUserQueryService.findAll(); appUsers.stream() @@ -71,6 +73,14 @@ public class ArticleUpsertEventListener { //ArticleUpsertEventListener::printArticle } + private void notifyMessage(CrawlTarget crawlTarget, List articles) { + var sb = new StringBuilder(); + sb.append("[").append(crawlTarget.getAlias()).append("]\n"); + articles.forEach(article -> sb.append(article.convertArticletoMessage()).append("\n")); + sb.append("-----------------------------------\n"); + userNotifyService.notify(sb.toString()); + } + private void notifyMessage(UserNotifyModel userNotifyModel) { System.out.println("article = " + userNotifyModel); if (userNotifyModel.getArticles().isEmpty()) {