Add Notify all of new articles
This commit is contained in:
parent
20c301ea57
commit
dae3dd52e4
|
@ -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() + ">";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,4 +22,7 @@ public class ArticleModel {
|
|||
private Integer recommended;
|
||||
private ZonedDateTime registeredAt;
|
||||
|
||||
public String convertArticletoMessage() {
|
||||
return "- <" + this.getArticleUrl() + "|" + this.getTitle() + ">";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,8 @@ public class ArticleUpsertEventListener {
|
|||
Map<CrawlTarget, List<ArticleModel>> articleMap =
|
||||
((List<ArticleModel>) event.getSource()).stream()
|
||||
.collect(Collectors.groupingBy(ArticleModel::getCrawlTarget));
|
||||
articleMap.forEach(this::notifyMessage);
|
||||
|
||||
List<AppUserModel> appUsers = appUserQueryService.findAll();
|
||||
|
||||
appUsers.stream()
|
||||
|
@ -71,6 +73,14 @@ public class ArticleUpsertEventListener {
|
|||
//ArticleUpsertEventListener::printArticle
|
||||
}
|
||||
|
||||
private void notifyMessage(CrawlTarget crawlTarget, List<ArticleModel> 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()) {
|
||||
|
|
Loading…
Reference in New Issue