Add delete report API
This commit is contained in:
parent
8dc2e4f3e7
commit
f61e06b49b
|
|
@ -16,6 +16,6 @@
|
||||||
| 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | ✅ 已修正 | 支持 `product_name/testing_date/contact_phone` 等表单字段 |
|
| 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | ✅ 已修正 | 支持 `product_name/testing_date/contact_phone` 等表单字段 |
|
||||||
| 11 | POST | `/api/reports/{id}/submit` | 用户确认提交 | `src/api/report.js` | ✅ 已修正 | OCR 通过后将状态置为 `pending` 并记录历史 |
|
| 11 | POST | `/api/reports/{id}/submit` | 用户确认提交 | `src/api/report.js` | ✅ 已修正 | OCR 通过后将状态置为 `pending` 并记录历史 |
|
||||||
| 12 | POST | `/api/reports/{id}/audit` | 审核提交 | `src/api/report.js` | ✅ 已修正 | 支持 `status/opinion/files`,保存附件并记录历史 |
|
| 12 | POST | `/api/reports/{id}/audit` | 审核提交 | `src/api/report.js` | ✅ 已修正 | 支持 `status/opinion/files`,保存附件并记录历史 |
|
||||||
| 13 | DELETE | `/api/reports/{id}` | 删除报告 | `src/api/report.js` | | |
|
| 13 | DELETE | `/api/reports/{id}` | 删除报告 | `src/api/report.js` | ✅ 已修正 | 删除任务并清理 pdf/预览/附件目录 |
|
||||||
| 14 | POST | `/api/validate-cma` | CMA 校验 | `src/api/report.js` | | |
|
| 14 | POST | `/api/validate-cma` | CMA 校验 | `src/api/report.js` | | |
|
||||||
| 15 | GET | `/api/reports/{id}/pdf` | PDF 预览 | `src/views/shibieneirong/shenhe/index.vue` | | |
|
| 15 | GET | `/api/reports/{id}/pdf` | PDF 预览 | `src/views/shibieneirong/shenhe/index.vue` | | |
|
||||||
|
|
|
||||||
|
|
@ -236,6 +236,23 @@ public class TaskController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/reports/{id}")
|
||||||
|
@SaCheckRole(value = { "ADMIN", "USER" }, mode = SaMode.OR)
|
||||||
|
public ResponseEntity<?> deleteReport(@PathVariable("id") String id) {
|
||||||
|
try {
|
||||||
|
taskService.deleteReport(id);
|
||||||
|
Map<String, Object> resp = new HashMap<>();
|
||||||
|
resp.put("code", 0);
|
||||||
|
resp.put("msg", "Deleted");
|
||||||
|
return ResponseEntity.ok(resp);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
Map<String, Object> resp = new HashMap<>();
|
||||||
|
resp.put("code", 1);
|
||||||
|
resp.put("msg", e.getMessage());
|
||||||
|
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("/statistics")
|
@GetMapping("/statistics")
|
||||||
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
|
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
|
||||||
public ResponseEntity<?> getStatistics() {
|
public ResponseEntity<?> getStatistics() {
|
||||||
|
|
|
||||||
|
|
@ -618,6 +618,51 @@ public class TaskService {
|
||||||
taskRepository.save(task);
|
taskRepository.save(task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void deleteReport(String approvalId) {
|
||||||
|
if (approvalId == null || approvalId.isBlank()) {
|
||||||
|
throw new IllegalArgumentException("approval_id is required");
|
||||||
|
}
|
||||||
|
Task task = taskRepository.findByApprovalId(approvalId);
|
||||||
|
if (task == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.getPdfPath() != null) {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(Paths.get(task.getPdfPath()));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
// ignore cleanup failure
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
deleteDirectory(Paths.get(previewDir, approvalId));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
deleteDirectory(Paths.get(attachmentDir, approvalId));
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
|
||||||
|
taskRepository.delete(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deleteDirectory(Path dir) throws IOException {
|
||||||
|
if (dir == null || !Files.exists(dir)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Files.walk(dir)
|
||||||
|
.sorted((a, b) -> b.compareTo(a))
|
||||||
|
.forEach(path -> {
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(path);
|
||||||
|
} catch (IOException ignored) {
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public Map<String, Object> getStatistics() {
|
public Map<String, Object> getStatistics() {
|
||||||
List<String> pendingStatuses = List.of("pending", "ocr_completed");
|
List<String> pendingStatuses = List.of("pending", "ocr_completed");
|
||||||
List<String> auditedStatuses = List.of("compliant", "non-compliant");
|
List<String> auditedStatuses = List.of("compliant", "non-compliant");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue