generated from root/miduo_server
Revert "Revert "服务器列表bug""
This reverts commit 1c1c0b2261
.
parent
1c1c0b2261
commit
a4f70e204c
|
@ -15,6 +15,7 @@ import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class GetServerListController extends HttpServlet {
|
public class GetServerListController extends HttpServlet {
|
||||||
private final static String _COLLECTION_NAME = "server_info";
|
private final static String _COLLECTION_NAME = "server_info";
|
||||||
|
@ -42,27 +43,29 @@ public class GetServerListController extends HttpServlet {
|
||||||
String openId = request.getParameter("openId");
|
String openId = request.getParameter("openId");
|
||||||
String channel = request.getParameter("channel");
|
String channel = request.getParameter("channel");
|
||||||
String sub_channel = request.getParameter("sub_channel");
|
String sub_channel = request.getParameter("sub_channel");
|
||||||
|
String server_version = request.getParameter("server_version");
|
||||||
String plat = request.getParameter("plat");
|
String plat = request.getParameter("plat");
|
||||||
if (StringUtils.checkIsEmpty(openId) || StringUtils.checkIsEmpty(channel) ||
|
if (StringUtils.checkIsEmpty(openId) || StringUtils.checkIsEmpty(channel) ||
|
||||||
StringUtils.checkIsEmpty(sub_channel) || StringUtils.checkIsEmpty(plat)) {
|
StringUtils.checkIsEmpty(sub_channel) || StringUtils.checkIsEmpty(plat) || StringUtils.checkIsEmpty(server_version)) {
|
||||||
response.sendError(400, "parm is wrong");
|
response.sendError(400, "parm is wrong");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
DBObject req = new BasicDBObject();
|
// DBObject req = new BasicDBObject();
|
||||||
req.put("channel", channel);
|
// req.put("channel", channel);
|
||||||
req.put("sub_channel", sub_channel);
|
// req.put("sub_channel", sub_channel);
|
||||||
req.put("plat", plat);
|
// req.put("plat", plat);
|
||||||
|
// req.put("server_version", Integer.valueOf(server_version));
|
||||||
|
|
||||||
List<DBObject> serverList = new ArrayList<>();
|
List<DBObject> serverList = new ArrayList<>();
|
||||||
long local = System.currentTimeMillis();
|
// long local = System.currentTimeMillis();
|
||||||
if ((local - lastRefreshTime) > 10 * 1000 || serverInfosCache.isEmpty()) {
|
// if ((local - lastRefreshTime) > 10 * 1000 || serverInfosCache.isEmpty()) {
|
||||||
serverInfosCache.clear();
|
serverInfosCache.clear();
|
||||||
lastRefreshTime = local;
|
// lastRefreshTime = local;
|
||||||
recommend = "";
|
recommend = "";
|
||||||
whiteListCache = BaseGlobal.getInstance().mongoDBPool.findOne(_WHITE_LIST, openId);
|
whiteListCache = BaseGlobal.getInstance().mongoDBPool.findOne(_WHITE_LIST, openId);
|
||||||
List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.find(_COLLECTION_NAME, req);
|
List<DBObject> serverInfoList = BaseGlobal.getInstance().mongoDBPool.findAll(_COLLECTION_NAME);
|
||||||
SortedSet<String> newServerList = new TreeSet<>();
|
SortedSet<String> newServerList = new TreeSet<>();
|
||||||
String maxNumServerId= "";
|
String maxNumServerId = "";
|
||||||
int maxNum = 0;
|
int maxNum = 0;
|
||||||
for (DBObject serverInfo : serverInfoList) {
|
for (DBObject serverInfo : serverInfoList) {
|
||||||
int state = Integer.parseInt(serverInfo.get("state").toString());
|
int state = Integer.parseInt(serverInfo.get("state").toString());
|
||||||
|
@ -77,16 +80,16 @@ public class GetServerListController extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
//state
|
//state
|
||||||
String server_id=serverInfo.get("server_id").toString();
|
String server_id = serverInfo.get("server_id").toString();
|
||||||
int num = getOnlineNum(server_id);
|
int num = getOnlineNum(server_id);
|
||||||
if (whiteListCache != null && state == 1) {
|
if (whiteListCache != null && state == 1) {
|
||||||
state = 2;
|
state = 2;
|
||||||
} else {
|
} else {
|
||||||
if (state == 5) {
|
if (state == 5) {
|
||||||
state = getState(server_id,num);
|
state = getState(server_id, num);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(state==2&&maxNum<num){
|
if (state == 2 && maxNum < num) {
|
||||||
maxNum = num;
|
maxNum = num;
|
||||||
maxNumServerId = server_id;
|
maxNumServerId = server_id;
|
||||||
}
|
}
|
||||||
|
@ -95,13 +98,13 @@ public class GetServerListController extends HttpServlet {
|
||||||
int isnew = 0;
|
int isnew = 0;
|
||||||
if (serverInfo.containsField("is_new"))
|
if (serverInfo.containsField("is_new"))
|
||||||
isnew = Integer.parseInt(serverInfo.get("is_new").toString());
|
isnew = Integer.parseInt(serverInfo.get("is_new").toString());
|
||||||
if(isnew==1){
|
if (isnew == 1) {
|
||||||
newServerList.add(server_id);
|
newServerList.add(server_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
DBObject res = new BasicDBObject();
|
DBObject res = new BasicDBObject();
|
||||||
res.put("name", serverInfo.get("name"));
|
res.put("name", serverInfo.get("name"));
|
||||||
res.put("server_id",server_id);
|
res.put("server_id", server_id);
|
||||||
res.put("state", state);
|
res.put("state", state);
|
||||||
res.put("open_time", serverInfo.get("open_time"));
|
res.put("open_time", serverInfo.get("open_time"));
|
||||||
res.put("isnew", isnew);
|
res.put("isnew", isnew);
|
||||||
|
@ -125,9 +128,23 @@ public class GetServerListController extends HttpServlet {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
// } else {
|
||||||
serverList.addAll(serverInfosCache.values());
|
// Set<DBObject> collect = serverInfosCache.values().stream().filter(dbObject -> {
|
||||||
}
|
//
|
||||||
|
// if(dbObject.containsField("channel")&&!dbObject.get("channel").equals(channel) ){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// if(dbObject.containsField("sub_channel")&&!dbObject.get("sub_channel").equals(sub_channel)){
|
||||||
|
// return false;
|
||||||
|
// } if( dbObject.containsField("plat")&&! dbObject.get("plat").equals(plat)){
|
||||||
|
// return false;
|
||||||
|
// } if( dbObject.containsField("server_version")&&!dbObject.get("server_version").equals(server_version)){
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }).collect(Collectors.toSet());
|
||||||
|
// serverList.addAll(collect);
|
||||||
|
// }
|
||||||
|
|
||||||
//获取我的服务器列表
|
//获取我的服务器列表
|
||||||
Map<String, UserRecentLoginInfo> userServerInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.USER_SERVER_INFO, openId, UserRecentLoginInfo.class, -1, false);
|
Map<String, UserRecentLoginInfo> userServerInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.USER_SERVER_INFO, openId, UserRecentLoginInfo.class, -1, false);
|
||||||
|
@ -135,13 +152,13 @@ public class GetServerListController extends HttpServlet {
|
||||||
List<String> myServerList = new ArrayList<>();
|
List<String> myServerList = new ArrayList<>();
|
||||||
long time = 0;
|
long time = 0;
|
||||||
for (Map.Entry<String, UserRecentLoginInfo> entry : userServerInfoMap.entrySet()) {
|
for (Map.Entry<String, UserRecentLoginInfo> entry : userServerInfoMap.entrySet()) {
|
||||||
if(!serverInfosCache.keySet().contains(entry.getKey())){
|
if (!serverInfosCache.keySet().contains(entry.getKey())) {
|
||||||
//服务器已清除
|
//服务器已清除
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
myServerList.add(entry.getKey());
|
myServerList.add(entry.getKey());
|
||||||
if (entry.getValue().getLoginTime() > time) {
|
if (entry.getValue().getLoginTime() > time) {
|
||||||
time =entry.getValue().getLoginTime();
|
time = entry.getValue().getLoginTime();
|
||||||
myLastServer = getDBObject(entry.getKey(), entry.getValue());
|
myLastServer = getDBObject(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -152,7 +169,7 @@ public class GetServerListController extends HttpServlet {
|
||||||
resp.put("myServerList", myServerList);
|
resp.put("myServerList", myServerList);
|
||||||
if (null != myLastServer)
|
if (null != myLastServer)
|
||||||
resp.put("lastServer", myLastServer);
|
resp.put("lastServer", myLastServer);
|
||||||
if(recommend!=null&&!recommend.equals("")){
|
if (recommend != null && !recommend.equals("")) {
|
||||||
resp.put("recommend", recommend);
|
resp.put("recommend", recommend);
|
||||||
}
|
}
|
||||||
out.print(resp.toString());
|
out.print(resp.toString());
|
||||||
|
@ -178,7 +195,7 @@ public class GetServerListController extends HttpServlet {
|
||||||
this.doGet(request, response);
|
this.doGet(request, response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getState(String server_id,int num) throws Exception {
|
private int getState(String server_id, int num) throws Exception {
|
||||||
int state = 2;
|
int state = 2;
|
||||||
Map<String, String> globalCfgMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.GLOBAL_SYS_PRO, "", String.class, -1, false);
|
Map<String, String> globalCfgMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.GLOBAL_SYS_PRO, "", String.class, -1, false);
|
||||||
int crowdnum = Integer.valueOf(globalCfgMap.getOrDefault("crowdnum", "0"));
|
int crowdnum = Integer.valueOf(globalCfgMap.getOrDefault("crowdnum", "0"));
|
||||||
|
|
Loading…
Reference in New Issue