diff --git a/src/main/java/com/jmfy/controller/GmController.java b/src/main/java/com/jmfy/controller/GmController.java index 9578c91..891664d 100644 --- a/src/main/java/com/jmfy/controller/GmController.java +++ b/src/main/java/com/jmfy/controller/GmController.java @@ -1,6 +1,7 @@ package com.jmfy.controller; import com.google.gson.Gson; +import com.jmfy.dao.BanFuctionDao; import com.jmfy.dao.ServerInfoDao; import com.jmfy.dao.UserInfoDao; import com.jmfy.model.*; @@ -34,6 +35,8 @@ public class GmController { private ServerInfoDao serverInfoDao; @Resource private UserInfoDao userInfoDao; + @Resource + private BanFuctionDao banFuctionDao; @RequestMapping(value = "/sendGm", method = {RequestMethod.POST, RequestMethod.GET}) public @ResponseBody int publishNotice(HttpServletRequest request) throws Exception { @@ -248,6 +251,54 @@ public class GmController { // in.close(); // out.close(); // } +@RequestMapping(value = "/banFunction", method = {RequestMethod.POST, RequestMethod.GET}) +public @ResponseBody int banFunction(HttpServletRequest request) throws Exception{ + String function = request.getParameter("function");// protocal/good + String action = request.getParameter("action");// ban/opend + String id = request.getParameter("id");// id + + + ServerBanPro banDao = banFuctionDao.findUserInfo(); + if(banDao == null ){ + ServerBanPro serverBanPro = new ServerBanPro(); + //serverBanPro.setId(1); + serverBanPro.setBanProtoId(new ArrayList(Arrays.asList(1,2))); + serverBanPro.setBanGoodList(new ArrayList<>()); + banFuctionDao.addServerBanPro(serverBanPro); + banDao = serverBanPro; + } + switch (function){ + case "protocal": + if(action.equals("ban")){ + if(!banDao.getBanProtoId().contains(Integer.valueOf(id))){ + banDao.getBanProtoId().add(Integer.valueOf(id)); + banFuctionDao.updateServerBanPro(banDao); + } + }else if(action.equals("open")){ + if(banDao.getBanProtoId().contains(Integer.valueOf(id))){ + banDao.getBanProtoId().remove(Integer.valueOf(id)); + banFuctionDao.updateServerBanPro(banDao); + } + + } + break; + case "good": + if(action.equals("ban")){ + if(!banDao.getBanGoodList().contains(Integer.valueOf(id))){ + banDao.getBanGoodList().add(Integer.valueOf(id)); + banFuctionDao.updateServerBanPro(banDao); + } + }else if(action.equals("open")){ + if(banDao.getBanGoodList().contains(Integer.valueOf(id))){ + banDao.getBanGoodList().remove(Integer.valueOf(id)); + banFuctionDao.updateServerBanPro(banDao); + } + + } + break; + } + return 0; +} public static void main(String[] args) throws IOException { String osName = System.getProperty("os.name"); String filePath = ""; diff --git a/src/main/java/com/jmfy/dao/BanFuctionDao.java b/src/main/java/com/jmfy/dao/BanFuctionDao.java new file mode 100644 index 0000000..32440b9 --- /dev/null +++ b/src/main/java/com/jmfy/dao/BanFuctionDao.java @@ -0,0 +1,11 @@ +package com.jmfy.dao; + +import com.jmfy.model.ServerBanPro; + +public interface BanFuctionDao { + ServerBanPro findUserInfo() throws Exception; + + void updateServerBanPro(ServerBanPro serverBanPro) throws Exception; + + void addServerBanPro(ServerBanPro serverBanPro) throws Exception; +} diff --git a/src/main/java/com/jmfy/dao/impl/BanFunctionImpl.java b/src/main/java/com/jmfy/dao/impl/BanFunctionImpl.java new file mode 100644 index 0000000..4a474f4 --- /dev/null +++ b/src/main/java/com/jmfy/dao/impl/BanFunctionImpl.java @@ -0,0 +1,46 @@ +package com.jmfy.dao.impl; + +import com.jmfy.dao.BanFuctionDao; +import com.jmfy.model.BlackList; +import com.jmfy.model.CAdmin; +import com.jmfy.model.Constant; +import com.jmfy.model.ServerBanPro; +import com.jmfy.utils.Connect; +import org.springframework.data.mongodb.core.MongoTemplate; +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; +import java.util.List; + +@Component +public class BanFunctionImpl implements BanFuctionDao { + @Resource + private Connect connect ; + String dbName = Constant.dbName; + @Override + public ServerBanPro findUserInfo() throws Exception { + MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName); + List list = mongoTemplate.findAll(ServerBanPro.class); + if(list.size()>0){ + return list.get(0) ; + } + return null ; + } + @Override + public void addServerBanPro(ServerBanPro serverBanPro) throws Exception{ + MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName); + mongoTemplate.insert(serverBanPro); + } + @Override + public void updateServerBanPro(ServerBanPro serverBanPro) throws Exception{ + MongoTemplate mongoTemplate = connect.getMongoTemplete(dbName); + Query query = new Query(); + Update update = new Update(); + update.set("banProtoId",serverBanPro.getBanProtoId()); + mongoTemplate.updateFirst(query,update,ServerBanPro.class); + + } + +} diff --git a/src/main/java/com/jmfy/model/ServerBanPro.java b/src/main/java/com/jmfy/model/ServerBanPro.java new file mode 100644 index 0000000..1fe1f39 --- /dev/null +++ b/src/main/java/com/jmfy/model/ServerBanPro.java @@ -0,0 +1,44 @@ +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; + +import java.util.List; + +@Document(collection = "server_ban_function") +public class ServerBanPro { + + @Id + private int id; + + @Field(value = "banProtoId") + private List banProtoId ; + + @Field(value = "banGoodList") + private List banGoodList ; + + public List getBanProtoId() { + return banProtoId; + } + + public void setBanProtoId(List banProtoId) { + this.banProtoId = banProtoId; + } + + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + + public List getBanGoodList() { + return banGoodList; + } + + public void setBanGoodList(List banGoodList) { + this.banGoodList = banGoodList; + } +}