generated from root/miduo_server
增加gamota获取战力排行榜接口
parent
bd2e6a1847
commit
b2d8243cf4
|
@ -41,6 +41,7 @@ public class WebSecurityConfig extends WebMvcConfigurerAdapter{
|
|||
addInterceptor.excludePathPatterns("/login**");
|
||||
addInterceptor.excludePathPatterns("/req/**");
|
||||
addInterceptor.excludePathPatterns("/gomotaGetRoleList**");
|
||||
addInterceptor.excludePathPatterns("/gamotaGetForceRank**");
|
||||
|
||||
addInterceptor.addPathPatterns("/**");
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.jmfy.dao.UserInfoDao;
|
|||
import com.jmfy.dao.impl.GSUserDaoImpl;
|
||||
import com.jmfy.handler.HeFuManager;
|
||||
import com.jmfy.model.*;
|
||||
import com.jmfy.model.vo.CSPlayer;
|
||||
import com.jmfy.model.vo.CUserVo;
|
||||
import com.jmfy.model.vo.Hero;
|
||||
import com.jmfy.model.vo.UserGodLvVo;
|
||||
|
@ -15,6 +16,7 @@ import com.mongodb.BasicDBObject;
|
|||
import com.mongodb.DBObject;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.ModelMap;
|
||||
|
@ -29,6 +31,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
import javax.servlet.http.HttpSession;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
/**
|
||||
* Created by huangds on 2017/10/24.
|
||||
|
@ -160,6 +163,131 @@ public class UserInfoController {
|
|||
return resp.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取战力排行榜信息
|
||||
* @param map
|
||||
* @param request
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@RequestMapping(value = "/gamotaGetForceRank", method = {RequestMethod.POST, RequestMethod.GET})
|
||||
@ResponseBody
|
||||
public String gamotaGetForceRankInfo(ModelMap map, HttpServletRequest request) throws Exception {
|
||||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
||||
String start_time = request.getParameter("start_time");
|
||||
String end_time = request.getParameter("end_time");
|
||||
String server_id = request.getParameter("server_id");
|
||||
String hash = request.getParameter("hash");
|
||||
String limit = request.getParameter("limit");
|
||||
DBObject resp = new BasicDBObject();
|
||||
List<JSONObject> roleList = new ArrayList<>();
|
||||
if (StringUtils.checkIsEmpty(start_time)) {
|
||||
resp.put("message", "start_time null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(end_time)) {
|
||||
resp.put("message", "end_time null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(server_id)) {
|
||||
resp.put("message", "server_id null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
if (StringUtils.checkIsEmpty(limit)) {
|
||||
resp.put("message", "limit null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
|
||||
if (StringUtils.checkIsEmpty(hash)) {
|
||||
resp.put("message", "hash null");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
// String signStr = start_time + appota_user_id + server_id + GamotaConstats.secretKey;
|
||||
// String sign = MD5Util.encrypByMd5New(signStr);
|
||||
// if(!sign.equals(signature)){
|
||||
// LOGGER.info("sign=" + sign + " --- signature="+signature);
|
||||
// resp.put("message", "signature error");
|
||||
// resp.put("error_code", 1);
|
||||
// resp.put("data", roleList);
|
||||
// return resp.toString();
|
||||
// }
|
||||
ServerInfo server = serverInfoDao.getServerInfo(server_id);
|
||||
if(server == null){
|
||||
resp.put("message", "server null with server_id : " + server_id);
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
int end = Integer.parseInt(limit);
|
||||
if(end <=0){
|
||||
resp.put("message", "limit 0");
|
||||
resp.put("error_code", 1);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
//考虑到性能开销,最多查100个
|
||||
int max = 100;
|
||||
if(end > max){
|
||||
end = max;
|
||||
}
|
||||
String key = server_id + RedisUserKey.Delimiter_colon + RedisUserKey.FORCE_CURR_RANK +RedisUserKey.Delimiter_colon;
|
||||
Set<ZSetOperations.TypedTuple<String>> zsetreverseRangeWithScores = RedisUtil.getInstence().getZsetreverseRangeWithScoresOrigin(key,0,end - 1);
|
||||
List<String> keys = new ArrayList<String>();
|
||||
Map<Integer,Integer> powers = new HashMap<Integer,Integer>();
|
||||
forEach(1, zsetreverseRangeWithScores, (index, data) -> {
|
||||
keys.add(RedisUserKey.CROSS_SERVER_USER + RedisUserKey.Delimiter_colon + data.getValue());
|
||||
int uid = Integer.parseInt(data.getValue());
|
||||
int power = data.getScore().intValue();
|
||||
powers.put(uid,power);
|
||||
});
|
||||
List<CSPlayer> list = RedisUtil.getInstence().multiGet(keys,CSPlayer.class);
|
||||
if(list != null && list.size() > 0){
|
||||
int order = 1;
|
||||
for(CSPlayer player : list){
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("order",order);
|
||||
obj.put("role_id",player.getUserId());
|
||||
obj.put("role_name",player.getName());
|
||||
obj.put("server_id",server_id);
|
||||
obj.put("server_name",server.getName());
|
||||
int power = 0;
|
||||
if(powers.containsKey(player.getUserId())){
|
||||
power = powers.get(player.getUserId());
|
||||
}
|
||||
obj.put("power",power);
|
||||
roleList.add(obj);
|
||||
order++;
|
||||
}
|
||||
}
|
||||
resp.put("message", "success");
|
||||
resp.put("error_code", 0);
|
||||
resp.put("data", roleList);
|
||||
return resp.toString();
|
||||
}
|
||||
|
||||
protected static <T> void forEach(int startIndex, Iterable<? extends T> elements, BiConsumer<Integer, ? super T> action) {
|
||||
Objects.requireNonNull(elements);
|
||||
Objects.requireNonNull(action);
|
||||
if (startIndex < 0) {
|
||||
startIndex = 0;
|
||||
}
|
||||
int index = startIndex;
|
||||
for (T element : elements) {
|
||||
index++;
|
||||
action.accept(index - 1, element);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value = "/getHeroInfo", method = {RequestMethod.POST, RequestMethod.GET})
|
||||
@ResponseBody
|
||||
|
|
|
@ -7,10 +7,12 @@ import com.jmfy.redisProperties.RedisUserKey;
|
|||
import com.jmfy.utils.RedisUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.redis.core.ZSetOperations;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
|
@ -77,4 +79,6 @@ public class RedisLogic {
|
|||
RedisUtil.getInstence().putMapEntry(RedisUserKey.SERVER_INFO,serverInfo.getServer_id(),serverInfo,-1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,246 @@
|
|||
package com.jmfy.model.vo;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/8/31 15:30:04
|
||||
* @Description: 角色信息
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class CSPlayer {
|
||||
private int userId;//角色id
|
||||
private int level;//等级
|
||||
private String name;//名字
|
||||
private int head;//头像
|
||||
private int headFrame;//头像框
|
||||
private int skin;//皮肤
|
||||
private int userTitle;//称号
|
||||
private int practiceLevel;//修行等级
|
||||
private int serverId;//服务器id
|
||||
private int sex;//性别
|
||||
private int userMount;//坐骑
|
||||
private int guildId;//公会id
|
||||
private long maxFore;//最高战力
|
||||
private int crossYuxulundaoOldScore;//玉虚论道旧分数
|
||||
private int crossYuxulundaoNewScore;//玉虚论道最新分数
|
||||
private int crossYxldMaxLevel;//玉虚论道历史达到的最高等级
|
||||
private long loginTime;// 登陆时间
|
||||
private long offLineTime;// 离线时间
|
||||
// 数字小游戏
|
||||
private int compareNumLevelId;
|
||||
private int compareNumLevelTime;
|
||||
private Map<Integer, List<Integer>> teamHeroIdMap = new HashMap<>();// 队伍内的英雄模板id
|
||||
private int arenaLvId;//段位id
|
||||
private Map<Integer, Long> teamForce = new HashMap<>();//队伍战力
|
||||
|
||||
public CSPlayer() {
|
||||
}
|
||||
|
||||
public int getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(int userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public int getSex() {
|
||||
return sex;
|
||||
}
|
||||
|
||||
public void setSex(int sex) {
|
||||
this.sex = sex;
|
||||
}
|
||||
|
||||
public int getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public void setHead(int head) {
|
||||
this.head = head;
|
||||
}
|
||||
|
||||
public int getHeadFrame() {
|
||||
return headFrame;
|
||||
}
|
||||
|
||||
public void setHeadFrame(int headFrame) {
|
||||
this.headFrame = headFrame;
|
||||
}
|
||||
|
||||
public int getSkin() {
|
||||
return skin;
|
||||
}
|
||||
|
||||
public void setSkin(int skin) {
|
||||
this.skin = skin;
|
||||
}
|
||||
|
||||
public int getUserTitle() {
|
||||
return userTitle;
|
||||
}
|
||||
|
||||
public void setUserTitle(int userTitle) {
|
||||
this.userTitle = userTitle;
|
||||
}
|
||||
|
||||
public int getUserMount() {
|
||||
return userMount;
|
||||
}
|
||||
|
||||
public void setUserMount(int userMount) {
|
||||
this.userMount = userMount;
|
||||
}
|
||||
|
||||
public int getPracticeLevel() {
|
||||
return practiceLevel;
|
||||
}
|
||||
|
||||
public void setPracticeLevel(int practiceLevel) {
|
||||
this.practiceLevel = practiceLevel;
|
||||
}
|
||||
|
||||
public int getGuildId() {
|
||||
return guildId;
|
||||
}
|
||||
|
||||
public void setGuildId(int guildId) {
|
||||
this.guildId = guildId;
|
||||
}
|
||||
|
||||
public int getServerId() {
|
||||
return this.serverId;
|
||||
}
|
||||
|
||||
public void setServerId(int serverId) {
|
||||
this.serverId = serverId;
|
||||
}
|
||||
|
||||
public long getMaxFore() {
|
||||
return maxFore;
|
||||
}
|
||||
|
||||
public void setMaxFore(long maxFore) {
|
||||
this.maxFore = maxFore;
|
||||
}
|
||||
|
||||
public int getCrossYuxulundaoNewScore() {
|
||||
return crossYuxulundaoNewScore;
|
||||
}
|
||||
|
||||
public void setCrossYuxulundaoNewScore(int crossYuxulundaoNewScore) {
|
||||
this.crossYuxulundaoNewScore = crossYuxulundaoNewScore;
|
||||
}
|
||||
|
||||
public int getCrossYuxulundaoOldScore() {
|
||||
return crossYuxulundaoOldScore;
|
||||
}
|
||||
|
||||
public void setCrossYuxulundaoOldScore(int crossYuxulundaoOldScore) {
|
||||
this.crossYuxulundaoOldScore = crossYuxulundaoOldScore;
|
||||
}
|
||||
|
||||
public int getCrossYxldMaxLevel() {
|
||||
return crossYxldMaxLevel;
|
||||
}
|
||||
|
||||
public void setCrossYxldMaxLevel(int crossYxldMaxLevel) {
|
||||
this.crossYxldMaxLevel = crossYxldMaxLevel;
|
||||
}
|
||||
|
||||
public long getOffLineTime() {
|
||||
return offLineTime;
|
||||
}
|
||||
|
||||
public void setOffLineTime(long offLineTime) {
|
||||
this.offLineTime = offLineTime;
|
||||
}
|
||||
|
||||
public long getLoginTime() {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(long loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public int getCompareNumLevelId() {
|
||||
return compareNumLevelId;
|
||||
}
|
||||
|
||||
public void setCompareNumLevelId(int compareNumLevelId) {
|
||||
this.compareNumLevelId = compareNumLevelId;
|
||||
}
|
||||
|
||||
public int getCompareNumLevelTime() {
|
||||
return compareNumLevelTime;
|
||||
}
|
||||
|
||||
public void setCompareNumLevelTime(int compareNumLevelTime) {
|
||||
this.compareNumLevelTime = compareNumLevelTime;
|
||||
}
|
||||
|
||||
public long getMainLineForce() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getYuxuForce() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long getLuofuForce(){
|
||||
return 0;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> getTeamHeroIdMap() {
|
||||
return teamHeroIdMap;
|
||||
}
|
||||
|
||||
public List<Integer> getTeamHeroId(int teamId) {
|
||||
return teamHeroIdMap.getOrDefault(teamId, new ArrayList<>(0));
|
||||
}
|
||||
|
||||
public void setTeamHeroIdMap(Map<Integer, List<Integer>> teamHeroIdMap) {
|
||||
this.teamHeroIdMap = teamHeroIdMap;
|
||||
}
|
||||
|
||||
public void putTeamHeroIds(int teamId, List<Integer> heroTIds) {
|
||||
this.teamHeroIdMap.put(teamId, heroTIds);
|
||||
}
|
||||
|
||||
public int getArenaLvId() {
|
||||
return arenaLvId;
|
||||
}
|
||||
|
||||
public void setArenaLvId(int arenaLvId) {
|
||||
this.arenaLvId = arenaLvId;
|
||||
}
|
||||
|
||||
public Map<Integer, Long> getTeamForce() {
|
||||
return teamForce;
|
||||
}
|
||||
|
||||
public void setTeamForce(Map<Integer, Long> teamForce) {
|
||||
this.teamForce = teamForce;
|
||||
}
|
||||
}
|
|
@ -52,6 +52,9 @@ public class RedisUserKey {
|
|||
|
||||
public static final String GOD_LEVEL_UP_TIME = "GOD_LEVEL_UP_TIME";//晋升神尊等级排序
|
||||
|
||||
public static final String FORCE_CURR_RANK = "FORCE_CURR_RANK";//战力排行榜
|
||||
public static final String CROSS_SERVER_USER = "CROSS_SERVER_USER";//redis存储个人基本信息
|
||||
|
||||
public static String getKey(String type, String key, int serverId) {
|
||||
if (serverId==0) {
|
||||
return type + Delimiter_colon + key;
|
||||
|
|
|
@ -96,6 +96,18 @@ public class RedisUtil {
|
|||
return null;
|
||||
}
|
||||
|
||||
public <T> List<T> multiGet(List<String> keys, Class<T> clazz){
|
||||
List<String> results = redisObjectTemplate.opsForValue().multiGet(keys);
|
||||
List<T> list = new ArrayList<>();
|
||||
for (String result : results) {
|
||||
if (StringUtil.isEmpty(result)) {
|
||||
continue;
|
||||
}
|
||||
list.add(gson.fromJson(result, clazz));
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public void delHash(String type, String key, String mapId) {
|
||||
redisObjectTemplate.opsForHash().delete(type + ":" + key, mapId);
|
||||
}
|
||||
|
@ -436,4 +448,18 @@ public class RedisUtil {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据分数逆向获取排行
|
||||
*/
|
||||
public Set<ZSetOperations.TypedTuple<String>> getZsetreverseRangeWithScoresOrigin(String key, long start, long end){
|
||||
for (int i = 0; i < MAX_TRY_TIMES; i++) {
|
||||
try {
|
||||
return redisObjectTemplate.opsForZSet().reverseRangeWithScores(key, start, end);
|
||||
} catch (Exception e) {
|
||||
sleep(FAILED_SLEEP);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue