Add report preview API
This commit is contained in:
parent
c7aa33c4a0
commit
e4f9b6f511
|
|
@ -12,7 +12,7 @@
|
||||||
| 6 | GET | `/api/statistics` | 报告统计 | `src/api/report.js` | ✅ 已修正 | 新增接口并返回 `{待审核报告, 已通过报告, 驳回报告, 本月审核量}` |
|
| 6 | GET | `/api/statistics` | 报告统计 | `src/api/report.js` | ✅ 已修正 | 新增接口并返回 `{待审核报告, 已通过报告, 驳回报告, 本月审核量}` |
|
||||||
| 7 | GET | `/api/reports` | 报告列表 | `src/api/report.js` | ✅ 已修正 | 支持 `status` 过滤并返回前端表格字段(含 `approval_id`、`报告编号`、`检测机构`、`提交时间`、`状态`) |
|
| 7 | GET | `/api/reports` | 报告列表 | `src/api/report.js` | ✅ 已修正 | 支持 `status` 过滤并返回前端表格字段(含 `approval_id`、`报告编号`、`检测机构`、`提交时间`、`状态`) |
|
||||||
| 8 | GET | `/api/reports/{id}` | 报告详情 | `src/api/report.js` | ✅ 已修正 | 返回 `status(0/1/2/3)`、`report_id`、`report_type`、`institution`、`submit_time`、`testing_date`、`audit_opinion`、`ocr_result`、`attachments`、`history` |
|
| 8 | GET | `/api/reports/{id}` | 报告详情 | `src/api/report.js` | ✅ 已修正 | 返回 `status(0/1/2/3)`、`report_id`、`report_type`、`institution`、`submit_time`、`testing_date`、`audit_opinion`、`ocr_result`、`attachments`、`history` |
|
||||||
| 9 | GET | `/api/reports/{id}/preview` | 报告预览(图片/历史) | `src/api/report.js` | | |
|
| 9 | GET | `/api/reports/{id}/preview` | 报告预览(图片/历史) | `src/api/report.js` | ✅ 已修正 | 返回 `ocr_result.API核验/org_exists/cma_exists`,并附带 `pages/history` 与 `status` |
|
||||||
| 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | | |
|
| 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | | |
|
||||||
| 11 | POST | `/api/reports/{id}/submit` | 用户确认提交 | `src/api/report.js` | | |
|
| 11 | POST | `/api/reports/{id}/submit` | 用户确认提交 | `src/api/report.js` | | |
|
||||||
| 12 | POST | `/api/reports/{id}/audit` | 审核提交 | `src/api/report.js` | | |
|
| 12 | POST | `/api/reports/{id}/audit` | 审核提交 | `src/api/report.js` | | |
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,23 @@ public class TaskController {
|
||||||
return ResponseEntity.ok(resp);
|
return ResponseEntity.ok(resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/reports/{id}/preview")
|
||||||
|
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
|
||||||
|
public ResponseEntity<?> getReportPreview(@PathVariable("id") String id) {
|
||||||
|
Map<String, Object> preview = taskService.getReportPreview(id);
|
||||||
|
if (preview == null) {
|
||||||
|
Map<String, Object> resp = new HashMap<>();
|
||||||
|
resp.put("code", 1);
|
||||||
|
resp.put("msg", "Report not found");
|
||||||
|
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(resp);
|
||||||
|
}
|
||||||
|
Map<String, Object> resp = new HashMap<>();
|
||||||
|
resp.put("code", 0);
|
||||||
|
resp.put("data", preview);
|
||||||
|
resp.put("msg", "Success");
|
||||||
|
return ResponseEntity.ok(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() {
|
||||||
|
|
|
||||||
|
|
@ -459,6 +459,78 @@ public class TaskService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String mapStatusForPreview(String internalStatus) {
|
||||||
|
if (internalStatus == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return switch (internalStatus) {
|
||||||
|
case "ocr_pending" -> "0";
|
||||||
|
case "ocr_completed" -> "4";
|
||||||
|
case "pending" -> "1";
|
||||||
|
case "compliant" -> "2";
|
||||||
|
case "non-compliant" -> "3";
|
||||||
|
default -> internalStatus;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(readOnly = true)
|
||||||
|
public Map<String, Object> getReportPreview(String approvalId) {
|
||||||
|
if (approvalId == null || approvalId.isBlank()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Task task = taskRepository.findByApprovalId(approvalId);
|
||||||
|
if (task == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> preview = new HashMap<>();
|
||||||
|
preview.put("approval_id", task.getApprovalId());
|
||||||
|
preview.put("status", mapStatusForPreview(task.getStatus()));
|
||||||
|
|
||||||
|
OCRResult ocr = task.getOcrResult();
|
||||||
|
Map<String, Object> ocrMap = new HashMap<>();
|
||||||
|
if (ocr == null || "ocr_pending".equals(task.getStatus())) {
|
||||||
|
ocrMap.put("API核验", "识别中...");
|
||||||
|
ocrMap.put("org_exists", false);
|
||||||
|
ocrMap.put("cma_exists", false);
|
||||||
|
ocrMap.put("api_status", null);
|
||||||
|
} else {
|
||||||
|
String apiStatus = ocr.getApiStatus();
|
||||||
|
ocrMap.put("API核验", apiStatus != null ? apiStatus : "识别中...");
|
||||||
|
ocrMap.put("org_exists", Boolean.TRUE.equals(ocr.getOrgExists()));
|
||||||
|
ocrMap.put("cma_exists", Boolean.TRUE.equals(ocr.getCmaExists()));
|
||||||
|
ocrMap.put("api_status", apiStatus);
|
||||||
|
}
|
||||||
|
preview.put("ocr_result", ocrMap);
|
||||||
|
|
||||||
|
if (task.getPages() != null) {
|
||||||
|
List<Map<String, Object>> pages = task.getPages().stream().map(p -> {
|
||||||
|
Map<String, Object> m = new HashMap<>();
|
||||||
|
m.put("page_number", p.getPageNumber());
|
||||||
|
m.put("image_path", p.getImagePath());
|
||||||
|
return m;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
preview.put("pages", pages);
|
||||||
|
} else {
|
||||||
|
preview.put("pages", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (task.getHistories() != null) {
|
||||||
|
List<Map<String, Object>> history = task.getHistories().stream().map(h -> {
|
||||||
|
Map<String, Object> m = new HashMap<>();
|
||||||
|
m.put("action", h.getAction());
|
||||||
|
m.put("timestamp", h.getTimestamp());
|
||||||
|
m.put("opinion", h.getOpinion());
|
||||||
|
return m;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
preview.put("history", history);
|
||||||
|
} else {
|
||||||
|
preview.put("history", List.of());
|
||||||
|
}
|
||||||
|
|
||||||
|
return preview;
|
||||||
|
}
|
||||||
|
|
||||||
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