fix: try-catch the field is null exception

This commit is contained in:
2025-08-05 10:49:31 +08:00
parent f61dac4b61
commit bc409e516f
3 changed files with 10 additions and 8 deletions

View File

@@ -24,7 +24,7 @@ public class StartupCompareRunner implements ApplicationRunner {
// compareService.compare(5, "vehicle"); // compareService.compare(5, "vehicle");
// compareService.compare(5, "device"); // compareService.compare(5, "device");
// compareService.compare(5, "business"); // compareService.compare(5, "business");
compareService.compare(5, "driver"); // compareService.compare(5, "driver");
// compareService.compare(5, "vehicle_device"); // compareService.compare(5, "vehicle_device");
// compareService.compare(5, "driver_vehicle"); // compareService.compare(5, "driver_vehicle");
// compareService.compare(5, "business_driver"); // compareService.compare(5, "business_driver");

View File

@@ -47,7 +47,6 @@ public class ApiService {
public <T> Mono<List<T>> getInfoPakistan(GetInfoVO getInfoVO) { public <T> Mono<List<T>> getInfoPakistan(GetInfoVO getInfoVO) {
ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(getInfoVO.getTableName()); ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(getInfoVO.getTableName());
if (typeRef == null) { if (typeRef == null) {
// throw new IllegalArgumentException("不支持该表名: " + getInfoVO.getTableName());
log.error("Pakistan API - 不支持该表名 : {}", getInfoVO.getTableName()); log.error("Pakistan API - 不支持该表名 : {}", getInfoVO.getTableName());
return Mono.empty(); return Mono.empty();
} }
@@ -66,7 +65,6 @@ public class ApiService {
log.warn("Pakistan API - WebClient 请求 eldData 失败,错误: {}", e.getMessage()); log.warn("Pakistan API - WebClient 请求 eldData 失败,错误: {}", e.getMessage());
return Mono.just(Collections.emptyList()); return Mono.just(Collections.emptyList());
}); });
} }
// Pro API // Pro API
@@ -74,7 +72,6 @@ public class ApiService {
public <T> Mono<List<T>> getInfoPro(Integer customerId, String tableName) { public <T> Mono<List<T>> getInfoPro(Integer customerId, String tableName) {
ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(tableName); ParameterizedTypeReference<List<T>> typeRef = (ParameterizedTypeReference<List<T>>) tableObjectMapping.get(tableName);
if (typeRef == null) { if (typeRef == null) {
// throw new IllegalArgumentException("不支持该表名: " + tableName);
log.error("Pro API - 不支持该表名 : {}", tableName); log.error("Pro API - 不支持该表名 : {}", tableName);
return Mono.empty(); return Mono.empty();
} }

View File

@@ -61,9 +61,15 @@ public class CompareService {
* @Description: 获取 value 字段 * @Description: 获取 value 字段
*/ */
private static List<String> getValueField(String tableName) { private static List<String> getValueField(String tableName) {
List<String> valueFields = KEY_FIELDS.get(tableName); List<String> valueFields = null;
if (valueFields == null) { try {
throw new IllegalArgumentException("未配置字段列表: " + tableName); valueFields = KEY_FIELDS.get(tableName);
if (valueFields == null) {
throw new IllegalArgumentException("未配置字段列表: " + tableName);
}
} catch (IllegalArgumentException e) {
log.error(e.getMessage());
return Collections.emptyList();
} }
return valueFields; return valueFields;
} }
@@ -207,7 +213,6 @@ public class CompareService {
.filter(key -> !(pakistanMap.containsKey(key) && proMap.containsKey(key))) .filter(key -> !(pakistanMap.containsKey(key) && proMap.containsKey(key)))
.map(key -> pakistanMap.getOrDefault(key, proMap.get(key))) // 取出差异项 .map(key -> pakistanMap.getOrDefault(key, proMap.get(key))) // 取出差异项
.collect(Collectors.toList()); .collect(Collectors.toList());
log.info("customerId = {} - tableName = {} - differList = {}", customerId, tableName, diffList); log.info("customerId = {} - tableName = {} - differList = {}", customerId, tableName, diffList);
Set<Integer> differIds = diffList.stream() Set<Integer> differIds = diffList.stream()