正在添加地图节点舰队排行榜功能
This commit is contained in:
parent
e0233e5b9d
commit
b6f56db524
81
src/main/java/com/yutou/Data/Ship.java
Normal file
81
src/main/java/com/yutou/Data/Ship.java
Normal file
@ -0,0 +1,81 @@
|
||||
package com.yutou.Data;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class Ship {
|
||||
private int level;
|
||||
private String title;
|
||||
private int shipCid;
|
||||
private int type;
|
||||
private List<String> equipment;
|
||||
|
||||
public int getLevel() {
|
||||
|
||||
return level;
|
||||
}
|
||||
|
||||
public void setLevel(int level) {
|
||||
this.level = level;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public int getShipCid() {
|
||||
return shipCid;
|
||||
}
|
||||
|
||||
public void setShipCid(int shipCid) {
|
||||
this.shipCid = shipCid;
|
||||
}
|
||||
|
||||
public List<String> getEquipment() {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public void setEquipment(List<String> equipment) {
|
||||
this.equipment = equipment;
|
||||
}
|
||||
|
||||
public int getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(int type) {
|
||||
this.type = type;
|
||||
}
|
||||
public static Ship getInstance(JSONObject json){
|
||||
try {
|
||||
Ship ship=new Ship();
|
||||
ship.setLevel(json.getInt("level"));
|
||||
ship.setShipCid(json.getInt("shipCid"));
|
||||
ship.setTitle(json.getString("title"));
|
||||
ship.setType(json.getInt("type"));
|
||||
List<String> equipment=new ArrayList<>();
|
||||
JSONArray equip=json.getJSONArray("equipment");
|
||||
for (int i = 0; i < equip.length(); i++) {
|
||||
try{
|
||||
equipment.add(equip.getInt(i)+"");
|
||||
}catch (Exception e){
|
||||
equipment.add(equip.getString(i));
|
||||
}
|
||||
}
|
||||
ship.setEquipment(equipment);
|
||||
return ship;
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
System.out.println(json.toString());
|
||||
System.exit(0);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -0,0 +1,70 @@
|
||||
package com.yutou.controller.MapTop;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.yutou.Data.Ship;
|
||||
import com.yutou.jianrdb.Bean.GameInfoLog;
|
||||
import com.yutou.jianrdb.Mapper.GameInfoLogService;
|
||||
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.JianrDataTools;
|
||||
import org.json.JSONObject;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class MapTopController {
|
||||
@Resource
|
||||
GameInfoLogService gameInfoLogService;
|
||||
@Resource
|
||||
UserTeamService userTeamService;
|
||||
@Resource
|
||||
MapTopService mapTopService;
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/map/update.do")
|
||||
public String updateMapTop() {
|
||||
updateMap(1);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
private void updateMap(int limit) {
|
||||
List<GameInfoLog> list = gameInfoLogService.getGameInfoLogByType("DealNode", limit, 500);
|
||||
tcapprocessData(list);
|
||||
if (list.size() == 500) {
|
||||
updateMap(limit + 500);
|
||||
}
|
||||
}
|
||||
|
||||
private void tcapprocessData(List<GameInfoLog> list) {
|
||||
for (GameInfoLog gameInfoLog : list) {
|
||||
try {
|
||||
if (!userTeamService.checkData(gameInfoLog.getUsername(), JianrDataTools.getMapNode(gameInfoLog.getExt()), JianrDataTools.getShip(new JSONObject(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));
|
||||
int id=mapTopService.insertMapTop(map);
|
||||
System.out.println(">>>>>>ID="+id);
|
||||
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.setCreateTime(gameInfoLog.getClient_time());
|
||||
userTeamService.insertTeam(team);
|
||||
}
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -38,25 +38,7 @@ public class test {
|
||||
return JSON.toJSONString(mod);
|
||||
}
|
||||
private static int index=0;
|
||||
@Resource
|
||||
UserTeamService daoServier;
|
||||
@ResponseBody
|
||||
@RequestMapping("/team/insert.do")
|
||||
public String searchMod(String id) {
|
||||
UserTeam team=new UserTeam();
|
||||
team.setUname("名字"+(index++));
|
||||
team.setCreateTime(new Date());
|
||||
team.setShip("aaabbbccc"+index);
|
||||
daoServier.insertTeam(team);
|
||||
return "ok";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/team/select.do")
|
||||
public String selectTeam(){
|
||||
List<UserTeam> list= daoServier.selectById(-1);
|
||||
return JSON.toJSONString(list);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@RequestMapping("/redis/set.do")
|
||||
@ResponseBody
|
||||
|
@ -9,10 +9,7 @@ import java.util.List;
|
||||
|
||||
@Qualifier("db2SqlSessionTemplate")
|
||||
public interface GameInfoLogDao {
|
||||
@Select("select * from game_info_log where id=#{id}")
|
||||
GameInfoLog getLog(@Param("id")int id);
|
||||
|
||||
|
||||
@Select("select * from game_info_log where type=#{type}")
|
||||
List<GameInfoLog> getAllByType(@Param("type")String type);
|
||||
@Select("select * from game_info_log where type=#{type} limit #{limit},#{count}")
|
||||
List<GameInfoLog> getAllByType(@Param("type")String type,@Param("limit")int limit,@Param("count")int count);
|
||||
}
|
||||
|
@ -5,13 +5,14 @@ import com.yutou.jianrdb.Dao.GameInfoLogDao;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class GameInfoLogService {
|
||||
@Resource
|
||||
GameInfoLogDao gameInfoLogDao;
|
||||
|
||||
public GameInfoLog selectGameInfoLogById(int id){
|
||||
return gameInfoLogDao.getLog(id);
|
||||
public List<GameInfoLog> getGameInfoLogByType(String type,int limit,int count){
|
||||
return gameInfoLogDao.getAllByType(type, limit, count);
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,15 @@
|
||||
package com.yutou.maptop.Bean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class MapTop {
|
||||
private int id;
|
||||
private int mapid;
|
||||
private String mapNode;
|
||||
private int mapId;
|
||||
private int mapNode;
|
||||
private String shipTeam;
|
||||
private int teamId;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
@ -16,34 +20,41 @@ public class MapTop {
|
||||
}
|
||||
|
||||
public int getMapid() {
|
||||
return mapid;
|
||||
return mapId;
|
||||
}
|
||||
|
||||
public void setMapid(int mapid) {
|
||||
this.mapid = mapid;
|
||||
this.mapId = mapid;
|
||||
}
|
||||
|
||||
public String getMapNode() {
|
||||
return mapNode;
|
||||
}
|
||||
|
||||
public void setMapNode(String mapNode) {
|
||||
this.mapNode = mapNode;
|
||||
}
|
||||
|
||||
public String getShipTeam() {
|
||||
return shipTeam;
|
||||
}
|
||||
|
||||
public void setShipTeam(String shipTeam) {
|
||||
List<Integer> list=new ArrayList<>();
|
||||
shipTeam=shipTeam.replace("[","");
|
||||
shipTeam=shipTeam.replace("]","");
|
||||
for (String ship : shipTeam.split(",")) {
|
||||
list.add(Integer.parseInt(ship));
|
||||
}
|
||||
Collections.sort(list);
|
||||
shipTeam="[";
|
||||
for (Integer integer : list) {
|
||||
shipTeam+=integer+",";
|
||||
}
|
||||
shipTeam = shipTeam.substring(0, shipTeam.length() - 1) + "]";
|
||||
|
||||
this.shipTeam = shipTeam;
|
||||
}
|
||||
|
||||
public int getTeamId() {
|
||||
return teamId;
|
||||
public int getMapNode() {
|
||||
return mapNode;
|
||||
}
|
||||
|
||||
public void setTeamId(int teamId) {
|
||||
this.teamId = teamId;
|
||||
public void setMapNode(int mapNode) {
|
||||
this.mapNode = mapNode;
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ import java.util.Date;
|
||||
|
||||
public class UserTeam {
|
||||
private int id;
|
||||
private int mid;
|
||||
private int mapNode;
|
||||
private String uname;
|
||||
private String equipment;
|
||||
private String ship;
|
||||
private Date createTime;
|
||||
|
||||
@ -39,4 +42,28 @@ public class UserTeam {
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public int getMid() {
|
||||
return mid;
|
||||
}
|
||||
|
||||
public void setMid(int mid) {
|
||||
this.mid = mid;
|
||||
}
|
||||
|
||||
public int getMapNode() {
|
||||
return mapNode;
|
||||
}
|
||||
|
||||
public void setMapNode(int mapNode) {
|
||||
this.mapNode = mapNode;
|
||||
}
|
||||
|
||||
public String getEquipment() {
|
||||
return equipment;
|
||||
}
|
||||
|
||||
public void setEquipment(String equipment) {
|
||||
this.equipment = equipment;
|
||||
}
|
||||
}
|
||||
|
@ -1,16 +1,24 @@
|
||||
package com.yutou.maptop.Dao;
|
||||
|
||||
import com.yutou.maptop.Bean.MapTop;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MapDao {
|
||||
@Select("select * from maptop where id=#{id}")
|
||||
List<MapTop> selectMapByMapId(@Param("id") int id);
|
||||
@Select("select * from maptop where mapId=#{mapId} limit #{limit},#{count}")
|
||||
List<MapTop> selectMapByMapId(@Param("mapId")int mapId,@Param("limit") int limit,@Param("count")int count);
|
||||
|
||||
@Insert("insert into maptop(mapId,mapNode,shipTeam,teamId) values(#{mapId},#{mapNode},#{shipTeam},#{teamId})")
|
||||
void insertMapTop(MapTop top);
|
||||
@Insert("insert into maptop(mapId,mapNode,shipTeam) values(#{mapId},#{mapNode},#{shipTeam})")
|
||||
@Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
|
||||
int insertMapTop(MapTop top);
|
||||
|
||||
@Select("select count(id) from maptop where mapId=#{mapId} and mapNode=#{mapNode}")
|
||||
int checkMap(MapTop top);
|
||||
|
||||
@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);
|
||||
}
|
||||
|
@ -1,9 +1,7 @@
|
||||
package com.yutou.maptop.Dao;
|
||||
|
||||
import com.yutou.maptop.Bean.UserTeam;
|
||||
import org.apache.ibatis.annotations.Insert;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import org.apache.ibatis.annotations.Select;
|
||||
import org.apache.ibatis.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -11,9 +9,15 @@ public interface UserTeamDao {
|
||||
@Select("select * from userTeam where id=#{id}")
|
||||
List<UserTeam> selectTeamById(@Param("id") int id);
|
||||
|
||||
@Insert("insert into userTeam(uname,ship,createTime) values(#{uname},#{ship},#{createTime})")
|
||||
@Insert("insert into userTeam(uname,ship,createTime,mid,mapNode,equipment) values(#{uname},#{ship},#{createTime},#{mid},#{mapNode},#{equipment})")
|
||||
void insertTeam( UserTeam param);
|
||||
|
||||
@Select("select * from userTeam")
|
||||
List<UserTeam> selectAll();
|
||||
@Select("select count(id) from userTeam where uname=#{uname} and ship=#{ship} and mapNode=#{mapNode}")
|
||||
int checkData(UserTeam userTeam);
|
||||
|
||||
|
||||
@Delete("delete from userTeam")
|
||||
void deleteData();
|
||||
@Delete("DELETE FROM sqlite_sequence WHERE name = 'userTeam'")
|
||||
void clear();
|
||||
}
|
||||
|
39
src/main/java/com/yutou/maptop/services/MapTopService.java
Normal file
39
src/main/java/com/yutou/maptop/services/MapTopService.java
Normal file
@ -0,0 +1,39 @@
|
||||
package com.yutou.maptop.services;
|
||||
|
||||
import com.yutou.maptop.Bean.MapTop;
|
||||
import com.yutou.maptop.Dao.MapDao;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class MapTopService {
|
||||
@Resource
|
||||
MapDao mapDao;
|
||||
|
||||
public List<MapTop> selectMapByMapId(int mapId, int limit, int count) {
|
||||
return mapDao.selectMapByMapId(mapId, 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{
|
||||
try {
|
||||
id=mapDao.getDescId();//获取最后的id
|
||||
}catch (Exception ignored){
|
||||
|
||||
}
|
||||
mapDao.insertMapTop(top);
|
||||
id++;
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
public int checkMap(MapTop top) {
|
||||
return mapDao.checkMap(top);
|
||||
}
|
||||
}
|
@ -12,14 +12,22 @@ public class UserTeamService {
|
||||
@Resource
|
||||
UserTeamDao dao;
|
||||
|
||||
public void insertTeam(UserTeam team){
|
||||
public void insertTeam(UserTeam team) {
|
||||
dao.insertTeam(team);
|
||||
}
|
||||
|
||||
public List<UserTeam> selectById(int id){
|
||||
if(id==-1){
|
||||
return dao.selectAll();
|
||||
}
|
||||
return dao.selectTeamById(id);
|
||||
public boolean checkData(String uname, int mapId, String ship) {
|
||||
if (ship == null)
|
||||
return true;
|
||||
UserTeam team = new UserTeam();
|
||||
team.setUname(uname);
|
||||
team.setMapNode(mapId);
|
||||
team.setShip(ship);
|
||||
return dao.checkData(team) > 0;
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
dao.deleteData();
|
||||
dao.clear();
|
||||
}
|
||||
}
|
||||
|
51
src/main/java/com/yutou/utlis/JianrDataTools.java
Normal file
51
src/main/java/com/yutou/utlis/JianrDataTools.java
Normal file
@ -0,0 +1,51 @@
|
||||
package com.yutou.utlis;
|
||||
|
||||
import com.yutou.Data.Ship;
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class JianrDataTools {
|
||||
public final static int SHIP_TYPE = 0;
|
||||
public final static int SHIP_TITLE = 1;
|
||||
public final static int SHIP_CID = 2;
|
||||
|
||||
public static String getShip(JSONObject message, int type) {
|
||||
String ship = null;
|
||||
if(message.isNull("warReport")){
|
||||
return null;
|
||||
}
|
||||
JSONArray array = message.getJSONObject("warReport").getJSONArray("selfShips");
|
||||
ship = "[";
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
Ship sp = Ship.getInstance(array.getJSONObject(i));
|
||||
switch (type) {
|
||||
case SHIP_CID:
|
||||
ship += sp.getShipCid() + ",";
|
||||
break;
|
||||
case SHIP_TITLE:
|
||||
ship += sp.getTitle() + ",";
|
||||
break;
|
||||
case SHIP_TYPE:
|
||||
ship += sp.getType() + ",";
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
ship = ship.substring(0, ship.length() - 1) + "]";
|
||||
return ship;
|
||||
}
|
||||
|
||||
|
||||
public static int getMapId(String ext) {
|
||||
JSONObject json = new JSONObject(ext);
|
||||
return json.getInt("n") / 100;
|
||||
}
|
||||
|
||||
public static int getMapNode(String ext) {
|
||||
JSONObject json = new JSONObject(ext);
|
||||
return json.getInt("n");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user