Add report PDF endpoint
This commit is contained in:
parent
1107ab18cc
commit
29b9773543
|
|
@ -18,4 +18,4 @@
|
|||
| 12 | POST | `/api/reports/{id}/audit` | 审核提交 | `src/api/report.js` | ✅ 已修正 | 支持 `status/opinion/files`,保存附件并记录历史 |
|
||||
| 13 | DELETE | `/api/reports/{id}` | 删除报告 | `src/api/report.js` | ✅ 已修正 | 删除任务并清理 pdf/预览/附件目录 |
|
||||
| 14 | POST | `/api/validate-cma` | CMA 校验 | `src/api/report.js` | ✅ 已修正 | 返回 `{valid, cma_number, institution}` |
|
||||
| 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` | ✅ 已修正 | 返回 PDF 文件(`Content-Type: application/pdf`) |
|
||||
|
|
|
|||
|
|
@ -9,11 +9,16 @@ import com.chinaweal.youfool.reportdetect.modules.task.entity.Task;
|
|||
import com.chinaweal.youfool.reportdetect.modules.task.service.TaskService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.time.LocalDate;
|
||||
|
|
@ -290,6 +295,24 @@ public class TaskController {
|
|||
return ResponseEntity.ok(resp);
|
||||
}
|
||||
|
||||
@GetMapping("/reports/{id}/pdf")
|
||||
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
|
||||
public ResponseEntity<Resource> getReportPdf(@PathVariable("id") String id) {
|
||||
String pdfPath = taskService.getPdfPath(id);
|
||||
if (pdfPath == null) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
File file = new File(pdfPath);
|
||||
if (!file.exists()) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
|
||||
}
|
||||
Resource resource = new FileSystemResource(file);
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + file.getName() + "\"")
|
||||
.contentType(MediaType.APPLICATION_PDF)
|
||||
.body(resource);
|
||||
}
|
||||
|
||||
@GetMapping("/statistics")
|
||||
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
|
||||
public ResponseEntity<?> getStatistics() {
|
||||
|
|
|
|||
|
|
@ -663,6 +663,14 @@ public class TaskService {
|
|||
});
|
||||
}
|
||||
|
||||
public String getPdfPath(String approvalId) {
|
||||
if (approvalId == null || approvalId.isBlank()) {
|
||||
return null;
|
||||
}
|
||||
Task task = taskRepository.findByApprovalId(approvalId);
|
||||
return task != null ? task.getPdfPath() : null;
|
||||
}
|
||||
|
||||
public Map<String, Object> getStatistics() {
|
||||
List<String> pendingStatuses = List.of("pending", "ocr_completed");
|
||||
List<String> auditedStatuses = List.of("compliant", "non-compliant");
|
||||
|
|
|
|||
Loading…
Reference in New Issue