generated from root/miduo_server
服务器列表 登录校验 最近服务器
parent
15a556af40
commit
413859fc59
|
|
@ -1,5 +1,6 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.ljsd.pojo.UserRecentLoginInfo;
|
||||
import com.ljsd.pojo.UserServerInfo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
|
|
@ -51,18 +52,25 @@ public class GetServerListController extends HttpServlet {
|
|||
if (System.currentTimeMillis() < time) {
|
||||
continue;
|
||||
}
|
||||
int state = 2;
|
||||
int state = Integer.parseInt(serverInfo.get("state").toString());
|
||||
|
||||
if (state == 0 ){
|
||||
continue;
|
||||
}
|
||||
if (whiteList != null && state ==1){
|
||||
state = 2;
|
||||
}
|
||||
|
||||
int isnew = 0;
|
||||
if(serverInfo.containsField("is_new"))
|
||||
isnew = Integer.parseInt(serverInfo.get("is_new").toString());
|
||||
|
||||
DBObject res = new BasicDBObject();
|
||||
res.put("name", serverInfo.get("name"));
|
||||
res.put("server_id", serverInfo.get("server_id"));
|
||||
res.put("state", state);
|
||||
res.put("open_time", serverInfo.get("open_time"));
|
||||
res.put("isnew", isnew);
|
||||
Object ip = serverInfo.get("ip");
|
||||
Object port = serverInfo.get("port");
|
||||
if (state ==1){ // 服务器状态为维护的话不传给前端ip端口
|
||||
|
|
@ -75,18 +83,22 @@ public class GetServerListController extends HttpServlet {
|
|||
}
|
||||
|
||||
//获取我的服务器列表
|
||||
Map<String, UserServerInfo> userServerInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.USER_SERVER_INFO, openId, UserServerInfo.class, -1, false);
|
||||
List<DBObject> myServerList = new ArrayList<>();
|
||||
for (Map.Entry<String, UserServerInfo> entry : userServerInfoMap.entrySet()) {
|
||||
DBObject res = new BasicDBObject();
|
||||
res.put("server_id", entry.getKey());
|
||||
res.put("login_time", entry.getValue().getLoginTime());
|
||||
res.put("level", entry.getValue().getLevel());
|
||||
myServerList.add(res);
|
||||
Map<String, UserRecentLoginInfo> userServerInfoMap = BaseGlobal.getInstance().redisApp.hgetAll(RedisKey.USER_SERVER_INFO, openId, UserRecentLoginInfo.class, -1, false);
|
||||
DBObject myLastServer = null;
|
||||
List<String> myServerList = new ArrayList<>();
|
||||
int time = 0;
|
||||
for (Map.Entry<String, UserRecentLoginInfo> entry : userServerInfoMap.entrySet()) {
|
||||
myServerList.add(entry.getKey());
|
||||
if(entry.getValue().getLoginTime()>time){
|
||||
myLastServer=getDBObject(entry.getKey(),entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
DBObject resp = new BasicDBObject();
|
||||
resp.put("serverList", serverList);
|
||||
resp.put("myServerList", myServerList);
|
||||
if(null!=myLastServer)
|
||||
resp.put("lastServer", myLastServer);
|
||||
out.print(resp.toString());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
@ -97,6 +109,14 @@ public class GetServerListController extends HttpServlet {
|
|||
|
||||
}
|
||||
|
||||
private DBObject getDBObject(String serverId,UserRecentLoginInfo userRecentLoginInfo){
|
||||
DBObject res = new BasicDBObject();
|
||||
res.put("serverid",serverId);
|
||||
res.put("name", userRecentLoginInfo.getName());
|
||||
res.put("level", userRecentLoginInfo.getLevel());
|
||||
return res;
|
||||
}
|
||||
|
||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
this.doGet(request, response);
|
||||
|
|
|
|||
|
|
@ -102,7 +102,7 @@ public class GetUserController extends HttpServlet {
|
|||
uid = (int) userInfos.get(0).get("uid");
|
||||
res.put("uid", uid);
|
||||
res.put("token", utoken);
|
||||
BaseGlobal.getInstance().redisApp.set(RedisKey.TOKEN, String.valueOf(uid), token, -1, false);
|
||||
BaseGlobal.getInstance().redisApp.set(RedisKey.TOKEN, String.valueOf(uid), utoken, -1, false);
|
||||
PrintWriter out = response.getWriter();
|
||||
out.print(res);
|
||||
out.flush();
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ public class RegistController extends HttpServlet {
|
|||
String state = request.getParameter("state");
|
||||
String open_time = request.getParameter("open_time");
|
||||
String token = request.getParameter("token");
|
||||
String isnew = request.getParameter("isnew");
|
||||
DBObject doc = new BasicDBObject();
|
||||
doc.put("_id", serverId);
|
||||
doc.put("name", name);
|
||||
|
|
@ -51,6 +52,7 @@ public class RegistController extends HttpServlet {
|
|||
doc.put("plat", plat);
|
||||
doc.put("state", state);
|
||||
doc.put("open_time", open_time);
|
||||
doc.put("isnew", isnew);
|
||||
BaseGlobal.getInstance().mongoDBPool.save("server_info", doc);
|
||||
response.setContentType("text/html");
|
||||
PrintWriter out = response.getWriter();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,51 @@
|
|||
package com.ljsd.pojo;
|
||||
|
||||
public class UserRecentLoginInfo {
|
||||
|
||||
private long loginTime;
|
||||
|
||||
private int level;
|
||||
|
||||
private int uid;
|
||||
|
||||
private String name;
|
||||
|
||||
public UserRecentLoginInfo(long loginTime, int level, int uid, String name) {
|
||||
this.loginTime = loginTime;
|
||||
this.level = level;
|
||||
this.uid = uid;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getLoginTime() {
|
||||
return loginTime;
|
||||
}
|
||||
|
||||
public void setLoginTime(long loginTime) {
|
||||
this.loginTime = loginTime;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public int getUid() {
|
||||
return uid;
|
||||
}
|
||||
|
||||
public void setUid(int uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,7 @@
|
|||
</select></p>
|
||||
<p>state: <input type="text" value="0" name="state" /></p>
|
||||
<p>open_time: <input type="text" value="0" name="open_time" /></p>
|
||||
<p>isnew: <input type="text" value="0" name="isnew" /></p>
|
||||
<input type="submit" value="Submit"/>
|
||||
</form>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue