diff --git a/assembly.xml b/assembly.xml index 2544339..3cf1bc8 100644 --- a/assembly.xml +++ b/assembly.xml @@ -11,7 +11,7 @@ ${project.build.directory} ${file.separator} - BeiDouPlatform.jar + GameDatabaseService.jar diff --git a/bin/log_clean.sh b/bin/log_clean.sh new file mode 100644 index 0000000..5a3fedc --- /dev/null +++ b/bin/log_clean.sh @@ -0,0 +1,3 @@ +# 把下面语句编辑到crontab里,定时清理日志,每天凌晨1点清理日志,保留7天日志 + +0 1 * * * find /apprun/phoenix_ddos_handle/logs -mtime +7 -name "*.log.*" -exec rm -rf {} \; \ No newline at end of file diff --git a/bin/processor_check.sh b/bin/processor_check.sh new file mode 100644 index 0000000..8a0efc7 --- /dev/null +++ b/bin/processor_check.sh @@ -0,0 +1,26 @@ +# crontab里加上进程自动拉起任务,做个简单的监控 +# */1 * * * * source /etc/profile;sh /apprun/${YOUR_APP_NAME}/bin/processor_check.sh +# processor_check.sh脚本内容如下 + +#!/bin/bash +APP_NAME=dispose_platform.jar +WORK_PATH=$(cd `dirname $0`; pwd) + +pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +if [ "$pids" -le 0 ] +then + echo "start $APP_NAME processor ......" + cd $WORK_PATH + cd .. + nohup sh bin/start.sh >/dev/null 2>&1 & + sleep 5 + pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` + if [ "$pids" -gt 0 ] + then + echo "$APP_NAME processor started" + else + echo "Failed to start $APP_NAME processor" + fi +else + echo "$APP_NAME processor is running ......" +fi \ No newline at end of file diff --git a/bin/start.sh b/bin/start.sh new file mode 100644 index 0000000..a3ada99 --- /dev/null +++ b/bin/start.sh @@ -0,0 +1,8 @@ +#!/bin/bash +JAVA_DEBUG_OPTS=" -Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=8003,server=y,suspend=n " +JAVA_JMX_OPTS=" -Dcom.sun.management.jmxremote.port=9998 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false " +JAVA_OPTS="-Djava.security.egd=file:/dev/./urandom -server -Xms512M -Xmx512M -Xss256K -XX:MetaspaceSize=16M -XX:MaxMetaspaceSize=128M -XX:MaxDirectMemorySize=1g -XX:SurvivorRatio=8 -XX:+UseG1GC -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/tmp/heapdump.hprof" +WORK_PATH=$(cd `dirname $0`; pwd) +cd $WORK_PATH +cd .. +$JAVA_HOME/bin/java $JAVA_DEBUG_OPTS $JAVA_JMX_OPTS $JAVA_OPTS -jar GameDatabaseService.jar & diff --git a/bin/stop.sh b/bin/stop.sh new file mode 100644 index 0000000..63de04c --- /dev/null +++ b/bin/stop.sh @@ -0,0 +1,15 @@ +#!/bin/bash +APP_NAME=GameDatabaseService.jar + +pids=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'` +for pid in $pids +do + echo stop $APP_NAME java process: $pid + kill -9 $pid +done + +nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +while [ $nr_pids -gt 0 ] +do + nr_pids=`ps -ef | grep $APP_NAME | grep -v grep | wc -l` +done \ No newline at end of file diff --git a/config/application-local.properties b/config/application-local.properties index 27ffb87..507a1a3 100644 --- a/config/application-local.properties +++ b/config/application-local.properties @@ -1,4 +1,4 @@ -server.port=9276 +server.port=9278 server.servlet.context-path=/cmhi # mysql diff --git a/pom.xml b/pom.xml index 558441a..bf7add4 100644 --- a/pom.xml +++ b/pom.xml @@ -142,6 +142,11 @@ reactor-core 3.4.16 + + org.jboss.xnio + xnio-nio + 3.8.10.Final + diff --git a/src/main/java/com/cmhi/gds/common/ErrorCode.java b/src/main/java/com/cmhi/gds/common/ErrorCode.java index fcb1417..6fd4d1c 100644 --- a/src/main/java/com/cmhi/gds/common/ErrorCode.java +++ b/src/main/java/com/cmhi/gds/common/ErrorCode.java @@ -107,7 +107,7 @@ public enum ErrorCode implements BaseEnum { /** * The Err nosuchtype. */ - ERR_NOSUCHTYPE(24, "没有这个类型的处置设备"), + ERR_NOSUCHTYPE(24, "没有这个类型的设备"), /** * The Err removemore. */ @@ -144,30 +144,22 @@ public enum ErrorCode implements BaseEnum { * The Err unabledisposeip. */ ERR_UNABLEDISPOSEIP(33, "无法处置该IP"), - /** - * The Err haohan error. - */ - ERR_HAOHAN_ERROR(34, "浩瀚设备返回错误"), /** * The Err database. */ - ERR_DATABASE(35, "操作数据库失败"), - /** - * The Err ipnodevice. - */ - ERR_IPNODEVICE(36, "找不到处置该IP的设备"), + ERR_DATABASE(34, "操作数据库失败"), /** * The Err untrusthost. */ - ERR_UNTRUSTHOST(37, "未经授权的客户端"), + ERR_UNTRUSTHOST(35, "未经授权的客户端"), /** * The Err untrusttoken. */ - ERR_UNTRUSTTOKEN(38, "未经授权的Token"), + ERR_UNTRUSTTOKEN(36, "未经授权的Token"), /** * The Err unknowninterface. */ - ERR_UNKNOWNINTERFACE(39, "未提供该接口"), + ERR_UNKNOWNINTERFACE(37, "未提供该接口"), /** * The Err decrypt base 64. */ @@ -219,7 +211,7 @@ public enum ErrorCode implements BaseEnum { /** * The Err nodevice areacode. */ - ERR_NODEVICE_AREACODE(112, "区域无该设备"), + ERR_NOSUCH_GAME(112, "该游戏不存在"), /** * The Err specifiedip exists. */ @@ -232,71 +224,6 @@ public enum ErrorCode implements BaseEnum { * The Err server processreq. */ ERR_SERVER_PROCESSREQ(115, "服务器处理请求错误"), - /** - * The Err huawei error. - */ - ERR_HUAWEI_ERROR(116, "华为设备返回错误"), - /** - * The Err pengxin error. - */ - ERR_PENGXIN_ERROR(117, "鹏信设备返回错误"), - /** - * The Err upf error. - */ - ERR_UPF_ERROR(118, "UPF设备返回错误"), - /** - * The Err nosuchumcprotectobject. - */ - ERR_NOSUCHUMCPROTECTOBJECT(200, "没有找到UMC防护对象"), - - /** - * The Err protectobjectexists. - */ - ERR_PROTECTOBJECTEXISTS(201, "该防护对象已经存在"), - - /** - * The Err tractionstrategyrunning. - */ - ERR_TRACTIONSTRATEGYRUNNING(201, "该防护策略正在运行"), - - /** - * The Err nosuchprotectstrategy. - */ - ERR_NOSUCHPROTECTSTRATEGY(202, "没有该防护策略"), - - - /** - * The Err businessexists. - */ - ERR_BUSINESSEXISTS(300, "该业务已经存在"), - - /** - * Err businessnotexists error code. - */ - ERR_BUSINESSNOTEXISTS(301, "该业务不存在"), - - /** - * Err addbusiness error code. - */ - ERR_ADDBUSINESS(302, "添加客户业务失败"), - - /** - * Err delbusiness error code. - */ - ERR_DELBUSINESS(303, "删除客户业务失败"), - - /** - * Err not found device error code. - */ - ERR_NOTFOUNDDEVICE(304, "找不到设备先添加设备"), - /** - * The Err huawei firewall error. - */ - ERR_HUAWEIFIREWALL_ERROR(305, "华为防火墙返回错误"), - /** - * The Err emos create message error. - */ - EMOS_CREATEMESSAGE_ERROR(306, "EMOS发送信息错误"), ; /** diff --git a/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java b/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java index 98ebaf0..2ffce8b 100644 --- a/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java +++ b/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java @@ -6,6 +6,7 @@ import com.cmhi.gds.pojo.dto.protocol.base.ProtocolRespDTO; import com.cmhi.gds.pojo.dto.protocol.info.GameInfoContent; import com.cmhi.gds.pojo.dto.protocol.info.GameInfoDetail; import com.cmhi.gds.pojo.dto.protocol.info.GameListSummary; +import com.cmhi.gds.pojo.dto.protocol.info.GameServerRet; import com.cmhi.gds.pojo.dto.protocol.info.GameServerRsp; import com.cmhi.gds.pojo.dto.protocol.info.GetGameInfoDetailReq; import com.cmhi.gds.pojo.dto.protocol.info.GetGamesInfoRsp; @@ -32,6 +33,7 @@ import javax.annotation.Resource; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -51,8 +53,8 @@ public class GameDatabaseInfoController { @ResponseBody public ProtocolRespDTO getGameListSummary() { GetGamesSummaryRsp rspInfo = GetGamesSummaryRsp.builder() - .items(new ArrayList<>()) - .build(); + .items(new ArrayList<>()) + .build(); List gameList = gameDatabaseServiceService.getGameTableSummaryItems(); @@ -60,8 +62,8 @@ public class GameDatabaseInfoController { for (GameTableItemsSummary v : gameList) { GameListSummary item = GameListSummary.builder() - .gameId(v.getGameId()) - .build(); + .gameId(v.getGameId()) + .build(); if (!v.getGameFilename().isEmpty()) { item.setGamesFilename(new ArrayList<>()); @@ -77,11 +79,17 @@ public class GameDatabaseInfoController { } rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); - rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()}); + rspInfo.setMessage(new String[] {ErrorCode.ERR_OK.getMsg()}); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); } + @PostMapping("gamelistsummary2") + @ResponseBody + public ProtocolRespDTO getGameListSummary2(@RequestBody ProtocolReqDTO mr) { + return getGameListSummary(); + } + @PostMapping("gamelistDetails") @ResponseBody public ProtocolRespDTO getGameInfoDetails(@Validated(ValidGroups.AddGameServiceValid.class) @@ -90,54 +98,54 @@ public class GameDatabaseInfoController { List gameContent = new ArrayList<>(); //获取TaskId列表 - List reqTaskIds = Optional.ofNullable(mr.getMsgContent().getItems()) - .orElse(new ArrayList<>()); + List reqIds = Optional.ofNullable(mr.getMsgContent().getItems()) + .orElse(new ArrayList<>()); - List ret = gameDatabaseServiceService.getGameTableItems(reqTaskIds); + List ret = gameDatabaseServiceService.getGameTableItems(reqIds); // 不存在的ID - reqTaskIds.stream() - .filter(v -> ret.stream().noneMatch(k -> k.getGameId().equals(v))) - .forEach(v -> { - GameInfoContent gi = GameInfoContent.builder().build(); - gi.setGameId(v); - gi.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); - gi.setMessage(new String[]{ErrorCode.ERR_NOSUCHTASK.getMsg()}); - gameContent.add(gi); - }); + reqIds.stream() + .filter(v -> ret.stream().noneMatch(k -> k.getGameId().equals(v))) + .forEach(v -> { + GameInfoContent gi = GameInfoContent.builder().build(); + gi.setGameId(v); + gi.setStatus(ErrorCode.ERR_NOSUCHTASK.getCode()); + gi.setMessage(new String[] {ErrorCode.ERR_NOSUCHTASK.getMsg()}); + gameContent.add(gi); + }); for (GameTableItemsDetail v : ret) { GameInfoContent gi = GameInfoContent.builder() - .gameId(v.getGameId()) - .company(v.getCompany()) - .name(v.getName()) - .gamesInfo(new ArrayList<>()) - .build(); + .gameId(v.getGameId()) + .company(v.getCompany()) + .name(v.getName()) + .gamesInfo(new ArrayList<>()) + .build(); gi.setStatus(ErrorCode.ERR_OK.getCode()); - gi.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()}); + gi.setMessage(new String[] {ErrorCode.ERR_OK.getMsg()}); v.getGameDetails() - .stream() - .sorted(Comparator.comparingLong(GameDetail::getGameInfoId)) - .forEach(k -> { - GameInfoDetail gd = GameInfoDetail.builder() - .gameInfoId(k.getGameInfoId()) - .version(k.getVersion()) - .gameFileName(k.getFilename()) - .md5sum(k.getMd5sum()) - .build(); + .stream() + .sorted(Comparator.comparingLong(GameDetail::getGameInfoId)) + .forEach(k -> { + GameInfoDetail gd = GameInfoDetail.builder() + .gameInfoId(k.getGameInfoId()) + .version(k.getVersion()) + .gameFileName(k.getFilename()) + .md5sum(k.getMd5sum()) + .build(); - gi.getGamesInfo().add(gd); - }); + gi.getGamesInfo().add(gd); + }); gameContent.add(gi); } rspInfo.getItems().addAll(gameContent.stream().sorted(Comparator.comparingLong(GameInfoContent::getGameId)) - .collect(Collectors.toList())); + .collect(Collectors.toList())); rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); - rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()}); + rspInfo.setMessage(new String[] {ErrorCode.ERR_OK.getMsg()}); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); } @@ -147,33 +155,20 @@ public class GameDatabaseInfoController { public ProtocolRespDTO reportGameServiceData( @Validated(ValidGroups.AddGameServiceValid.class) @RequestBody ProtocolReqDTO mr) { - GameServerRsp rspInfo = new GameServerRsp(); - rspInfo.setItems(new ArrayList<>()); -// -// // 请求参数转换 -// List devs = requestToDeviceList(mr.getMsgContent()); -// -// // 更新设备信息 -// List> ret = disposeDeviceManagerService.upgradeDisposeDevice(devs); -// -// CommDeviceListRsp rspInfo = new CommDeviceListRsp(); -// rspInfo.setItems(new ArrayList<>()); -// -// ret.forEach(v -> { -// DeviceInfoRsp rsp = new DeviceInfoRsp(); -// DisposeDevice dev = v.getSecondParam(); -// -// disposeDeviceManagerService.getAllDisposeDevice().parallelStream() -// .filter(k -> k.getId().equals(dev.getId())) -// .findAny().ifPresent(device -> rsp.setDevStatus(device.getStatus().getValue())); -// -// rsp.setId(String.valueOf(dev.getId())); -// rsp.setStatus(v.getFirstParam().getCode()); -// rsp.setMessage(new String[]{v.getFirstParam().getMsg()}); -// -// rspInfo.getItems().add(rsp); -// }); -// + GameServerRsp rspInfo = GameServerRsp.builder().items(new ArrayList<>()).build(); + List gameServer = new ArrayList<>(); + Map ret = gameDatabaseServiceService.addGameServerInfo(mr.getMsgContent().getItems()); + ret.forEach((key, value) -> { + GameServerRet gs = new GameServerRet(); + gs.setGameId(key); + gs.setStatus(value.getValue()); + gs.setMessage(new String[] {value.getMsg()}); + gameServer.add(gs); + }); + + rspInfo.getItems().addAll(gameServer); + rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); + rspInfo.setMessage(new String[] {ErrorCode.ERR_OK.getMsg()}); return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); } } diff --git a/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java b/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java index 6202777..f7950d6 100644 --- a/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java +++ b/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java @@ -1,5 +1,6 @@ package com.cmhi.gds.manager; +import com.cmhi.gds.pojo.entry.GameServer; import com.cmhi.gds.pojo.vo.GameTableItemsDetail; import com.cmhi.gds.pojo.vo.GameTableSummary; @@ -9,4 +10,8 @@ public interface GameDatabaseServiceManager { List getGameTableSummary(); List getGameTableDetails(List gameId); + + List getGameServerInfoByGameInfoId(List gameInfoId); + + int addGameServerInfo(List gsList); } diff --git a/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java b/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java index f62bd6a..73c9283 100644 --- a/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java +++ b/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java @@ -4,6 +4,7 @@ import com.cmhi.gds.manager.GameDatabaseServiceManager; import com.cmhi.gds.mapper.GameInfoMapper; import com.cmhi.gds.mapper.GameServerMapper; import com.cmhi.gds.mapper.GameTableMapper; +import com.cmhi.gds.pojo.entry.GameServer; import com.cmhi.gds.pojo.vo.GameTableItemsDetail; import com.cmhi.gds.pojo.vo.GameTableSummary; import lombok.extern.slf4j.Slf4j; @@ -33,4 +34,14 @@ public class GameDatabaseServiceManagerImpl implements GameDatabaseServiceManage public List getGameTableDetails(List gameId) { return gameTableMapper.selectAllGameDetailById(gameId); } + + @Override + public List getGameServerInfoByGameInfoId(List gameInfoId) { + return gameServerMapper.selectAllByGameInfoId(gameInfoId); + } + + @Override + public int addGameServerInfo(List gsList) { + return gameServerMapper.addGameServerInfoList(gsList); + } } diff --git a/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java b/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java index 4369b57..4c82cf0 100644 --- a/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java +++ b/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java @@ -1,6 +1,8 @@ package com.cmhi.gds.mapper; import com.cmhi.gds.pojo.entry.GameInfo; +import com.cmhi.gds.pojo.entry.GameServer; +import org.apache.ibatis.annotations.Param; import java.util.List; diff --git a/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java b/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java index 78a302d..b73014e 100644 --- a/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java +++ b/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java @@ -1,9 +1,15 @@ package com.cmhi.gds.mapper; +import com.cmhi.gds.pojo.entry.GameInfo; import com.cmhi.gds.pojo.entry.GameServer; +import org.apache.ibatis.annotations.Param; import java.util.List; public interface GameServerMapper { List selectAll(); + + List selectAllByGameInfoId(@Param("idList") List idList); + + int addGameServerInfoList(@Param("gameSvrInfo") List gameSvrInfo); } diff --git a/src/main/java/com/cmhi/gds/misc/Helper.java b/src/main/java/com/cmhi/gds/misc/Helper.java index 181b2a4..f916381 100644 --- a/src/main/java/com/cmhi/gds/misc/Helper.java +++ b/src/main/java/com/cmhi/gds/misc/Helper.java @@ -1,11 +1,16 @@ package com.cmhi.gds.misc; +import inet.ipaddr.HostName; +import inet.ipaddr.HostNameException; +import inet.ipaddr.IPAddress; +import inet.ipaddr.IPAddressString; import lombok.extern.slf4j.Slf4j; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; +import java.math.BigInteger; import java.nio.charset.StandardCharsets; import java.sql.Timestamp; import java.time.LocalDateTime; @@ -92,7 +97,7 @@ public class Helper { StringBuilder sb = new StringBuilder(); try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, - StandardCharsets.UTF_8))) { + StandardCharsets.UTF_8))) { String line; while ((line = reader.readLine()) != null) { sb.append(line); @@ -103,4 +108,57 @@ public class Helper { return sb.toString(); } + + public static Boolean ipAddressIsHostname(String hostStr) { + HostName host = new HostName(hostStr); + try { + host.validate(); + return !host.isAddress(); + } catch (HostNameException e) { + return null; + } + } + + public static boolean ipAddressIsIpv6(String ipAddr) { + IPAddress loopback = new IPAddressString(ipAddr).getAddress(); + + if (loopback.isIPAddress()) { + return loopback.isIPv6(); + } else { + return false; + } + } + + public static boolean isIpAddressEqual(String ip1, String ip2) { + if (ipAddressIsHostname(ip1) == null || ipAddressIsHostname(ip1) == null) { + return false; + } + + if (ipAddressIsHostname(ip1) == ipAddressIsHostname(ip2)) { + if (Boolean.TRUE.equals(ipAddressIsHostname(ip1))) { + return ip1.equals(ip2); + } else { + BigInteger v1 = ipAddressToBigInteger(ip1); + BigInteger v2 = ipAddressToBigInteger(ip2); + + if (ipAddressIsIpv6(ip1) == ipAddressIsIpv6(ip2)) { + return (v1 != null && v1.equals(v2)); + } else { + return false; + } + } + } else { + return false; + } + } + + public static BigInteger ipAddressToBigInteger(String ipAddr) { + IPAddress loopback = new IPAddressString(ipAddr).getAddress(); + + if (loopback.isIPAddress()) { + return loopback.getValue(); + } else { + return null; + } + } } diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java index 9b12afc..367590a 100644 --- a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java @@ -1,18 +1,23 @@ package com.cmhi.gds.pojo.dto.protocol.info; +import com.cmhi.gds.pojo.dto.protocol.base.BaseRespStatus; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; import java.util.List; +@EqualsAndHashCode(callSuper = true) @Data @Builder @NoArgsConstructor @AllArgsConstructor +@JsonPropertyOrder({"items", "status", "message"}) @JsonInclude(JsonInclude.Include.NON_NULL) -public class GameServerRsp { +public class GameServerRsp extends BaseRespStatus { List items; } diff --git a/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java b/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java index 77a05ce..0ffffe9 100644 --- a/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java +++ b/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java @@ -1,13 +1,18 @@ package com.cmhi.gds.service; +import com.cmhi.gds.common.ErrorCode; +import com.cmhi.gds.pojo.dto.protocol.info.GameServerContent; import com.cmhi.gds.pojo.vo.GameTableItemsDetail; import com.cmhi.gds.pojo.vo.GameTableItemsSummary; import java.util.List; +import java.util.Map; public interface GameDatabaseServiceService { List getGameTableSummaryItems(); List getGameTableItems(List gameIds); + + Map addGameServerInfo(List gameServerContents); } diff --git a/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java b/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java index 460a931..f1da076 100644 --- a/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java +++ b/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java @@ -1,6 +1,12 @@ package com.cmhi.gds.service.impl; +import com.cmhi.gds.common.CommonEnumHandler; +import com.cmhi.gds.common.ErrorCode; +import com.cmhi.gds.common.TransportProtocolType; import com.cmhi.gds.manager.GameDatabaseServiceManager; +import com.cmhi.gds.misc.Helper; +import com.cmhi.gds.pojo.dto.protocol.info.GameServerContent; +import com.cmhi.gds.pojo.entry.GameServer; import com.cmhi.gds.pojo.vo.GameSummary; import com.cmhi.gds.pojo.vo.GameTableItemsDetail; import com.cmhi.gds.pojo.vo.GameTableItemsSummary; @@ -12,7 +18,11 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; @Service @Slf4j @@ -52,4 +62,52 @@ public class GameDatabaseServiceServiceImpl implements GameDatabaseServiceServic public List getGameTableItems(List gameIds) { return gameDatabaseServiceManager.getGameTableDetails(gameIds); } + + @Override + public Map addGameServerInfo(List gameServerContents) { + Map ret = new HashMap<>(); + List gameInfoIds = new ArrayList<>(); + List gsAddList = new ArrayList<>(); + + for (GameServerContent v : gameServerContents) { + gameInfoIds.add(v.getGameId()); + } + + // GAME ID 不存在 + List allInfo = getGameTableItems(gameInfoIds); + gameInfoIds.stream() + .filter(v -> allInfo.stream().noneMatch(k -> k.getGameId().equals(v))) + .forEach(v -> { + ret.put(v, ErrorCode.ERR_NOSUCH_GAME); + }); + + // 当前GAME所有已经存在的游戏信息 + List gsList = gameDatabaseServiceManager.getGameServerInfoByGameInfoId(gameInfoIds); + gameServerContents.forEach(k -> { + List f = gsList.stream().filter(v -> Objects.equals(v.getGameInfoId(), k.getGameId())) + .collect(Collectors.toList()); + k.getServices().forEach(v -> { + if (f.stream().noneMatch(m -> Helper.isIpAddressEqual(m.getIpaddr(), v.getIpAddr()) + && m.getPort().equals(Integer.parseInt(v.getIpPort())) + && m.getProtocol().getValue().equals(v.getProtoType()))) { + // 添加 + GameServer gs = GameServer.builder() + .gameInfoId(k.getGameId()) + .ipaddr(v.getIpAddr()) + .port(Integer.parseInt(v.getIpPort())) + .protocol(CommonEnumHandler.codeOf(TransportProtocolType.class, v.getProtoType())) + .build(); + gsAddList.add(gs); + //log.info(""); + ret.put(k.getGameId(), ErrorCode.ERR_OK); + } else { + ret.put(k.getGameId(), ErrorCode.ERR_SPECIFIEDIP_EXISTS); + } + }); + }); + + // 更新数据库 + gameDatabaseServiceManager.addGameServerInfo(gsAddList); + return ret; + } } diff --git a/src/main/resources/mappers/GameServer.xml b/src/main/resources/mappers/GameServer.xml index 8969b24..8196108 100644 --- a/src/main/resources/mappers/GameServer.xml +++ b/src/main/resources/mappers/GameServer.xml @@ -14,4 +14,21 @@ SELECT * FROM game_server + + + + + INSERT IGNORE INTO game_server(gameInfoId, ipaddr, port, protocol) + VALUES + + (#{item.gameInfoId}, #{item.ipaddr}, #{item.port}, #{item.protocol}) + + \ No newline at end of file