热榜点赞bug修改

duhui 2022-12-12 16:29:33 +08:00
parent ce9d4f5b27
commit 514e19b210
2 changed files with 24 additions and 10 deletions

View File

@ -17,8 +17,11 @@ import org.springframework.stereotype.Component;
import rpc.protocols.HeroInfoProto;
import rpc.protocols.MessageTypeProto;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author hj
@ -41,9 +44,13 @@ public class LikeHeroRankHandler extends BaseHandler<HeroInfoProto.LikeHeroRankR
String userId = String.valueOf(user.getId());
// 英雄是否点赞过验证
HashSet<Integer> entry = RedisUtil.getInstence().getMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, HashSet.class);
if (entry != null && entry.contains(heroTid)){
throw new ErrorCodeException(ErrorCode.SERVER_DEFINE,"该英雄已点赞");
HashSet<Double> entry = RedisUtil.getInstence().getMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, HashSet.class);
List<Integer> list = new ArrayList<>();
if (entry != null){
list = entry.stream().mapToInt(Double::intValue).boxed().collect(Collectors.toList());
if (list.contains(heroTid)){
throw new ErrorCodeException(ErrorCode.SERVER_DEFINE,"该英雄已点赞");
}
}
// 排行榜是否开启验证
@ -58,11 +65,8 @@ public class LikeHeroRankHandler extends BaseHandler<HeroInfoProto.LikeHeroRankR
rank.addRank(proto.getHeroTid(), rankSubId, 1);
// 更新点赞记录
if (entry == null){
entry = new HashSet<>();
}
entry.add(heroTid);
RedisUtil.getInstence().putMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, entry);
list.add(heroTid);
RedisUtil.getInstence().putMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, list);
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LIKE_HERO_RANK_RESPONSE_VALUE, null, true);
}

View File

@ -1,5 +1,8 @@
package com.ljsd.jieling.handler.rank;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
@ -11,7 +14,10 @@ import org.springframework.stereotype.Component;
import rpc.protocols.HeroInfoProto;
import rpc.protocols.MessageTypeProto;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author hj
@ -33,8 +39,12 @@ public class UserLikeHeroRankInfoHandler extends BaseHandler<HeroInfoProto.userL
String userId = String.valueOf(user.getId());
// 用户点赞英雄记录
HashSet<Integer> entry = RedisUtil.getInstence().getMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, HashSet.class);
HeroInfoProto.userLikeHeroRankInfoResponse.Builder builder = HeroInfoProto.userLikeHeroRankInfoResponse.newBuilder().addAllHeroTid(entry);
HashSet<Double> entry = RedisUtil.getInstence().getMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, HashSet.class);
List<Integer> list = new ArrayList<>();
if (entry != null){
list = entry.stream().mapToInt(Double::intValue).boxed().collect(Collectors.toList());
}
HeroInfoProto.userLikeHeroRankInfoResponse.Builder builder = HeroInfoProto.userLikeHeroRankInfoResponse.newBuilder().addAllHeroTid(list);
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.USER_LIKE_HERO_RANK_INFO_RESPONSE_VALUE, builder.build(), true);
}