mirror of
https://gitee.com/durcframework/SOP.git
synced 2025-08-11 12:56:28 +08:00
5.0
This commit is contained in:
@@ -1,176 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<!DOCTYPE module PUBLIC
|
||||
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
|
||||
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
|
||||
|
||||
<module name="Checker">
|
||||
<!-- 文件长度不超过1500行 -->
|
||||
<module name="FileLength">
|
||||
<property name="max" value="2500"/>
|
||||
</module>
|
||||
|
||||
<!-- 长度检查 -->
|
||||
<!-- 每行不超过200个字符 -->
|
||||
<module name="LineLength">
|
||||
<property name="max" value="400"/>
|
||||
</module>
|
||||
<module name="SuppressWarningsFilter" />
|
||||
<!-- 每个java文件一个语法树 -->
|
||||
<module name="TreeWalker">
|
||||
<module name="SuppressWarningsHolder" />
|
||||
<!-- import检查-->
|
||||
<!-- 检查是否从非法的包中导入了类 -->
|
||||
<module name="IllegalImport"/>
|
||||
<!-- 检查是否导入了多余的包 -->
|
||||
<module name="RedundantImport"/>
|
||||
<!-- 没用的import检查,比如:1.没有被用到2.重复的3.import java.lang的4.import 与该类在同一个package的 -->
|
||||
<module name="UnusedImports"/>
|
||||
|
||||
<!-- 注释检查 -->
|
||||
<!-- 检查构造函数的javadoc -->
|
||||
<module name="JavadocType">
|
||||
<property name="allowUnknownTags" value="true"/>
|
||||
<message key="javadoc.missing" value="类注释:缺少Javadoc注释。"/>
|
||||
</module>
|
||||
|
||||
<!-- 命名检查 -->
|
||||
<!-- 局部的final变量,包括catch中的参数的检查 -->
|
||||
<module name="LocalFinalVariableName"/>
|
||||
<!-- 局部的非final型的变量,包括catch中的参数的检查 -->
|
||||
<module name="LocalVariableName"/>
|
||||
<!-- 包名的检查(只允许小写字母),默认^[a-z]+(\.[a-zA-Z_][a-zA-Z_0-9_]*)*$ -->
|
||||
<module name="PackageName">
|
||||
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
|
||||
<message key="name.invalidPattern" value="包名 ''{0}'' 要符合 ''{1}''格式."/>
|
||||
</module>
|
||||
<!-- 仅仅是static型的变量(不包括static final型)的检查 -->
|
||||
<module name="StaticVariableName"/>
|
||||
<!-- Class或Interface名检查,默认^[A-Z][a-zA-Z0-9]*$-->
|
||||
<module name="TypeName">
|
||||
<property name="severity" value="warning"/>
|
||||
<message key="name.invalidPattern" value="名称 ''{0}'' 要符合 ''{1}''格式."/>
|
||||
</module>
|
||||
<!-- 非static型变量的检查
|
||||
<module name="MemberName"/>
|
||||
-->
|
||||
<!-- 方法名的检查 -->
|
||||
<module name="MethodName"/>
|
||||
<!-- 方法的参数名
|
||||
<module name="ParameterName "/>
|
||||
-->
|
||||
<!-- 常量名的检查(只允许大写),默认^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$ -->
|
||||
<module name="ConstantName"/>
|
||||
|
||||
<!-- 定义检查 -->
|
||||
<!-- 检查数组类型定义的样式 -->
|
||||
<module name="ArrayTypeStyle"/>
|
||||
<!-- 检查long型定义是否有大写的“L” -->
|
||||
<module name="UpperEll"/>
|
||||
<!-- 方法不超过100行 -->
|
||||
<module name="MethodLength">
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
<property name="max" value="300"/>
|
||||
</module>
|
||||
<!-- 方法的参数个数不超过8个。 并且不对构造方法进行检查-->
|
||||
<module name="ParameterNumber">
|
||||
<property name="max" value="8"/>
|
||||
<property name="ignoreOverriddenMethods" value="true"/>
|
||||
<property name="tokens" value="METHOD_DEF"/>
|
||||
</module>
|
||||
|
||||
<!-- 空格检查-->
|
||||
<!-- 方法名后跟左圆括号"(" -->
|
||||
<module name="MethodParamPad"/>
|
||||
<!-- 在类型转换时,不允许左圆括号右边有空格,也不允许与右圆括号左边有空格 -->
|
||||
<module name="TypecastParenPad"/>
|
||||
<!-- 检查在某个特定关键字之后应保留空格 -->
|
||||
<module name="NoWhitespaceAfter"/>
|
||||
<!-- 检查在某个特定关键字之前应保留空格 -->
|
||||
<module name="NoWhitespaceBefore"/>
|
||||
<!-- 圆括号空白 -->
|
||||
<module name="ParenPad"/>
|
||||
<!-- 检查分隔符是否在空白之后 -->
|
||||
<module name="WhitespaceAfter"/>
|
||||
<!-- 检查分隔符周围是否有空白 -->
|
||||
<module name="WhitespaceAround"/>
|
||||
|
||||
<!-- 修饰符检查 -->
|
||||
<!-- 检查修饰符的顺序是否遵照java语言规范,默认public、protected、private、abstract、static、final、transient、volatile、synchronized、native、strictfp -->
|
||||
<module name="ModifierOrder"/>
|
||||
<!-- 检查接口和annotation中是否有多余修饰符,如接口方法不必使用public -->
|
||||
<module name="RedundantModifier"/>
|
||||
|
||||
<!-- 代码块检查 -->
|
||||
<!-- 检查是否有嵌套代码块 -->
|
||||
<module name="AvoidNestedBlocks"/>
|
||||
<!-- 检查是否有空代码块 -->
|
||||
<module name="EmptyBlock"/>
|
||||
<!-- 检查左大括号位置 -->
|
||||
<module name="LeftCurly"/>
|
||||
<!-- 检查代码块是否缺失{} -->
|
||||
<module name="NeedBraces"/>
|
||||
<!-- 检查右大括号位置 -->
|
||||
<module name="RightCurly"/>
|
||||
|
||||
<!-- 代码检查 -->
|
||||
<!-- 检查空的代码段 -->
|
||||
<module name="EmptyStatement"/>
|
||||
<!-- 检查在重写了equals方法后是否重写了hashCode方法 -->
|
||||
<module name="EqualsHashCode"/>
|
||||
<!-- 检查局部变量或参数是否隐藏了类中的变量 -->
|
||||
<module name="HiddenField">
|
||||
<property name="tokens" value="VARIABLE_DEF"/>
|
||||
</module>
|
||||
<!-- 检查子表达式中是否有赋值操作 -->
|
||||
<module name="InnerAssignment"/>
|
||||
<!-- 检查switch语句是否有default -->
|
||||
<module name="MissingSwitchDefault"/>
|
||||
<!-- 检查是否有过度复杂的布尔表达式 -->
|
||||
<module name="SimplifyBooleanExpression"/>
|
||||
<!-- 检查是否有过于复杂的布尔返回代码段 -->
|
||||
<module name="SimplifyBooleanReturn"/>
|
||||
|
||||
<!-- 类设计检查 -->
|
||||
<!-- 检查类是否为扩展设计l -->
|
||||
<!-- 检查只有private构造函数的类是否声明为final
|
||||
<module name="FinalClass"/>
|
||||
-->
|
||||
<!-- 检查接口是否仅定义类型 -->
|
||||
<module name="InterfaceIsType"/>
|
||||
<!-- 检查类成员的可见度 检查类成员的可见性。只有static final 成员是public的
|
||||
除非在本检查的protectedAllowed和packagedAllowed属性中进行了设置-->
|
||||
<module name="VisibilityModifier">
|
||||
<property name="packageAllowed" value="true"/>
|
||||
<property name="protectedAllowed" value="true"/>
|
||||
</module>
|
||||
|
||||
<!-- 语法 -->
|
||||
<!-- String的比较不能用!= 和 == -->
|
||||
<module name="StringLiteralEquality"/>
|
||||
<!-- 限制for循环最多嵌套2层 -->
|
||||
<module name="NestedForDepth">
|
||||
<property name="max" value="2"/>
|
||||
</module>
|
||||
<!-- if最多嵌套3层 -->
|
||||
<module name="NestedIfDepth">
|
||||
<property name="max" value="10"/>
|
||||
</module>
|
||||
<!-- 检查未被注释的main方法,排除以Appllication结尾命名的类 -->
|
||||
<module name="UncommentedMain">
|
||||
<property name="excludedClasses" value=".*[Application,Test]$"/>
|
||||
</module>
|
||||
<!-- 禁止使用System.out.println -->
|
||||
<module name="Regexp">
|
||||
<property name="format" value="System\.out\.println"/>
|
||||
<property name="illegalPattern" value="true"/>
|
||||
</module>
|
||||
<!--try catch 异常处理数量 3-->
|
||||
<module name="NestedTryDepth ">
|
||||
<property name="max" value="3"/>
|
||||
</module>
|
||||
<!-- clone方法必须调用了super.clone() -->
|
||||
<module name="SuperClone"/>
|
||||
<!-- finalize 必须调用了super.finalize() -->
|
||||
<module name="SuperFinalize"/>
|
||||
</module>
|
||||
</module>
|
@@ -4,41 +4,17 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.6.15</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-parent</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>com.gitee.sop</groupId>
|
||||
<artifactId>sop-gateway</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<!-- springboot 版本-->
|
||||
<spring-boot.version>2.6.15</spring-boot.version>
|
||||
<!-- spring cloud 版本 -->
|
||||
<spring-cloud.version>2021.0.5</spring-cloud.version>
|
||||
<!-- spring cloud alibaba 版本 -->
|
||||
<!-- 具体版本对应关系见:https://github.com/alibaba/spring-cloud-alibaba/wiki/%E7%89%88%E6%9C%AC%E8%AF%B4%E6%98%8E -->
|
||||
<spring-cloud-alibaba.version>2021.0.5.0</spring-cloud-alibaba.version>
|
||||
<!-- dubbo版本 -->
|
||||
<dubbo.version>3.2.10</dubbo.version>
|
||||
|
||||
<junit.version>4.11</junit.version>
|
||||
<commons-io.version>2.5</commons-io.version>
|
||||
<commons-fileupload.version>1.3.3</commons-fileupload.version>
|
||||
<commons-collection.version>3.2.2</commons-collection.version>
|
||||
<commons-lang3.version>3.8.1</commons-lang3.version>
|
||||
<commons-codec.version>1.11</commons-codec.version>
|
||||
<commons-logging.version>1.2</commons-logging.version>
|
||||
<validation-api.version>2.0.1.Final</validation-api.version>
|
||||
<hibernate-validator.version>6.0.13.Final</hibernate-validator.version>
|
||||
<fastmybatis.version>3.0.12</fastmybatis.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@@ -139,106 +115,6 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!-- 加了这个就不需要加版本号了 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-dependencies</artifactId>
|
||||
<version>${spring-boot.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-dependencies</artifactId>
|
||||
<version>${spring-cloud.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cloud</groupId>
|
||||
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
|
||||
<version>${spring-cloud-alibaba.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.dubbo</groupId>
|
||||
<artifactId>dubbo-bom</artifactId>
|
||||
<version>${dubbo.version}</version>
|
||||
<type>pom</type>
|
||||
<scope>import</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.gitee.durcframework</groupId>
|
||||
<artifactId>fastmybatis-spring-boot-starter</artifactId>
|
||||
<version>${fastmybatis.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>3.14.7</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.validation</groupId>
|
||||
<artifactId>validation-api</artifactId>
|
||||
<version>${validation-api.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
<artifactId>hibernate-validator</artifactId>
|
||||
<version>${hibernate-validator.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- commons -->
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>${commons-collection.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>${commons-io.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>${commons-codec.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>${commons-fileupload.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
<version>${commons-logging.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.34</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.servlet</groupId>
|
||||
<artifactId>javax.servlet-api</artifactId>
|
||||
<version>3.1.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>aliyun</id>
|
||||
|
@@ -72,12 +72,12 @@ public class ApiResponse {
|
||||
/**
|
||||
* 业务异常码
|
||||
*/
|
||||
private String sub_code = "";
|
||||
private String subCode = "";
|
||||
|
||||
/**
|
||||
* 业务异常信息
|
||||
*/
|
||||
private String sub_msg = "";
|
||||
private String subMsg = "";
|
||||
|
||||
/**
|
||||
* 返回对象
|
||||
@@ -98,8 +98,8 @@ public class ApiResponse {
|
||||
IError error = e.getError();
|
||||
apiResponse.setCode(error.getCode());
|
||||
apiResponse.setMsg(error.getMsg());
|
||||
apiResponse.setSub_code(error.getSubCode());
|
||||
apiResponse.setSub_msg(error.getSubMsg());
|
||||
apiResponse.setSubCode(error.getSubCode());
|
||||
apiResponse.setSubMsg(error.getSubMsg());
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
@@ -109,8 +109,8 @@ public class ApiResponse {
|
||||
IError error = errorMeta.getError(locale);
|
||||
apiResponse.setCode(error.getCode());
|
||||
apiResponse.setMsg(error.getMsg());
|
||||
apiResponse.setSub_code(error.getSubCode());
|
||||
apiResponse.setSub_msg(subMsg);
|
||||
apiResponse.setSubCode(error.getSubCode());
|
||||
apiResponse.setSubMsg(subMsg);
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
@@ -120,8 +120,8 @@ public class ApiResponse {
|
||||
IError error = errorMeta.getError(locale);
|
||||
apiResponse.setCode(error.getCode());
|
||||
apiResponse.setMsg(error.getMsg());
|
||||
apiResponse.setSub_code(error.getSubCode());
|
||||
apiResponse.setSub_msg(error.getSubMsg());
|
||||
apiResponse.setSubCode(error.getSubCode());
|
||||
apiResponse.setSubMsg(error.getSubMsg());
|
||||
return apiResponse;
|
||||
}
|
||||
|
||||
|
@@ -8,11 +8,13 @@ import com.gitee.sop.gateway.service.manager.ApiManager;
|
||||
import com.gitee.sop.gateway.util.CopyUtil;
|
||||
import com.gitee.sop.support.service.ApiRegisterService;
|
||||
import com.gitee.sop.support.service.dto.RegisterDTO;
|
||||
import com.gitee.sop.support.service.dto.RegisterResult;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.annotation.DubboService;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author 六如
|
||||
*/
|
||||
@@ -23,26 +25,44 @@ public class ApiRegisterServiceImpl implements ApiRegisterService {
|
||||
private static final int REG_SOURCE_SYS = 1;
|
||||
|
||||
@Autowired
|
||||
private ApiManager apiCacheManager;
|
||||
private ApiManager apiManager;
|
||||
|
||||
@Autowired
|
||||
private ApiInfoMapper apiInfoMapper;
|
||||
|
||||
@Override
|
||||
public void register(RegisterDTO registerDTO) {
|
||||
public RegisterResult register(RegisterDTO registerDTO) {
|
||||
log.info("收到接口注册, registerDTO={}", registerDTO);
|
||||
ApiInfoDTO apiInfoDTO = CopyUtil.copyBean(registerDTO, ApiInfoDTO::new);
|
||||
apiInfoDTO.setStatus(StatusEnum.ENABLE.getValue());
|
||||
|
||||
ApiInfo apiInfo = apiInfoMapper.getByNameVersion(apiInfoDTO.getApiName(), apiInfoDTO.getApiVersion());
|
||||
if (apiInfo == null) {
|
||||
apiInfo = new ApiInfo();
|
||||
try {
|
||||
ApiInfoDTO apiInfoDTO = CopyUtil.copyBean(registerDTO, ApiInfoDTO::new);
|
||||
apiInfoDTO.setStatus(StatusEnum.ENABLE.getValue());
|
||||
|
||||
ApiInfo apiInfo = apiInfoMapper.getByNameVersion(apiInfoDTO.getApiName(), apiInfoDTO.getApiVersion());
|
||||
|
||||
if (apiInfo == null) {
|
||||
apiInfo = new ApiInfo();
|
||||
} else {
|
||||
check(apiInfo, registerDTO);
|
||||
}
|
||||
CopyUtil.copyPropertiesIgnoreNull(apiInfoDTO, apiInfo);
|
||||
apiInfo.setRegSource(REG_SOURCE_SYS);
|
||||
// 保存到数据库
|
||||
apiInfoMapper.saveOrUpdate(apiInfo);
|
||||
apiInfoDTO.setId(apiInfo.getId());
|
||||
// 保存到缓存
|
||||
apiManager.save(apiInfoDTO);
|
||||
return RegisterResult.success();
|
||||
} catch (Exception e) {
|
||||
log.error("接口注册失败, registerDTO={}", registerDTO, e);
|
||||
return RegisterResult.error(e.getMessage());
|
||||
}
|
||||
CopyUtil.copyPropertiesIgnoreNull(apiInfoDTO, apiInfo);
|
||||
apiInfo.setRegSource(REG_SOURCE_SYS);
|
||||
// 保存到数据库
|
||||
apiInfoMapper.saveOrUpdate(apiInfo);
|
||||
// 保存到缓存
|
||||
apiCacheManager.save(apiInfoDTO);
|
||||
}
|
||||
|
||||
private void check(ApiInfo apiInfo, RegisterDTO registerDTO) {
|
||||
if (!Objects.equals(apiInfo.getApplication(), registerDTO.getApplication())) {
|
||||
throw new RuntimeException("接口[" + registerDTO + "]已存在于[" + apiInfo.getApplication() + "]应用中.必须保证接口全局唯一");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ public class ResultRouteInterceptor implements RouteInterceptor {
|
||||
}
|
||||
|
||||
if (result instanceof Map) {
|
||||
Map<String, Object> map = (Map<String, Object>) result;
|
||||
Map<?, ?> map = (Map<?, ?>) result;
|
||||
Object className = map.get(CLASS);
|
||||
// 处理文件下载
|
||||
if (Objects.equals(className, FileData.class.getName()) || Objects.equals(className, CommonFileData.class.getName())) {
|
||||
|
@@ -62,7 +62,7 @@ public class ApiValidator implements Validator {
|
||||
private ApiConfig apiConfig;
|
||||
|
||||
@Autowired
|
||||
private ApiManager apiCacheManager;
|
||||
private ApiManager apiManager;
|
||||
|
||||
@Autowired
|
||||
private IpBlacklistManager ipBlacklistManager;
|
||||
@@ -94,7 +94,7 @@ public class ApiValidator implements Validator {
|
||||
checkIP(apiRequestContext);
|
||||
|
||||
ApiRequest apiRequest = apiRequestContext.getApiRequest();
|
||||
ApiInfoDTO apiInfo = apiCacheManager.get(apiRequest.getMethod(), apiRequest.getVersion());
|
||||
ApiInfoDTO apiInfo = apiManager.get(apiRequest.getMethod(), apiRequest.getVersion());
|
||||
// 检查接口信息
|
||||
checkApiInfo(apiRequestContext, apiInfo, isvDTO);
|
||||
|
||||
|
Reference in New Issue
Block a user