generated from root/miduo_server
parent
6569f0c60f
commit
7fcecdc205
|
|
@ -2,8 +2,6 @@ package com.jmfy.handler;
|
|||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
public abstract class BaseHandler {
|
||||
private int pid;
|
||||
private int gid;
|
||||
|
|
@ -12,7 +10,7 @@ public abstract class BaseHandler {
|
|||
return "";
|
||||
}
|
||||
|
||||
public abstract int execute(HttpServletRequest request) throws Exception ;
|
||||
public abstract int execute(JSONObject json) throws Exception ;
|
||||
|
||||
public int getPid() {
|
||||
return pid;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
|
|
@ -23,9 +22,129 @@ public class GMHandler extends BaseHandler {
|
|||
@Resource
|
||||
private UserInfoDao gsUserDao;
|
||||
|
||||
public int execute(HttpServletRequest request) throws Exception {
|
||||
public int execute(JSONObject jsonObject) throws Exception {
|
||||
|
||||
return 1;
|
||||
String uid;
|
||||
int dsid;
|
||||
int treat_type;
|
||||
uid = jsonObject.getString("uid");
|
||||
dsid = jsonObject.getIntValue("dsid");
|
||||
treat_type = jsonObject.getIntValue("treat_type");
|
||||
|
||||
boolean allServer = false;
|
||||
|
||||
String cmd = "";
|
||||
switch (treat_type){
|
||||
case 1:
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String actor_id_ban = jsonObject.getString("actor_id");
|
||||
cmd="silence "+actor_id_ban+" 1";
|
||||
break;
|
||||
case 2:
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String actor_id_no_ban = jsonObject.getString("actor_id");
|
||||
cmd="silence "+actor_id_no_ban+" 0";
|
||||
break;
|
||||
case 4:
|
||||
if(dsid==0){
|
||||
allServer=true;
|
||||
cmd="addblack ";
|
||||
}else {
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String id = jsonObject.getString("actor_id");
|
||||
cmd="addblack "+id;
|
||||
}
|
||||
break;
|
||||
case 5:
|
||||
if(dsid==0){
|
||||
allServer=true;
|
||||
cmd="reblack ";
|
||||
}else {
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String id2 = jsonObject.getString("actor_id");
|
||||
cmd="reblack "+id2;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String actor_id = jsonObject.getString("actor_id");
|
||||
cmd="kick "+actor_id;
|
||||
break;
|
||||
case 6:
|
||||
if(!jsonObject.containsKey("actor_id")){
|
||||
throw new Exception("缺少参数");
|
||||
}
|
||||
String actor_id2 = jsonObject.getString("actor_id");
|
||||
if(!jsonObject.containsKey("actor_name")){
|
||||
cmd="changename "+actor_id2;
|
||||
}else {
|
||||
String actor_name = jsonObject.getString("actor_name");
|
||||
cmd="changename "+actor_id2+" "+actor_name;
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if(allServer){
|
||||
List<CUserInfo> coreUserInfoList = gsUserDao.findUserInfo(uid);
|
||||
if (coreUserInfoList == null) {
|
||||
throw new Exception("帐号不存在");
|
||||
} else {
|
||||
if (coreUserInfoList.size() == 0)
|
||||
throw new Exception("帐号不存在");
|
||||
for (CUserInfo coreUserInfo : coreUserInfoList) {
|
||||
ServerInfo coreServerList = serverListDao.getServerinfo(coreUserInfo.getServerid());
|
||||
if (null == coreServerList) {
|
||||
continue;
|
||||
} else {
|
||||
String thriftIp = coreServerList.getIP();
|
||||
String thriftPort = String.valueOf(7901);
|
||||
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
continue;
|
||||
} else {
|
||||
cmd = cmd+coreUserInfo.getUserId();
|
||||
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
|
||||
//异常或者错误
|
||||
// if (result.getResultCode() != 0) {
|
||||
// continue;
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}else {
|
||||
|
||||
ServerInfo coreServerList = serverListDao.getServerinfo(dsid);
|
||||
if (null == coreServerList) {
|
||||
throw new Exception("应用不存在");
|
||||
} else {
|
||||
String thriftIp = coreServerList.getIP();
|
||||
String thriftPort = String.valueOf(7900 + 1);
|
||||
if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) {
|
||||
throw new Exception("serverAddress not exist");
|
||||
} else {
|
||||
|
||||
Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort);
|
||||
if (result.getResultCode() != 0) {
|
||||
throw new Exception(result.getResultMsg());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue