热度排行榜

back_recharge
duhui 2022-08-04 16:42:32 +08:00
parent b085fc0b2b
commit bb16d01442
12 changed files with 305 additions and 33 deletions

View File

@ -402,6 +402,17 @@ public class RedisKey {
*/
public final static String EXPLORE_RANK = "EXPLORE_RANK";
/**
*
* key
*/
public final static String HERO_HOT_RANK = "HERO_HOT_RANK";
/**
*
* key
*/
public static final String USER_LIKE_HERO_HOT_RANK = "USER_LIKE_HERO_HOT_RANK";
/**
* mongo

View File

@ -1400,14 +1400,14 @@ public class RedisUtil {
return -1;
}
public String getKey(String type,String key){
return getKey(type,key,true);
}
public String getGuildReleaseKey(String type,int serverId){
return serverId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon;
}
public String getKey(String type,String key){
return getKey(type,key,true);
}
/**
* key
* @param type
@ -1418,10 +1418,26 @@ public class RedisUtil {
*/
public String getKey(String type,String key,boolean judge) {
String result = null;
if (!judge) {
if (judge) {
result = getKeyImpl(type, key);
} else{
result = type + RedisKey.Delimiter_colon + key;
} else if (
RedisKey.PLAYER_INFO_CACHE.equals(type) || RedisKey.FAMILY_INFO.equals(type) ||
}
// 保存需要清理的key
saveRemoveKeyHandler(result);
return result;
}
/**
* key
* @param type
* @param key
* true false
* @return
*/
public String getKeyImpl(String type,String key) {
String result = null;
if (RedisKey.PLAYER_INFO_CACHE.equals(type) || RedisKey.FAMILY_INFO.equals(type) ||
RedisKey.PIDGIDTEMP.equals(type) || RedisKey.SERVER_WORLDLEVE_INFO.equals(type) ||
RedisKey.FAMILY_RED_PACKAGE.equals(type) || "red_remain_list".equals(type) ||
RedisKey.FAMILY_RED_PACKAGE_INCRE_ID.equals(type) || /*RedisKey.GUILD_FORCE_RANK.equals(type) ||*/
@ -1432,10 +1448,13 @@ public class RedisUtil {
RedisKey.WORLD_ARENA_MY_PRON.equals(type) || RedisKey.WORLD_ARENA_RRECORD.equals(type) ||
RedisKey.TOKEN.equals(type) || RedisKey.USER_SERVER_INFO.equals(type) ||
RedisKey.CDKEY.equals(type) || RedisKey.ServerArenaJob.equals(type) ||
RedisKey.CROSS_SERVER_GROUP.equals(type)
) {
RedisKey.CROSS_SERVER_GROUP.equals(type) || RedisKey.HERO_HOT_RANK.equals(type) ||
RedisKey.USER_LIKE_HERO_HOT_RANK.equals(type))
{
result = type + RedisKey.Delimiter_colon + key;
} else if (!RedisKey.newAreaCacChe.contains(type) && !RedisKey.rankCacChe.contains(type)) {
}
else if (!RedisKey.newAreaCacChe.contains(type) && !RedisKey.rankCacChe.contains(type))
{
if (key.length() == 8) {
Integer serverId = RedisUtil.getInstence().getObject(RedisKey.CUser_ServerId_Key, key, Integer.class, GlobalsDef.REDIS_OVER_TIME_DAY * 10);
if (serverId != null && !AreaManager.getInstance().checkServerIdAllowPermit(serverId)) {
@ -1455,20 +1474,13 @@ public class RedisUtil {
RedisKey.CROSS_YUXULUNDAO_RANK.equals(type) || RedisKey.CROSS_YUXULUNDAO_ROBOT_INFO.equals(type) ||
RedisKey.CROSS_YUXULUNDAO_RECORD.equals(type) || RedisKey.CROSS_YUXULUNDAO_RANK_PERSON.equals(type)
|| RedisKey.CROSS_LINGMAISECRET_INFO.equals(type) || RedisKey.CROSS_LINGMAISECRET_RECORD.equals(type)
|| RedisKey.CROSS_LINGMAI_RANK_PERSON.equals(type)
) {
|| RedisKey.CROSS_LINGMAI_RANK_PERSON.equals(type))
{
return type + RedisKey.Delimiter_colon + key;
}
if (result == null) {
// if (RedisKey.GUILD_RELEASE.equals(type)) {
// RedisUtil.getInstence().get(RedisKey.GUILD_SERVERID + RedisKey.Delimiter_colon + )
// result = + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
// }else {
result = AreaManager.areaId + RedisKey.Delimiter_colon + type + RedisKey.Delimiter_colon + key;
// }
}
// 保存需要清理的key
saveRemoveKeyHandler(result);
return result;
}

View File

@ -0,0 +1,67 @@
package com.ljsd.jieling.handler.rank;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.rank.RankEnum;
import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.MessageUtil;
import config.SHotRanking;
import manager.STableManager;
import org.springframework.stereotype.Component;
import rpc.protocols.HeroInfoProto;
import rpc.protocols.MessageTypeProto;
import java.util.HashSet;
import java.util.Map;
/**
* @author hj
*
*/
@Component
public class LikeHeroRankHandler extends BaseHandler<HeroInfoProto.LikeHeroRankRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.LIKE_HERO_RANK_REQUEST;
}
@Override
public void processWithProto(ISession iSession, HeroInfoProto.LikeHeroRankRequest proto) throws Exception {
User user = UserManager.getUser(iSession.getUid());
String rankSubId = String.valueOf(proto.getRankSubId());
int heroTid = proto.getHeroTid();
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,"该英雄已点赞");
}
// 排行榜是否开启验证
Map<Integer, SHotRanking> config = STableManager.getConfig(SHotRanking.class);
SHotRanking hotRanking = config.get(rankSubId);
if (hotRanking == null || hotRanking.getOpen() == 0){
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE,"排行榜未开启:"+rankSubId);
}
// 更新热度排行榜
AbstractRank rank = RankEnum.toRank(RankEnum.HERO_HOT_RANK.getType());
rank.addRank(proto.getHeroTid(), rankSubId, 1);
// 更新点赞记录
entry.add(heroTid);
RedisUtil.getInstence().putMapEntry(RedisKey.USER_LIKE_HERO_HOT_RANK, rankSubId, userId, entry);
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.LIKE_HERO_RANK_RESPONSE_VALUE, null, true);
}
}

View File

@ -0,0 +1,41 @@
package com.ljsd.jieling.handler.rank;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.MessageUtil;
import org.springframework.stereotype.Component;
import rpc.protocols.HeroInfoProto;
import rpc.protocols.MessageTypeProto;
import java.util.HashSet;
/**
* @author hj
*
*/
@Component
public class UserLikeHeroRankInfoHandler extends BaseHandler<HeroInfoProto.userLikeHeroRankInfoRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return MessageTypeProto.MessageType.USER_LIKE_HERO_RANK_INFO_REQUEST;
}
@Override
public void processWithProto(ISession iSession, HeroInfoProto.userLikeHeroRankInfoRequest proto) throws Exception {
User user = UserManager.getUser(iSession.getUid());
String rankSubId = String.valueOf(proto.getRankSubId());
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);
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.USER_LIKE_HERO_RANK_INFO_RESPONSE_VALUE, builder.build(), true);
}
}

View File

@ -36,6 +36,7 @@ import com.ljsd.jieling.logic.mission.GameMisionType;
import com.ljsd.jieling.logic.mission.data.DataManagerDistributor;
import com.ljsd.jieling.logic.mission.event.MissionEventDistributor;
import com.ljsd.jieling.logic.player.PlayerLogic;
import com.ljsd.jieling.logic.rank.RankLogic;
import com.ljsd.jieling.logic.redpacket.WelfareRedPackSendHandler;
import com.ljsd.jieling.logic.ridingSward.RidingSwardLogic;
import com.ljsd.jieling.logic.sevenworld.SevenWorldLogic;
@ -309,8 +310,7 @@ public class GlobalDataManaager implements IManager {
new SummonTreasureHandler();
new ArchitectureUnLockHandler();
new SaveHeroForceEventHandler();
// 四灵试炼转移数据,只执行一次
// FourChallengeLogic.getInstance().redisToMongoDB();
RankLogic.heroHotRankInit();//英雄热度排行榜同步更新英雄配置表
ChampionshipLogic.minuteCheck(true);
GuildFightLogic.minuteCheckForCarFight();
} catch (Exception e) {

View File

@ -108,7 +108,7 @@ public enum ActivityTypeEnum {
EXPLORE_EXPECT_ACTIVITY(ActivityType.EXPLORE_EXPECT_ACTIVITY,ExploreExpectActivity::new),
POWER_RICE_ACTIVITY(ActivityType.POWER_RICE_ACTIVITY,PowerRiceActivity::new),//战力冲刺
DONGHAI_XUNXIAN_ACTIVITY(ActivityType.DonghaiXunxian,DonghaiXunxianActivity::new),//东海寻仙
WHOEL_LIFE_ACTIVITY(ActivityType.WHOLE_LIFE_CARD,WholeLifeActivity::new),//东海寻仙
WHOEL_LIFE_ACTIVITY(ActivityType.WHOLE_LIFE_CARD,WholeLifeActivity::new),//神尊特权
WEEK_CARD(ActivityType.WEEK_CARD,WeekCardActivity::new),//月卡
;

View File

@ -51,8 +51,6 @@ public enum RankEnum {
POWER_RICE_RANK(42,RedisKey.POWER_RICE_RANK,PowerRiceRank::new,false),//战力冲刺排行榜
EXPLORE_RANK(43,RedisKey.EXPLORE_RANK,ExploreRank::new,false),//探索排行榜
// 以下为跨服排行榜
WARLD_DIS_ARENA_RANK(28,RedisKey.WARLD_DIS_ARENA_RANK,ArenaRank::new,true),//世界服排行
@ -67,7 +65,7 @@ public enum RankEnum {
CROSS_SEVEN_WORLD_RANK(39,RedisKey.SEVEN_WORLD_INTEGRAL_RANK,CrossRank::new,true),//跨服七届试炼
CROSS_YUXULUNDAO_RANK_PERSON(40,RedisKey.CROSS_YUXULUNDAO_RANK_PERSON,CrossYuXuLunDaoPersonRank::new,true),//跨服玉虚论道真人排行榜
CROSS_LINGMAI_RANK_PERSON(41,RedisKey.CROSS_LINGMAI_RANK_PERSON,CrossLingmaiSecretRank::new,true),//跨服灵脉秘境积分排行榜
HERO_HOT_RANK(44,RedisKey.HERO_HOT_RANK, HeroHotRank::new,true),//英雄热度排行榜(全频道性质)
;
private int type;

View File

@ -1,5 +1,7 @@
package com.ljsd.jieling.logic.rank;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
@ -12,7 +14,9 @@ import com.ljsd.jieling.logic.rank.rankImpl.AbstractRank;
import com.ljsd.jieling.network.session.ISession;
import com.ljsd.jieling.util.ItemUtil;
import com.ljsd.jieling.util.MessageUtil;
import config.SCHero;
import config.SExpeditionSetting;
import config.SHotRanking;
import config.SSpecialConfig;
import manager.STableManager;
import org.slf4j.Logger;
@ -23,9 +27,7 @@ import rpc.protocols.PlayerInfoProto;
import util.MathUtils;
import util.TimeUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -250,4 +252,38 @@ public class RankLogic {
AbstractRank rank = RankContext.getRankEnum(type);
rank.removeAllRank(rkey);
}
/**
*
*/
public static void heroHotRankInit(){
// 英雄合集
Map<Integer, SCHero> heroMap = SCHero.getsCHero();
// 热度排行榜列表
Map<Integer, SHotRanking> hotRankingMap = STableManager.getConfig(SHotRanking.class);
// 上榜英雄品质限制
int naturalLimit = SSpecialConfig.getIntegerValue(SSpecialConfig.HotRanking_Natural);
// 满足条件可显示到排行榜上的英雄id
HashSet<Integer> heroSet = new HashSet<>();
for (SCHero hero : heroMap.values()) {
if (hero.getNatural() < naturalLimit || hero.getIsSoulOpen() == 0){
continue;
}
heroSet.add(hero.getId());
}
AbstractRank rank = RankEnum.toRank(RankEnum.HERO_HOT_RANK.getType());
for (SHotRanking hotRanking : hotRankingMap.values()) {
if (hotRanking.getOpen() == 0){
LOGGER.info("英雄热度排行榜未开启排行榜:{}",hotRanking.getId());
continue;
}
// 获取排行榜信息
for (Integer heroTid : heroSet) {
// 添加排行榜中未显示的新英雄
rank.addRank(heroTid,String.valueOf(hotRanking.getId()),0);
}
}
LOGGER.info("英雄热度排行榜,初始化==============================");
}
}

View File

@ -94,14 +94,14 @@ public abstract class AbstractRank implements IRank {
/**
*
* @param uid id
* @param mapKey id
* @param rkey redis key
* @param data getScore
*/
@Override
public void addRank(int uid, String rkey, double... data){
String key = RedisKey.getKey(redisKey,rkey,false);
RedisUtil.getInstence().zsetAddOne(key,String.valueOf(uid), getScore(data));
public void addRank(int mapKey, String rkey, double... data){
String key = RedisUtil.getInstence().getKey(redisKey, rkey);
RedisUtil.getInstence().zsetAddOne(key,String.valueOf(mapKey), getScore(data));
}
/**

View File

@ -0,0 +1,95 @@
package com.ljsd.jieling.logic.rank.rankImpl;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.logic.activity.crossService.CrossServiceLogic;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.cross.CSPlayer;
import com.ljsd.jieling.logic.dao.root.GuildInfo;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.family.CrossDeathPathLogic;
import config.SCHero;
import config.SHotRanking;
import config.SSpecialConfig;
import manager.STableManager;
import org.springframework.data.redis.core.ZSetOperations;
import rpc.protocols.CommonProto;
import rpc.protocols.PlayerInfoProto;
import java.util.*;
/**
* @author lvxinran
* @date 2019/11/27
* @discribe
*/
public class HeroHotRank extends ForceRank {
public HeroHotRank(int type, String redisKey) {
super(type, redisKey);
}
@Override
public void addRank(int mapKey, String rkey, double... data){
RedisUtil.getInstence().incrementZsetScore(redisKey,rkey,String.valueOf(mapKey),getScore(data),false);
}
public int getParam1(String data) {
return Integer.parseInt(data);
}
@Override
public int getParam2(Double data) {
return data.intValue();
}
public PlayerInfoProto.RankResponse getCrossRank(int uid, String rkey, int page, int rankEndLine) throws Exception {
// 每页数量
rankEndLine = rankEndLine==-1?100:rankEndLine;
// 第几页
page = page == 0?1:page;
// 开始和结束位置
int start = (page - 1) * rankEndLine, end = page * rankEndLine - 1;
Set<ZSetOperations.TypedTuple<String>> scores = getRankByKey(rkey, start, end);
if(start % rankEndLine == 0){
start++;
}
PlayerInfoProto.RankResponse.Builder allUserResponse = getCrossAllUserResponse(scores,start);
return allUserResponse.build();
}
protected void getCrossOptional(int index, ZSetOperations.TypedTuple<String> data, PlayerInfoProto.RankResponse.Builder builder) {
CommonProto.RankInfo.Builder everyRankInfo = CommonProto.RankInfo.newBuilder()
.setRank(index)
.setParam1(getParam1(data.getValue()))
.setParam2(getParam2(data.getScore()))
.setParam3(0);
CommonProto.UserRank.Builder oneRank = CommonProto.UserRank.newBuilder().setRankInfo(everyRankInfo);
builder.addRanks(oneRank);
}
public Set<ZSetOperations.TypedTuple<String>> getRankByKey(String rkey, int start, int end){
Map<Integer, SCHero> heroMap = SCHero.getsCHero();
Map<Integer, SHotRanking> config = STableManager.getConfig(SHotRanking.class);
SHotRanking ranking = config.get(Integer.parseInt(rkey));
if (ranking == null || ranking.getOpen() == 0){
LOGGER.error("获取英雄热度排行榜,榜单未开启:{}",rkey);
return new HashSet<>();
}
int naturalLimit = SSpecialConfig.getIntegerValue(SSpecialConfig.HotRanking_Natural);
Set<ZSetOperations.TypedTuple<String>> range = RedisUtil.getInstence().getZsetreverseRangeWithScores(redisKey, rkey, start, end);
Iterator<ZSetOperations.TypedTuple<String>> iterator = range.iterator();
while (iterator.hasNext()){
ZSetOperations.TypedTuple<String> next = iterator.next();
String heroTid = next.getValue();
SCHero scHero = heroMap.get(Integer.parseInt(heroTid));
// 英雄不存在,品质不够,未开放
if (scHero == null || scHero.getNatural() < naturalLimit || scHero.getIsSoulOpen() == 0){
iterator.remove();
}
}
return range;
}
}

View File

@ -38,6 +38,7 @@ import com.ljsd.jieling.logic.mission.MissionType;
import com.ljsd.jieling.logic.question.QuestionLogic;
import com.ljsd.jieling.logic.rank.CrossRankManager;
import com.ljsd.jieling.logic.rank.RankEnum;
import com.ljsd.jieling.logic.rank.RankLogic;
import com.ljsd.jieling.logic.ridingSward.RidingSwardLogic;
import com.ljsd.jieling.logic.sevenworld.SevenWorldLogic;
import com.ljsd.jieling.logic.store.BuyGoodsNewLogic;
@ -97,10 +98,21 @@ public class MinuteTask extends Thread {
// 竞技场,每日晚九点刷新
ArenaLogic.getInstance().sendReward(GlobalsDef.ARENA_DAILY_REWARD);
}
}catch (Exception e){
e.printStackTrace();
LOGGER.error("竞技场Exception::=>{}",e.toString());
}
try {
// 每天晚上10点半英雄热度排行榜同步更新英雄表
if (TimeUtils.getHourOfDay() == 22 && TimeUtils.getMiunte() == 30){
RankLogic.heroHotRankInit();
}
}catch (Exception e){
e.printStackTrace();
LOGGER.error("Exception::=>{}",e.toString());
}
try {
SevenWorldLogic.getInstance().sendRankReward();
}catch (Exception e){

View File

@ -130,8 +130,8 @@ public class SSpecialConfig implements BaseConfig {
public static final String EXPLORERE_LIVETIME = "ExploreReliveTime";//探索时我方阵亡后复活时长
public static final String BUILDING_TIME_REDUCE = "BuildingTimeReduce";//浮生特权每日每次减少建筑升级时间:秒
public static final String CHANGE_CAMP_COST = "ChangeCampCost";//神转换阵营消耗
public static final String GodSignOpenStar = "GodSignOpenStar";//神印格子开启所需神将星级
public static final String HotRanking_Natural = "HotRanking_Natural";//热度排行榜——神将品质(达到这个品质可以显示在热度榜上)
@Override
public void init() throws Exception {