Make task APIs Java 8 compatible

This commit is contained in:
黄仁欢 2026-03-16 16:50:04 +08:00
parent ded3f2f537
commit 47fac2f6bc
2 changed files with 55 additions and 32 deletions

View File

@ -26,6 +26,7 @@ import java.util.Map;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.List;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api")
@ -157,10 +158,10 @@ public class TaskController {
@GetMapping("/reports")
@SaCheckRole(value = { "ADMIN", "AUDITOR", "USER" }, mode = SaMode.OR)
public ResponseEntity<?> getReports(@RequestParam(value = "status", required = false) String status) {
var tasks = taskService.getTasksByStatus(status);
List<Task> tasks = taskService.getTasksByStatus(status);
Map<String, Object> resp = new HashMap<>();
resp.put("code", 0);
resp.put("data", tasks.stream().map(taskService::toReportListItem).toList());
resp.put("data", tasks.stream().map(taskService::toReportListItem).collect(Collectors.toList()));
resp.put("msg", "Success");
return ResponseEntity.ok(resp);
}

View File

@ -8,6 +8,7 @@ import com.chinaweal.youfool.reportdetect.modules.ocr.service.OCRTaskProducer;
import com.chinaweal.youfool.reportdetect.modules.sys.repository.InstitutionRepository;
import com.chinaweal.youfool.reportdetect.modules.sys.repository.SysUserRepository;
import com.chinaweal.youfool.reportdetect.modules.task.entity.AuditHistory;
import com.chinaweal.youfool.reportdetect.modules.task.entity.AuditAttachment;
import com.chinaweal.youfool.reportdetect.modules.task.entity.OCRResult;
import com.chinaweal.youfool.reportdetect.modules.task.entity.Page;
import com.chinaweal.youfool.reportdetect.modules.task.entity.Task;
@ -31,8 +32,11 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
@ -417,7 +421,7 @@ public class TaskService {
}).collect(Collectors.toList());
detail.put("attachments", attachments);
} else {
detail.put("attachments", List.of());
detail.put("attachments", Collections.emptyList());
}
if (task.getHistories() != null) {
@ -430,7 +434,7 @@ public class TaskService {
}).collect(Collectors.toList());
detail.put("history", history);
} else {
detail.put("history", List.of());
detail.put("history", Collections.emptyList());
}
return detail;
@ -438,42 +442,60 @@ public class TaskService {
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;
};
switch (status) {
case "0":
return Collections.singleton("ocr_pending");
case "1":
return Collections.singleton("pending");
case "2":
return Collections.singleton("compliant");
case "3":
return Collections.singleton("non-compliant");
case "audited":
return new HashSet<>(Arrays.asList("compliant", "non-compliant"));
default:
return 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;
};
switch (internalStatus) {
case "ocr_pending":
return "0";
case "ocr_completed":
return "1";
case "pending":
return "1";
case "compliant":
return "2";
case "non-compliant":
return "3";
default:
return internalStatus;
}
}
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;
};
switch (internalStatus) {
case "ocr_pending":
return "0";
case "ocr_completed":
return "4";
case "pending":
return "1";
case "compliant":
return "2";
case "non-compliant":
return "3";
default:
return internalStatus;
}
}
@Transactional(readOnly = true)
@ -515,7 +537,7 @@ public class TaskService {
}).collect(Collectors.toList());
preview.put("pages", pages);
} else {
preview.put("pages", List.of());
preview.put("pages", Collections.emptyList());
}
if (task.getHistories() != null) {
@ -528,7 +550,7 @@ public class TaskService {
}).collect(Collectors.toList());
preview.put("history", history);
} else {
preview.put("history", List.of());
preview.put("history", Collections.emptyList());
}
return preview;
@ -686,8 +708,8 @@ public class TaskService {
}
public Map<String, Object> getStatistics() {
List<String> pendingStatuses = List.of("pending", "ocr_completed");
List<String> auditedStatuses = List.of("compliant", "non-compliant");
List<String> pendingStatuses = Arrays.asList("pending", "ocr_completed");
List<String> auditedStatuses = Arrays.asList("compliant", "non-compliant");
LocalDate monthStart = LocalDate.now().withDayOfMonth(1);
Date monthStartDate = Date.from(monthStart.atStartOfDay(ZoneId.systemDefault()).toInstant());