fix: 批量解析过滤无URL旧数据,解析失败或内容为空时返回明确消息
This commit is contained in:
@@ -103,11 +103,12 @@ public class AdapterController {
|
||||
try { adapterConfig = objectMapper.readValue(configJson, AdapterConfig.class); }
|
||||
catch (Exception e) { return ApiResponse.error(400, "配置格式无效: " + e.getMessage()); }
|
||||
|
||||
// 获取该站点所有结果,按URL分组取最新
|
||||
// 获取该站点所有结果,按URL分组取最新(过滤无URL的旧数据)
|
||||
List<AccessResult> allResults = accessResultMapper.selectBySiteId(siteId);
|
||||
Map<String, AccessResult> latestByUrl = allResults.stream()
|
||||
.filter(r -> r.getUrl() != null && !r.getUrl().isBlank())
|
||||
.collect(Collectors.toMap(
|
||||
r -> r.getUrl() != null && !r.getUrl().isBlank() ? r.getUrl() : "(未指定URL)",
|
||||
AccessResult::getUrl,
|
||||
r -> r,
|
||||
(a, b) -> a.getCreatedAt().isAfter(b.getCreatedAt()) ? a : b));
|
||||
|
||||
@@ -125,6 +126,7 @@ public class AdapterController {
|
||||
Map<String, Object> item = new LinkedHashMap<>();
|
||||
item.put("url", url);
|
||||
item.put("accessResultId", ar.getId());
|
||||
item.put("contentType", ar.getContentType());
|
||||
item.put("statusCode", ar.getStatusCode());
|
||||
item.put("responseTimeMs", ar.getResponseTimeMs());
|
||||
item.put("createdAt", ar.getCreatedAt());
|
||||
@@ -139,9 +141,11 @@ public class AdapterController {
|
||||
if (content != null) {
|
||||
Map<String, Object> parsed = adapterEngine.extract(adapterConfig, content, ar.getContentType(), url);
|
||||
item.put("parsed", parsed);
|
||||
} else {
|
||||
item.put("parsed", Map.of("matched", false, "message", "内容为空,可能已从存储中删除"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
item.put("parseError", e.getMessage());
|
||||
item.put("parsed", Map.of("matched", false, "message", "解析异常: " + e.getMessage()));
|
||||
}
|
||||
|
||||
pages.add(item);
|
||||
|
||||
Reference in New Issue
Block a user