From 517a9a70dc204ca087cc5227510c84add03fddb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E6=98=95?= Date: Thu, 26 Oct 2023 15:42:54 +0800 Subject: [PATCH] =?UTF-8?q?OCT=201.=20=E5=A2=9E=E5=8A=A0=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E6=93=8D=E4=BD=9C=202.=20=E5=A2=9E=E5=8A=A0=E6=8E=A7?= =?UTF-8?q?=E5=88=B6=E6=8E=A5=E5=8F=A3=203.=20=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=9C=8D=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/application-local.properties | 14 +-- config/logback.xml | 2 +- pom.xml | 22 +++- .../common/ConstValue.java | 15 --- .../pojo/dto/protocol/base/IdArraysReq.java | 40 ------- .../GameDatabaseServiceApplication.java | 4 +- .../common/BaseEnum.java | 2 +- .../common/CommonEnumHandler.java | 2 +- .../java/com/cmhi/gds/common/ConstValue.java | 28 +++++ .../common/ErrorCode.java | 2 +- .../common/ProtoCryptoType.java | 2 +- .../common/SecurityConfigValue.java | 2 +- .../gds/common/TransportProtocolType.java | 61 ++++++++++ .../GameDatabaseInfoController.java | 111 ++++++++++++++++++ .../ControllerNotSupportException.java | 4 +- .../ControllerRequestTimeoutException.java | 4 +- .../exception/GlobalExceptionHandler.java | 12 +- .../exception/SecurityProtocolException.java | 4 +- .../manager/GameDatabaseServiceManager.java | 11 ++ .../impl/GameDatabaseServiceManagerImpl.java | 30 +++++ .../com/cmhi/gds/mapper/GameInfoMapper.java | 9 ++ .../com/cmhi/gds/mapper/GameServerMapper.java | 9 ++ .../com/cmhi/gds/mapper/GameTableMapper.java | 12 ++ .../misc/Helper.java | 7 +- .../pojo/dto/protocol/base/BaseIdResp.java | 2 +- .../dto/protocol/base/BaseProtocolDTO.java | 4 +- .../dto/protocol/base/BaseRespStatus.java | 2 +- .../dto/protocol/base/ProtocolReqDTO.java | 4 +- .../dto/protocol/base/ProtocolRespDTO.java | 8 +- .../dto/protocol/info/GameInfoContent.java | 22 ++++ .../dto/protocol/info/GameInfoDetail.java | 20 ++++ .../dto/protocol/info/GameListSummary.java | 20 ++++ .../dto/protocol/info/GameServerContent.java | 32 +++++ .../dto/protocol/info/GameServerDetail.java | 36 ++++++ .../pojo/dto/protocol/info/GameServerReq.java | 27 +++++ .../pojo/dto/protocol/info/GameServerRet.java | 21 ++++ .../pojo/dto/protocol/info/GameServerRsp.java | 18 +++ .../dto/protocol/info/GetGamesInfoRsp.java | 23 ++++ .../dto/protocol/info/GetGamesSummaryRsp.java | 23 ++++ .../com/cmhi/gds/pojo/entry/GameInfo.java | 47 ++++++++ .../com/cmhi/gds/pojo/entry/GameServer.java | 50 ++++++++ .../com/cmhi/gds/pojo/entry/GameSummary.java | 15 +++ .../com/cmhi/gds/pojo/entry/GameTable.java | 43 +++++++ .../cmhi/gds/pojo/entry/GameTableSummary.java | 17 +++ .../com/cmhi/gds/pojo/vo/GameTableItems.java | 19 +++ .../gds/security/annotation/Decryption.java | 16 +++ .../gds/security/annotation/Encryption.java | 16 +++ .../security/arithmetic/CryptoHelper.java | 2 +- .../configure/EncryptionPropertyResolver.java | 4 +- .../protocol/DecryptRequestProtocol.java | 2 +- .../service/GameDatabaseServiceService.java | 10 ++ .../impl/GameDatabaseServiceServiceImpl.java | 49 ++++++++ .../validation/group}/ValidGroups.java | 6 +- .../gds/validation/valids/ValidBaseEnum.java | 51 ++++++++ .../gds/validation/valids/ValidIpAddr.java | 43 +++++++ .../gds/validation/valids/ValidIpPort.java | 43 +++++++ .../valids/impl/ValidBaseEnumImpl.java | 73 ++++++++++++ .../valids/impl/ValidIpAddrImpl.java | 56 +++++++++ .../valids/impl/ValidIpPortImpl.java | 54 +++++++++ src/main/resources/mappers/GameInfo.xml | 16 +++ src/main/resources/mappers/GameServer.xml | 17 +++ src/main/resources/mappers/GameTable.xml | 26 ++++ .../GameDatabaseServiceApplicationTests.java | 2 +- 63 files changed, 1238 insertions(+), 110 deletions(-) delete mode 100644 src/main/java/com/cmhi/game_database_service/common/ConstValue.java delete mode 100644 src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/IdArraysReq.java rename src/main/java/com/cmhi/{game_database_service => gds}/GameDatabaseServiceApplication.java (80%) rename src/main/java/com/cmhi/{game_database_service => gds}/common/BaseEnum.java (86%) rename src/main/java/com/cmhi/{game_database_service => gds}/common/CommonEnumHandler.java (98%) create mode 100644 src/main/java/com/cmhi/gds/common/ConstValue.java rename src/main/java/com/cmhi/{game_database_service => gds}/common/ErrorCode.java (99%) rename src/main/java/com/cmhi/{game_database_service => gds}/common/ProtoCryptoType.java (96%) rename src/main/java/com/cmhi/{game_database_service => gds}/common/SecurityConfigValue.java (92%) create mode 100644 src/main/java/com/cmhi/gds/common/TransportProtocolType.java create mode 100644 src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java rename src/main/java/com/cmhi/{game_database_service => gds}/exception/ControllerNotSupportException.java (82%) rename src/main/java/com/cmhi/{game_database_service => gds}/exception/ControllerRequestTimeoutException.java (88%) rename src/main/java/com/cmhi/{game_database_service => gds}/exception/GlobalExceptionHandler.java (95%) rename src/main/java/com/cmhi/{game_database_service => gds}/exception/SecurityProtocolException.java (86%) create mode 100644 src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java create mode 100644 src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java create mode 100644 src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java create mode 100644 src/main/java/com/cmhi/gds/mapper/GameServerMapper.java create mode 100644 src/main/java/com/cmhi/gds/mapper/GameTableMapper.java rename src/main/java/com/cmhi/{game_database_service => gds}/misc/Helper.java (93%) rename src/main/java/com/cmhi/{game_database_service => gds}/pojo/dto/protocol/base/BaseIdResp.java (92%) rename src/main/java/com/cmhi/{game_database_service => gds}/pojo/dto/protocol/base/BaseProtocolDTO.java (92%) rename src/main/java/com/cmhi/{game_database_service => gds}/pojo/dto/protocol/base/BaseRespStatus.java (87%) rename src/main/java/com/cmhi/{game_database_service => gds}/pojo/dto/protocol/base/ProtocolReqDTO.java (91%) rename src/main/java/com/cmhi/{game_database_service => gds}/pojo/dto/protocol/base/ProtocolRespDTO.java (91%) create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoContent.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoDetail.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameListSummary.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerContent.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerDetail.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerReq.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRet.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesInfoRsp.java create mode 100644 src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesSummaryRsp.java create mode 100644 src/main/java/com/cmhi/gds/pojo/entry/GameInfo.java create mode 100644 src/main/java/com/cmhi/gds/pojo/entry/GameServer.java create mode 100644 src/main/java/com/cmhi/gds/pojo/entry/GameSummary.java create mode 100644 src/main/java/com/cmhi/gds/pojo/entry/GameTable.java create mode 100644 src/main/java/com/cmhi/gds/pojo/entry/GameTableSummary.java create mode 100644 src/main/java/com/cmhi/gds/pojo/vo/GameTableItems.java create mode 100644 src/main/java/com/cmhi/gds/security/annotation/Decryption.java create mode 100644 src/main/java/com/cmhi/gds/security/annotation/Encryption.java rename src/main/java/com/cmhi/{game_database_service => gds}/security/arithmetic/CryptoHelper.java (99%) rename src/main/java/com/cmhi/{game_database_service => gds}/security/configure/EncryptionPropertyResolver.java (93%) rename src/main/java/com/cmhi/{game_database_service => gds}/security/protocol/DecryptRequestProtocol.java (96%) create mode 100644 src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java create mode 100644 src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java rename src/main/java/com/cmhi/{game_database_service/validation => gds/validation/group}/ValidGroups.java (93%) create mode 100644 src/main/java/com/cmhi/gds/validation/valids/ValidBaseEnum.java create mode 100644 src/main/java/com/cmhi/gds/validation/valids/ValidIpAddr.java create mode 100644 src/main/java/com/cmhi/gds/validation/valids/ValidIpPort.java create mode 100644 src/main/java/com/cmhi/gds/validation/valids/impl/ValidBaseEnumImpl.java create mode 100644 src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpAddrImpl.java create mode 100644 src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpPortImpl.java create mode 100644 src/main/resources/mappers/GameInfo.xml create mode 100644 src/main/resources/mappers/GameServer.xml create mode 100644 src/main/resources/mappers/GameTable.xml rename src/test/java/com/cmhi/{game_database_service => gds}/GameDatabaseServiceApplicationTests.java (83%) diff --git a/config/application-local.properties b/config/application-local.properties index c00f424..27ffb87 100644 --- a/config/application-local.properties +++ b/config/application-local.properties @@ -1,18 +1,12 @@ server.port=9276 -server.servlet.context-path=/tunnel +server.servlet.context-path=/cmhi # mysql -spring.datasource.url=jdbc:mysql://101.35.234.160:32306/beidou?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true +spring.datasource.url=jdbc:mysql://101.35.234.160:32306/GameDatabase?serverTimezone=Asia/Shanghai&zeroDateTimeBehavior=convertToNull&useUnicode=true spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.username=cmhi spring.datasource.password=cmHi10086! -# SQL Server -#spring.datasource.url=jdbc:sqlserver://localhost:1433;database=BeiDouDataBase;integratedSecurity=true;encrypt=true;trustServerCertificate=true -#spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver -#spring.datasource.username=sa -#spring.datasource.password=sa123456 - #spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource spring.datasource.dbcp2.max-total=128 spring.datasource.dbcp2.max-wait-millis=10000 @@ -26,8 +20,8 @@ spring.datasource.dbcp2.connection-properties=characterEncoding=utf8 #mybatis #mybatis.configuration.map-underscore-to-camel-case: true mybatis.mapper-locations=classpath*:mappers/*.xml -mybatis.type-aliases-package=com.cmhi.game_database_service.pojo.entry -mybatis.configuration.default-enum-type-handler=com.cmhi.game_database_service.common.CommonEnumHandler +mybatis.type-aliases-package=com.cmhi.gds.pojo.entry +mybatis.configuration.default-enum-type-handler=com.cmhi.gds.common.CommonEnumHandler #mybatis.configuration.log-impl=lombok.extern.slf4j.Slf4j #pagehelper diff --git a/config/logback.xml b/config/logback.xml index 8b68eb2..c17654a 100644 --- a/config/logback.xml +++ b/config/logback.xml @@ -46,7 +46,7 @@ - + diff --git a/pom.xml b/pom.xml index 43d0d5b..0592ece 100644 --- a/pom.xml +++ b/pom.xml @@ -112,6 +112,26 @@ commons-lang 2.6 + + com.github.seancfoley + ipaddress + 5.4.0 + + + javax.persistence + persistence-api + 1.0 + + + tk.mybatis + mapper-core + 1.1.5 + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + 3.0.2 + @@ -160,7 +180,7 @@ - com.cmhi.game_database_service.GameDatabaseServiceApplication + com.cmhi.gds.GameDatabaseServiceApplication true lib/ diff --git a/src/main/java/com/cmhi/game_database_service/common/ConstValue.java b/src/main/java/com/cmhi/game_database_service/common/ConstValue.java deleted file mode 100644 index b238592..0000000 --- a/src/main/java/com/cmhi/game_database_service/common/ConstValue.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.cmhi.game_database_service.common; - -public class ConstValue { - /** - * The constant STRING_HTTP_AUTH_HEAD. - */ - public static final String STRING_HTTP_AUTH_HEAD = "Bearer "; - - public static class Protocol { - /** - * The constant VERSION. - */ - public static final int VERSION = 1; - } -} diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/IdArraysReq.java b/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/IdArraysReq.java deleted file mode 100644 index 54dd43d..0000000 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/IdArraysReq.java +++ /dev/null @@ -1,40 +0,0 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; - -import com.cmhi.game_database_service.validation.ValidGroups; -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; - -import javax.validation.constraints.NotNull; -import javax.validation.constraints.Size; - -/** - * The type Id arrays req. - * - * @author - */ -@Getter -@Builder -@NoArgsConstructor -@AllArgsConstructor -@JsonInclude(JsonInclude.Include.NON_NULL) -public class IdArraysReq { - - /** - * The Id. - */ - @NotNull(message = "id 字段不能为空", - groups = {ValidGroups.IdArrayValid.class, ValidGroups.GetDevVerReqValid.class}) - @Size(min = 1, message = "id 字段必须指定明确id编号", groups = ValidGroups.ExplicitIdArrayValid.class) - private String[] id; - - /** - * The Task id. - */ - @NotNull(message = "taskId 字段不能为空", groups = ValidGroups.TaskStopReqValid.class) - @Size(min = 1, max = 20, message = "taskId 字段id个数取值范围为[1, 20]", - groups = ValidGroups.TaskStopReqValid.class) - private String[] taskId; -} diff --git a/src/main/java/com/cmhi/game_database_service/GameDatabaseServiceApplication.java b/src/main/java/com/cmhi/gds/GameDatabaseServiceApplication.java similarity index 80% rename from src/main/java/com/cmhi/game_database_service/GameDatabaseServiceApplication.java rename to src/main/java/com/cmhi/gds/GameDatabaseServiceApplication.java index e2d0f4e..bda6ed4 100644 --- a/src/main/java/com/cmhi/game_database_service/GameDatabaseServiceApplication.java +++ b/src/main/java/com/cmhi/gds/GameDatabaseServiceApplication.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service; +package com.cmhi.gds; import org.mybatis.spring.annotation.MapperScan; import org.springframework.boot.SpringApplication; @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.scheduling.annotation.EnableScheduling; @SpringBootApplication -@MapperScan(basePackages = {"com.cmhi.game_database_service.mapper"}) +@MapperScan(basePackages = {"com.cmhi.gds.mapper"}) @EnableScheduling public class GameDatabaseServiceApplication { diff --git a/src/main/java/com/cmhi/game_database_service/common/BaseEnum.java b/src/main/java/com/cmhi/gds/common/BaseEnum.java similarity index 86% rename from src/main/java/com/cmhi/game_database_service/common/BaseEnum.java rename to src/main/java/com/cmhi/gds/common/BaseEnum.java index c535c08..f404bea 100644 --- a/src/main/java/com/cmhi/game_database_service/common/BaseEnum.java +++ b/src/main/java/com/cmhi/gds/common/BaseEnum.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.common; +package com.cmhi.gds.common; /** * The interface Base enum. diff --git a/src/main/java/com/cmhi/game_database_service/common/CommonEnumHandler.java b/src/main/java/com/cmhi/gds/common/CommonEnumHandler.java similarity index 98% rename from src/main/java/com/cmhi/game_database_service/common/CommonEnumHandler.java rename to src/main/java/com/cmhi/gds/common/CommonEnumHandler.java index d4bae2d..8d536b7 100644 --- a/src/main/java/com/cmhi/game_database_service/common/CommonEnumHandler.java +++ b/src/main/java/com/cmhi/gds/common/CommonEnumHandler.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.common; +package com.cmhi.gds.common; import org.apache.ibatis.type.BaseTypeHandler; import org.apache.ibatis.type.JdbcType; diff --git a/src/main/java/com/cmhi/gds/common/ConstValue.java b/src/main/java/com/cmhi/gds/common/ConstValue.java new file mode 100644 index 0000000..2e19b79 --- /dev/null +++ b/src/main/java/com/cmhi/gds/common/ConstValue.java @@ -0,0 +1,28 @@ +package com.cmhi.gds.common; + +public class ConstValue { + /** + * The constant STRING_HTTP_AUTH_HEAD. + */ + public static final String STRING_HTTP_AUTH_HEAD = "Bearer "; + + public static final String IP_ADDR_REG = "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^" + + "([\\da-fA-F]{1,4}:){6}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^::" + + "([\\da-fA-F]{1,4}:){0,4}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^" + + "([\\da-fA-F]{1,4}:):([\\da-fA-F]{1,4}:){0,3}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}" + + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^([\\da-fA-F]{1,4}:){2}:([\\da-fA-F]{1,4}:){0,2}(" + + "(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^([\\da-fA-F]{1,4}:){3}:" + + "([\\da-fA-F]{1,4}:){0,1}((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^" + + "([\\da-fA-F]{1,4}:){4}:((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$|^" + + "([\\da-fA-F]{1,4}:){7}[\\da-fA-F]{1,4}$|^:((:[\\da-fA-F]{1,4}){1,6}|:)$|^[\\da-fA-F]{1,4}:((:[\\da-fA-F]{1," + + "4}){1,5}|:)$|^([\\da-fA-F]{1,4}:){2}((:[\\da-fA-F]{1,4}){1,4}|:)$|^([\\da-fA-F]{1,4}:){3}((:[\\da-fA-F]{1," + + "4}){1,3}|:)$|^([\\da-fA-F]{1,4}:){4}((:[\\da-fA-F]{1,4}){1,2}|:)$|^([\\da-fA-F]{1,4}:){5}:([\\da-fA-F]{1,4})" + + "?$|^([\\da-fA-F]{1,4}:){6}:$"; + public static class Protocol { + /** + * The constant VERSION. + */ + public static final int VERSION = 1; + } +} diff --git a/src/main/java/com/cmhi/game_database_service/common/ErrorCode.java b/src/main/java/com/cmhi/gds/common/ErrorCode.java similarity index 99% rename from src/main/java/com/cmhi/game_database_service/common/ErrorCode.java rename to src/main/java/com/cmhi/gds/common/ErrorCode.java index 879035d..fcb1417 100644 --- a/src/main/java/com/cmhi/game_database_service/common/ErrorCode.java +++ b/src/main/java/com/cmhi/gds/common/ErrorCode.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.common; +package com.cmhi.gds.common; import javax.servlet.http.HttpServletResponse; diff --git a/src/main/java/com/cmhi/game_database_service/common/ProtoCryptoType.java b/src/main/java/com/cmhi/gds/common/ProtoCryptoType.java similarity index 96% rename from src/main/java/com/cmhi/game_database_service/common/ProtoCryptoType.java rename to src/main/java/com/cmhi/gds/common/ProtoCryptoType.java index 7341b53..f16212e 100644 --- a/src/main/java/com/cmhi/game_database_service/common/ProtoCryptoType.java +++ b/src/main/java/com/cmhi/gds/common/ProtoCryptoType.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.common; +package com.cmhi.gds.common; /** * The enum Proto crypto type. diff --git a/src/main/java/com/cmhi/game_database_service/common/SecurityConfigValue.java b/src/main/java/com/cmhi/gds/common/SecurityConfigValue.java similarity index 92% rename from src/main/java/com/cmhi/game_database_service/common/SecurityConfigValue.java rename to src/main/java/com/cmhi/gds/common/SecurityConfigValue.java index f63f7a2..faecf91 100644 --- a/src/main/java/com/cmhi/game_database_service/common/SecurityConfigValue.java +++ b/src/main/java/com/cmhi/gds/common/SecurityConfigValue.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.common; +package com.cmhi.gds.common; /** * The type Security config value. diff --git a/src/main/java/com/cmhi/gds/common/TransportProtocolType.java b/src/main/java/com/cmhi/gds/common/TransportProtocolType.java new file mode 100644 index 0000000..b81afc5 --- /dev/null +++ b/src/main/java/com/cmhi/gds/common/TransportProtocolType.java @@ -0,0 +1,61 @@ +package com.cmhi.gds.common; + +/** + * The enum Dispose device type. + * + * @author + */ +public enum TransportProtocolType implements BaseEnum { + /** + * The Dptech umc. + */ + TCP_PROTOCOL(0, "TCP"), + /** + * The Haohan platform. + */ + UDP_PROTOCOL(1, "UDP"), + /** + * The Pengxin platform. + */ + UNKNOWN_PROTOCOL(2, "UNKNOWN"); + + /** + * The Code. + */ + private final int code; + /** + * The Readme. + */ + private final String readme; + + /** + * Instantiates a new Dispose device type. + * + * @param code the code + * @param readme the readme + */ + TransportProtocolType(int code, String readme) { + this.code = code; + this.readme = readme; + } + + /** + * Gets value. + * + * @return the value + */ + @Override + public Integer getValue() { + return this.code; + } + + /** + * Gets description. + * + * @return the description + */ + @Override + public String getDescription() { + return this.readme; + } +} diff --git a/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java b/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java new file mode 100644 index 0000000..1b76714 --- /dev/null +++ b/src/main/java/com/cmhi/gds/controller/GameDatabaseInfoController.java @@ -0,0 +1,111 @@ +package com.cmhi.gds.controller; + +import com.cmhi.gds.common.ErrorCode; +import com.cmhi.gds.pojo.dto.protocol.base.ProtocolReqDTO; +import com.cmhi.gds.pojo.dto.protocol.base.ProtocolRespDTO; +import com.cmhi.gds.pojo.dto.protocol.info.GameListSummary; +import com.cmhi.gds.pojo.dto.protocol.info.GameServerReq; +import com.cmhi.gds.pojo.dto.protocol.info.GameServerRsp; +import com.cmhi.gds.pojo.dto.protocol.info.GetGamesSummaryRsp; +import com.cmhi.gds.pojo.vo.GameTableItems; +import com.cmhi.gds.security.annotation.Decryption; +import com.cmhi.gds.security.annotation.Encryption; +import com.cmhi.gds.service.GameDatabaseServiceService; +import com.cmhi.gds.validation.group.ValidGroups; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; +import org.springframework.stereotype.Controller; +import org.springframework.validation.annotation.Validated; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.ArrayList; +import java.util.List; + +@Controller +@RequestMapping(value = "/gameinfo") +@Slf4j +@Component +@Validated +@Encryption +@Decryption +public class GameDatabaseInfoController { + + @Resource + private GameDatabaseServiceService gameDatabaseServiceService; + + @GetMapping("gamelistsummary") + @ResponseBody + + public ProtocolRespDTO getGameListSummary() { + GetGamesSummaryRsp rspInfo = GetGamesSummaryRsp.builder() + .items(new ArrayList<>()) + .build(); + + List gameList = gameDatabaseServiceService.getGameTableSummaryItems(); + + if (!gameList.isEmpty()) { + + for (GameTableItems v : gameList) { + GameListSummary item = GameListSummary.builder() + .gameId(v.getGameId()) + .build(); + + if (!v.getGameFilename().isEmpty()) { + item.setGamesFilename(new ArrayList<>()); + + for (String p : v.getGameFilename()) { + item.getGamesFilename().add(p); + } + } else { + item.setGamesFilename(new ArrayList<>()); + } + rspInfo.getItems().add(item); + } + } + + rspInfo.setStatus(ErrorCode.ERR_OK.getCode()); + rspInfo.setMessage(new String[]{ErrorCode.ERR_OK.getMsg()}); + + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } + + @PostMapping("/gamedata") + @ResponseBody + 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); +// }); +// + return ProtocolRespDTO.result(ErrorCode.ERR_OK, rspInfo); + } +} diff --git a/src/main/java/com/cmhi/game_database_service/exception/ControllerNotSupportException.java b/src/main/java/com/cmhi/gds/exception/ControllerNotSupportException.java similarity index 82% rename from src/main/java/com/cmhi/game_database_service/exception/ControllerNotSupportException.java rename to src/main/java/com/cmhi/gds/exception/ControllerNotSupportException.java index f59a72d..18dab39 100644 --- a/src/main/java/com/cmhi/game_database_service/exception/ControllerNotSupportException.java +++ b/src/main/java/com/cmhi/gds/exception/ControllerNotSupportException.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.exception; +package com.cmhi.gds.exception; -import com.cmhi.game_database_service.common.ErrorCode; +import com.cmhi.gds.common.ErrorCode; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/cmhi/game_database_service/exception/ControllerRequestTimeoutException.java b/src/main/java/com/cmhi/gds/exception/ControllerRequestTimeoutException.java similarity index 88% rename from src/main/java/com/cmhi/game_database_service/exception/ControllerRequestTimeoutException.java rename to src/main/java/com/cmhi/gds/exception/ControllerRequestTimeoutException.java index 3b4355c..a3eb0a7 100644 --- a/src/main/java/com/cmhi/game_database_service/exception/ControllerRequestTimeoutException.java +++ b/src/main/java/com/cmhi/gds/exception/ControllerRequestTimeoutException.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.exception; +package com.cmhi.gds.exception; -import com.cmhi.game_database_service.common.ErrorCode; +import com.cmhi.gds.common.ErrorCode; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/cmhi/game_database_service/exception/GlobalExceptionHandler.java b/src/main/java/com/cmhi/gds/exception/GlobalExceptionHandler.java similarity index 95% rename from src/main/java/com/cmhi/game_database_service/exception/GlobalExceptionHandler.java rename to src/main/java/com/cmhi/gds/exception/GlobalExceptionHandler.java index cd063fc..4171558 100644 --- a/src/main/java/com/cmhi/game_database_service/exception/GlobalExceptionHandler.java +++ b/src/main/java/com/cmhi/gds/exception/GlobalExceptionHandler.java @@ -1,10 +1,10 @@ -package com.cmhi.game_database_service.exception; +package com.cmhi.gds.exception; -import com.cmhi.game_database_service.common.ConstValue; -import com.cmhi.game_database_service.common.ErrorCode; -import com.cmhi.game_database_service.misc.Helper; -import com.cmhi.game_database_service.pojo.dto.protocol.base.BaseRespStatus; -import com.cmhi.game_database_service.pojo.dto.protocol.base.ProtocolRespDTO; +import com.cmhi.gds.common.ConstValue; +import com.cmhi.gds.common.ErrorCode; +import com.cmhi.gds.misc.Helper; +import com.cmhi.gds.pojo.dto.protocol.base.BaseRespStatus; +import com.cmhi.gds.pojo.dto.protocol.base.ProtocolRespDTO; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.ObjectError; import org.springframework.web.bind.MethodArgumentNotValidException; diff --git a/src/main/java/com/cmhi/game_database_service/exception/SecurityProtocolException.java b/src/main/java/com/cmhi/gds/exception/SecurityProtocolException.java similarity index 86% rename from src/main/java/com/cmhi/game_database_service/exception/SecurityProtocolException.java rename to src/main/java/com/cmhi/gds/exception/SecurityProtocolException.java index 827d54d..75c7609 100644 --- a/src/main/java/com/cmhi/game_database_service/exception/SecurityProtocolException.java +++ b/src/main/java/com/cmhi/gds/exception/SecurityProtocolException.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.exception; +package com.cmhi.gds.exception; -import com.cmhi.game_database_service.common.ErrorCode; +import com.cmhi.gds.common.ErrorCode; import lombok.Getter; import lombok.Setter; diff --git a/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java b/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java new file mode 100644 index 0000000..a2e03dd --- /dev/null +++ b/src/main/java/com/cmhi/gds/manager/GameDatabaseServiceManager.java @@ -0,0 +1,11 @@ +package com.cmhi.gds.manager; + +import com.cmhi.gds.pojo.entry.GameInfo; +import com.cmhi.gds.pojo.entry.GameTable; +import com.cmhi.gds.pojo.entry.GameTableSummary; + +import java.util.List; + +public interface GameDatabaseServiceManager { + List getGameTableSummary(); +} diff --git a/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java b/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java new file mode 100644 index 0000000..5ec84f2 --- /dev/null +++ b/src/main/java/com/cmhi/gds/manager/impl/GameDatabaseServiceManagerImpl.java @@ -0,0 +1,30 @@ +package com.cmhi.gds.manager.impl; + +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.GameTableSummary; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@Slf4j +public class GameDatabaseServiceManagerImpl implements GameDatabaseServiceManager { + @Resource + private GameInfoMapper gameInfoMapper; + + @Resource + private GameTableMapper gameTableMapper; + + @Resource + private GameServerMapper gameServerMapper; + + @Override + public List getGameTableSummary() { + return gameTableMapper.selectAllGameSummary(); + } +} diff --git a/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java b/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java new file mode 100644 index 0000000..4369b57 --- /dev/null +++ b/src/main/java/com/cmhi/gds/mapper/GameInfoMapper.java @@ -0,0 +1,9 @@ +package com.cmhi.gds.mapper; + +import com.cmhi.gds.pojo.entry.GameInfo; + +import java.util.List; + +public interface GameInfoMapper { + List selectAll(); +} diff --git a/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java b/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java new file mode 100644 index 0000000..78a302d --- /dev/null +++ b/src/main/java/com/cmhi/gds/mapper/GameServerMapper.java @@ -0,0 +1,9 @@ +package com.cmhi.gds.mapper; + +import com.cmhi.gds.pojo.entry.GameServer; + +import java.util.List; + +public interface GameServerMapper { + List selectAll(); +} diff --git a/src/main/java/com/cmhi/gds/mapper/GameTableMapper.java b/src/main/java/com/cmhi/gds/mapper/GameTableMapper.java new file mode 100644 index 0000000..71ff570 --- /dev/null +++ b/src/main/java/com/cmhi/gds/mapper/GameTableMapper.java @@ -0,0 +1,12 @@ +package com.cmhi.gds.mapper; + +import com.cmhi.gds.pojo.entry.GameTable; +import com.cmhi.gds.pojo.entry.GameTableSummary; + +import java.util.List; + +public interface GameTableMapper { + List selectAll(); + + List selectAllGameSummary(); +} diff --git a/src/main/java/com/cmhi/game_database_service/misc/Helper.java b/src/main/java/com/cmhi/gds/misc/Helper.java similarity index 93% rename from src/main/java/com/cmhi/game_database_service/misc/Helper.java rename to src/main/java/com/cmhi/gds/misc/Helper.java index 48efdc0..181b2a4 100644 --- a/src/main/java/com/cmhi/game_database_service/misc/Helper.java +++ b/src/main/java/com/cmhi/gds/misc/Helper.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.misc; +package com.cmhi.gds.misc; import lombok.extern.slf4j.Slf4j; @@ -10,11 +10,6 @@ import java.nio.charset.StandardCharsets; import java.sql.Timestamp; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; /** * The type Helper. diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseIdResp.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseIdResp.java similarity index 92% rename from src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseIdResp.java rename to src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseIdResp.java index ff34711..5a35d68 100644 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseIdResp.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseIdResp.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; +package com.cmhi.gds.pojo.dto.protocol.base; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonPropertyOrder; diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseProtocolDTO.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseProtocolDTO.java similarity index 92% rename from src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseProtocolDTO.java rename to src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseProtocolDTO.java index cf3b4ad..364d2c5 100644 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseProtocolDTO.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseProtocolDTO.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; +package com.cmhi.gds.pojo.dto.protocol.base; -import com.cmhi.game_database_service.validation.ValidGroups; +import com.cmhi.gds.validation.group.ValidGroups; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import lombok.Data; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseRespStatus.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseRespStatus.java similarity index 87% rename from src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseRespStatus.java rename to src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseRespStatus.java index 2cc47d0..209a4dd 100644 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/BaseRespStatus.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/BaseRespStatus.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; +package com.cmhi.gds.pojo.dto.protocol.base; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolReqDTO.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolReqDTO.java similarity index 91% rename from src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolReqDTO.java rename to src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolReqDTO.java index 8043878..34f2cad 100644 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolReqDTO.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolReqDTO.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; +package com.cmhi.gds.pojo.dto.protocol.base; -import com.cmhi.game_database_service.common.ConstValue; +import com.cmhi.gds.common.ConstValue; import lombok.NoArgsConstructor; import lombok.ToString; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolRespDTO.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolRespDTO.java similarity index 91% rename from src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolRespDTO.java rename to src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolRespDTO.java index 05b9cd9..be71175 100644 --- a/src/main/java/com/cmhi/game_database_service/pojo/dto/protocol/base/ProtocolRespDTO.java +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/base/ProtocolRespDTO.java @@ -1,9 +1,9 @@ -package com.cmhi.game_database_service.pojo.dto.protocol.base; +package com.cmhi.gds.pojo.dto.protocol.base; -import com.cmhi.game_database_service.common.ConstValue; -import com.cmhi.game_database_service.common.ErrorCode; -import com.cmhi.game_database_service.common.SecurityConfigValue; +import com.cmhi.gds.common.ConstValue; +import com.cmhi.gds.common.ErrorCode; +import com.cmhi.gds.common.SecurityConfigValue; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.databind.ObjectMapper; import lombok.AllArgsConstructor; diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoContent.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoContent.java new file mode 100644 index 0000000..24f6127 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoContent.java @@ -0,0 +1,22 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameId", "gamesInfo"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameInfoContent { + private Long gameId; + + List gamesInfo; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoDetail.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoDetail.java new file mode 100644 index 0000000..49b72a5 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameInfoDetail.java @@ -0,0 +1,20 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameFileName", "md5sum", "version"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameInfoDetail { + private String gameFileName; + private String md5sum; + private String version; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameListSummary.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameListSummary.java new file mode 100644 index 0000000..6a1de1b --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameListSummary.java @@ -0,0 +1,20 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameId", "gamesFilename"}) +public class GameListSummary { + List gamesFilename; + private Long gameId; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerContent.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerContent.java new file mode 100644 index 0000000..d40a997 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerContent.java @@ -0,0 +1,32 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.cmhi.gds.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.Valid; +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameId", "services"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameServerContent { + @NotNull(message = "gameId 游戏ID不能为空", groups = ValidGroups.AddGameServiceValid.class) + @Min(message = "gameId > 0", groups = ValidGroups.AddGameServiceValid.class, value = 1L) + private Long gameId; + + @NotNull(message = "items 设备列表不能为空", groups = ValidGroups.AddGameServiceValid.class) + @Size(min = 1, message = "items 至少需要有一个元素", groups = ValidGroups.AddGameServiceValid.class) + @Valid + private List services; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerDetail.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerDetail.java new file mode 100644 index 0000000..b7d202d --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerDetail.java @@ -0,0 +1,36 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.cmhi.gds.common.TransportProtocolType; +import com.cmhi.gds.validation.group.ValidGroups; +import com.cmhi.gds.validation.valids.ValidBaseEnum; +import com.cmhi.gds.validation.valids.ValidIpAddr; +import com.cmhi.gds.validation.valids.ValidIpPort; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"ipAddr", "ipPort", "protoType"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameServerDetail { + @NotBlank(message = "ipAddr IP地址不能为空", groups = ValidGroups.AddGameServiceValid.class) + @ValidIpAddr(message = "disposeIp Ip地址格式错误", groups = ValidGroups.AddGameServiceValid.class) + private String ipAddr; + + @NotNull(message = "ipPort 端口不能为null, 默认端口用空字符串表示", groups = ValidGroups.AddGameServiceValid.class) + @ValidIpPort(message = "ipPort 端口取值范围为 [1, 65536]", groups = ValidGroups.AddGameServiceValid.class) + private String ipPort; + + @NotNull(message = "protoType 协议类型不能为空", groups = ValidGroups.AddGameServiceValid.class) + @ValidBaseEnum(enumClass = TransportProtocolType.class, groups = ValidGroups.AddGameServiceValid.class) + private Integer protoType; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerReq.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerReq.java new file mode 100644 index 0000000..24f1ddf --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerReq.java @@ -0,0 +1,27 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.cmhi.gds.validation.group.ValidGroups; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import javax.validation.Valid; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameId", "services"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameServerReq { + @NotNull(message = "items 设备列表不能为空", groups = ValidGroups.AddGameServiceValid.class) + @Size(min = 1, message = "items 至少需要有一个元素", groups = ValidGroups.AddGameServiceValid.class) + @Valid + private List items; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRet.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRet.java new file mode 100644 index 0000000..60c1401 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRet.java @@ -0,0 +1,21 @@ +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; + +@EqualsAndHashCode(callSuper = true) +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonPropertyOrder({"gameId", "status", "message"}) +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameServerRet extends BaseRespStatus { + private Long gameId; +} 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 new file mode 100644 index 0000000..9b12afc --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GameServerRsp.java @@ -0,0 +1,18 @@ +package com.cmhi.gds.pojo.dto.protocol.info; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameServerRsp { + List items; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesInfoRsp.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesInfoRsp.java new file mode 100644 index 0000000..7e4ff99 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesInfoRsp.java @@ -0,0 +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 GetGamesInfoRsp extends BaseRespStatus { + List items; +} diff --git a/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesSummaryRsp.java b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesSummaryRsp.java new file mode 100644 index 0000000..4fa13cf --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/dto/protocol/info/GetGamesSummaryRsp.java @@ -0,0 +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 GetGamesSummaryRsp extends BaseRespStatus { + List items; +} diff --git a/src/main/java/com/cmhi/gds/pojo/entry/GameInfo.java b/src/main/java/com/cmhi/gds/pojo/entry/GameInfo.java new file mode 100644 index 0000000..721240e --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/entry/GameInfo.java @@ -0,0 +1,47 @@ +package com.cmhi.gds.pojo.entry; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serial; +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "game_info") +@NameStyle(Style.normal) +public class GameInfo implements Serializable { + /** + * The constant serialVersionUID. + */ + @Serial + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + private Long gameId; + + private String version; + + private String filename; + + private String md5sum; +} diff --git a/src/main/java/com/cmhi/gds/pojo/entry/GameServer.java b/src/main/java/com/cmhi/gds/pojo/entry/GameServer.java new file mode 100644 index 0000000..5b17fa4 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/entry/GameServer.java @@ -0,0 +1,50 @@ +package com.cmhi.gds.pojo.entry; + +import com.cmhi.gds.common.TransportProtocolType; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serial; +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "game_server") +@NameStyle(Style.normal) +public class GameServer implements Serializable { + /** + * The constant serialVersionUID. + */ + @Serial + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + private Long gameInfoId; + + private String ipaddr; + + private Integer port; + + private TransportProtocolType protocol; + + private String add; +} diff --git a/src/main/java/com/cmhi/gds/pojo/entry/GameSummary.java b/src/main/java/com/cmhi/gds/pojo/entry/GameSummary.java new file mode 100644 index 0000000..3afe5c0 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/entry/GameSummary.java @@ -0,0 +1,15 @@ +package com.cmhi.gds.pojo.entry; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GameSummary { + private Long id; + private String filename; +} diff --git a/src/main/java/com/cmhi/gds/pojo/entry/GameTable.java b/src/main/java/com/cmhi/gds/pojo/entry/GameTable.java new file mode 100644 index 0000000..3911fbe --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/entry/GameTable.java @@ -0,0 +1,43 @@ +package com.cmhi.gds.pojo.entry; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonPropertyOrder; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import tk.mybatis.mapper.annotation.KeySql; +import tk.mybatis.mapper.annotation.NameStyle; +import tk.mybatis.mapper.code.Style; + +import javax.persistence.Id; +import javax.persistence.Table; +import java.io.Serial; +import java.io.Serializable; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +@JsonPropertyOrder(alphabetic = true) +@Table(name = "game_tables") +@NameStyle(Style.normal) +public class GameTable implements Serializable { + /** + * The constant serialVersionUID. + */ + @Serial + private static final long serialVersionUID = 1L; + + /** + * The Id. + */ + @Id + @KeySql(useGeneratedKeys = true) + private Long id; + + private String name; + + private String company; +} diff --git a/src/main/java/com/cmhi/gds/pojo/entry/GameTableSummary.java b/src/main/java/com/cmhi/gds/pojo/entry/GameTableSummary.java new file mode 100644 index 0000000..1f49d4c --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/entry/GameTableSummary.java @@ -0,0 +1,17 @@ +package com.cmhi.gds.pojo.entry; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +public class GameTableSummary { + private Long id; + private List gameFilename; +} diff --git a/src/main/java/com/cmhi/gds/pojo/vo/GameTableItems.java b/src/main/java/com/cmhi/gds/pojo/vo/GameTableItems.java new file mode 100644 index 0000000..8fa8a73 --- /dev/null +++ b/src/main/java/com/cmhi/gds/pojo/vo/GameTableItems.java @@ -0,0 +1,19 @@ +package com.cmhi.gds.pojo.vo; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +@Data +@AllArgsConstructor +@NoArgsConstructor +@Builder +@JsonInclude(JsonInclude.Include.NON_NULL) +public class GameTableItems { + private Long gameId; + private List gameFilename; +} diff --git a/src/main/java/com/cmhi/gds/security/annotation/Decryption.java b/src/main/java/com/cmhi/gds/security/annotation/Decryption.java new file mode 100644 index 0000000..184f459 --- /dev/null +++ b/src/main/java/com/cmhi/gds/security/annotation/Decryption.java @@ -0,0 +1,16 @@ +package com.cmhi.gds.security.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The interface Decryption. + * + * @author + */ +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Decryption { +} diff --git a/src/main/java/com/cmhi/gds/security/annotation/Encryption.java b/src/main/java/com/cmhi/gds/security/annotation/Encryption.java new file mode 100644 index 0000000..51e71ce --- /dev/null +++ b/src/main/java/com/cmhi/gds/security/annotation/Encryption.java @@ -0,0 +1,16 @@ +package com.cmhi.gds.security.annotation; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The interface Encryption. + * + * @author + */ +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +public @interface Encryption { +} diff --git a/src/main/java/com/cmhi/game_database_service/security/arithmetic/CryptoHelper.java b/src/main/java/com/cmhi/gds/security/arithmetic/CryptoHelper.java similarity index 99% rename from src/main/java/com/cmhi/game_database_service/security/arithmetic/CryptoHelper.java rename to src/main/java/com/cmhi/gds/security/arithmetic/CryptoHelper.java index 44225c4..ddeac8e 100644 --- a/src/main/java/com/cmhi/game_database_service/security/arithmetic/CryptoHelper.java +++ b/src/main/java/com/cmhi/gds/security/arithmetic/CryptoHelper.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.security.arithmetic; +package com.cmhi.gds.security.arithmetic; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; diff --git a/src/main/java/com/cmhi/game_database_service/security/configure/EncryptionPropertyResolver.java b/src/main/java/com/cmhi/gds/security/configure/EncryptionPropertyResolver.java similarity index 93% rename from src/main/java/com/cmhi/game_database_service/security/configure/EncryptionPropertyResolver.java rename to src/main/java/com/cmhi/gds/security/configure/EncryptionPropertyResolver.java index 3c5defc..1888bf4 100644 --- a/src/main/java/com/cmhi/game_database_service/security/configure/EncryptionPropertyResolver.java +++ b/src/main/java/com/cmhi/gds/security/configure/EncryptionPropertyResolver.java @@ -1,6 +1,6 @@ -package com.cmhi.game_database_service.security.configure; +package com.cmhi.gds.security.configure; -import com.cmhi.game_database_service.security.arithmetic.CryptoHelper; +import com.cmhi.gds.security.arithmetic.CryptoHelper; import com.ulisesbocchio.jasyptspringboot.EncryptablePropertyResolver; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/cmhi/game_database_service/security/protocol/DecryptRequestProtocol.java b/src/main/java/com/cmhi/gds/security/protocol/DecryptRequestProtocol.java similarity index 96% rename from src/main/java/com/cmhi/game_database_service/security/protocol/DecryptRequestProtocol.java rename to src/main/java/com/cmhi/gds/security/protocol/DecryptRequestProtocol.java index cfa600c..c83ae34 100644 --- a/src/main/java/com/cmhi/game_database_service/security/protocol/DecryptRequestProtocol.java +++ b/src/main/java/com/cmhi/gds/security/protocol/DecryptRequestProtocol.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.security.protocol; +package com.cmhi.gds.security.protocol; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; diff --git a/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java b/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java new file mode 100644 index 0000000..980a823 --- /dev/null +++ b/src/main/java/com/cmhi/gds/service/GameDatabaseServiceService.java @@ -0,0 +1,10 @@ +package com.cmhi.gds.service; + +import com.cmhi.gds.pojo.vo.GameTableItems; + +import java.util.List; + +public interface GameDatabaseServiceService { + + List getGameTableSummaryItems(); +} diff --git a/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java b/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java new file mode 100644 index 0000000..3769738 --- /dev/null +++ b/src/main/java/com/cmhi/gds/service/impl/GameDatabaseServiceServiceImpl.java @@ -0,0 +1,49 @@ +package com.cmhi.gds.service.impl; + +import com.cmhi.gds.manager.GameDatabaseServiceManager; +import com.cmhi.gds.pojo.entry.GameSummary; +import com.cmhi.gds.pojo.entry.GameTableSummary; +import com.cmhi.gds.pojo.vo.GameTableItems; +import com.cmhi.gds.service.GameDatabaseServiceService; +import jakarta.annotation.Resource; +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@Service +@Slf4j +public class GameDatabaseServiceServiceImpl implements GameDatabaseServiceService { + @Resource + private GameDatabaseServiceManager gameDatabaseServiceManager; + + + @Override + public List getGameTableSummaryItems() { + List items = new ArrayList<>(); + + List gs = gameDatabaseServiceManager.getGameTableSummary(); + + if (!gs.isEmpty()) { + for (GameTableSummary v : gs) { + GameTableItems item = GameTableItems.builder() + .gameId(v.getId()) + .build(); + + if (!v.getGameFilename().isEmpty()) { + item.setGameFilename(new ArrayList<>()); + + for (GameSummary p : v.getGameFilename()) { + item.getGameFilename().add(p.getFilename()); + } + + item.getGameFilename().removeAll(Collections.singleton(null)); + } + items.add(item); + } + } + return items; + } +} diff --git a/src/main/java/com/cmhi/game_database_service/validation/ValidGroups.java b/src/main/java/com/cmhi/gds/validation/group/ValidGroups.java similarity index 93% rename from src/main/java/com/cmhi/game_database_service/validation/ValidGroups.java rename to src/main/java/com/cmhi/gds/validation/group/ValidGroups.java index cca99b8..31b1fd0 100644 --- a/src/main/java/com/cmhi/game_database_service/validation/ValidGroups.java +++ b/src/main/java/com/cmhi/gds/validation/group/ValidGroups.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service.validation; +package com.cmhi.gds.validation.group; /** * The interface Valid groups. @@ -35,7 +35,7 @@ public interface ValidGroups { * * @author */ - interface UpgradeDeviceValid extends ProtocolCommonValid { + interface AddGameServiceValid extends ProtocolCommonValid { } /** @@ -43,7 +43,7 @@ public interface ValidGroups { * * @author */ - interface AddDeviceValid extends UpgradeDeviceValid { + interface AddDeviceValid extends AddGameServiceValid { } /** diff --git a/src/main/java/com/cmhi/gds/validation/valids/ValidBaseEnum.java b/src/main/java/com/cmhi/gds/validation/valids/ValidBaseEnum.java new file mode 100644 index 0000000..5fff059 --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/ValidBaseEnum.java @@ -0,0 +1,51 @@ +package com.cmhi.gds.validation.valids; + +import com.cmhi.gds.common.TransportProtocolType; +import com.cmhi.gds.validation.valids.impl.ValidBaseEnumImpl; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The interface Valid custom base enum. + * + * @author + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint(validatedBy = {ValidBaseEnumImpl.class}) +public @interface ValidBaseEnum { + /** + * Enum class class. + * + * @return the class + */ + Class enumClass(); + + /** + * Message string. + * + * @return the string + */ + String message() default ""; + + /** + * Groups class [ ]. + * + * @return the class [ ] + */ + Class[] groups() default {}; + + /** + * Payload class [ ]. + * + * @return the class [ ] + */ + Class[] payload() default {}; +} diff --git a/src/main/java/com/cmhi/gds/validation/valids/ValidIpAddr.java b/src/main/java/com/cmhi/gds/validation/valids/ValidIpAddr.java new file mode 100644 index 0000000..03ad9cf --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/ValidIpAddr.java @@ -0,0 +1,43 @@ +package com.cmhi.gds.validation.valids; + +import com.cmhi.gds.validation.valids.impl.ValidIpAddrImpl; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The interface Valid ip addr. + * + * @author + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint(validatedBy = {ValidIpAddrImpl.class}) +public @interface ValidIpAddr { + /** + * Message string. + * + * @return the string + */ + String message(); + + /** + * Groups class [ ]. + * + * @return the class [ ] + */ + Class[] groups() default {}; + + /** + * Payload class [ ]. + * + * @return the class [ ] + */ + Class[] payload() default {}; +} diff --git a/src/main/java/com/cmhi/gds/validation/valids/ValidIpPort.java b/src/main/java/com/cmhi/gds/validation/valids/ValidIpPort.java new file mode 100644 index 0000000..a9a4064 --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/ValidIpPort.java @@ -0,0 +1,43 @@ +package com.cmhi.gds.validation.valids; + +import com.cmhi.gds.validation.valids.impl.ValidIpPortImpl; + +import javax.validation.Constraint; +import javax.validation.Payload; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * The interface Valid ip port. + * + * @author + */ +@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Constraint(validatedBy = {ValidIpPortImpl.class}) +public @interface ValidIpPort { + /** + * Message string. + * + * @return the string + */ + String message(); + + /** + * Groups class [ ]. + * + * @return the class [ ] + */ + Class[] groups() default {}; + + /** + * Payload class [ ]. + * + * @return the class [ ] + */ + Class[] payload() default {}; +} diff --git a/src/main/java/com/cmhi/gds/validation/valids/impl/ValidBaseEnumImpl.java b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidBaseEnumImpl.java new file mode 100644 index 0000000..836f3c7 --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidBaseEnumImpl.java @@ -0,0 +1,73 @@ +package com.cmhi.gds.validation.valids.impl; + + +import com.cmhi.gds.common.BaseEnum; +import com.cmhi.gds.validation.valids.ValidBaseEnum; +import lombok.extern.slf4j.Slf4j; +import org.hibernate.validator.internal.engine.constraintvalidation.ConstraintValidatorContextImpl; + + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.Arrays; +import java.util.List; + +/** + * The type Valid custom base enum. + * + * @author + */ +@Slf4j +public class ValidBaseEnumImpl implements ConstraintValidator { + + /** + * The Enum class. + */ + private Class enumClass; + + /** + * The Message. + */ + private String message; + + /** + * Initialize. + * + * @param constraintAnnotation the constraint annotation + */ + @Override + public void initialize(ValidBaseEnum constraintAnnotation) { + this.enumClass = constraintAnnotation.enumClass(); + this.message = constraintAnnotation.message(); + } + + /** + * Is valid boolean. + * + * @param integer the integer + * @param ctx the constraint validator context + * @return the boolean + */ + @Override + public boolean isValid(Integer integer, ConstraintValidatorContext ctx) { + + // null 由其它校验器处理 + if (integer == null) { + return true; + } + + List enumValues = Arrays.stream(enumClass.getEnumConstants()) + .map(BaseEnum::getValue).toList(); + + String errMsg = this.message + " 字段 " + + ((ConstraintValidatorContextImpl) ctx).getConstraintViolationCreationContexts() + .get(0).getPath().getLeafNode().getName() + + " 值 {" + integer + "} 错误, 字段取值范围:" + enumValues; + + // 重新设置消息 + ctx.disableDefaultConstraintViolation(); + ctx.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation(); + + return enumValues.contains(integer); + } +} diff --git a/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpAddrImpl.java b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpAddrImpl.java new file mode 100644 index 0000000..767207c --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpAddrImpl.java @@ -0,0 +1,56 @@ +package com.cmhi.gds.validation.valids.impl; + +import com.cmhi.gds.common.ConstValue; +import com.cmhi.gds.validation.valids.ValidIpAddr; +import inet.ipaddr.IPAddress; +import inet.ipaddr.IPAddressString; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; +import java.util.regex.Pattern; + +/** + * The type Valid ip addr. + * + * @author + */ +public class ValidIpAddrImpl implements ConstraintValidator { + + /** + * Initialize. + * + * @param constraintAnnotation the constraint annotation + */ + @Override + public void initialize(ValidIpAddr constraintAnnotation) { + } + + /** + * Is valid boolean. + * + * @param s the s + * @param constraintValidatorContext the constraint validator context + * @return the boolean + */ + @Override + public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { + + if (s == null || s.isEmpty()) { + return true; + } + + if (!Pattern.matches(ConstValue.IP_ADDR_REG, s)) { + return false; + } + + IPAddressString addrString = new IPAddressString(s); + + IPAddress addr = addrString.getAddress(); + + if (addr == null) { + return false; + } + + return addr.isIPv4() || addr.isIPv6(); + } +} diff --git a/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpPortImpl.java b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpPortImpl.java new file mode 100644 index 0000000..9901aeb --- /dev/null +++ b/src/main/java/com/cmhi/gds/validation/valids/impl/ValidIpPortImpl.java @@ -0,0 +1,54 @@ +package com.cmhi.gds.validation.valids.impl; + + + +import com.cmhi.gds.validation.valids.ValidIpPort; + +import javax.validation.ConstraintValidator; +import javax.validation.ConstraintValidatorContext; + +/** + * The type Valid ip port. + * + * @author + */ +public class ValidIpPortImpl implements ConstraintValidator { + /** + * Initialize. + * + * @param constraintAnnotation the constraint annotation + */ + @Override + public void initialize(ValidIpPort constraintAnnotation) { + + } + + /** + * Is valid boolean. + * + * @param s the s + * @param constraintValidatorContext the constraint validator context + * @return the boolean + */ + @Override + public boolean isValid(String s, ConstraintValidatorContext constraintValidatorContext) { + final int minSocketPort = 1; + final int maxSocketPort = 65535; + + if (s == null || s.isEmpty()) { + return true; + } + + try { + int port = Integer.parseInt(s); + + if (port >= minSocketPort && port <= maxSocketPort) { + return true; + } + } catch (Exception e) { + return false; + } + + return false; + } +} diff --git a/src/main/resources/mappers/GameInfo.xml b/src/main/resources/mappers/GameInfo.xml new file mode 100644 index 0000000..9cd6e0f --- /dev/null +++ b/src/main/resources/mappers/GameInfo.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mappers/GameServer.xml b/src/main/resources/mappers/GameServer.xml new file mode 100644 index 0000000..8969b24 --- /dev/null +++ b/src/main/resources/mappers/GameServer.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/mappers/GameTable.xml b/src/main/resources/mappers/GameTable.xml new file mode 100644 index 0000000..c294bf6 --- /dev/null +++ b/src/main/resources/mappers/GameTable.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/test/java/com/cmhi/game_database_service/GameDatabaseServiceApplicationTests.java b/src/test/java/com/cmhi/gds/GameDatabaseServiceApplicationTests.java similarity index 83% rename from src/test/java/com/cmhi/game_database_service/GameDatabaseServiceApplicationTests.java rename to src/test/java/com/cmhi/gds/GameDatabaseServiceApplicationTests.java index 6d6014b..610f7aa 100644 --- a/src/test/java/com/cmhi/game_database_service/GameDatabaseServiceApplicationTests.java +++ b/src/test/java/com/cmhi/gds/GameDatabaseServiceApplicationTests.java @@ -1,4 +1,4 @@ -package com.cmhi.game_database_service; +package com.cmhi.gds; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;