[Change] PreLoadDataComparator, PreLoadDataAttribute 将PreLoadData的属性Enum迁移到单独的类;

[Change] BotCommandProcess 适配更改;
This commit is contained in:
2020-06-12 22:28:14 +08:00
parent ebb3dea99e
commit ad54dbfbf3
3 changed files with 54 additions and 52 deletions

View File

@ -9,6 +9,7 @@ import net.lamgc.cgj.bot.cache.CacheStore;
import net.lamgc.cgj.bot.cache.CacheStoreCentral; import net.lamgc.cgj.bot.cache.CacheStoreCentral;
import net.lamgc.cgj.bot.cache.JsonRedisCacheStore; import net.lamgc.cgj.bot.cache.JsonRedisCacheStore;
import net.lamgc.cgj.bot.event.BufferMessageEvent; 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.bot.sort.PreLoadDataComparator;
import net.lamgc.cgj.pixiv.PixivDownload; import net.lamgc.cgj.pixiv.PixivDownload;
import net.lamgc.cgj.pixiv.PixivDownload.PageQuality; import net.lamgc.cgj.pixiv.PixivDownload.PageQuality;
@ -109,11 +110,11 @@ public class BotCommandProcess {
"\n作品标题" + illustPreLoadData.get("illustTitle").getAsString() + "\n作品标题" + illustPreLoadData.get("illustTitle").getAsString() +
"\n作者(作者Id)" + illustPreLoadData.get("userName").getAsString() + "\n作者(作者Id)" + illustPreLoadData.get("userName").getAsString() +
"(" + illustPreLoadData.get("userId").getAsInt() + ")" + "(" + illustPreLoadData.get("userId").getAsInt() + ")" +
"\n点赞数" + illustPreLoadData.get(PreLoadDataComparator.Attribute.LIKE.attrName).getAsInt() + "\n点赞数" + illustPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt() +
"\n收藏数" + illustPreLoadData.get(PreLoadDataComparator.Attribute.BOOKMARK.attrName).getAsInt() + "\n收藏数" + illustPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt() +
"\n围观数" + illustPreLoadData.get(PreLoadDataComparator.Attribute.VIEW.attrName).getAsInt() + "\n围观数" + illustPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt() +
"\n评论数" + illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt() + "\n评论数" + illustPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt() +
"\n页数" + illustPreLoadData.get(PreLoadDataComparator.Attribute.PAGE.attrName).getAsInt() + "" + "\n页数" + illustPreLoadData.get(PreLoadDataAttribute.PAGE.attrName).getAsInt() + "" +
"\n作品链接" + artworksLink(fromGroup, illustId) + "\n" + "\n作品链接" + artworksLink(fromGroup, illustId) + "\n" +
"---------------- 作品图片 ----------------\n" + "---------------- 作品图片 ----------------\n" +
CacheStoreCentral.getCentral().getImageById(fromGroup, illustId, PageQuality.REGULAR, 1) + "\n" + CacheStoreCentral.getCentral().getImageById(fromGroup, illustId, PageQuality.REGULAR, 1) + "\n" +
@ -337,7 +338,7 @@ public class BotCommandProcess {
.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data"); .getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data");
ArrayList<JsonElement> illustsList = new ArrayList<>(); ArrayList<JsonElement> illustsList = new ArrayList<>();
illustsArray.forEach(illustsList::add); illustsArray.forEach(illustsList::add);
illustsList.sort(new PreLoadDataComparator(PreLoadDataComparator.Attribute.LIKE)); illustsList.sort(new PreLoadDataComparator(PreLoadDataAttribute.LIKE));
log.debug("已找到与 {} 相关插图信息({})", content, searchArea.name().toLowerCase()); log.debug("已找到与 {} 相关插图信息({})", content, searchArea.name().toLowerCase());
int count = 1; int count = 1;
@ -394,13 +395,13 @@ public class BotCommandProcess {
.append("\n\t作品标题: ").append(illustObj.get("illustTitle").getAsString()) .append("\n\t作品标题: ").append(illustObj.get("illustTitle").getAsString())
.append("\n\t作品页数: ").append(illustObj.get("pageCount").getAsInt()).append("") .append("\n\t作品页数: ").append(illustObj.get("pageCount").getAsInt()).append("")
.append("\n\t点赞数") .append("\n\t点赞数")
.append(illustPreLoadData.get(PreLoadDataComparator.Attribute.LIKE.attrName).getAsInt()) .append(illustPreLoadData.get(PreLoadDataAttribute.LIKE.attrName).getAsInt())
.append("\n\t收藏数") .append("\n\t收藏数")
.append(illustPreLoadData.get(PreLoadDataComparator.Attribute.BOOKMARK.attrName).getAsInt()) .append(illustPreLoadData.get(PreLoadDataAttribute.BOOKMARK.attrName).getAsInt())
.append("\n\t围观数") .append("\n\t围观数")
.append(illustPreLoadData.get(PreLoadDataComparator.Attribute.VIEW.attrName).getAsInt()) .append(illustPreLoadData.get(PreLoadDataAttribute.VIEW.attrName).getAsInt())
.append("\n\t评论数") .append("\n\t评论数")
.append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt()) .append(illustPreLoadData.get(PreLoadDataAttribute.COMMENT.attrName).getAsInt())
.append("\n").append(imageMsg).append("\n"); .append("\n").append(imageMsg).append("\n");
count++; count++;
totalCount++; totalCount++;

View File

@ -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;
}
}

View File

@ -12,9 +12,9 @@ import java.util.Comparator;
*/ */
public class PreLoadDataComparator implements Comparator<JsonElement> { public class PreLoadDataComparator implements Comparator<JsonElement> {
private final Attribute attribute; private final PreLoadDataAttribute attribute;
public PreLoadDataComparator(Attribute attribute) { public PreLoadDataComparator(PreLoadDataAttribute attribute) {
this.attribute = attribute; this.attribute = attribute;
} }
@ -52,44 +52,4 @@ public class PreLoadDataComparator implements Comparator<JsonElement> {
} }
} }
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;
}
}
} }