修复问题

This commit is contained in:
2026-05-28 18:40:56 +08:00
parent 31e11ad18a
commit 1d20e095f7
2 changed files with 30 additions and 10 deletions

View File

@@ -9,8 +9,8 @@ import cn.wepact.dfm.training.dto.entity.*;
import cn.wepact.dfm.training.mapper.*; import cn.wepact.dfm.training.mapper.*;
import cn.wepact.dfm.training.util.HttpClientUtil; import cn.wepact.dfm.training.util.HttpClientUtil;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.itextpdf.text.log.Logger; import org.slf4j.Logger;
import com.itextpdf.text.log.LoggerFactory; import org.slf4j.LoggerFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
@@ -107,9 +107,14 @@ public class SyncTaskService {
// 将返回的数据解析为 JSONObject // 将返回的数据解析为 JSONObject
JSONObject responseJson = new JSONObject(response); JSONObject responseJson = new JSONObject(response);
// 响应中没有data字段如权限错误终止同步
if (!responseJson.containsKey("data")) {
logger.error("全量同步响应中不存在data字段终止同步 - offset: {}, 响应: {}", offset, response);
break;
}
// 检查返回的 "data" 是否为空 // 检查返回的 "data" 是否为空
if (responseJson.containsKey("data") && responseJson.getJSONArray("data").size() == 0) { if (responseJson.getJSONArray("data").size() == 0) {
System.out.println("Data is empty, exiting the loop."); logger.info("全量同步完成,没有更多数据 - offset: {}", offset);
break; // 如果 "data" 为空,跳出循环 break; // 如果 "data" 为空,跳出循环
} }
@@ -119,7 +124,7 @@ public class SyncTaskService {
} catch (JSONException e) { } catch (JSONException e) {
// 如果 JSON 解析出错,打印异常并跳出循环 // 如果 JSON 解析出错,打印异常并跳出循环
System.err.println("Error parsing JSON response: " + e.getMessage()); logger.error("全量同步JSON解析失败 - offset: {}, 错误: {}", offset, e.getMessage());
break; break;
} }
// 解析返回数据并保存到数据库 // 解析返回数据并保存到数据库
@@ -165,9 +170,14 @@ public class SyncTaskService {
// 将返回的数据解析为 JSONObject // 将返回的数据解析为 JSONObject
JSONObject responseJson = new JSONObject(response); JSONObject responseJson = new JSONObject(response);
// 响应中没有data字段如权限错误终止同步
if (!responseJson.containsKey("data")) {
logger.error("增量同步响应中不存在data字段终止同步 - offset: {}, 响应: {}", offset, response);
break;
}
// 检查返回的 "data" 是否为空 // 检查返回的 "data" 是否为空
if (responseJson.containsKey("data") && responseJson.getJSONArray("data").size() == 0) { if (responseJson.getJSONArray("data").size() == 0) {
System.out.println("Data is empty, exiting the loop."); logger.info("增量同步完成,没有更多数据 - offset: {}", offset);
break; // 如果 "data" 为空,跳出循环 break; // 如果 "data" 为空,跳出循环
} }
@@ -177,7 +187,7 @@ public class SyncTaskService {
} catch (JSONException e) { } catch (JSONException e) {
// 如果 JSON 解析出错,打印异常并跳出循环 // 如果 JSON 解析出错,打印异常并跳出循环
System.err.println("Error parsing JSON response: " + e.getMessage()); logger.error("增量同步JSON解析失败 - offset: {}, 错误: {}", offset, e.getMessage());
break; break;
} }
// 解析返回数据并保存到数据库 // 解析返回数据并保存到数据库

View File

@@ -119,8 +119,13 @@ public class SyncUserInfoService {
// 将返回的数据解析为 JSONObject // 将返回的数据解析为 JSONObject
JSONObject responseJson = new JSONObject(response); JSONObject responseJson = new JSONObject(response);
// 响应中没有data字段如权限错误终止同步
if (!responseJson.containsKey("data")) {
logger.error("全量同步响应中不存在data字段终止同步 - offset: {}, 响应: {}", offset, response);
break;
}
// 检查返回的 "data" 是否为空 // 检查返回的 "data" 是否为空
if (responseJson.containsKey("data") && responseJson.getJSONArray("data").size() == 0) { if (responseJson.getJSONArray("data").size() == 0) {
logger.info("全量同步完成,没有更多数据 - offset: {}", offset); logger.info("全量同步完成,没有更多数据 - offset: {}", offset);
break; // 如果 "data" 为空,跳出循环 break; // 如果 "data" 为空,跳出循环
} }
@@ -188,8 +193,13 @@ public class SyncUserInfoService {
// 将返回的数据解析为 JSONObject // 将返回的数据解析为 JSONObject
JSONObject responseJson = new JSONObject(response); JSONObject responseJson = new JSONObject(response);
// 响应中没有data字段如权限错误终止同步
if (!responseJson.containsKey("data")) {
logger.error("增量同步响应中不存在data字段终止同步 - offset: {}, 响应: {}", offset, response);
break;
}
// 检查返回的 "data" 是否为空 // 检查返回的 "data" 是否为空
if (responseJson.containsKey("data") && responseJson.getJSONArray("data").size() == 0) { if (responseJson.getJSONArray("data").size() == 0) {
logger.info("增量同步完成,没有更多数据 - offset: {}", offset); logger.info("增量同步完成,没有更多数据 - offset: {}", offset);
break; // 如果 "data" 为空,跳出循环 break; // 如果 "data" 为空,跳出循环
} }