diff --git a/sqlite.db b/sqlite.db index c461d6f..2ca4b37 100644 Binary files a/sqlite.db and b/sqlite.db differ diff --git a/src/main/java/com/yutou/Data/Ship.java b/src/main/java/com/yutou/Data/Ship.java index 9b3779e..b0d6937 100644 --- a/src/main/java/com/yutou/Data/Ship.java +++ b/src/main/java/com/yutou/Data/Ship.java @@ -1,7 +1,8 @@ package com.yutou.Data; -import org.json.JSONArray; -import org.json.JSONObject; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import java.util.ArrayList; import java.util.List; @@ -56,15 +57,15 @@ public class Ship { public static Ship getInstance(JSONObject json){ try { Ship ship=new Ship(); - ship.setLevel(json.getInt("level")); - ship.setShipCid(json.getInt("shipCid")); + ship.setLevel(json.getInteger("level")); + ship.setShipCid(json.getInteger("shipCid")); ship.setTitle(json.getString("title")); - ship.setType(json.getInt("type")); + ship.setType(json.getInteger("type")); List equipment=new ArrayList<>(); JSONArray equip=json.getJSONArray("equipment"); - for (int i = 0; i < equip.length(); i++) { + for (int i = 0; i < equip.size(); i++) { try{ - equipment.add(equip.getInt(i)+""); + equipment.add(equip.getInteger(i)+""); }catch (Exception e){ equipment.add(equip.getString(i)); } diff --git a/src/main/java/com/yutou/controller/MapTop/AndroidMapController.java b/src/main/java/com/yutou/controller/MapTop/AndroidMapController.java new file mode 100644 index 0000000..b1b3fa8 --- /dev/null +++ b/src/main/java/com/yutou/controller/MapTop/AndroidMapController.java @@ -0,0 +1,138 @@ +package com.yutou.controller.MapTop; + +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.yutou.enums.UserEnum; +import com.yutou.maptop.Bean.MapTop; +import com.yutou.maptop.Bean.UserTeam; +import com.yutou.maptop.services.MapTopService; +import com.yutou.maptop.services.UserTeamService; +import com.yutou.utlis.Tools; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.util.Arrays; +import java.util.List; + +@Controller +public class AndroidMapController { + @Resource + UserTeamService userTeamService; + @Resource + MapTopService mapTopService; + + /** + * 全部数据 + */ + @ResponseBody + @RequestMapping("/android/map/all.do") + public String getMapTop(HttpServletRequest request,int limit){ + + JSONObject json=new JSONObject(); + if(Tools.getUidOfToken(request)<=0){ + json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg); + json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); + return json.toString(); + } + int count=100; + + List list=mapTopService.selectMap(limit,count); + json.put("count",list.size()); + json.put("data", JSONArray.toJSON(list)); + if(list.size()==count){ + json.put("next",true); + }else{ + json.put("next",false); + } + return json.toJSONString(); + } + + @ResponseBody + @RequestMapping("/android/map/mid.do") + public String getMapId(HttpServletRequest request,int id,int limit){ + JSONObject json=new JSONObject(); + if(Tools.getUidOfToken(request)<=0){ + json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg); + json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); + return json.toString(); + } + + int count=100; + List list=mapTopService.selectMapByMapId(id,limit,count); + json.put("count",list.size()); + json.put("data", JSONArray.toJSON(list)); + if(list.size()==count){ + json.put("next",true); + }else{ + json.put("next",false); + } + return json.toJSONString(); + } + @ResponseBody + @RequestMapping("/android/map/team/node.do") + public String getTeamByMapNode(HttpServletRequest request,int node,int limit){ + JSONObject json=new JSONObject(); + if(Tools.getUidOfToken(request)<=0){ + json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg); + json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); + return json.toString(); + } + + int count=100; + List list=userTeamService.searchMapNode(node,limit,count); + json.put("count",list.size()); + json.put("data", JSONArray.toJSON(list)); + if(list.size()==count){ + json.put("next",true); + }else{ + json.put("next",false); + } + return json.toJSONString(); + } + @ResponseBody + @RequestMapping("/android/map/team/nodeAndLike.do") + public String getTeamByMapNodeAndLike(HttpServletRequest request,int node,int limit,String likeArray){ + JSONObject json=new JSONObject(); + if(Tools.getUidOfToken(request)<=0){ + json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg); + json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); + return json.toString(); + } + + int count=100; + JSONArray array=new JSONArray(); + array.addAll(Arrays.asList(likeArray.split(","))); + List list=userTeamService.searchType(node,array,limit,count); + json.put("count",list.size()); + json.put("data", JSONArray.toJSON(list)); + if(list.size()==count){ + json.put("next",true); + }else{ + json.put("next",false); + } + return json.toJSONString(); + } + @ResponseBody + @RequestMapping("/android/map/team/topid.do") + public String getTeamByMapTop(HttpServletRequest request,int id,int limit){ + JSONObject json=new JSONObject(); + if(Tools.getUidOfToken(request)<=0){ + json.put("msg",UserEnum.LOGIN_NOT_LOGIN.msg); + json.put("code", UserEnum.LOGIN_NOT_LOGIN.code); + return json.toString(); + } + int count=100; + List list=userTeamService.selectByMapTopId(id,limit,count); + json.put("count",list.size()); + json.put("data", JSONArray.toJSON(list)); + if(list.size()==count){ + json.put("next",true); + }else{ + json.put("next",false); + } + return json.toJSONString(); + } +} diff --git a/src/main/java/com/yutou/controller/MapTop/MapTopController.java b/src/main/java/com/yutou/controller/MapTop/MapTopController.java index 05ed720..81f5d90 100644 --- a/src/main/java/com/yutou/controller/MapTop/MapTopController.java +++ b/src/main/java/com/yutou/controller/MapTop/MapTopController.java @@ -1,7 +1,7 @@ package com.yutou.controller.MapTop; -import com.alibaba.fastjson.JSONArray; -import com.yutou.Data.Ship; +import com.alibaba.fastjson.JSONObject; +import com.yutou.enums.UserEnum; import com.yutou.jianrdb.Bean.GameInfoLog; import com.yutou.jianrdb.Mapper.GameInfoLogService; import com.yutou.maptop.Bean.MapTop; @@ -9,13 +9,19 @@ import com.yutou.maptop.Bean.UserTeam; import com.yutou.maptop.services.MapTopService; import com.yutou.maptop.services.UserTeamService; import com.yutou.utlis.JianrDataTools; -import org.json.JSONObject; +import com.yutou.utlis.Tools; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import javax.servlet.http.HttpServletRequest; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; +import java.util.Locale; @Controller public class MapTopController { @@ -28,35 +34,40 @@ public class MapTopController { @ResponseBody @RequestMapping("/map/update.do") - public String updateMapTop() { - updateMap(1); + public String updateMapTop(String key) { + if(!"2LwK8xlmMXiMR22ru6WriR9eBllePWWYUVqrS4G5jOPWg8jGtt76gsZPi41yUTpe".equals(key)){ + return ""; + } + updateMap(); return "ok"; } - private void updateMap(int limit) { - List list = gameInfoLogService.getGameInfoLogByType("DealNode", limit, 500); + + private void updateMap() { + List list = gameInfoLogService.getGameInfoLogByType("DealNode", 1, 500); tcapprocessData(list); - if (list.size() == 500) { - updateMap(limit + 500); - } + Tools.getHTTPUrlString("https://sc.ftqq.com/SCU64034T5adf5c5940dcecc016e0e9d0cf9b1e725da126ff47475.send?text=盒子更新MAP数据&desp=成功更新500条数据"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.CHINA).format(new Date())); } private void tcapprocessData(List list) { for (GameInfoLog gameInfoLog : list) { try { - if (!userTeamService.checkData(gameInfoLog.getUsername(), JianrDataTools.getMapNode(gameInfoLog.getExt()), JianrDataTools.getShip(new JSONObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TITLE))) { + if(!JSONObject.parseObject(gameInfoLog.getExt()).getString("s").equals("pve")){ + continue; + } + if (!userTeamService.checkData(gameInfoLog.getUsername(), JianrDataTools.getMapNode(gameInfoLog.getExt()), JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TITLE))) { MapTop map = new MapTop(); map.setMapid(JianrDataTools.getMapId(gameInfoLog.getExt())); map.setMapNode(JianrDataTools.getMapNode(gameInfoLog.getExt())); - map.setShipTeam(JianrDataTools.getShip(new JSONObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TYPE)); + map.setShipTeam(JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TYPE)); int id=mapTopService.insertMapTop(map); - System.out.println(">>>>>>ID="+id); + System.out.println(">>>>>>ID="+id+" ---> "+JSONObject.parseObject(gameInfoLog.getExt()).getInteger("n")+" "+gameInfoLog.getId()); UserTeam team=new UserTeam(); team.setMid(id); team.setMapNode(map.getMapNode()); team.setUname(gameInfoLog.getUsername()); - team.setEquipment(JSONArray.toJSONString(Ship.getInstance(new JSONObject(gameInfoLog.getMessage())).getEquipment())); - team.setShip(JianrDataTools.getShip(new JSONObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TITLE)); + team.setShip(JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage())).toString()); + team.setTitle(JianrDataTools.getShip(JSONObject.parseObject(gameInfoLog.getMessage()),JianrDataTools.SHIP_TITLE)); team.setCreateTime(gameInfoLog.getClient_time()); userTeamService.insertTeam(team); } diff --git a/src/main/java/com/yutou/jianrdb/Dao/GameInfoLogDao.java b/src/main/java/com/yutou/jianrdb/Dao/GameInfoLogDao.java index 2011ede..f434462 100644 --- a/src/main/java/com/yutou/jianrdb/Dao/GameInfoLogDao.java +++ b/src/main/java/com/yutou/jianrdb/Dao/GameInfoLogDao.java @@ -10,6 +10,6 @@ import java.util.List; @Qualifier("db2SqlSessionTemplate") public interface GameInfoLogDao { - @Select("select * from game_info_log where type=#{type} limit #{limit},#{count}") + @Select("select * from game_info_log where type=#{type} order by id desc limit #{limit},#{count}") List getAllByType(@Param("type")String type,@Param("limit")int limit,@Param("count")int count); } diff --git a/src/main/java/com/yutou/maptop/Bean/UserTeam.java b/src/main/java/com/yutou/maptop/Bean/UserTeam.java index 5f9f8a5..633fd6c 100644 --- a/src/main/java/com/yutou/maptop/Bean/UserTeam.java +++ b/src/main/java/com/yutou/maptop/Bean/UserTeam.java @@ -7,8 +7,8 @@ public class UserTeam { private int mid; private int mapNode; private String uname; - private String equipment; private String ship; + private String title; private Date createTime; public int getId() { @@ -59,11 +59,11 @@ public class UserTeam { this.mapNode = mapNode; } - public String getEquipment() { - return equipment; + public String getTitle() { + return title; } - public void setEquipment(String equipment) { - this.equipment = equipment; + public void setTitle(String title) { + this.title = title; } } diff --git a/src/main/java/com/yutou/maptop/Dao/MapDao.java b/src/main/java/com/yutou/maptop/Dao/MapDao.java index 1a3e34e..cf73614 100644 --- a/src/main/java/com/yutou/maptop/Dao/MapDao.java +++ b/src/main/java/com/yutou/maptop/Dao/MapDao.java @@ -6,7 +6,11 @@ import org.apache.ibatis.annotations.*; import java.util.List; public interface MapDao { - @Select("select * from maptop where mapId=#{mapId} limit #{limit},#{count}") + /** + 根据mapid来查询 + 接口 + */ + @Select("select * from maptop where mapId=#{mapId} order by mapNode limit #{limit},#{count}") List selectMapByMapId(@Param("mapId")int mapId,@Param("limit") int limit,@Param("count")int count); @Insert("insert into maptop(mapId,mapNode,shipTeam) values(#{mapId},#{mapNode},#{shipTeam})") @@ -19,6 +23,16 @@ public interface MapDao { @Select("select id from maptop order by id desc limit 1,1") int getDescId(); + /** + * 获取完全条件 + */ @Select("select * from maptop where mapId=#{mapId} and mapNode=#{mapNode} and shipTeam=#{shipTeam}") MapTop selectMapByData(@Param("mapId")int mapId,@Param("mapNode")int mapNode,@Param("shipTeam")String shipTeam); + + /** + * 全部数据 + */ + @Select("select * from maptop order by mapNode limit #{limit},#{count}") + List selectMap(@Param("limit") int limit,@Param("count")int count); + } diff --git a/src/main/java/com/yutou/maptop/Dao/UserTeamDao.java b/src/main/java/com/yutou/maptop/Dao/UserTeamDao.java index 33abdf0..0008773 100644 --- a/src/main/java/com/yutou/maptop/Dao/UserTeamDao.java +++ b/src/main/java/com/yutou/maptop/Dao/UserTeamDao.java @@ -6,10 +6,26 @@ import org.apache.ibatis.annotations.*; import java.util.List; public interface UserTeamDao { - @Select("select * from userTeam where id=#{id}") - List selectTeamById(@Param("id") int id); + /** + * 根据具体节点来查询详细列表 + * @param mapNode 具体节点 + */ + @Select("select userTeam.* from userTeam INNER join maptop as map on userTeam.mid=map.id where map.mapNode=#{mapid} order by id desc limit #{limit},#{count}") + List selectTeamByMapId(@Param("mapid") int mapNode,@Param("limit") int limit,@Param("count")int count); - @Insert("insert into userTeam(uname,ship,createTime,mid,mapNode,equipment) values(#{uname},#{ship},#{createTime},#{mid},#{mapNode},#{equipment})") + /** + * 根据具体节点及筛选包含类型列表 + */ + @Select("select userTeam.* from userTeam INNER join maptop as map on userTeam.mid=map.id where map.mapNode=#{mapnode} and map.shipTeam like #{llike} or shipTeam like #{like} or shipTeam like #{rlike} order by id desc limit #{limit},#{count}") + List selectByMapIdAndTeamLike(@Param("mapnode")int mapnode,@Param("llike")String llike,@Param("like")String like,@Param("rlike")String rlike,@Param("limit") int limit,@Param("count")int count); + + /** + * 根据mapTop的id来获取列表 + */ + @Select(" select userTeam.* from userTeam INNER join maptop as map on userTeam.mid=map.id where map.id=#{id} order by id desc limit #{limit},#{count}") + List selectByMapTopId(@Param("id")int id,@Param("limit") int limit,@Param("count")int count); + + @Insert("insert into userTeam(uname,ship,createTime,mid,mapNode,title) values(#{uname},#{ship},#{createTime},#{mid},#{mapNode},#{title})") void insertTeam( UserTeam param); @Select("select count(id) from userTeam where uname=#{uname} and ship=#{ship} and mapNode=#{mapNode}") @@ -20,4 +36,6 @@ public interface UserTeamDao { void deleteData(); @Delete("DELETE FROM sqlite_sequence WHERE name = 'userTeam'") void clear(); + + } diff --git a/src/main/java/com/yutou/maptop/services/MapTopService.java b/src/main/java/com/yutou/maptop/services/MapTopService.java index 2a79012..5327f1a 100644 --- a/src/main/java/com/yutou/maptop/services/MapTopService.java +++ b/src/main/java/com/yutou/maptop/services/MapTopService.java @@ -1,5 +1,6 @@ package com.yutou.maptop.services; +import com.alibaba.fastjson.JSONArray; import com.yutou.maptop.Bean.MapTop; import com.yutou.maptop.Dao.MapDao; import org.springframework.stereotype.Service; @@ -16,24 +17,28 @@ public class MapTopService { return mapDao.selectMapByMapId(mapId, limit, count); } + public List selectMap(int limit,int count){ + return mapDao.selectMap(limit, count); + } + public int insertMapTop(MapTop top) { int id=0; MapTop old=mapDao.selectMapByData(top.getMapid(),top.getMapNode(),top.getShipTeam()); if(old!=null){//检测到有对应的map数据,返回id return old.getId(); }else{ + mapDao.insertMapTop(top); try { id=mapDao.getDescId();//获取最后的id }catch (Exception ignored){ } - mapDao.insertMapTop(top); - id++; + + id+=1; } return id; } - public int checkMap(MapTop top) { - return mapDao.checkMap(top); - } + + } diff --git a/src/main/java/com/yutou/maptop/services/UserTeamService.java b/src/main/java/com/yutou/maptop/services/UserTeamService.java index 4e8940a..5a47328 100644 --- a/src/main/java/com/yutou/maptop/services/UserTeamService.java +++ b/src/main/java/com/yutou/maptop/services/UserTeamService.java @@ -1,5 +1,6 @@ package com.yutou.maptop.services; +import com.alibaba.fastjson.JSONArray; import com.yutou.maptop.Bean.UserTeam; import com.yutou.maptop.Dao.UserTeamDao; import org.springframework.stereotype.Service; @@ -30,4 +31,18 @@ public class UserTeamService { dao.deleteData(); dao.clear(); } + public List searchType(int mapnode, JSONArray like, int limit, int count){ + String likesql=""; + for (Object o : like) { + likesql+=(String)o+","; + } + likesql=likesql.substring(0,likesql.length()-1)+""; + return dao.selectByMapIdAndTeamLike(mapnode,"["+likesql+",%","%,"+likesql+",%","%,"+likesql+"]",limit,count); + } + public List searchMapNode(int mapnode, int limit, int count){ + return dao.selectTeamByMapId(mapnode,limit,count); + } + public List selectByMapTopId(int id, int limit, int count){ + return dao.selectByMapTopId(id,limit,count); + } } diff --git a/src/main/java/com/yutou/utlis/JianrDataTools.java b/src/main/java/com/yutou/utlis/JianrDataTools.java index bfa827f..c36eeb1 100644 --- a/src/main/java/com/yutou/utlis/JianrDataTools.java +++ b/src/main/java/com/yutou/utlis/JianrDataTools.java @@ -1,8 +1,8 @@ package com.yutou.utlis; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; import com.yutou.Data.Ship; -import org.json.JSONArray; -import org.json.JSONObject; import java.util.ArrayList; import java.util.List; @@ -14,12 +14,12 @@ public class JianrDataTools { public static String getShip(JSONObject message, int type) { String ship = null; - if(message.isNull("warReport")){ + if(message.getJSONObject("warReport")==null){ return null; } JSONArray array = message.getJSONObject("warReport").getJSONArray("selfShips"); ship = "["; - for (int i = 0; i < array.length(); i++) { + for (int i = 0; i < array.size(); i++) { Ship sp = Ship.getInstance(array.getJSONObject(i)); switch (type) { case SHIP_CID: @@ -38,14 +38,29 @@ public class JianrDataTools { return ship; } - + public static JSONArray getShip(JSONObject message){ + JSONArray equipment = new JSONArray(); + if(message.getJSONObject("warReport").isEmpty()){ + return equipment; + } + JSONArray array = message.getJSONObject("warReport").getJSONArray("selfShips"); + for (int i = 0; i < array.size(); i++) { + Ship sp = Ship.getInstance(array.getJSONObject(i)); + JSONObject item=new JSONObject(); + item.put("cid",sp.getShipCid()); + item.put("equipment", com.alibaba.fastjson.JSONArray.toJSON(sp.getEquipment())); + item.put("level",sp.getLevel()); + equipment.add(item); + } + return equipment; + } public static int getMapId(String ext) { - JSONObject json = new JSONObject(ext); - return json.getInt("n") / 100; + JSONObject json = JSONObject.parseObject(ext); + return json.getInteger("n") / 100; } public static int getMapNode(String ext) { - JSONObject json = new JSONObject(ext); - return json.getInt("n"); + JSONObject json = JSONObject.parseObject(ext); + return json.getInteger("n"); } } diff --git a/src/main/java/com/yutou/utlis/Tools.java b/src/main/java/com/yutou/utlis/Tools.java index 368fb74..0465443 100644 --- a/src/main/java/com/yutou/utlis/Tools.java +++ b/src/main/java/com/yutou/utlis/Tools.java @@ -198,7 +198,6 @@ public class Tools { } /** * 设置Cookie - * @param request * @param response * @param key * @param value @@ -521,12 +520,11 @@ public class Tools { if(reJson.getString("msg").equals("注册成功")) { return 0; } - int uid = reJson.getInt("uid"); - return uid; + return reJson.getInt("uid"); } catch (Exception e) { // TODO: handle exception } - return 0; + return 1; } public static boolean getUserBen(UUserdata udata) { if(udata.getUnbeantime()!=null) {