Merge branch 'master' into cc_20251029_smz
This commit is contained in:
@@ -397,7 +397,7 @@
|
|||||||
and eu.active = true
|
and eu.active = true
|
||||||
-- and sr.source = 'create'
|
-- and sr.source = 'create'
|
||||||
<if test="positionType != null and positionType != '' ">
|
<if test="positionType != null and positionType != '' ">
|
||||||
and (sr.position_type = #{positionType} or sr.id in (180000000,120000000,40000000))
|
and (sr.position_type = #{positionType} or sr.id in (180000000,120000000,40000000,1762761165005))
|
||||||
</if>
|
</if>
|
||||||
and eu.user_status = '1'
|
and eu.user_status = '1'
|
||||||
</select>
|
</select>
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
</foreach>
|
</foreach>
|
||||||
</if>
|
</if>
|
||||||
<if test="positionType!=null and positionType!=''">
|
<if test="positionType!=null and positionType!=''">
|
||||||
and (b.position_type =#{positionType} or b.id in (180000000,120000000,40000000) )
|
and (b.position_type =#{positionType} or b.id in (180000000,120000000,40000000,1762761165005))
|
||||||
</if>
|
</if>
|
||||||
<if test="notRoleAuth!=null and notRoleAuth!=''">
|
<if test="notRoleAuth!=null and notRoleAuth!=''">
|
||||||
and b.role_auth !=#{notRoleAuth}
|
and b.role_auth !=#{notRoleAuth}
|
||||||
|
|||||||
@@ -327,33 +327,66 @@ public class XinFaDeviceService {
|
|||||||
|
|
||||||
private String sendPostRequest(String requestBody, String requestUrl) {
|
private String sendPostRequest(String requestBody, String requestUrl) {
|
||||||
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
|
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
|
||||||
|
|
||||||
int maxRetries = 3;
|
|
||||||
for (int i = 0; i < maxRetries; i++) {
|
|
||||||
try {
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(requestUrl)
|
.url(requestUrl)
|
||||||
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
|
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
return sendPost(requestUrl, request);
|
return sendPost(requestUrl, request);
|
||||||
} catch (Exception e) {
|
|
||||||
log.warn("请求失败,第{}次重试,错误: {}", i + 1, e.getMessage());
|
|
||||||
if (i == maxRetries - 1) {
|
|
||||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR, "请求重试失败: " + e.getMessage());
|
|
||||||
}
|
|
||||||
// 重试前等待
|
|
||||||
try {
|
|
||||||
Thread.sleep(1000 * (i + 1));
|
|
||||||
} catch (InterruptedException ie) {
|
|
||||||
Thread.currentThread().interrupt();
|
|
||||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR, "重试被中断");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR, "请求重试失败");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 不重试 请求接口
|
||||||
|
* @param requestBody
|
||||||
|
* @param requestUrl
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
private String sendPostRequestNoRetryByToken(String requestBody, String requestUrl, String token) {
|
||||||
|
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Request request = new Request.Builder()
|
||||||
|
.url(requestUrl)
|
||||||
|
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
|
||||||
|
.addHeader("token", token)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
String result = sendPost(requestUrl, request);
|
||||||
|
|
||||||
|
// 检查是否token失效
|
||||||
|
if (isTokenExpired(result)) {
|
||||||
|
log.warn("Token已失效,清除缓存并重新获取token");
|
||||||
|
// 清除对应账号的token缓存并获取新token
|
||||||
|
String newToken = clearAccountTokenCacheForToken(token);
|
||||||
|
|
||||||
|
if (newToken != null) {
|
||||||
|
// 使用新token重新发起一次请求
|
||||||
|
Request newRequest = new Request.Builder()
|
||||||
|
.url(requestUrl)
|
||||||
|
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
|
||||||
|
.addHeader("token", newToken)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
result = sendPost(requestUrl, newRequest);
|
||||||
|
} else {
|
||||||
|
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR, "Token失效且无法获取新token");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("请求异常,错误: {}", e.getMessage());
|
||||||
|
throw new ServiceException(ErrorCodeEnum.THIRD_API_ERROR, "请求失败: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 包含重试 适用于批量拉取数据 ,正常页面接口无需重试
|
||||||
|
* @param requestBody
|
||||||
|
* @param requestUrl
|
||||||
|
* @param token
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
private String sendPostRequestByToken(String requestBody, String requestUrl, String token) {
|
private String sendPostRequestByToken(String requestBody, String requestUrl, String token) {
|
||||||
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
|
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user