Skip to content

Commit 6b2dbb9

Browse files
committed
【common】补全注释
1 parent 03f7f91 commit 6b2dbb9

File tree

11 files changed

+177
-18
lines changed

11 files changed

+177
-18
lines changed

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/ApiRequest.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,35 +10,50 @@
1010
import com.hyq0719.mktapi.common.util.StringUtil;
1111
import org.apache.commons.lang3.StringUtils;
1212

13-
import java.io.File;
1413
import java.lang.reflect.ParameterizedType;
1514
import java.lang.reflect.Type;
1615
import java.util.*;
1716

1817
public abstract class ApiRequest<T, R> implements ParamHandler<T> {
1918

19+
/**
20+
* 响应类型Type
21+
*/
2022
private Type localVarReturnType = getRType();
2123

2224
public R execute(T t) throws ApiException {
2325
return execute(t, null, null);
2426
}
2527

2628
/**
27-
* 新增钩子函数用于使用时增强
29+
* 钩子函数用于使用时增强
2830
*
29-
* @param t
30-
* @param apiRequestAdvice
31-
* @return
31+
* @param t 请求
32+
* @param apiRequestAdvice 请求增强
33+
* @return 响应
3234
* @throws ApiException
3335
*/
3436
public R execute(T t, ApiRequestAdvice apiRequestAdvice) throws ApiException {
3537
return execute(t, apiRequestAdvice, null);
3638
}
3739

40+
/**
41+
* @param t 请求
42+
* @param token access token, 传参后不去缓存中取token
43+
* @return 响应
44+
* @throws ApiException
45+
*/
3846
public R execute(T t, String token) throws ApiException {
3947
return execute(t, null, token);
4048
}
4149

50+
/**
51+
* @param t 请求
52+
* @param apiRequestAdvice 请求增强
53+
* @param token access token, 传参后不去缓存中取token
54+
* @return
55+
* @throws ApiException
56+
*/
4257
public R execute(T t, ApiRequestAdvice apiRequestAdvice, String token) throws ApiException {
4358
if (Objects.nonNull(apiRequestAdvice)) {
4459
apiRequestAdvice.before();
@@ -50,11 +65,17 @@ public R execute(T t, ApiRequestAdvice apiRequestAdvice, String token) throws Ap
5065
return retry(resp, t, apiRequestAdvice, token);
5166
}
5267

68+
/**
69+
* 重试机制,默认不重试
70+
*/
5371
public R retry(ApiResponse<R> resp, T t, ApiRequestAdvice apiRequestAdvice, String token)
5472
throws ApiException {
5573
return resp.getData();
5674
}
5775

76+
/**
77+
* 重试请求
78+
*/
5879
public R retryRequest(T t, ApiRequestAdvice apiRequestAdvice, String token) throws ApiException {
5980
if (Objects.nonNull(apiRequestAdvice)) {
6081
apiRequestAdvice.before();
@@ -66,6 +87,13 @@ public R retryRequest(T t, ApiRequestAdvice apiRequestAdvice, String token) thro
6687
return retryResponse.getData();
6788
}
6889

90+
/**
91+
* 用注解和继承方法构造请求参数
92+
*
93+
* @param t 请求体
94+
* @param token access token
95+
* @return RequestParam 请求参数
96+
*/
6997
@Override
7098
public RequestParam constructParameters(T t, String token) {
7199
Object localVarPostBody = null;
@@ -195,6 +223,9 @@ protected ApiResponse<R> executeWithHttp(T t, String token) throws ApiException
195223
return getApiClient().execute(param, localVarReturnType);
196224
}
197225

226+
/**
227+
* 响应类型Type
228+
*/
198229
private Type getRType() {
199230
return ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[1];
200231
}

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/RetryStrategy.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,45 @@
11
package com.hyq0719.mktapi.common;
22

3+
/**
4+
* api请求重试策略
5+
*
6+
* @author hyq0719
7+
*/
38
public interface RetryStrategy {
49

510
/**
6-
* 重试次数
11+
* 重试次数,默认为3次
712
*
8-
* @return
13+
* @return 重试次数
914
*/
1015
default Integer retryCount() {
1116
return 3;
1217
}
1318

1419
/**
15-
* 重试条件
20+
* 根据各渠道返回码判断是否重试
1621
*
17-
* @return
22+
* @return 重试条件
1823
*/
1924
default Boolean retryCondition(Long code) {
2025
return false;
2126
}
2227

2328
/**
24-
* 是否启用
29+
* 是否开启重试
2530
*
26-
* @return
31+
* @return 是否开启重试
2732
*/
2833
default Boolean enable() {
2934
return true;
3035
}
3136

37+
/**
38+
* 根据返回码判断token是否过期
39+
*
40+
* @param code 请求返回码
41+
* @return token是否过期
42+
*/
3243
default Boolean isTokenExpired(Long code) {
3344
return false;
3445
}

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/advice/ApiRequestAdvice.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

33
import com.hyq0719.mktapi.common.ApiResponse;
44

5+
/**
6+
* api请求增强,类似AOP
7+
*
8+
* @author hyq0719
9+
*/
510
@FunctionalInterface
611
public interface ApiRequestAdvice {
712

13+
/**
14+
* 请求前执行
15+
*/
816
default void before() {
917

1018
}
1119

20+
/**
21+
* 请求后执行
22+
*
23+
* @param response 请求的返回内容
24+
*/
1225
void after(ApiResponse response);
1326
}

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/annotation/ApiRequestMapping.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,48 @@
55

66
import java.lang.annotation.*;
77

8+
/**
9+
* 请求参数注解
10+
*
11+
* @author hyq0719
12+
*/
813
@Target({ElementType.METHOD, ElementType.TYPE})
914
@Retention(RetentionPolicy.RUNTIME)
1015
@Inherited
1116
public @interface ApiRequestMapping {
17+
/**
18+
* 请求路径后缀,和BaseUrl拼接
19+
* @return 请求路径后缀
20+
*/
1221
String value();
1322

23+
/**
24+
* 请求版本号,默认从BaseUrl获取
25+
* @return 请求版本号
26+
*/
1427
String version() default "";
1528

29+
/**
30+
* 请求host地址,默认从BaseUrl获取
31+
* @return 请求host地址
32+
*/
1633
String host() default "";
1734

35+
/**
36+
* 请求方法:GET,POST等
37+
* @return 请求方法
38+
*/
1839
String method();
1940

41+
/**
42+
* 是否使用请求体,默认为true
43+
* @return 是否使用请求体
44+
*/
2045
boolean usePostBody() default true;
2146

47+
/**
48+
* 请求头中的Content-Type
49+
* @return Content-Type
50+
*/
2251
String[] contentTypes() default {RequestConstants.CONTENT_TYPE_JSON, RequestConstants.CONTENT_TYPE_XML};
2352
}

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/constant/AuthConstants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
package com.hyq0719.mktapi.common.constant;
22

3+
/**
4+
* 各渠道请求中的授权参数
5+
*
6+
* @author hyq0719
7+
*/
38
public interface AuthConstants {
49

510
/**

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/executor/http/ApacheHttpHandler.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,17 @@ public <T> T handleResponse(HttpResponse response, Type returnType) throws ApiEx
131131
code, toMultimap(response.getAllHeaders()), respBody);
132132
}
133133

134+
/**
135+
* Deserialize response body to Java object, according to the return type and the Content-Type
136+
* response header.
137+
*
138+
* @param <T> Type
139+
* @param response HTTP response
140+
* @param returnType The type of the Java object
141+
* @return The deserialized Java object
142+
* @throws ApiException If fail to deserialize response body, i.e. cannot read response body or
143+
* the Content-Type of the response is not supported.
144+
*/
134145
public <T> T deserialize(HttpResponse response, Type returnType) throws ApiException {
135146
if (response == null || returnType == null) {
136147
return null;

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/executor/http/BaseHttpHandler.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,15 @@
99
import java.net.URLEncoder;
1010
import java.util.List;
1111

12+
/**
13+
* HttpHandler抽象类,提供url构造的默认实现
14+
*
15+
* @author hyq0719
16+
*/
1217
public abstract class BaseHttpHandler implements HttpHandler {
1318

14-
private JSON json;
15-
private boolean verifyingSsl;
19+
private final JSON json;
20+
private final boolean verifyingSsl;
1621

1722
protected BaseHttpHandler() {
1823
json = new JSON();
@@ -72,6 +77,12 @@ public boolean isJsonMime(String mime) {
7277
return mime != null && (mime.matches(jsonMime) || "*/*".equals(mime));
7378
}
7479

80+
/**
81+
* 添加请求参数
82+
*
83+
* @param url 当前url
84+
* @param requestParam 请求参数
85+
*/
7586
private void appendQueryParams(StringBuilder url, RequestParam requestParam) {
7687
List<Pair> queryParams = requestParam.getQueryParams();
7788
if (queryParams != null && !queryParams.isEmpty()) {
@@ -92,6 +103,12 @@ private void appendQueryParams(StringBuilder url, RequestParam requestParam) {
92103
}
93104
}
94105

106+
/**
107+
* 添加请求参数集合
108+
*
109+
* @param url 当前url
110+
* @param requestParam 请求参数
111+
*/
95112
private void appendCollectionQueryParams(StringBuilder url, RequestParam requestParam) {
96113
List<Pair> collectionQueryParams = requestParam.getCollectionQueryParams();
97114
if (collectionQueryParams != null && !collectionQueryParams.isEmpty()) {

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/executor/parameter/BaseUrl.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
import lombok.Builder;
44
import lombok.Data;
55

6+
/**
7+
* 请求基础url
8+
*
9+
* @author hyq0719
10+
*/
611
@Data
712
@Builder
813
public class BaseUrl {
9-
String scheme;
10-
String host;
11-
String version;
14+
/**
15+
* 协议:http,https
16+
*/
17+
private String scheme;
18+
/**
19+
* host地址
20+
*/
21+
private String host;
22+
/**
23+
* api版本
24+
*/
25+
private String version;
1226

1327
@Override
1428
public String toString() {

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/token/ExternalTokenService.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44

55
public interface ExternalTokenService {
66

7+
/**
8+
* 刷新所有token
9+
*
10+
* @return token列表
11+
*/
712
List<IToken> refreshAllToken();
813

14+
/**
15+
* 刷新单个token
16+
*
17+
* @param tokenKey token key
18+
* @return token
19+
*/
920
IToken refreshToken(String tokenKey);
1021
}

marketing-api-common/src/main/java/com/hyq0719/mktapi/common/token/ITokenCronService.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,14 @@
1212
@Slf4j
1313
public class ITokenCronService implements CronService {
1414

15+
/**
16+
* 外部token授权服务
17+
*/
1518
private ExternalTokenService externalTokenService;
16-
19+
/**
20+
* tokwn本地缓存
21+
*/
1722
private volatile ITokenLocalCache iTokenLocalCache;
18-
1923
private String cron;
2024

2125
public ITokenCronService(ExternalTokenService externalTokenService, ITokenLocalCache iTokenLocalCache,

0 commit comments

Comments
 (0)