Make task APIs Java 8 compatible
This commit is contained in:
parent
ded3f2f537
commit
47fac2f6bc
|
|
@ -26,6 +26,7 @@ import java.util.Map;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
|
|
@ -157,10 +158,10 @@ 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(@RequestParam(value = "status", required = false) String status) {
|
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<>();
|
Map<String, Object> resp = new HashMap<>();
|
||||||
resp.put("code", 0);
|
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");
|
resp.put("msg", "Success");
|
||||||
return ResponseEntity.ok(resp);
|
return ResponseEntity.ok(resp);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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.InstitutionRepository;
|
||||||
import com.chinaweal.youfool.reportdetect.modules.sys.repository.SysUserRepository;
|
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.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.OCRResult;
|
||||||
import com.chinaweal.youfool.reportdetect.modules.task.entity.Page;
|
import com.chinaweal.youfool.reportdetect.modules.task.entity.Page;
|
||||||
import com.chinaweal.youfool.reportdetect.modules.task.entity.Task;
|
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.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -417,7 +421,7 @@ public class TaskService {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
detail.put("attachments", attachments);
|
detail.put("attachments", attachments);
|
||||||
} else {
|
} else {
|
||||||
detail.put("attachments", List.of());
|
detail.put("attachments", Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.getHistories() != null) {
|
if (task.getHistories() != null) {
|
||||||
|
|
@ -430,7 +434,7 @@ public class TaskService {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
detail.put("history", history);
|
detail.put("history", history);
|
||||||
} else {
|
} else {
|
||||||
detail.put("history", List.of());
|
detail.put("history", Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return detail;
|
return detail;
|
||||||
|
|
@ -438,42 +442,60 @@ public class TaskService {
|
||||||
|
|
||||||
private Set<String> mapStatusFilter(String statusParam) {
|
private Set<String> mapStatusFilter(String statusParam) {
|
||||||
String status = statusParam.trim();
|
String status = statusParam.trim();
|
||||||
return switch (status) {
|
switch (status) {
|
||||||
case "0" -> Set.of("ocr_pending");
|
case "0":
|
||||||
case "1" -> Set.of("pending");
|
return Collections.singleton("ocr_pending");
|
||||||
case "2" -> Set.of("compliant");
|
case "1":
|
||||||
case "3" -> Set.of("non-compliant");
|
return Collections.singleton("pending");
|
||||||
case "audited" -> Set.of("compliant", "non-compliant");
|
case "2":
|
||||||
default -> null;
|
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) {
|
private String mapStatusForList(String internalStatus) {
|
||||||
if (internalStatus == null) {
|
if (internalStatus == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return switch (internalStatus) {
|
switch (internalStatus) {
|
||||||
case "ocr_pending" -> "0";
|
case "ocr_pending":
|
||||||
case "ocr_completed" -> "1";
|
return "0";
|
||||||
case "pending" -> "1";
|
case "ocr_completed":
|
||||||
case "compliant" -> "2";
|
return "1";
|
||||||
case "non-compliant" -> "3";
|
case "pending":
|
||||||
default -> internalStatus;
|
return "1";
|
||||||
};
|
case "compliant":
|
||||||
|
return "2";
|
||||||
|
case "non-compliant":
|
||||||
|
return "3";
|
||||||
|
default:
|
||||||
|
return internalStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private String mapStatusForPreview(String internalStatus) {
|
private String mapStatusForPreview(String internalStatus) {
|
||||||
if (internalStatus == null) {
|
if (internalStatus == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return switch (internalStatus) {
|
switch (internalStatus) {
|
||||||
case "ocr_pending" -> "0";
|
case "ocr_pending":
|
||||||
case "ocr_completed" -> "4";
|
return "0";
|
||||||
case "pending" -> "1";
|
case "ocr_completed":
|
||||||
case "compliant" -> "2";
|
return "4";
|
||||||
case "non-compliant" -> "3";
|
case "pending":
|
||||||
default -> internalStatus;
|
return "1";
|
||||||
};
|
case "compliant":
|
||||||
|
return "2";
|
||||||
|
case "non-compliant":
|
||||||
|
return "3";
|
||||||
|
default:
|
||||||
|
return internalStatus;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional(readOnly = true)
|
@Transactional(readOnly = true)
|
||||||
|
|
@ -515,7 +537,7 @@ public class TaskService {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
preview.put("pages", pages);
|
preview.put("pages", pages);
|
||||||
} else {
|
} else {
|
||||||
preview.put("pages", List.of());
|
preview.put("pages", Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (task.getHistories() != null) {
|
if (task.getHistories() != null) {
|
||||||
|
|
@ -528,7 +550,7 @@ public class TaskService {
|
||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
preview.put("history", history);
|
preview.put("history", history);
|
||||||
} else {
|
} else {
|
||||||
preview.put("history", List.of());
|
preview.put("history", Collections.emptyList());
|
||||||
}
|
}
|
||||||
|
|
||||||
return preview;
|
return preview;
|
||||||
|
|
@ -686,8 +708,8 @@ public class TaskService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Object> getStatistics() {
|
public Map<String, Object> getStatistics() {
|
||||||
List<String> pendingStatuses = List.of("pending", "ocr_completed");
|
List<String> pendingStatuses = Arrays.asList("pending", "ocr_completed");
|
||||||
List<String> auditedStatuses = List.of("compliant", "non-compliant");
|
List<String> auditedStatuses = Arrays.asList("compliant", "non-compliant");
|
||||||
|
|
||||||
LocalDate monthStart = LocalDate.now().withDayOfMonth(1);
|
LocalDate monthStart = LocalDate.now().withDayOfMonth(1);
|
||||||
Date monthStartDate = Date.from(monthStart.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
Date monthStartDate = Date.from(monthStart.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue