feat: 新增 access-result 删除接口,同时清理存储文件
This commit is contained in:
@@ -136,4 +136,17 @@ public class AccessResultController {
|
|||||||
int affected = accessResultService.batchValidateUrl(siteId, url, isValid);
|
int affected = accessResultService.batchValidateUrl(siteId, url, isValid);
|
||||||
return ApiResponse.success(Map.of("affected", affected));
|
return ApiResponse.success(Map.of("affected", affected));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除访问结果(含存储文件)
|
||||||
|
*/
|
||||||
|
@DeleteMapping("/api/v1/admin/access-results/{id}")
|
||||||
|
public ApiResponse<Void> delete(@PathVariable("id") Long id) {
|
||||||
|
try {
|
||||||
|
accessResultService.delete(id);
|
||||||
|
return ApiResponse.success();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
return ApiResponse.error(404, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ public class AdapterController {
|
|||||||
try { adapterConfig = objectMapper.readValue(configJson, AdapterConfig.class); }
|
try { adapterConfig = objectMapper.readValue(configJson, AdapterConfig.class); }
|
||||||
catch (Exception e) { return ApiResponse.error(400, "配置格式无效: " + e.getMessage()); }
|
catch (Exception e) { return ApiResponse.error(400, "配置格式无效: " + e.getMessage()); }
|
||||||
|
|
||||||
// 获取该站点所有结果,按URL分组取最新(过滤无URL的旧数据)
|
// 获取该站点所有结果,按URL分组取最新
|
||||||
List<AccessResult> allResults = accessResultMapper.selectBySiteId(siteId);
|
List<AccessResult> allResults = accessResultMapper.selectBySiteId(siteId);
|
||||||
Map<String, AccessResult> latestByUrl = allResults.stream()
|
Map<String, AccessResult> latestByUrl = allResults.stream()
|
||||||
.filter(r -> r.getUrl() != null && !r.getUrl().isBlank())
|
.filter(r -> r.getUrl() != null && !r.getUrl().isBlank())
|
||||||
@@ -112,6 +112,8 @@ public class AdapterController {
|
|||||||
r -> r,
|
r -> r,
|
||||||
(a, b) -> a.getCreatedAt().isAfter(b.getCreatedAt()) ? a : b));
|
(a, b) -> a.getCreatedAt().isAfter(b.getCreatedAt()) ? a : b));
|
||||||
|
|
||||||
|
int skippedNoUrl = (int) allResults.stream().filter(r -> r.getUrl() == null || r.getUrl().isBlank()).count();
|
||||||
|
|
||||||
// 批量解析
|
// 批量解析
|
||||||
Map<String, Object> response = new LinkedHashMap<>();
|
Map<String, Object> response = new LinkedHashMap<>();
|
||||||
response.put("configId", configId);
|
response.put("configId", configId);
|
||||||
|
|||||||
@@ -43,6 +43,11 @@ public interface AccessResultService {
|
|||||||
*/
|
*/
|
||||||
List<SiteAccessSummaryDTO> listSiteSummaries();
|
List<SiteAccessSummaryDTO> listSiteSummaries();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除访问结果(含存储文件)
|
||||||
|
*/
|
||||||
|
void delete(Long id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 批量标记站点某个URL的所有未验证结果为有效/无效
|
* 批量标记站点某个URL的所有未验证结果为有效/无效
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -191,6 +191,16 @@ public class AccessResultServiceImpl implements AccessResultService {
|
|||||||
return new ArrayList<>(siteMap.values());
|
return new ArrayList<>(siteMap.values());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void delete(Long id) {
|
||||||
|
AccessResult result = mapper.selectById(id);
|
||||||
|
if (result == null) throw new IllegalArgumentException("访问结果不存在: " + id);
|
||||||
|
// 删除存储文件
|
||||||
|
try { storageService.delete(result.getStoragePath()); } catch (Exception ignored) {}
|
||||||
|
mapper.deleteById(id);
|
||||||
|
log.info("Access result deleted: id={}, siteId={}", id, result.getSiteId());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int batchValidateUrl(String siteId, String url, Boolean isValid) {
|
public int batchValidateUrl(String siteId, String url, Boolean isValid) {
|
||||||
int affected = mapper.batchValidateUrl(siteId, url, isValid);
|
int affected = mapper.batchValidateUrl(siteId, url, isValid);
|
||||||
|
|||||||
Reference in New Issue
Block a user