From ad54dbfbf345e101088b58fb9d835bcb9233c784 Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 12 Jun 2020 22:28:14 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20PreLoadDataComparator,=20PreLoadData?= =?UTF-8?q?Attribute=20=E5=B0=86PreLoadData=E7=9A=84=E5=B1=9E=E6=80=A7Enum?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=88=B0=E5=8D=95=E7=8B=AC=E7=9A=84=E7=B1=BB?= =?UTF-8?q?;=20[Change]=20BotCommandProcess=20=E9=80=82=E9=85=8D=E6=9B=B4?= =?UTF-8?q?=E6=94=B9;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotCommandProcess.java | 21 ++++----- .../cgj/bot/sort/PreLoadDataAttribute.java | 41 +++++++++++++++++ .../cgj/bot/sort/PreLoadDataComparator.java | 44 +------------------ 3 files changed, 54 insertions(+), 52 deletions(-) create mode 100644 src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataAttribute.java diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 2af2b3f..3ff9e10 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -9,6 +9,7 @@ import net.lamgc.cgj.bot.cache.CacheStore; import net.lamgc.cgj.bot.cache.CacheStoreCentral; import net.lamgc.cgj.bot.cache.JsonRedisCacheStore; import net.lamgc.cgj.bot.event.BufferMessageEvent; +import net.lamgc.cgj.bot.sort.PreLoadDataAttribute; import net.lamgc.cgj.bot.sort.PreLoadDataComparator; import net.lamgc.cgj.pixiv.PixivDownload; import net.lamgc.cgj.pixiv.PixivDownload.PageQuality; @@ -109,11 +110,11 @@ public class BotCommandProcess { "\n作品标题:" + illustPreLoadData.get("illustTitle").getAsString() + "\n作者(作者Id):" + illustPreLoadData.get("userName").getAsString() + "(" + illustPreLoadData.get("userId").getAsInt() + ")" + - "\n点赞数:" + illustPreLoadData.get(PreLoadDataComparator.Attribute.LIKE.attrName).getAsInt() + - "\n收藏数:" + illustPreLoadData.get(PreLoadDataComparator.Attribute.BOOKMARK.attrName).getAsInt() + - "\n围观数:" + illustPreLoadData.get(PreLoadDataComparator.Attribute.VIEW.attrName).getAsInt() + - "\n评论数:" + illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt() + - "\n页数:" + illustPreLoadData.get(PreLoadDataComparator.Attribute.PAGE.attrName).getAsInt() + "页" + + "\n点赞数:" + illustPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt() + + "\n收藏数:" + illustPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt() + + "\n围观数:" + illustPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt() + + "\n评论数:" + illustPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt() + + "\n页数:" + illustPreLoadData.get(PreLoadDataAttribute.PAGE.attrName).getAsInt() + "页" + "\n作品链接:" + artworksLink(fromGroup, illustId) + "\n" + "---------------- 作品图片 ----------------\n" + CacheStoreCentral.getCentral().getImageById(fromGroup, illustId, PageQuality.REGULAR, 1) + "\n" + @@ -337,7 +338,7 @@ public class BotCommandProcess { .getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data"); ArrayList illustsList = new ArrayList<>(); illustsArray.forEach(illustsList::add); - illustsList.sort(new PreLoadDataComparator(PreLoadDataComparator.Attribute.LIKE)); + illustsList.sort(new PreLoadDataComparator(PreLoadDataAttribute.LIKE)); log.debug("已找到与 {} 相关插图信息({}):", content, searchArea.name().toLowerCase()); int count = 1; @@ -394,13 +395,13 @@ public class BotCommandProcess { .append("\n\t作品标题: ").append(illustObj.get("illustTitle").getAsString()) .append("\n\t作品页数: ").append(illustObj.get("pageCount").getAsInt()).append("页") .append("\n\t点赞数:") - .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.LIKE.attrName).getAsInt()) + .append(illustPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt()) .append("\n\t收藏数:") - .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.BOOKMARK.attrName).getAsInt()) + .append(illustPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt()) .append("\n\t围观数:") - .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.VIEW.attrName).getAsInt()) + .append(illustPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt()) .append("\n\t评论数:") - .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt()) + .append(illustPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt()) .append("\n").append(imageMsg).append("\n"); count++; totalCount++; diff --git a/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataAttribute.java b/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataAttribute.java new file mode 100644 index 0000000..095aa9a --- /dev/null +++ b/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataAttribute.java @@ -0,0 +1,41 @@ +package net.lamgc.cgj.bot.sort; + +@SuppressWarnings("unused") +public enum PreLoadDataAttribute { + /** + * 按点赞数排序 + */ + LIKE("likeCount"), + + /** + * 按页面数排序 + */ + PAGE("pageCount"), + + /** + * 按收藏数排序 + */ + BOOKMARK("bookmarkCount"), + + /** + * 按评论数排序 + */ + COMMENT("commentCount"), + + /** + * 不明 + */ + RESPONSE("responseCount"), + + /** + * 按查看次数排序 + */ + VIEW("viewCount"), + ; + + public final String attrName; + + PreLoadDataAttribute(String attrName) { + this.attrName = attrName; + } +} \ No newline at end of file diff --git a/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataComparator.java b/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataComparator.java index 5b9aaa9..369a2c5 100644 --- a/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataComparator.java +++ b/src/main/java/net/lamgc/cgj/bot/sort/PreLoadDataComparator.java @@ -12,9 +12,9 @@ import java.util.Comparator; */ public class PreLoadDataComparator implements Comparator { - private final Attribute attribute; + private final PreLoadDataAttribute attribute; - public PreLoadDataComparator(Attribute attribute) { + public PreLoadDataComparator(PreLoadDataAttribute attribute) { this.attribute = attribute; } @@ -52,44 +52,4 @@ public class PreLoadDataComparator implements Comparator { } } - public enum Attribute { - /** - * 按点赞数排序 - */ - LIKE("likeCount"), - - /** - * 按页面数排序 - */ - PAGE("pageCount"), - - /** - * 按收藏数排序 - */ - BOOKMARK("bookmarkCount"), - - /** - * 按评论数排序 - */ - COMMENT("commentCount"), - - /** - * 不明 - */ - RESPONSE("responseCount"), - - /** - * 按查看次数排序 - */ - VIEW("viewCount"), - ; - - public final String attrName; - - Attribute(String attrName) { - this.attrName = attrName; - } - } - - }