Merge branch 'cc_20251110_bugfix' into 'master'

Cc 20251110 bugfix

See merge request hangzhou/java/custom_zxjp!185
This commit is contained in:
苏竹红
2025-11-10 08:16:31 +00:00
3 changed files with 60 additions and 27 deletions

View File

@@ -397,7 +397,7 @@
and eu.active = true
-- and sr.source = 'create'
<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>
and eu.user_status = '1'
</select>

View File

@@ -55,7 +55,7 @@
</foreach>
</if>
<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 test="notRoleAuth!=null and notRoleAuth!=''">
and b.role_auth !=#{notRoleAuth}

View File

@@ -327,33 +327,66 @@ public class XinFaDeviceService {
private String sendPostRequest(String requestBody, String requestUrl) {
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);
int maxRetries = 3;
for (int i = 0; i < maxRetries; i++) {
try {
Request request = new Request.Builder()
.url(requestUrl)
.post(RequestBody.create(MediaType.parse("application/json"), requestBody))
.build();
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) {
log.info("开始发送请求,url:{},requestBody:{}", requestUrl, requestBody);