Align report list API with frontend

This commit is contained in:
黄仁欢 2026-03-16 14:01:06 +08:00
parent 5a78c8c01f
commit 90eba91756
3 changed files with 58 additions and 3 deletions

View File

@ -10,7 +10,7 @@
| 4 | GET | `/api/sys/institutions` | 机构列表 | `src/api/user.js` | ✅ 已核对 | 返回 `id/name/cmaNumber` 列表,前端可直接使用 | | 4 | GET | `/api/sys/institutions` | 机构列表 | `src/api/user.js` | ✅ 已核对 | 返回 `id/name/cmaNumber` 列表,前端可直接使用 |
| 5 | POST | `/api/auditor/switch-institution` | 切换机构 | `src/api/user.js` | ✅ 已核对 | 后端存在并接收 `{ institutionId }` | | 5 | POST | `/api/auditor/switch-institution` | 切换机构 | `src/api/user.js` | ✅ 已核对 | 后端存在并接收 `{ institutionId }` |
| 6 | GET | `/api/statistics` | 报告统计 | `src/api/report.js` | ✅ 已修正 | 新增接口并返回 `{待审核报告, 已通过报告, 驳回报告, 本月审核量}` | | 6 | GET | `/api/statistics` | 报告统计 | `src/api/report.js` | ✅ 已修正 | 新增接口并返回 `{待审核报告, 已通过报告, 驳回报告, 本月审核量}` |
| 7 | GET | `/api/reports` | 报告列表 | `src/api/report.js` | | | | 7 | GET | `/api/reports` | 报告列表 | `src/api/report.js` | ✅ 已修正 | 支持 `status` 过滤并返回前端表格字段(含 `approval_id`、`报告编号`、`检测机构`、`提交时间`、`状态` |
| 8 | GET | `/api/reports/{id}` | 报告详情 | `src/api/report.js` | | | | 8 | GET | `/api/reports/{id}` | 报告详情 | `src/api/report.js` | | |
| 9 | GET | `/api/reports/{id}/preview` | 报告预览(图片/历史) | `src/api/report.js` | | | | 9 | GET | `/api/reports/{id}/preview` | 报告预览(图片/历史) | `src/api/report.js` | | |
| 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | | | | 10 | POST | `/api/tasks` | 创建识别任务 | `src/api/report.js` | | |

View File

@ -133,10 +133,11 @@ public class TaskController {
@GetMapping("/reports") @GetMapping("/reports")
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR) @SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
public ResponseEntity<?> getReports() { public ResponseEntity<?> getReports(@RequestParam(value = "status", required = false) String status) {
var tasks = taskService.getTasksByStatus(status);
Map<String, Object> resp = new HashMap<>(); Map<String, Object> resp = new HashMap<>();
resp.put("code", 0); resp.put("code", 0);
resp.put("data", taskService.getAllTasks()); resp.put("data", tasks.stream().map(taskService::toReportListItem).toList());
resp.put("msg", "Success"); resp.put("msg", "Success");
return ResponseEntity.ok(resp); return ResponseEntity.ok(resp);
} }

View File

@ -36,7 +36,9 @@ import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
@ -343,6 +345,58 @@ public class TaskService {
} }
} }
public List<Task> getTasksByStatus(String statusParam) {
List<Task> tasks = getAllTasks();
if (statusParam == null || statusParam.isBlank()) {
return tasks;
}
Set<String> internalStatuses = mapStatusFilter(statusParam);
if (internalStatuses == null || internalStatuses.isEmpty()) {
return tasks;
}
return tasks.stream()
.filter(t -> internalStatuses.contains(t.getStatus()))
.collect(Collectors.toList());
}
public Map<String, Object> toReportListItem(Task task) {
Map<String, Object> row = new HashMap<>();
row.put("approval_id", task.getApprovalId());
row.put("报告编号", task.getReportId());
row.put("检测机构", task.getInstitution());
row.put("提交时间", task.getSubmitTime());
row.put("状态", mapStatusForList(task.getStatus()));
row.put("product_name", task.getProductName());
row.put("report_type", task.getReportType());
return row;
}
private Set<String> mapStatusFilter(String statusParam) {
String status = statusParam.trim();
return switch (status) {
case "0" -> Set.of("ocr_pending");
case "1" -> Set.of("pending");
case "2" -> Set.of("compliant");
case "3" -> Set.of("non-compliant");
case "audited" -> Set.of("compliant", "non-compliant");
default -> null;
};
}
private String mapStatusForList(String internalStatus) {
if (internalStatus == null) {
return "";
}
return switch (internalStatus) {
case "ocr_pending" -> "0";
case "ocr_completed" -> "1";
case "pending" -> "1";
case "compliant" -> "2";
case "non-compliant" -> "3";
default -> internalStatus;
};
}
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");