From 6d0f061a58418b4a47078d1ea01efb5b944b46e8 Mon Sep 17 00:00:00 2001 From: zhangshanxue Date: Wed, 11 Sep 2019 10:16:39 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B7=91=E9=A9=AC=E7=81=AF=20=E5=85=AC?= =?UTF-8?q?=E5=91=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jmfy/controller/GameTitleController.java | 38 +----- .../com/jmfy/controller/MsgController.java | 74 ++++++++++ .../com/jmfy/controller/NoticeController.java | 27 ++++ .../jmfy/controller/QuestionController.java | 23 ++-- src/main/java/com/jmfy/dao/NoticeInfoDao.java | 7 + .../com/jmfy/dao/impl/NoticeInfoDaoImpl.java | 33 +++++ .../java/com/jmfy/handler/BaseHandler.java | 4 +- src/main/java/com/jmfy/handler/GMHandler.java | 125 +---------------- src/main/java/com/jmfy/model/NoticeInfo.java | 40 ++++++ .../resources/static/html/member-add.html | 3 + .../resources/static/html/sendSysMSG.html | 124 +++++++++++++++++ .../resources/static/html/sendSysNotice.html | 129 ++++++++++++++++++ src/main/resources/templates/index.html | 4 + 13 files changed, 469 insertions(+), 162 deletions(-) create mode 100644 src/main/java/com/jmfy/controller/MsgController.java create mode 100644 src/main/java/com/jmfy/controller/NoticeController.java create mode 100644 src/main/java/com/jmfy/dao/NoticeInfoDao.java create mode 100644 src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java create mode 100644 src/main/java/com/jmfy/model/NoticeInfo.java create mode 100644 src/main/resources/static/html/sendSysMSG.html create mode 100644 src/main/resources/static/html/sendSysNotice.html diff --git a/src/main/java/com/jmfy/controller/GameTitleController.java b/src/main/java/com/jmfy/controller/GameTitleController.java index 546e47c..bdad9d3 100644 --- a/src/main/java/com/jmfy/controller/GameTitleController.java +++ b/src/main/java/com/jmfy/controller/GameTitleController.java @@ -72,13 +72,13 @@ public class GameTitleController { @RequestMapping(value = "/backC", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int backC(HttpSession session, ModelMap map , HttpServletRequest request) { try { - JSONObject jsonObject; - HashMap parameterMap = JsonUtil.getInstence().getParameterMap(request); - String jsonString = JSON.toJSONString(parameterMap); - jsonObject = JSON.parseObject(jsonString); - BaseHandler handler = ManagerManager.getInstance().getBaseHandler("gm"); - int result = handler.execute(jsonObject); - return result; +// JSONObject jsonObject; +// HashMap parameterMap = JsonUtil.getInstence().getParameterMap(request); +// String jsonString = JSON.toJSONString(parameterMap); +// jsonObject = JSON.parseObject(jsonString); +// BaseHandler handler = ManagerManager.getInstance().getBaseHandler("gm"); +// int result = handler.execute(jsonObject); + return 1; } catch (Exception e) { return 0; } @@ -252,30 +252,6 @@ public class GameTitleController { userInfoDao.updateStatus(update, cuserinfo); } - private void updateBlackInfo(int banTime, String banReason, BlackList blackList, int banEndTime) throws Exception { - Map blackMap = blackList.getBlackListMap(); - blackMap.put(0, banEndTime + "|" + banReason); - blackList.setBlackListMap(blackMap); - Map sealTimeLengthMap = blackList.getSealTimeLength(); - sealTimeLengthMap.put(0, banTime); - blackList.setSealTimeLength(sealTimeLengthMap); - Update update = new Update(); - update.set("black_list_map", blackMap); - update.set("sealTime_length", sealTimeLengthMap); - userInfoDao.updateBlack(update, blackList); - } - private void addBlackList(int banTime, String banReason,int banEndTime,String userId) throws Exception { - BlackList blackList = new BlackList(); - Map blackMap = new HashMap<>(); - blackMap.put(0, banEndTime + "|" + banReason); - Map sealTimeLengthMap = new HashMap<>(); - sealTimeLengthMap.put(0, banTime); - blackList.setBlack_openid(userId); - blackList.setServerid(0); - blackList.setBlackListMap(blackMap); - blackList.setSealTimeLength(sealTimeLengthMap); - userInfoDao.addBlackList(blackList); - } } diff --git a/src/main/java/com/jmfy/controller/MsgController.java b/src/main/java/com/jmfy/controller/MsgController.java new file mode 100644 index 0000000..2adcf46 --- /dev/null +++ b/src/main/java/com/jmfy/controller/MsgController.java @@ -0,0 +1,74 @@ +package com.jmfy.controller; + +import com.jmfy.dao.ServerInfoDao; +import com.jmfy.dao.impl.NoticeInfoDaoImpl; +import com.jmfy.model.CServerOpenTime; +import com.jmfy.model.ServerInfo; +import com.jmfy.thrift.idl.Result; +import com.jmfy.utils.RPCClient; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.ArrayList; +import java.util.List; + + +@Controller +public class MsgController { + @Resource + private ServerInfoDao serverInfoDao; + + @RequestMapping(value = "/publishMSG", method = {RequestMethod.POST, RequestMethod.GET}) + public @ResponseBody + int publishNotice(HttpServletRequest request) throws Exception { + + List allServerInfo = serverInfoDao.getAllServerInfo(); + List serverList = new ArrayList<>(); + + for (ServerInfo serverInfo : allServerInfo) { + serverList.add(serverInfo.getServer_id()); + } + + String content = request.getParameter("content1"); + String serverId = request.getParameter("serverId"); + String cmd = "sendmsg " + content; + + String[] split = serverId.split(","); + + if (split.length==1&&split[0].equals("0")) {//全服 + serverList.toArray(split); + } + for (String str : split) { + + if (!serverList.contains(str)) { + continue; + } + try { + ServerInfo serverInfo = serverInfoDao.getServerinfo(Integer.valueOf(serverId)); + //TODO 分服 + String thriftIp = serverInfo.getIP(); + String thriftPort = String.valueOf(7901); + if (thriftIp == null || thriftIp.isEmpty() || null == thriftPort || thriftPort.isEmpty()) { + return -1; + } else { + Result result = RPCClient.gmSend(cmd, thriftIp, thriftPort); + //异常或者错误 + if (result.getResultCode() != 0) { + continue; + } + } + } catch (Exception e) { + e.printStackTrace(); + return 1; + } + } + + + return 0; + } + +} diff --git a/src/main/java/com/jmfy/controller/NoticeController.java b/src/main/java/com/jmfy/controller/NoticeController.java new file mode 100644 index 0000000..e667aef --- /dev/null +++ b/src/main/java/com/jmfy/controller/NoticeController.java @@ -0,0 +1,27 @@ +package com.jmfy.controller; + +import com.jmfy.dao.impl.NoticeInfoDaoImpl; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; + + +@Controller +public class NoticeController { + @Resource + private NoticeInfoDaoImpl noticeInfoDao; + + @RequestMapping(value = "/publishNotice", method = {RequestMethod.POST, RequestMethod.GET}) + public @ResponseBody + int publishNotice(HttpServletRequest request) throws Exception { + String content = request.getParameter("content1"); + String title = request.getParameter("title1"); + noticeInfoDao.updateNoticeInfo(title,content); + return 0; + } + +} diff --git a/src/main/java/com/jmfy/controller/QuestionController.java b/src/main/java/com/jmfy/controller/QuestionController.java index 0df87c7..8866079 100644 --- a/src/main/java/com/jmfy/controller/QuestionController.java +++ b/src/main/java/com/jmfy/controller/QuestionController.java @@ -197,11 +197,11 @@ public class QuestionController { @RequestMapping(value = "/sendquestion", method = {RequestMethod.POST, RequestMethod.GET}) public String sendquestion(HttpSession session, ModelMap map, HttpServletRequest request) throws Exception { - Set cQuestSendVo; + + Set cQuestSendVo; HashMap parameterMap = JsonUtil.getInstence().getParameterMap(request); String serveIds = request.getParameter("serverId"); - String backtype = parameterMap.get("backtype"); switch (backtype) { case "0": @@ -234,19 +234,19 @@ public class QuestionController { List filter = new ArrayList<>(); if (!serveIds.equals("0")) { String[] split = serveIds.split(","); - filter = Arrays.asList(split); + if (split.length != 1 || !split[0].equals("")) { + filter = Arrays.asList(split); + } } - + final List filterfinal = filter; Map valueMap = RedisUtil.getInstence().getRedisMapString(RedisUserKey.QUESTION_FROMBACK_ALL + RedisUserKey.Delimiter_colon); - if (filter.size() != 0) { - filter.forEach(valueMap::remove); - } Map treeMap = new TreeMap<>(valueMap); treeMap.forEach((key, value) -> { CQuestionCoreBean cQuestionCoreBean = gson.fromJson(value, CQuestionCoreBean.class); CQuestSendVo cQuestSendVo1 = new CQuestSendVo(); + String[] split2 = cQuestionCoreBean.getServerId().split(","); cQuestSendVo1.setServerid(cQuestionCoreBean.getServerId()); cQuestSendVo1.setId(Integer.valueOf(key)); Date data = new Date(Long.valueOf(cQuestionCoreBean.getcQuestionBean().getStart()) * 1000L); @@ -254,7 +254,14 @@ public class QuestionController { Date data2 = new Date(Long.valueOf(cQuestionCoreBean.getcQuestionBean().getEnd()) * 1000L); cQuestSendVo1.setEnd(ymdhmsFormat_new.format(data2)); cQuestSendVo1.setValue(value); - cQuestSendVo.add(cQuestSendVo1); + + if (filterfinal.size() == 0) { + cQuestSendVo.add(cQuestSendVo1); + } else { + if (filterfinal.containsAll(Arrays.asList(split2))||cQuestionCoreBean.getServerId().equals("0")) + cQuestSendVo.add(cQuestSendVo1); + } + }); map.addAttribute("cQuestSendVo", cQuestSendVo); return "questsendInfo"; diff --git a/src/main/java/com/jmfy/dao/NoticeInfoDao.java b/src/main/java/com/jmfy/dao/NoticeInfoDao.java new file mode 100644 index 0000000..53a39a8 --- /dev/null +++ b/src/main/java/com/jmfy/dao/NoticeInfoDao.java @@ -0,0 +1,7 @@ +package com.jmfy.dao; + +public interface NoticeInfoDao { + + void updateNoticeInfo(String title,String content) throws Exception; + +} diff --git a/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java b/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java new file mode 100644 index 0000000..8fd03d2 --- /dev/null +++ b/src/main/java/com/jmfy/dao/impl/NoticeInfoDaoImpl.java @@ -0,0 +1,33 @@ +package com.jmfy.dao.impl; + +import com.jmfy.dao.NoticeInfoDao; +import com.jmfy.model.Constant; +import com.jmfy.model.NoticeInfo; +import com.jmfy.utils.Connect; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.data.mongodb.core.query.Update; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +@Component +public class NoticeInfoDaoImpl implements NoticeInfoDao { + + @Resource + private Connect connect; + public static final String dbName = Constant.dbName; + @Override + public void updateNoticeInfo(String title, String content) throws Exception { + Update update = new Update(); + update.set("title",title); + update.set("content",content); + MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName); + Query query = new Query(Criteria.where("_id").is("1")); + mongoTemplate.updateMulti(query, update, NoticeInfo.class); + } + + + +} diff --git a/src/main/java/com/jmfy/handler/BaseHandler.java b/src/main/java/com/jmfy/handler/BaseHandler.java index f28d3cb..1fb3b8d 100644 --- a/src/main/java/com/jmfy/handler/BaseHandler.java +++ b/src/main/java/com/jmfy/handler/BaseHandler.java @@ -2,6 +2,8 @@ package com.jmfy.handler; import com.alibaba.fastjson.JSONObject; +import javax.servlet.http.HttpServletRequest; + public abstract class BaseHandler { private int pid; private int gid; @@ -10,7 +12,7 @@ public abstract class BaseHandler { return ""; } - public abstract int execute(JSONObject json) throws Exception ; + public abstract int execute(HttpServletRequest request) throws Exception ; public int getPid() { return pid; diff --git a/src/main/java/com/jmfy/handler/GMHandler.java b/src/main/java/com/jmfy/handler/GMHandler.java index c97bd7c..15d99a5 100644 --- a/src/main/java/com/jmfy/handler/GMHandler.java +++ b/src/main/java/com/jmfy/handler/GMHandler.java @@ -11,6 +11,7 @@ import org.slf4j.LoggerFactory; import org.springframework.stereotype.Component; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; import java.util.List; @Component @@ -22,129 +23,9 @@ public class GMHandler extends BaseHandler { @Resource private UserInfoDao gsUserDao; - public int execute(JSONObject jsonObject) throws Exception { + public int execute(HttpServletRequest request) throws Exception { - 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 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; - } + return 1; } diff --git a/src/main/java/com/jmfy/model/NoticeInfo.java b/src/main/java/com/jmfy/model/NoticeInfo.java new file mode 100644 index 0000000..531f76f --- /dev/null +++ b/src/main/java/com/jmfy/model/NoticeInfo.java @@ -0,0 +1,40 @@ +package com.jmfy.model; + +import org.springframework.data.annotation.Id; +import org.springframework.data.mongodb.core.mapping.Document; +import org.springframework.data.mongodb.core.mapping.Field; + +/** + * + * @author Administrator + * @date 2015/8/13 + */ + +@Document(collection = "notice_info") +public class NoticeInfo { + @Id + private String _id; + + @Field(value = "content") + private String content; + + @Field(value = "title") + private String title; + + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } +} diff --git a/src/main/resources/static/html/member-add.html b/src/main/resources/static/html/member-add.html index db2b950..12e122b 100644 --- a/src/main/resources/static/html/member-add.html +++ b/src/main/resources/static/html/member-add.html @@ -82,6 +82,9 @@ + diff --git a/src/main/resources/static/html/sendSysMSG.html b/src/main/resources/static/html/sendSysMSG.html new file mode 100644 index 0000000..d1b6f7b --- /dev/null +++ b/src/main/resources/static/html/sendSysMSG.html @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + +基本设置 + + + +
+ +
+
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + diff --git a/src/main/resources/static/html/sendSysNotice.html b/src/main/resources/static/html/sendSysNotice.html new file mode 100644 index 0000000..c07cf63 --- /dev/null +++ b/src/main/resources/static/html/sendSysNotice.html @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + +基本设置 + + + +
+ +
+
+ +
+ + +
+
+ +
+ +
+ + +
+
+ +
+
+ +
+
+
+ +
+ + + + + + + + + + + + + + + + + diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html index a097a4a..e01ce6e 100644 --- a/src/main/resources/templates/index.html +++ b/src/main/resources/templates/index.html @@ -86,6 +86,8 @@ @@ -131,6 +133,8 @@ + +