Merge branch 'feature/mybatis-plus' into 'master'
Feature/mybatis plus See merge request infra/axzo-framework-commons!20
This commit is contained in:
commit
dcea967232
@ -17,5 +17,4 @@ axzo-framework-commons是常用基础类库和框架实践。包含子模块如
|
||||
- axzo-framework-math: 封装科学计算相关工具
|
||||
- axzo-framework-web: 封装spring-web
|
||||
- axzo-framework-webmvc: 封装spring-webmvc
|
||||
- axzo-framework-dependencies: 管理所有依赖
|
||||
- . ...
|
||||
|
||||
@ -95,5 +95,4 @@
|
||||
<artifactId>spring-security-web</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@ -84,6 +84,11 @@ public class ApplicationReadyInfoAutoConfiguration {
|
||||
s.append("\tSwaggerUI:\t\t").append(protocol).append("://").append(ip)
|
||||
.append(":").append(port).append("/swagger-ui.html\n");
|
||||
}
|
||||
String knife4jPageLocation = "classpath:META-INF/resources/doc.html";
|
||||
if (Seq.of(activeProfiles).contains("swagger") && Resources.exists(knife4jPageLocation)) {
|
||||
s.append("\tSwaggerUI:\t\t").append(protocol).append("://").append(ip)
|
||||
.append(":").append(port).append("/doc.html\n");
|
||||
}
|
||||
}
|
||||
s.append("\tProfile(s):\t\t").append(Arrays.toString(activeProfiles)).append("\n");
|
||||
s.append("----------------------------------------------------------------");
|
||||
@ -1,17 +1,18 @@
|
||||
package cn.axzo.framework.autoconfigure.jackson;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.USE_DEFAULTS;
|
||||
import static com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_FLOAT_AS_INT;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.READ_DATE_TIMESTAMPS_AS_NANOSECONDS;
|
||||
import static com.fasterxml.jackson.databind.MapperFeature.PROPAGATE_TRANSIENT_MARKER;
|
||||
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS;
|
||||
|
||||
import java.util.TimeZone;
|
||||
import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
|
||||
import java.util.TimeZone;
|
||||
|
||||
import static com.fasterxml.jackson.annotation.JsonInclude.Include.NON_ABSENT;
|
||||
import static com.fasterxml.jackson.core.JsonParser.Feature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER;
|
||||
import static com.fasterxml.jackson.databind.DeserializationFeature.*;
|
||||
import static com.fasterxml.jackson.databind.MapperFeature.PROPAGATE_TRANSIENT_MARKER;
|
||||
import static com.fasterxml.jackson.databind.SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS;
|
||||
|
||||
/**
|
||||
* @Description
|
||||
* @Author liyong.tian
|
||||
@ -22,7 +23,7 @@ public class JacksonCustomer implements Jackson2ObjectMapperBuilderCustomizer, O
|
||||
|
||||
@Override
|
||||
public void customize(Jackson2ObjectMapperBuilder builder) {
|
||||
builder.serializationInclusion(NON_ABSENT);
|
||||
builder.serializationInclusion(USE_DEFAULTS);
|
||||
builder.timeZone(TimeZone.getDefault());
|
||||
|
||||
// disable
|
||||
@ -1,11 +1,13 @@
|
||||
package cn.axzo.framework.autoconfigure.validation;
|
||||
|
||||
import lombok.val;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnResource;
|
||||
import org.springframework.boot.autoconfigure.validation.ValidationAutoConfiguration;
|
||||
import org.springframework.boot.validation.beanvalidation.MethodValidationExcludeFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.env.Environment;
|
||||
@ -28,7 +30,10 @@ public class MethodValidationAutoConfiguration {
|
||||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public MethodValidationPostProcessor methodValidationPostProcessor(Environment environment, Validator validator) {
|
||||
val processor = ValidationAutoConfiguration.methodValidationPostProcessor(environment, validator, null);
|
||||
MethodValidationPostProcessor processor = new MethodValidationPostProcessor();
|
||||
boolean proxyTargetClass = (Boolean)environment.getProperty("spring.aop.proxy-target-class", Boolean.class, true);
|
||||
processor.setProxyTargetClass(proxyTargetClass);
|
||||
processor.setValidator(validator);
|
||||
processor.setBeforeExistingAdvisors(true);
|
||||
return processor;
|
||||
}
|
||||
@ -16,8 +16,6 @@ public class AxzoProperties {
|
||||
|
||||
private Swagger swagger;
|
||||
|
||||
private YApi yApi;
|
||||
|
||||
@Data
|
||||
public static class Swagger {
|
||||
private boolean enabled = false;
|
||||
@ -35,32 +33,4 @@ public class AxzoProperties {
|
||||
private String host = null;
|
||||
private String[] protocols = new String[0];
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class YApi {
|
||||
/**
|
||||
* 是否同步YApi
|
||||
*/
|
||||
public boolean enabled = false;
|
||||
|
||||
/**
|
||||
* 数据同步方式 normal"(普通模式) , "good"(智能合并), "merge"(完全覆盖) 三种模式
|
||||
*/
|
||||
private String merge = "normal";
|
||||
|
||||
/**
|
||||
* 对应文件夹的 token
|
||||
*/
|
||||
private String token;
|
||||
|
||||
/**
|
||||
* json 数据来源(代替 json 字符串)。
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 组名称,一般 默认 default
|
||||
*/
|
||||
private String groupName = "default";
|
||||
}
|
||||
}
|
||||
@ -7,9 +7,9 @@ import cn.axzo.framework.domain.web.result.ApiListResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiPageResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.framework.context.Placeholders;
|
||||
import cn.axzo.framework.web.http.ApiEntity;
|
||||
import cn.axzo.framework.web.http.ApiListEntity;
|
||||
import cn.axzo.framework.web.http.ApiPageEntity;
|
||||
import cn.axzo.framework.web.http.ApiResponse;
|
||||
import cn.axzo.framework.web.http.ApiListResponse;
|
||||
import cn.axzo.framework.web.http.ApiPageResponse;
|
||||
import com.fasterxml.classmate.TypeResolver;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -124,35 +124,35 @@ public class SwaggerAutoConfiguration {
|
||||
);
|
||||
}
|
||||
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiEntity")
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiResponse")
|
||||
@Bean
|
||||
public AlternateTypeRule apiEntityAlternateTypeRule(TypeResolver typeResolver) {
|
||||
public AlternateTypeRule apiResponseAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return AlternateTypeRules.newRule(
|
||||
typeResolver.resolve(ApiEntity.class, WildcardType.class),
|
||||
typeResolver.resolve(ApiResponse.class, WildcardType.class),
|
||||
typeResolver.resolve(ApiResult.class, WildcardType.class)
|
||||
);
|
||||
}
|
||||
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiEntity")
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiResponse")
|
||||
@Bean
|
||||
public AlternateTypeRule callableApiEntityAlternateTypeRule(TypeResolver typeResolver) {
|
||||
public AlternateTypeRule callableApiResponseAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return newRule(
|
||||
typeResolver.resolve(Callable.class, typeResolver.resolve(ApiEntity.class, WildcardType.class)),
|
||||
typeResolver.resolve(Callable.class, typeResolver.resolve(ApiResponse.class, WildcardType.class)),
|
||||
typeResolver.resolve(ApiResult.class, WildcardType.class)
|
||||
);
|
||||
}
|
||||
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiListEntity")
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiListResponse")
|
||||
@Bean
|
||||
public AlternateTypeRule apiListEntityAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return newRule(typeResolver.resolve(ApiListEntity.class, WildcardType.class),
|
||||
public AlternateTypeRule apiListResponseAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return newRule(typeResolver.resolve(ApiListResponse.class, WildcardType.class),
|
||||
typeResolver.resolve(ApiListResult.class, WildcardType.class));
|
||||
}
|
||||
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiPageEntity")
|
||||
@ConditionalOnClass(name = "cn.axzo.framework.web.http.ApiPageResponse")
|
||||
@Bean
|
||||
public AlternateTypeRule apiPageEntityAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return newRule(typeResolver.resolve(ApiPageEntity.class, WildcardType.class),
|
||||
public AlternateTypeRule apiPageResponseAlternateTypeRule(TypeResolver typeResolver) {
|
||||
return newRule(typeResolver.resolve(ApiPageResponse.class, WildcardType.class),
|
||||
typeResolver.resolve(ApiPageResult.class, WildcardType.class));
|
||||
}
|
||||
|
||||
@ -11,8 +11,8 @@ cn.axzo.framework.autoconfigure.data.IdAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.cors.CorsAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.PageWebAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.exception.ExceptionHandlerAutoConfiguration,\
|
||||
# cn.axzo.framework.autoconfigure.web.swagger.SwaggerAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.validation.SpringValidatorAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.advice.BodyAdviceAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.FilterAutoConfiguration,\
|
||||
cn.axzo.framework.autoconfigure.web.context.WebMvcAwareAutoConfiguration
|
||||
# cn.axzo.framework.autoconfigure.web.swagger.SwaggerAutoConfiguration,\
|
||||
|
||||
65
axzo-common-clients/feign-starter/pom.xml
Normal file
65
axzo-common-clients/feign-starter/pom.xml
Normal file
@ -0,0 +1,65 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
<artifactId>axzo-common-clients</artifactId>
|
||||
<groupId>cn.axzo.framework.client</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>feign-starter</artifactId>
|
||||
<name>Axzo Common Client Feign Starter</name>
|
||||
|
||||
<dependencies>
|
||||
<!--Compile-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-domain</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-slf4j</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-hystrix</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign</groupId>
|
||||
<artifactId>feign-okhttp</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Optional-->
|
||||
<dependency>
|
||||
<groupId>io.github.openfeign.form</groupId>
|
||||
<artifactId>feign-form-spring</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,64 @@
|
||||
package cn.axzo.framework.client.feign;
|
||||
|
||||
import cn.axzo.framework.domain.web.ApiException;
|
||||
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||
import cn.axzo.framework.domain.web.result.ApiListResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiPageResult;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* @author liyong.tian
|
||||
* @since 2022/11/3
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Getter
|
||||
@Slf4j
|
||||
public class FeignFallback {
|
||||
|
||||
@Nullable
|
||||
private final Throwable cause;
|
||||
|
||||
private final IRespCode respCode;
|
||||
|
||||
public <T> ApiResult<T> resp() {
|
||||
if (cause != null) {
|
||||
log.error("Enter feign fallback", cause);
|
||||
if (cause instanceof ApiException) {
|
||||
return ApiResult.err(((ApiException) cause).getCode(), cause.getMessage());
|
||||
}
|
||||
return ApiResult.err(respCode, cause.getMessage());
|
||||
}
|
||||
log.error("Enter feign fallback,no cause catch");
|
||||
return ApiResult.err(respCode);
|
||||
}
|
||||
|
||||
public <T> ApiPageResult<T> pageResp() {
|
||||
if (cause != null) {
|
||||
log.error("Enter feign fallback", cause);
|
||||
if (cause instanceof ApiException) {
|
||||
return ApiPageResult.err(((ApiException) cause).getCode(), cause.getMessage());
|
||||
}
|
||||
return ApiPageResult.err(respCode, cause.getMessage());
|
||||
}
|
||||
log.error("Enter feign fallback,no cause catch");
|
||||
|
||||
return ApiPageResult.err(respCode);
|
||||
}
|
||||
|
||||
public <T> ApiListResult<T> listResp() {
|
||||
if (cause != null) {
|
||||
log.error("Enter feign fallback", cause);
|
||||
if (cause instanceof ApiException) {
|
||||
return ApiListResult.err(((ApiException) cause).getCode(), cause.getMessage());
|
||||
}
|
||||
return ApiListResult.err(respCode, cause.getMessage());
|
||||
}
|
||||
log.error("Enter feign fallback,no cause catch");
|
||||
return ApiListResult.err(respCode);
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,64 @@
|
||||
package cn.axzo.framework.client.feign.decoder;
|
||||
|
||||
import cn.axzo.framework.core.util.ClassUtil;
|
||||
import cn.axzo.framework.domain.ServiceException;
|
||||
import cn.axzo.framework.domain.web.ApiException;
|
||||
import cn.axzo.framework.domain.web.ClientException;
|
||||
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||
import cn.axzo.framework.domain.web.code.RespCode;
|
||||
import cn.axzo.framework.domain.web.http.HttpStatus;
|
||||
import cn.axzo.framework.domain.web.result.ApiResult;
|
||||
import cn.axzo.framework.jackson.utility.JSON;
|
||||
import feign.Response;
|
||||
import feign.codec.ErrorDecoder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import static cn.axzo.framework.core.Constants.CLIENT_MARKER;
|
||||
import static cn.axzo.framework.domain.web.code.BaseCode.NOT_FOUND;
|
||||
import static java.lang.String.format;
|
||||
|
||||
/**
|
||||
* @author liyong.tian
|
||||
* @since 2022/11/3
|
||||
*/
|
||||
@Slf4j
|
||||
public class ApiResultErrorDecoder implements ErrorDecoder {
|
||||
|
||||
private static final boolean isHystrixPresent;
|
||||
|
||||
static {
|
||||
isHystrixPresent = ClassUtil.isPresent(
|
||||
"com.netflix.hystrix.exception.HystrixBadRequestException",
|
||||
ApiResultErrorDecoder.class.getClassLoader()
|
||||
);
|
||||
}
|
||||
|
||||
public ApiResultErrorDecoder() {
|
||||
log.info(format("Add Feign ErrorDecoder: %s, isHystrixPresent: %s", "ApiResultErrorDecoder", isHystrixPresent));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Exception decode(String methodKey, Response response) {
|
||||
try {
|
||||
HttpStatus status = HttpStatus.valueOf(response.status());
|
||||
if (status == HttpStatus.NOT_FOUND) {
|
||||
return new ApiException("url[" + response.request().url() + "] not found", NOT_FOUND);
|
||||
}
|
||||
|
||||
ApiResult<?> apiResult = JSON.parseObject(response.body().asInputStream(), ApiResult.class);
|
||||
String code = apiResult.getCode();
|
||||
if (code == null) {
|
||||
return new ServiceException("ApiResult code is null");
|
||||
}
|
||||
|
||||
IRespCode respCode = new RespCode(code, apiResult.getMsg());
|
||||
if (isHystrixPresent && status.is4xxClientError()) {
|
||||
return new ClientException(respCode); // 不熔断
|
||||
}
|
||||
return new ApiException(respCode);
|
||||
} catch (Exception e) {
|
||||
log.error(CLIENT_MARKER, format("%s reading %s ", e.getMessage(), methodKey), e);
|
||||
return e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
package cn.axzo.framework.client.feign.logger;
|
||||
|
||||
import feign.Client;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author liyong.tian
|
||||
* @since 2022/11/3
|
||||
*/
|
||||
public class ClientDecorator implements Client {
|
||||
|
||||
private final Client delegate;
|
||||
|
||||
public ClientDecorator(Client delegate) {
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response execute(Request request, Request.Options options) throws RequestIOException {
|
||||
try {
|
||||
return delegate.execute(request, options);
|
||||
} catch (IOException e) {
|
||||
throw new RequestIOException(request, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,179 @@
|
||||
package cn.axzo.framework.client.feign.logger;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import cn.axzo.framework.domain.http.*;
|
||||
import cn.axzo.framework.domain.web.http.HttpStatus;
|
||||
import feign.Request;
|
||||
import feign.Response;
|
||||
import feign.Util;
|
||||
import feign.slf4j.Slf4jLogger;
|
||||
import lombok.val;
|
||||
import org.javatuples.Pair;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.framework.core.Constants.CLIENT_MARKER;
|
||||
import static java.nio.charset.Charset.defaultCharset;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static jodd.util.StringPool.*;
|
||||
|
||||
/**
|
||||
* @author liyong.tian
|
||||
* @since 2022/11/2
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public class FeignLogger extends Slf4jLogger {
|
||||
|
||||
private final Logger log;
|
||||
|
||||
private final HttpLogFormatter formatter;
|
||||
|
||||
public FeignLogger(Class<?> clazz) {
|
||||
this(clazz, JsonHttpLogFormatter.INSTANCE);
|
||||
}
|
||||
|
||||
public FeignLogger(Class<?> clazz, HttpLogFormatter formatter) {
|
||||
super(clazz);
|
||||
this.log = LoggerFactory.getLogger(clazz);
|
||||
if (formatter == null) {
|
||||
this.formatter = JsonHttpLogFormatter.INSTANCE;
|
||||
} else {
|
||||
this.formatter = formatter;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void log(String configKey, String format, Object... args) {
|
||||
IllegalStateException exception = new IllegalStateException("this method may not be invoked");
|
||||
log.error("will not happen", exception);
|
||||
throw exception;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logRequest(String configKey, Level logLevel, Request request) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
protected IOException logIOException(String configKey, Level logLevel, IOException ioe, long elapsedTime) {
|
||||
if (logLevel == Level.NONE || !(ioe instanceof RequestIOException)) {
|
||||
//响应日志
|
||||
HttpResponseLog responseLog = _responseLog(configKey, ioe, elapsedTime);
|
||||
|
||||
//打印响应日志
|
||||
log.error(CLIENT_MARKER, formatter.format(responseLog), ioe);
|
||||
return ioe;
|
||||
}
|
||||
|
||||
Request request = ((RequestIOException) ioe).getRequest();
|
||||
|
||||
//请求日志
|
||||
HttpRequestLog requestLog = _requestLog(request);
|
||||
|
||||
//响应日志
|
||||
HttpResponseLog responseLog = _responseLog(request.url(), ioe, elapsedTime);
|
||||
|
||||
//打印完整的请求响应日志
|
||||
log.error(CLIENT_MARKER, formatter.format(requestLog, responseLog), ioe);
|
||||
return ioe;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void logRetry(String configKey, Level logLevel) {
|
||||
log.info(CLIENT_MARKER, methodTag(configKey) + "---> RETRYING");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Response logAndRebufferResponse(String configKey, Level logLevel, Response response, long elapsedTime)
|
||||
throws IOException {
|
||||
if (logLevel == Level.NONE) {
|
||||
return response;
|
||||
}
|
||||
|
||||
//请求日志
|
||||
val requestLog = _requestLog(response.request());
|
||||
|
||||
//响应日志
|
||||
val responsePair = _responseLog(response, elapsedTime);
|
||||
|
||||
//打印完整的请求响应日志
|
||||
log.info(CLIENT_MARKER, formatter.format(requestLog, responsePair.getValue0()));
|
||||
return responsePair.getValue1();
|
||||
}
|
||||
|
||||
private HttpRequestLog _requestLog(Request request) {
|
||||
Objects.requireNonNull(request, "request cannot be null");
|
||||
|
||||
val logBuilder = HttpRequestLog.builder();
|
||||
|
||||
//protocol
|
||||
logBuilder.protocol("HTTP/1.1");
|
||||
|
||||
//method
|
||||
logBuilder.method(request.method());
|
||||
|
||||
//url
|
||||
logBuilder.url(request.url());
|
||||
|
||||
//headers
|
||||
List<String> requestHeaders = request.headers().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + COLON + SPACE + Joiner.on(COMMA + SPACE).join(entry.getValue()))
|
||||
.collect(toList());
|
||||
logBuilder.headers(requestHeaders);
|
||||
|
||||
//body
|
||||
if (!HttpHeaderUtil.isMultipartRequest(requestHeaders)) {
|
||||
logBuilder.body(request.body() == null ? null : new String(request.body()));
|
||||
}
|
||||
|
||||
return logBuilder.build();
|
||||
}
|
||||
|
||||
private Pair<HttpResponseLog, Response> _responseLog(Response response, long elapsedTime) throws IOException {
|
||||
val logBuilder = HttpResponseLog.builder();
|
||||
|
||||
HttpStatus status = HttpStatus.valueOf(response.status());
|
||||
List<String> responseHeaders = response.headers().entrySet().stream()
|
||||
.map(entry -> entry.getKey() + COLON + SPACE + Joiner.on(COMMA + SPACE).join(entry.getValue()))
|
||||
.collect(toList());
|
||||
//url
|
||||
logBuilder.url(response.request().url());
|
||||
|
||||
//status
|
||||
logBuilder.status(status.value());
|
||||
|
||||
//msg
|
||||
logBuilder.msg(status.getReasonPhrase());
|
||||
|
||||
//headers
|
||||
logBuilder.headers(responseHeaders);
|
||||
|
||||
//tookMs
|
||||
logBuilder.tookMs(elapsedTime);
|
||||
|
||||
//body
|
||||
boolean canReadBody = response.body() != null && !HttpHeaderUtil.isDownloadResponse(responseHeaders);
|
||||
if (canReadBody) {
|
||||
byte[] bodyBytes = Util.toByteArray(response.body().asInputStream());
|
||||
logBuilder.body(new String(bodyBytes, defaultCharset()));
|
||||
//流只能读一次,需要把响应重新构造一次
|
||||
response = response.toBuilder().body(bodyBytes).build();
|
||||
} else {
|
||||
logBuilder.body(EMPTY);
|
||||
}
|
||||
|
||||
return Pair.with(logBuilder.build(), response);
|
||||
}
|
||||
|
||||
private HttpResponseLog _responseLog(String url, IOException ioe, long elapsedTime) {
|
||||
return HttpResponseLog.builder()
|
||||
.url(url)
|
||||
.tookMs(elapsedTime)
|
||||
.errorMsg(ioe.getClass().getSimpleName() + ": " + ioe.getMessage())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
package cn.axzo.framework.client.feign.logger;
|
||||
|
||||
import feign.Request;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author liyong.tian
|
||||
* @since 2022/11/2
|
||||
*/
|
||||
public class RequestIOException extends IOException {
|
||||
|
||||
@Getter
|
||||
private final Request request;
|
||||
|
||||
private final IOException exception;
|
||||
|
||||
public RequestIOException(Request request, IOException cause) {
|
||||
super(cause instanceof RequestIOException ? ((RequestIOException) cause).exception : cause);
|
||||
this.request = request;
|
||||
this.exception = cause;
|
||||
}
|
||||
}
|
||||
@ -17,5 +17,6 @@
|
||||
|
||||
<modules>
|
||||
<module>retrofit-starter</module>
|
||||
<module>feign-starter</module>
|
||||
</modules>
|
||||
</project>
|
||||
@ -1,5 +1,6 @@
|
||||
package cn.axzo.framework.client.retrofit;
|
||||
|
||||
import cn.axzo.framework.core.net.FilterUtil;
|
||||
import cn.axzo.framework.domain.http.*;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -11,6 +12,9 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static cn.axzo.framework.core.Constants.CLIENT_MARKER;
|
||||
import static java.lang.System.nanoTime;
|
||||
import static java.util.concurrent.TimeUnit.NANOSECONDS;
|
||||
import static okhttp3.Protocol.HTTP_1_1;
|
||||
|
||||
/**
|
||||
@ -46,7 +50,33 @@ public class HttpLogInterceptor implements Interceptor {
|
||||
@Override
|
||||
@ParametersAreNonnullByDefault
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
return null;
|
||||
//0.判断该请求是否要打日志
|
||||
Request request = chain.request();
|
||||
if (FilterUtil.matchFiltersURL(request.url().encodedPath(), ignoreUrlPatterns)) {
|
||||
return chain.proceed(request);
|
||||
}
|
||||
|
||||
// 1.请求日志
|
||||
HttpRequestLog requestLog = _requestLog(chain.connection(), request);
|
||||
|
||||
// 2.发送请求, 接收响应
|
||||
long startNs = nanoTime();
|
||||
Response response;
|
||||
try {
|
||||
response = chain.proceed(request);
|
||||
} catch (Exception e) {
|
||||
// 3.异常响应日志
|
||||
long tookMs = NANOSECONDS.toMillis(nanoTime() - startNs);
|
||||
HttpResponseLog responseLog = _responseLog(request, tookMs, e);
|
||||
log.error(CLIENT_MARKER, formatter.format(requestLog, responseLog), e);
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 3.正常响应日志
|
||||
long tookMs = NANOSECONDS.toMillis(nanoTime() - startNs);
|
||||
HttpResponseLog responseLog = _responseLog(response, tookMs);
|
||||
log.info(CLIENT_MARKER, formatter.format(requestLog, responseLog));
|
||||
return response;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
49
axzo-common-datas/axzo-data-mybatis-plus/pom.xml
Normal file
49
axzo-common-datas/axzo-data-mybatis-plus/pom.xml
Normal file
@ -0,0 +1,49 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
<artifactId>axzo-common-datas</artifactId>
|
||||
<groupId>cn.axzo.framework.data</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>axzo-data-mybatis-plus</artifactId>
|
||||
<name>Axzo Common Data Mybatis Plus</name>
|
||||
|
||||
<dependencies>
|
||||
<!-- Compile -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||
</dependency>
|
||||
<!--spring-->
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework</groupId>
|
||||
<artifactId>spring-tx</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--mybatis-plus-->
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!--Optional-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -0,0 +1,56 @@
|
||||
package cn.axzo.framework.data.mybatisplus.config;
|
||||
|
||||
import cn.axzo.framework.data.mybatisplus.model.BaseEntity;
|
||||
import cn.axzo.framework.data.mybatisplus.model.BaseOwnEntity;
|
||||
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/11/4 11:34
|
||||
* @Description:
|
||||
*/
|
||||
public class EntityMetaObjectHandler implements MetaObjectHandler {
|
||||
|
||||
@Override
|
||||
public void insertFill(MetaObject metaObject) {
|
||||
Object entity = metaObject.getOriginalObject();
|
||||
if (entity instanceof BaseEntity) {
|
||||
//默认有值不覆盖
|
||||
this.fillStrategy(metaObject, "createAt", new Date());
|
||||
this.fillStrategy(metaObject, "updateAt", new Date());
|
||||
}
|
||||
|
||||
if (entity instanceof BaseOwnEntity) {
|
||||
//默认有值不覆盖
|
||||
this.fillStrategy(metaObject, "createBy", getAcctId());
|
||||
this.fillStrategy(metaObject, "updateBy", getAcctId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
Object entity = metaObject.getOriginalObject();
|
||||
if (entity instanceof BaseEntity) {
|
||||
//强制覆盖
|
||||
this.setFieldValByName("updateAt", new Date(), metaObject);
|
||||
}
|
||||
|
||||
if (entity instanceof BaseOwnEntity) {
|
||||
//强制覆盖
|
||||
this.setFieldValByName("updateBy", getAcctId(), metaObject);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前用户账户id
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private Long getAcctId() {
|
||||
return 1L;
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package cn.axzo.framework.data.mybatisplus.config;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/11/4 10:40
|
||||
* @Description:
|
||||
*/
|
||||
@EnableTransactionManagement
|
||||
@Configuration
|
||||
public class MybatisPlusAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public EntityMetaObjectHandler EntityMetaObjectHandler () {
|
||||
return new EntityMetaObjectHandler();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,12 @@
|
||||
package cn.axzo.framework.data.mybatisplus.model;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/11/4 10:29
|
||||
* @Description: 支持类
|
||||
*/
|
||||
public abstract class BaseDataEntity <T extends Model<T>> extends BaseEntity<T>{
|
||||
|
||||
}
|
||||
@ -0,0 +1,41 @@
|
||||
package cn.axzo.framework.data.mybatisplus.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/11/4 10:26
|
||||
* @Description: 实体基础类
|
||||
*/
|
||||
@Data
|
||||
public abstract class BaseEntity<T extends Model<?>> extends Model<T> {
|
||||
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 是否删除:0否 1是
|
||||
*/
|
||||
@TableField(value = "is_delete", fill = FieldFill.INSERT)
|
||||
private Integer isDelete = 0;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "create_at", fill = FieldFill.INSERT)
|
||||
private Date createAt;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@TableField(value = "update_at", fill = FieldFill.INSERT_UPDATE)
|
||||
private Date updateAt;
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package cn.axzo.framework.data.mybatisplus.model;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.FieldFill;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.extension.activerecord.Model;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/11/4 10:30
|
||||
* @Description: 支持类
|
||||
*/
|
||||
@Data
|
||||
public abstract class BaseOwnEntity<T extends Model<T>> extends BaseDataEntity<T> {
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
protected Long createBy;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
protected Long updateBy;
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
package cn.axzo.framework.data.mybatisplus;
|
||||
@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
cn.axzo.framework.data.mybatisplus.config.MybatisPlusAutoConfiguration
|
||||
21
axzo-common-datas/pom.xml
Normal file
21
axzo-common-datas/pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>
|
||||
<artifactId>axzo-framework-commons</artifactId>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>cn.axzo.framework.data</groupId>
|
||||
<artifactId>axzo-common-datas</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<name>Axzo Common Data Parent</name>
|
||||
|
||||
<modules>
|
||||
<module>axzo-data-mybatis-plus</module>
|
||||
</modules>
|
||||
</project>
|
||||
@ -1,120 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
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>cn.axzo.infra</groupId>
|
||||
<artifactId>axzo-dependencies</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<artifactId>axzo-common-dependencies</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>Axzo Common Dependencies</name>
|
||||
|
||||
<properties>
|
||||
<axzo.commons.version>1.0.0-SNAPSHOT</axzo.commons.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!--commons-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-core</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-math</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-validator</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-domain</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<!--common framework-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.framework</groupId>
|
||||
<artifactId>axzo-common-context</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-boot</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-web</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework</groupId>
|
||||
<artifactId>axzo-common-webmvc</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--axzo commons loggings-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.logging</groupId>
|
||||
<artifactId>log4j2-starter</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.logging</groupId>
|
||||
<artifactId>logback-starter</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--axzo common clients-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.client</groupId>
|
||||
<artifactId>retrofit-starter</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!--common jackson-->
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-datatype-enumstd</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-datatype-fraction</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-datatype-period</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-datatype-string-trim</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-utility</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.axzo.framework.jackson</groupId>
|
||||
<artifactId>jackson-starter</artifactId>
|
||||
<version>${axzo.commons.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
</project>
|
||||
@ -97,5 +97,10 @@
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-extension</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -1,6 +1,5 @@
|
||||
package cn.axzo.framework.domain.page;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@ -49,7 +49,6 @@ public class PageImpl<T> implements Page<T> {
|
||||
}
|
||||
return new PageImpl<>(result, current, total);
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public <S> Page<S> mapAll(Function<List<T>, List<S>> mapper) {
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
package cn.axzo.framework.domain.page;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/10/28
|
||||
* @Description: 基于mybatis-plus封装分页请求类
|
||||
*/
|
||||
@Data
|
||||
public class PageQO {
|
||||
|
||||
@ApiModelProperty("当前页")
|
||||
private Long page = 1L;
|
||||
|
||||
@ApiModelProperty("每页大小")
|
||||
private Long pageSize = 10L;
|
||||
|
||||
//排序字段
|
||||
private String sortType;
|
||||
//排序类型,(desc 降序,asc 升序)
|
||||
private String sortDirection;
|
||||
|
||||
//是否查询详情
|
||||
private boolean needDetail = true;
|
||||
|
||||
public PageQO() {
|
||||
}
|
||||
|
||||
public <T> Page<T> toPage() {
|
||||
if (this.page != null && this.page == -1L) {
|
||||
this.page = 1L;
|
||||
this.pageSize = 9999L;
|
||||
return new Page(this.page, this.pageSize);
|
||||
} else {
|
||||
if (this.page == null || this.page == 0L) {
|
||||
this.page = 1L;
|
||||
}
|
||||
|
||||
if (this.pageSize == null || this.pageSize == 0L) {
|
||||
this.pageSize = 20L;
|
||||
}
|
||||
|
||||
return new Page(this.page, this.pageSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package cn.axzo.framework.domain.page;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
/**
|
||||
* @Author: liyong.tian
|
||||
* @Date: 2022/10/28
|
||||
* @Description: 基于mybatis-plus封装分页返回类
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class PageResp<T> {
|
||||
|
||||
/**
|
||||
* 页码(从第1页开始)
|
||||
*/
|
||||
private Long page;
|
||||
|
||||
/**
|
||||
* 每页条数
|
||||
*/
|
||||
private Long pageSize;
|
||||
|
||||
/**
|
||||
* 总记录数
|
||||
*/
|
||||
private Long totalCount;
|
||||
|
||||
private List<T> list;
|
||||
|
||||
public static <T> PageResp<T> zero(Long pageNum, Long pageSize) {
|
||||
return new PageResp<T>(pageNum, pageSize, 0L, new ArrayList<>());
|
||||
}
|
||||
|
||||
public static <T> PageResp<T> list(Long pageNum, Long pageSize, Long totalCount, List<T> data) {
|
||||
if (CollectionUtils.isEmpty(data)) {
|
||||
return zero(pageNum, pageSize);
|
||||
}
|
||||
return new PageResp<T>(pageNum, pageSize, totalCount, data);
|
||||
}
|
||||
|
||||
public static <T> PageResp<T> list(IPage<?> page, List<T> data) {
|
||||
if (CollectionUtils.isEmpty(data)) {
|
||||
return zero(page.getCurrent(), page.getSize());
|
||||
}
|
||||
return new PageResp<T>(page.getCurrent(), page.getSize(), page.getTotal(), data);
|
||||
}
|
||||
|
||||
public static <T> PageResp<T> list(PageQO page, Long totalCount, List<T> data) {
|
||||
if (CollectionUtils.isEmpty(data)) {
|
||||
return zero(page.getPage(), page.getPageSize());
|
||||
}
|
||||
return new PageResp<T>(page.getPage(), page.getPageSize(), totalCount, data);
|
||||
|
||||
}
|
||||
}
|
||||
@ -16,10 +16,10 @@ import java.util.stream.Stream;
|
||||
@Description("基础错误码")
|
||||
public enum BaseCode implements IModuleRespCode{
|
||||
|
||||
SUCCESS("000", "成功", 200) {
|
||||
SUCCESS("000", "success", 200) {
|
||||
@Override
|
||||
public String getRespCode() {
|
||||
return "0";
|
||||
return "200";
|
||||
}
|
||||
},
|
||||
BAD_REQUEST("400", "请求参数错误", 400),
|
||||
|
||||
@ -10,7 +10,7 @@ import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.beans.Transient;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@ -23,8 +23,8 @@ import static jodd.util.StringUtil.isNotBlank;
|
||||
* @Date 2020/9/7 20:28
|
||||
**/
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder({"code", "msg", "data"})
|
||||
public abstract class ApiCoreResult<E> implements Result {
|
||||
|
||||
@ -74,7 +74,7 @@ public abstract class ApiCoreResult<E> implements Result {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> toMap() {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("code", code);
|
||||
map.put("msg", msg);
|
||||
map.put("data", data);
|
||||
|
||||
@ -60,7 +60,7 @@ public class ApiListResult<E> extends ApiCoreResult<List<E>> {
|
||||
return new ApiListResult<>(code, message, data);
|
||||
}
|
||||
|
||||
@ConstructorProperties({"code", "message", "data"})
|
||||
@ConstructorProperties({"code", "msg", "data"})
|
||||
public ApiListResult(String code, String message, List<E> data) {
|
||||
super(code, message, data);
|
||||
}
|
||||
|
||||
@ -1,17 +1,12 @@
|
||||
package cn.axzo.framework.domain.web.result;
|
||||
|
||||
import cn.axzo.framework.domain.page.Page;
|
||||
import cn.axzo.framework.domain.page.PageImpl;
|
||||
import cn.axzo.framework.domain.page.PageVerbose;
|
||||
import cn.axzo.framework.domain.page.Pageable;
|
||||
import cn.axzo.framework.domain.page.*;
|
||||
import cn.axzo.framework.domain.web.code.IRespCode;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import com.google.common.collect.Lists;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.beans.ConstructorProperties;
|
||||
@ -28,22 +23,9 @@ import static com.google.common.collect.Lists.newArrayList;
|
||||
* @Date 2020/9/7 20:32
|
||||
**/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@JsonPropertyOrder({"total", "code", "msg", "data", "pageNum", "pageSize", "verbose"})
|
||||
public class ApiPageResult<E> extends ApiCoreResult<List<E>> {
|
||||
|
||||
@ApiModelProperty(value = "总记录数", position = 101, required = true)
|
||||
private final Long total;
|
||||
|
||||
@ApiModelProperty(value = "当前页", position = 102)
|
||||
private final Integer pageNum;
|
||||
|
||||
@ApiModelProperty(value = "每页显示数量", position = 103)
|
||||
private final Integer pageSize;
|
||||
|
||||
@ApiModelProperty(value = "分页冗余信息", position = 104)
|
||||
private final PageVerbose verbose;
|
||||
@JsonPropertyOrder({"code", "msg", "data"})
|
||||
public class ApiPageResult<E> extends ApiCoreResult<PageData<E>>{
|
||||
|
||||
public static <E> ApiPageResult<E> empty() {
|
||||
return ok(newArrayList(), 0L);
|
||||
@ -83,9 +65,13 @@ public class ApiPageResult<E> extends ApiCoreResult<List<E>> {
|
||||
return ok(page.getRecords(), page.getTotal(), (int)page.getCurrent(), (int)page.getSize());
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> ok(PageResp<E> page) {
|
||||
return ok(page.getList(), page.getTotalCount(), page.getPage().intValue(), page.getPageSize().intValue());
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> ok(List<E> data, Long total) {
|
||||
return build(total, SUCCESS.getRespCode(), SUCCESS.getMessage(), data,
|
||||
null, null, null);
|
||||
null, null, null);
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> ok(List<E> data, Long total, Integer pageNumber, Integer pageSize) {
|
||||
@ -93,7 +79,7 @@ public class ApiPageResult<E> extends ApiCoreResult<List<E>> {
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> ok(List<E> data, Long total, Integer pageNumber, Integer pageSize,
|
||||
PageVerbose verbose) {
|
||||
PageVerbose verbose) {
|
||||
return build(total, SUCCESS.getRespCode(), SUCCESS.getMessage(), data, pageNumber, pageSize, verbose);
|
||||
}
|
||||
|
||||
@ -114,28 +100,31 @@ public class ApiPageResult<E> extends ApiCoreResult<List<E>> {
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> build(Long total, IRespCode code, List<E> data,
|
||||
Integer pageNum, Integer pageSize) {
|
||||
Integer pageNum, Integer pageSize) {
|
||||
return build(total, code.getRespCode(), code.getMessage(), data, pageNum, pageSize, null);
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> build(Long total, String code, String message, List<E> data,
|
||||
Integer pageNum, Integer pageSize) {
|
||||
Integer pageNum, Integer pageSize) {
|
||||
return new ApiPageResult<>(total, code, message, data, pageNum, pageSize, null);
|
||||
}
|
||||
|
||||
public static <E> ApiPageResult<E> build(Long total, String code, String message, List<E> data,
|
||||
Integer pageNum, Integer pageSize, PageVerbose verbose) {
|
||||
Integer pageNum, Integer pageSize, PageVerbose verbose) {
|
||||
return new ApiPageResult<>(total, code, message, data, pageNum, pageSize, verbose);
|
||||
}
|
||||
|
||||
@ConstructorProperties({"total", "code", "message", "data", "pageNum", "pageSize", "verbose"})
|
||||
public ApiPageResult(Long total, String code, String message, List<E> data, Integer pageNum, Integer pageSize,
|
||||
@ConstructorProperties({"code", "msg", "data"})
|
||||
public ApiPageResult(Long total, String code, String message, List<E> list, Integer pageNum, Integer pageSize,
|
||||
PageVerbose verbose) {
|
||||
super(code, message, data);
|
||||
this.total = total;
|
||||
this.pageNum = pageNum;
|
||||
this.pageSize = pageSize;
|
||||
this.verbose = verbose;
|
||||
PageData<E> data = new PageData<E>();
|
||||
data.setList(list);
|
||||
data.setTotalCount(total);
|
||||
data.setPage(pageNum);
|
||||
data.setPageSize(pageSize);
|
||||
this.code = code;
|
||||
this.msg = message;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -143,15 +132,15 @@ public class ApiPageResult<E> extends ApiCoreResult<List<E>> {
|
||||
Map<String, Object> map = new LinkedHashMap<>();
|
||||
map.put("code", code);
|
||||
map.put("msg", msg);
|
||||
map.put("total", total);
|
||||
map.put("data", data);
|
||||
map.put("pageNum", pageNum);
|
||||
map.put("pageSize", pageSize);
|
||||
map.put("verbose", verbose);
|
||||
return map;
|
||||
}
|
||||
|
||||
public Page<E> toPage(Pageable pageable) {
|
||||
return new PageImpl<>(data == null ? Lists.newArrayList() : data, pageable, total);
|
||||
return new PageImpl<>(data == null ? Lists.newArrayList() : data.getList(), pageable, data.getTotalCount());
|
||||
}
|
||||
|
||||
public PageResp<E> toPage() {
|
||||
return new PageResp<E>(data.getPage().longValue(), data.getPageSize().longValue(), data.getTotalCount(), data.getList() == null ? Lists.newArrayList() : data.getList());
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,33 @@
|
||||
package cn.axzo.framework.domain.web.result;
|
||||
|
||||
import cn.axzo.framework.domain.page.PageVerbose;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class PageData<E> {
|
||||
|
||||
@ApiModelProperty(value = "列表", position = 100, required = true)
|
||||
private List<E> list;
|
||||
|
||||
@ApiModelProperty(value = "总记录数", position = 101, required = true)
|
||||
private Long totalCount;
|
||||
|
||||
@ApiModelProperty(value = "当前页", position = 102)
|
||||
private Integer page;
|
||||
|
||||
@ApiModelProperty(value = "每页显示数量", position = 103)
|
||||
private Integer pageSize;
|
||||
|
||||
// @ApiModelProperty(value = "分页冗余信息", position = 104)
|
||||
// private PageVerbose verbose;
|
||||
|
||||
}
|
||||
@ -20,7 +20,7 @@ import static jodd.util.StringPool.COMMA;
|
||||
* 1/100
|
||||
* [1,100]
|
||||
*
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/3/3
|
||||
*/
|
||||
public class BigFractionDeserializer extends JsonDeserializer<BigFraction> {
|
||||
|
||||
@ -20,7 +20,7 @@ import static jodd.util.StringPool.COMMA;
|
||||
* 1/100
|
||||
* [1,100]
|
||||
*
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/3/2
|
||||
*/
|
||||
public class FractionDeserializer extends JsonDeserializer<Fraction> {
|
||||
|
||||
@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
* 1/100
|
||||
* [1,100]
|
||||
*
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/3/2
|
||||
*/
|
||||
public class BigFractionSerializer extends JsonSerializer<BigFraction> {
|
||||
|
||||
@ -14,7 +14,7 @@ import java.io.IOException;
|
||||
* 1/100
|
||||
* [1,100]
|
||||
*
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/3/2
|
||||
*/
|
||||
public class FractionSerializer extends JsonSerializer<Fraction> {
|
||||
|
||||
@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import static cn.axzo.framework.jackson.datatype.string.PackageVersion.VERSION;
|
||||
|
||||
/**
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/1/6
|
||||
*/
|
||||
public class TrimModule extends SimpleModule {
|
||||
|
||||
@ -8,7 +8,7 @@ import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/1/6
|
||||
*/
|
||||
public class TrimDeserializer extends StdScalarDeserializer<String> {
|
||||
|
||||
@ -7,7 +7,7 @@ import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
|
||||
import com.fasterxml.jackson.databind.deser.std.StringDeserializer;
|
||||
|
||||
/**
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/1/6
|
||||
*/
|
||||
public class TrimDeserializerModifier extends BeanDeserializerModifier {
|
||||
|
||||
@ -12,7 +12,7 @@ import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author jearton
|
||||
* @author liyong.tian
|
||||
* @since 2017/1/6
|
||||
*/
|
||||
public class TrimSerializer extends StdScalarSerializer<String> {
|
||||
|
||||
@ -1,22 +1,22 @@
|
||||
# Assuming a custom constraint annotation @FractionMax
|
||||
FractionMaxConstraintValidator
|
||||
BigFractionMaxConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.FractionMaxConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.BigFractionMaxConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @FractionMin
|
||||
FractionMinConstraintValidator
|
||||
BigFractionMinConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.FractionMinConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.BigFractionMinConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @PeriodMax
|
||||
PeriodMaxConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.PeriodMaxConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @PeriodMin
|
||||
PeriodMinConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.PeriodMinConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @SizeIn
|
||||
SizeInConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.SizeInConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @ASCII
|
||||
ASCIIConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.ASCIIConstraintValidator
|
||||
|
||||
# Assuming a custom constraint annotation @UTF8
|
||||
UTF8ConstraintValidator
|
||||
cn.axzo.framework.validator.constraintvalidators.UTF8ConstraintValidator
|
||||
@ -37,13 +37,11 @@
|
||||
<dependency>
|
||||
<groupId>com.github.pagehelper</groupId>
|
||||
<artifactId>pagehelper</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.baomidou</groupId>
|
||||
<artifactId>mybatis-plus-core</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@ -18,7 +18,7 @@ import java.util.Set;
|
||||
*/
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public abstract class ApiCoreEntity<E, R extends ApiCoreResult<E>> extends HttpEntity<R> {
|
||||
public abstract class ApiCoreResponse<E, R extends ApiCoreResult<E>> extends HttpEntity<R> {
|
||||
|
||||
private final Object status;
|
||||
|
||||
@ -29,7 +29,7 @@ public abstract class ApiCoreEntity<E, R extends ApiCoreResult<E>> extends HttpE
|
||||
* @param headers the entity headers
|
||||
* @param status the status code
|
||||
*/
|
||||
public ApiCoreEntity(R body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
public ApiCoreResponse(R body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
super(body, headers);
|
||||
Assert.notNull(status, "HttpStatus must not be null");
|
||||
this.status = status;
|
||||
@ -16,7 +16,7 @@ import java.util.List;
|
||||
* @author liyong.tian
|
||||
* @since 2017/11/14 下午8:00
|
||||
*/
|
||||
public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
public class ApiListResponse<E> extends ApiCoreResponse<List<E>, ApiListResult<E>> {
|
||||
|
||||
/**
|
||||
* Create a new {@code HttpEntity} with the given body, headers, and status code.
|
||||
@ -25,7 +25,7 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @param headers the entity headers
|
||||
* @param status the status code
|
||||
*/
|
||||
ApiListEntity(ApiListResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
ApiListResponse(ApiListResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
super(body, headers, status);
|
||||
}
|
||||
|
||||
@ -35,7 +35,7 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiListEntity<E> ok() {
|
||||
public static <E> ApiListResponse<E> ok() {
|
||||
return status(HttpStatus.OK).ok();
|
||||
}
|
||||
|
||||
@ -46,20 +46,20 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created {@code ResponseEntity}
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiListEntity<E> ok(List<E> data) {
|
||||
public static <E> ApiListResponse<E> ok(List<E> data) {
|
||||
return status(HttpStatus.OK).ok(data);
|
||||
}
|
||||
|
||||
public static ApiListEntityBuilder status(@Nonnull HttpStatus status) {
|
||||
public static ApiListResponseBuilder status(@Nonnull HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus must not be null");
|
||||
return new ApiListEntityBuilder(status);
|
||||
return new ApiListResponseBuilder(status);
|
||||
}
|
||||
|
||||
public static ApiListEntityBuilder header(String headerName, String... headerValues) {
|
||||
public static ApiListResponseBuilder header(String headerName, String... headerValues) {
|
||||
return status(HttpStatus.OK).header(headerName, headerValues);
|
||||
}
|
||||
|
||||
public static ApiListEntityBuilder headers(HttpHeaders headers) {
|
||||
public static ApiListResponseBuilder headers(HttpHeaders headers) {
|
||||
return status(HttpStatus.OK).headers(headers);
|
||||
}
|
||||
|
||||
@ -71,11 +71,11 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiListEntityBuilder created(URI location) {
|
||||
public static ApiListResponseBuilder created(URI location) {
|
||||
return status(HttpStatus.CREATED).location(location);
|
||||
}
|
||||
|
||||
public static ApiListEntityBuilder created(String location) {
|
||||
public static ApiListResponseBuilder created(String location) {
|
||||
return status(HttpStatus.CREATED).location(Nets.uri(location));
|
||||
}
|
||||
|
||||
@ -85,7 +85,7 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiListEntityBuilder accepted() {
|
||||
public static ApiListResponseBuilder accepted() {
|
||||
return status(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiListEntityBuilder badRequest() {
|
||||
public static ApiListResponseBuilder badRequest() {
|
||||
return status(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ -105,58 +105,58 @@ public class ApiListEntity<E> extends ApiCoreEntity<List<E>, ApiListResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiListEntityBuilder notFound() {
|
||||
public static ApiListResponseBuilder notFound() {
|
||||
return status(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
public static class ApiListEntityBuilder extends AbstractBodySetter<ApiListEntityBuilder> {
|
||||
public static class ApiListResponseBuilder extends AbstractBodySetter<ApiListResponseBuilder> {
|
||||
|
||||
private ApiListEntityBuilder(HttpStatus status) {
|
||||
private ApiListResponseBuilder(HttpStatus status) {
|
||||
super(status);
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> ok() {
|
||||
public <E> ApiListResponse<E> ok() {
|
||||
return wrapper(ApiListResult.ok());
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> ok(List<E> data) {
|
||||
public <E> ApiListResponse<E> ok(List<E> data) {
|
||||
return wrapper(ApiListResult.ok(data));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> err(IRespCode code) {
|
||||
public <E> ApiListResponse<E> err(IRespCode code) {
|
||||
return wrapper(ApiListResult.err(code));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> err(IRespCode code, String message) {
|
||||
public <E> ApiListResponse<E> err(IRespCode code, String message) {
|
||||
return wrapper(ApiListResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> err(String message) {
|
||||
public <E> ApiListResponse<E> err(String message) {
|
||||
return wrapper(ApiListResult.err(message));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> err(IRespCode code, List<E> data) {
|
||||
public <E> ApiListResponse<E> err(IRespCode code, List<E> data) {
|
||||
return wrapper(ApiListResult.err(code, data));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> err(String code, String message) {
|
||||
public <E> ApiListResponse<E> err(String code, String message) {
|
||||
return wrapper(ApiListResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> build(IRespCode code) {
|
||||
public <E> ApiListResponse<E> build(IRespCode code) {
|
||||
return wrapper(ApiListResult.build(code));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> build(IRespCode code, List<E> data) {
|
||||
public <E> ApiListResponse<E> build(IRespCode code, List<E> data) {
|
||||
return wrapper(ApiListResult.build(code, data));
|
||||
}
|
||||
|
||||
public <E> ApiListEntity<E> build(String code, String message, List<E> data) {
|
||||
public <E> ApiListResponse<E> build(String code, String message, List<E> data) {
|
||||
return wrapper(ApiListResult.build(code, message, data));
|
||||
}
|
||||
|
||||
private <E> ApiListEntity<E> wrapper(ApiListResult<E> result) {
|
||||
return new ApiListEntity<>(result, super.headers, super.status);
|
||||
private <E> ApiListResponse<E> wrapper(ApiListResult<E> result) {
|
||||
return new ApiListResponse<>(result, super.headers, super.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,5 +1,7 @@
|
||||
package cn.axzo.framework.web.http;
|
||||
|
||||
import cn.axzo.framework.domain.page.PageResp;
|
||||
import cn.axzo.framework.domain.web.result.PageData;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.github.pagehelper.PageInfo;
|
||||
import cn.axzo.framework.core.net.Nets;
|
||||
@ -19,7 +21,7 @@ import java.util.List;
|
||||
* @author liyong.tian
|
||||
* @since 2017/11/14 下午7:52
|
||||
*/
|
||||
public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
public class ApiPageResponse<E> extends ApiCoreResponse<PageData<E>, ApiPageResult<E>> {
|
||||
|
||||
/**
|
||||
* Create a new {@code HttpEntity} with the given body, headers, and status code.
|
||||
@ -28,7 +30,7 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @param headers the entity headers
|
||||
* @param status the status code
|
||||
*/
|
||||
public ApiPageEntity(ApiPageResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
public ApiPageResponse(ApiPageResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
super(body, headers, status);
|
||||
}
|
||||
|
||||
@ -38,7 +40,7 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiPageEntity<E> empty() {
|
||||
public static <E> ApiPageResponse<E> empty() {
|
||||
return status(HttpStatus.OK).empty();
|
||||
}
|
||||
|
||||
@ -49,32 +51,32 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created {@code ResponseEntity}
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiPageEntity<E> ok(Page<E> page) {
|
||||
public static <E> ApiPageResponse<E> ok(Page<E> page) {
|
||||
return status(HttpStatus.OK).ok(page);
|
||||
}
|
||||
|
||||
public static <E> ApiPageEntity<E> ok(org.springframework.data.domain.Page<E> page) {
|
||||
public static <E> ApiPageResponse<E> ok(org.springframework.data.domain.Page<E> page) {
|
||||
return status(HttpStatus.OK).ok(page);
|
||||
}
|
||||
|
||||
// public static <E> ApiPageEntity<E> ok(PageInfo<E> pageInfo) {
|
||||
// return status(HttpStatus.OK).ok(pageInfo);
|
||||
// }
|
||||
public static <E> ApiPageResponse<E> ok(PageInfo<E> pageInfo) {
|
||||
return status(HttpStatus.OK).ok(pageInfo);
|
||||
}
|
||||
|
||||
public static <E> ApiPageEntity<E> ok(IPage<E> page) {
|
||||
public static <E> ApiPageResponse<E> ok(PageResp<E> page) {
|
||||
return status(HttpStatus.OK).ok(page);
|
||||
}
|
||||
|
||||
public static ApiPageEntityBuilder status(@Nonnull HttpStatus status) {
|
||||
public static ApiPageResponseBuilder status(@Nonnull HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus must not be null");
|
||||
return new ApiPageEntityBuilder(status);
|
||||
return new ApiPageResponseBuilder(status);
|
||||
}
|
||||
|
||||
public static ApiPageEntityBuilder header(String headerName, String... headerValues) {
|
||||
public static ApiPageResponseBuilder header(String headerName, String... headerValues) {
|
||||
return status(HttpStatus.OK).header(headerName, headerValues);
|
||||
}
|
||||
|
||||
public static ApiPageEntityBuilder headers(HttpHeaders headers) {
|
||||
public static ApiPageResponseBuilder headers(HttpHeaders headers) {
|
||||
return status(HttpStatus.OK).headers(headers);
|
||||
}
|
||||
|
||||
@ -86,11 +88,11 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiPageEntityBuilder created(URI location) {
|
||||
public static ApiPageResponseBuilder created(URI location) {
|
||||
return status(HttpStatus.CREATED).location(location);
|
||||
}
|
||||
|
||||
public static ApiPageEntityBuilder created(String location) {
|
||||
public static ApiPageResponseBuilder created(String location) {
|
||||
return status(HttpStatus.CREATED).location(Nets.uri(location));
|
||||
}
|
||||
|
||||
@ -100,7 +102,7 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiPageEntityBuilder accepted() {
|
||||
public static ApiPageResponseBuilder accepted() {
|
||||
return status(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@ -110,7 +112,7 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiPageEntityBuilder badRequest() {
|
||||
public static ApiPageResponseBuilder badRequest() {
|
||||
return status(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ -120,70 +122,70 @@ public class ApiPageEntity<E> extends ApiCoreEntity<List<E>, ApiPageResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiPageEntityBuilder notFound() {
|
||||
public static ApiPageResponseBuilder notFound() {
|
||||
return status(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
public static class ApiPageEntityBuilder extends AbstractBodySetter<ApiPageEntityBuilder> {
|
||||
public static class ApiPageResponseBuilder extends AbstractBodySetter<ApiPageResponseBuilder> {
|
||||
|
||||
private ApiPageEntityBuilder(HttpStatus status) {
|
||||
private ApiPageResponseBuilder(HttpStatus status) {
|
||||
super(status);
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> empty() {
|
||||
public <E> ApiPageResponse<E> empty() {
|
||||
return wrapper(ApiPageResult.empty());
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> ok(Page<E> page) {
|
||||
public <E> ApiPageResponse<E> ok(Page<E> page) {
|
||||
return wrapper(ApiPageResult.ok(page));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> ok(org.springframework.data.domain.Page<E> page) {
|
||||
public <E> ApiPageResponse<E> ok(org.springframework.data.domain.Page<E> page) {
|
||||
return wrapper(ApiPageResult.ok(page));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> ok(PageInfo<E> pageInfo) {
|
||||
public <E> ApiPageResponse<E> ok(PageInfo<E> pageInfo) {
|
||||
return wrapper(ApiPageResult.ok(pageInfo));
|
||||
}
|
||||
public <E> ApiPageEntity<E> ok(IPage<E> page) {
|
||||
public <E> ApiPageResponse<E> ok(PageResp<E> page) {
|
||||
return wrapper(ApiPageResult.ok(page));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> ok(List<E> data, Long total) {
|
||||
public <E> ApiPageResponse<E> ok(List<E> data, Long total) {
|
||||
return wrapper(ApiPageResult.ok(data, total));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> ok(List<E> data, Long total, Integer pageNumber, Integer pageSize) {
|
||||
public <E> ApiPageResponse<E> ok(List<E> data, Long total, Integer pageNumber, Integer pageSize) {
|
||||
return wrapper(ApiPageResult.ok(data, total, pageNumber, pageSize));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> err(IRespCode code) {
|
||||
public <E> ApiPageResponse<E> err(IRespCode code) {
|
||||
return wrapper(ApiPageResult.err(code));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> err(IRespCode code, String message) {
|
||||
public <E> ApiPageResponse<E> err(IRespCode code, String message) {
|
||||
return wrapper(ApiPageResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> err(String code, String message) {
|
||||
public <E> ApiPageResponse<E> err(String code, String message) {
|
||||
return wrapper(ApiPageResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> build(IRespCode code) {
|
||||
public <E> ApiPageResponse<E> build(IRespCode code) {
|
||||
return wrapper(ApiPageResult.build(code));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> build(Long total, IRespCode code, List<E> data, Integer pageNum, Integer pageSize) {
|
||||
public <E> ApiPageResponse<E> build(Long total, IRespCode code, List<E> data, Integer pageNum, Integer pageSize) {
|
||||
return wrapper(ApiPageResult.build(total, code, data, pageNum, pageSize));
|
||||
}
|
||||
|
||||
public <E> ApiPageEntity<E> build(Long total, String code, String message, List<E> data,
|
||||
public <E> ApiPageResponse<E> build(Long total, String code, String message, List<E> data,
|
||||
Integer pageNum, Integer pageSize) {
|
||||
return wrapper(ApiPageResult.build(total, code, message, data, pageNum, pageSize));
|
||||
}
|
||||
|
||||
private <E> ApiPageEntity<E> wrapper(ApiPageResult<E> result) {
|
||||
return new ApiPageEntity<>(result, super.headers, super.status);
|
||||
private <E> ApiPageResponse<E> wrapper(ApiPageResult<E> result) {
|
||||
return new ApiPageResponse<>(result, super.headers, super.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,7 +18,7 @@ import java.util.function.Function;
|
||||
* @author liyong.tian
|
||||
* @since 2017/11/14 下午7:55
|
||||
*/
|
||||
public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
public class ApiResponse<E> extends ApiCoreResponse<E, ApiResult<E>> {
|
||||
|
||||
/**
|
||||
* Create a new {@code HttpEntity} with the given body, headers, and status code.
|
||||
@ -27,16 +27,16 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @param headers the entity headers
|
||||
* @param status the status code
|
||||
*/
|
||||
ApiEntity(ApiResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
ApiResponse(ApiResult<E> body, MultiValueMap<String, String> headers, HttpStatus status) {
|
||||
super(body, headers, status);
|
||||
}
|
||||
|
||||
public <T> ApiEntity<T> map(Function<E, T> mapper) {
|
||||
public <T> ApiResponse<T> map(Function<E, T> mapper) {
|
||||
ApiResult<T> result = getBody().map(mapper);
|
||||
return status(getStatusCode()).headers(getHeaders()).wrapper(result);
|
||||
}
|
||||
|
||||
public static <E> ApiEntity<E> of(ResponseEntity<E> entity) {
|
||||
public static <E> ApiResponse<E> of(ResponseEntity<E> entity) {
|
||||
return status(entity.getStatusCode()).headers(entity.getHeaders()).ok(entity.getBody());
|
||||
}
|
||||
|
||||
@ -46,7 +46,7 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiEntity<E> ok() {
|
||||
public static <E> ApiResponse<E> ok() {
|
||||
return status(HttpStatus.OK).ok();
|
||||
}
|
||||
|
||||
@ -57,24 +57,24 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created {@code ResponseEntity}
|
||||
* @since 4.1
|
||||
*/
|
||||
public static <E> ApiEntity<E> ok(E data) {
|
||||
public static <E> ApiResponse<E> ok(E data) {
|
||||
return status(HttpStatus.OK).ok(data);
|
||||
}
|
||||
|
||||
public static <E> ApiEntity<E> build(IRespCode code, E data) {
|
||||
public static <E> ApiResponse<E> build(IRespCode code, E data) {
|
||||
return status(HttpStatus.OK).build(code, data);
|
||||
}
|
||||
|
||||
public static ApiEntityBuilder status(@Nonnull HttpStatus status) {
|
||||
public static ApiResponseBuilder status(@Nonnull HttpStatus status) {
|
||||
Assert.notNull(status, "HttpStatus must not be null");
|
||||
return new ApiEntityBuilder(status);
|
||||
return new ApiResponseBuilder(status);
|
||||
}
|
||||
|
||||
public static ApiEntityBuilder header(String headerName, String... headerValues) {
|
||||
public static ApiResponseBuilder header(String headerName, String... headerValues) {
|
||||
return status(HttpStatus.OK).header(headerName, headerValues);
|
||||
}
|
||||
|
||||
public static ApiEntityBuilder headers(HttpHeaders headers) {
|
||||
public static ApiResponseBuilder headers(HttpHeaders headers) {
|
||||
return status(HttpStatus.OK).headers(headers);
|
||||
}
|
||||
|
||||
@ -86,11 +86,11 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiEntityBuilder created(URI location) {
|
||||
public static ApiResponseBuilder created(URI location) {
|
||||
return status(HttpStatus.CREATED).location(location);
|
||||
}
|
||||
|
||||
public static ApiEntityBuilder created(String location) {
|
||||
public static ApiResponseBuilder created(String location) {
|
||||
return status(HttpStatus.CREATED).location(Nets.uri(location));
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiEntityBuilder accepted() {
|
||||
public static ApiResponseBuilder accepted() {
|
||||
return status(HttpStatus.ACCEPTED);
|
||||
}
|
||||
|
||||
@ -110,7 +110,7 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiEntityBuilder badRequest() {
|
||||
public static ApiResponseBuilder badRequest() {
|
||||
return status(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
@ -120,69 +120,69 @@ public class ApiEntity<E> extends ApiCoreEntity<E, ApiResult<E>> {
|
||||
* @return the created builder
|
||||
* @since 4.1
|
||||
*/
|
||||
public static ApiEntityBuilder notFound() {
|
||||
public static ApiResponseBuilder notFound() {
|
||||
return status(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
public static class ApiEntityBuilder extends AbstractBodySetter<ApiEntityBuilder> {
|
||||
public static class ApiResponseBuilder extends AbstractBodySetter<ApiResponseBuilder> {
|
||||
|
||||
private ApiEntityBuilder(HttpStatus status) {
|
||||
private ApiResponseBuilder(HttpStatus status) {
|
||||
super(status);
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> ok() {
|
||||
public <E> ApiResponse<E> ok() {
|
||||
return wrapper(ApiResult.ok());
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> ok(E data) {
|
||||
public <E> ApiResponse<E> ok(E data) {
|
||||
return wrapper(ApiResult.ok(data));
|
||||
}
|
||||
|
||||
@SuppressWarnings("all")
|
||||
public <E> ApiEntity<E> okOrNotFound(Optional<E> optional) {
|
||||
public <E> ApiResponse<E> okOrNotFound(Optional<E> optional) {
|
||||
return optional.map(o -> wrapper(ApiResult.ok(o))).orElseGet(() -> {
|
||||
return wrapper(ApiResult.ok());
|
||||
});
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> err(IRespCode code) {
|
||||
public <E> ApiResponse<E> err(IRespCode code) {
|
||||
return wrapper(ApiResult.err(code));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> err(IRespCode code, String message) {
|
||||
public <E> ApiResponse<E> err(IRespCode code, String message) {
|
||||
return wrapper(ApiResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> err(IRespCode code, E data) {
|
||||
public <E> ApiResponse<E> err(IRespCode code, E data) {
|
||||
return wrapper(ApiResult.err(code, data));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> err(String message) {
|
||||
public <E> ApiResponse<E> err(String message) {
|
||||
return wrapper(ApiResult.err(message));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> err(String code, String message) {
|
||||
public <E> ApiResponse<E> err(String code, String message) {
|
||||
return wrapper(ApiResult.err(code, message));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> with(Throwable e) {
|
||||
public <E> ApiResponse<E> with(Throwable e) {
|
||||
return wrapper(ApiResult.with(e));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> build(IRespCode code) {
|
||||
public <E> ApiResponse<E> build(IRespCode code) {
|
||||
return build(code, null);
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> build(IRespCode code, E data) {
|
||||
public <E> ApiResponse<E> build(IRespCode code, E data) {
|
||||
return wrapper(ApiResult.build(code, data));
|
||||
}
|
||||
|
||||
public <E> ApiEntity<E> build(String code, String message, E data) {
|
||||
public <E> ApiResponse<E> build(String code, String message, E data) {
|
||||
return wrapper(ApiResult.build(code, message, data));
|
||||
}
|
||||
|
||||
<E> ApiEntity<E> wrapper(ApiResult<E> result) {
|
||||
return new ApiEntity<>(result, super.headers, super.status);
|
||||
<E> ApiResponse<E> wrapper(ApiResult<E> result) {
|
||||
return new ApiResponse<>(result, super.headers, super.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,7 @@ package cn.axzo.framework.web.servlet.filter;
|
||||
|
||||
import cn.axzo.framework.core.util.ClassUtil;
|
||||
import cn.axzo.framework.domain.web.code.BaseCode;
|
||||
import cn.axzo.framework.web.http.ApiEntity;
|
||||
import cn.axzo.framework.web.http.ApiResponse;
|
||||
import cn.axzo.framework.web.servlet.context.RequestMappingHandlerAdapterLazyAware;
|
||||
import io.undertow.server.RequestTooBigException;
|
||||
import io.undertow.server.handlers.form.MultiPartParserDefinition;
|
||||
@ -87,7 +87,7 @@ public class OrderedBadRequestFilter extends OncePerRequestFilter implements Ord
|
||||
return;
|
||||
}
|
||||
|
||||
ApiEntity<Void> returnValue = _decideReturnValue(ex);
|
||||
ApiResponse<Void> returnValue = _decideReturnValue(ex);
|
||||
MethodParameter returnType = new ReturnValueMethodParameter(returnValue);
|
||||
val returnValueHandler = _getReturnValueHandler(returnType);
|
||||
if (returnValueHandler == null) {
|
||||
@ -125,38 +125,38 @@ public class OrderedBadRequestFilter extends OncePerRequestFilter implements Ord
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
private ApiEntity<Void> _decideReturnValue(Exception ex) {
|
||||
ApiEntity<Void> returnValue;
|
||||
private ApiResponse<Void> _decideReturnValue(Exception ex) {
|
||||
ApiResponse<Void> returnValue;
|
||||
if (ex instanceof IllegalArgumentException) {
|
||||
return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
} else if (ex instanceof StringIndexOutOfBoundsException) {
|
||||
return ApiEntity.badRequest().err(BAD_REQUEST, ERROR_FORM_DATA_NOT_ENCODED);
|
||||
return ApiResponse.badRequest().err(BAD_REQUEST, ERROR_FORM_DATA_NOT_ENCODED);
|
||||
} else if (ex instanceof IllegalStateException) {
|
||||
return _decideReturnValue((IllegalStateException) ex);
|
||||
} else if (ex instanceof RuntimeException) {
|
||||
return _decideReturnValue((RuntimeException) ex);
|
||||
}
|
||||
return ApiEntity.status(INTERNAL_SERVER_ERROR).err(BaseCode.SERVER_ERROR);
|
||||
return ApiResponse.status(INTERNAL_SERVER_ERROR).err(BaseCode.SERVER_ERROR);
|
||||
}
|
||||
|
||||
private ApiEntity<Void> _decideReturnValue(IllegalStateException ex) {
|
||||
private ApiResponse<Void> _decideReturnValue(IllegalStateException ex) {
|
||||
if (isUndertow) {
|
||||
Throwable cause = ex.getCause();
|
||||
if (cause instanceof RequestTooBigException) {
|
||||
return ApiEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage());
|
||||
return ApiResponse.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage());
|
||||
}
|
||||
if (cause instanceof MultiPartParserDefinition.FileTooLargeException) {
|
||||
return ApiEntity.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage());
|
||||
return ApiResponse.status(HttpStatus.PAYLOAD_TOO_LARGE).err(PAYLOAD_TOO_LARGE, cause.getMessage());
|
||||
}
|
||||
}
|
||||
return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
}
|
||||
|
||||
private ApiEntity<Void> _decideReturnValue(RuntimeException ex) {
|
||||
private ApiResponse<Void> _decideReturnValue(RuntimeException ex) {
|
||||
if (ex.getCause() instanceof IOException) {
|
||||
return ApiEntity.badRequest().err(BAD_REQUEST, ex.getCause().getMessage());
|
||||
return ApiResponse.badRequest().err(BAD_REQUEST, ex.getCause().getMessage());
|
||||
}
|
||||
return ApiEntity.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
return ApiResponse.badRequest().err(BAD_REQUEST, ex.getMessage());
|
||||
}
|
||||
|
||||
/**
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user