@@ -185,27 +185,63 @@ public class ViolationService {
|
|||||||
Collectors.counting()));
|
Collectors.counting()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
||||||
|
// LocalDateTime startDate, LocalDateTime endDate,
|
||||||
|
// String sortDirection) {
|
||||||
|
// List<Violation> violations;
|
||||||
|
//
|
||||||
|
// Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC,
|
||||||
|
// "createdDate");
|
||||||
|
//
|
||||||
|
// if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
||||||
|
// violations = violationRepository.findByFileEntityInAndStatusAndCreatedDateBetween(files, status, startDate, endDate, sort);
|
||||||
|
// } else if (status != null && !status.isEmpty()) {
|
||||||
|
// violations = violationRepository.findByFileEntityInAndStatus(files, status, sort);
|
||||||
|
// } else if (startDate != null && endDate != null) {
|
||||||
|
// violations = violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate, sort);
|
||||||
|
// } else {
|
||||||
|
// violations = violationRepository.findByFileEntityIn(files, sort);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return violations.stream()
|
||||||
|
// .collect(Collectors.groupingBy(
|
||||||
|
// v -> extractGroupKey(v.getPageUrl(), groupBy),
|
||||||
|
// Collectors.counting()));
|
||||||
|
// }
|
||||||
|
|
||||||
public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
public Map<String, Long> getGroupedViolations(List<FileEntity> files, String groupBy, String status,
|
||||||
LocalDateTime startDate, LocalDateTime endDate,
|
LocalDateTime startDate, LocalDateTime endDate,
|
||||||
String sortDirection) {
|
String sortDirection) {
|
||||||
List<Violation> violations;
|
List<Violation> violations;
|
||||||
|
|
||||||
Sort sort = Sort.by(sortDirection.equalsIgnoreCase("desc") ? Sort.Direction.DESC : Sort.Direction.ASC, "createdDate");
|
|
||||||
|
|
||||||
if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
if (status != null && !status.isEmpty() && startDate != null && endDate != null) {
|
||||||
violations = violationRepository.findByFileEntityInAndStatusAndCreatedDateBetween(files, status, startDate, endDate, sort);
|
violations = violationRepository.findByFileEntityInAndStatusAndCreatedDateBetween(files, status, startDate, endDate);
|
||||||
} else if (status != null && !status.isEmpty()) {
|
} else if (status != null && !status.isEmpty()) {
|
||||||
violations = violationRepository.findByFileEntityInAndStatus(files, status, sort);
|
violations = violationRepository.findByFileEntityInAndStatus(files, status);
|
||||||
} else if (startDate != null && endDate != null) {
|
} else if (startDate != null && endDate != null) {
|
||||||
violations = violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate, sort);
|
violations = violationRepository.findByFileEntityInAndCreatedDateBetween(files, startDate, endDate);
|
||||||
} else {
|
} else {
|
||||||
violations = violationRepository.findByFileEntityIn(files, sort);
|
violations = violationRepository.findByFileEntityIn(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
return violations.stream()
|
Map<String, Long> grouped = violations.stream()
|
||||||
.collect(Collectors.groupingBy(
|
.collect(Collectors.groupingBy(
|
||||||
v -> extractGroupKey(v.getPageUrl(), groupBy),
|
v -> extractGroupKey(v.getPageUrl(), groupBy),
|
||||||
Collectors.counting()));
|
Collectors.counting()));
|
||||||
|
|
||||||
|
return grouped.entrySet().stream()
|
||||||
|
.sorted((e1, e2) -> {
|
||||||
|
if (sortDirection.equalsIgnoreCase("desc")) {
|
||||||
|
return e2.getValue().compareTo(e1.getValue());
|
||||||
|
} else {
|
||||||
|
return e1.getValue().compareTo(e2.getValue());
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect(Collectors.toMap(
|
||||||
|
Map.Entry::getKey,
|
||||||
|
Map.Entry::getValue,
|
||||||
|
(e1, e2) -> e1,
|
||||||
|
LinkedHashMap::new));
|
||||||
}
|
}
|
||||||
|
|
||||||
public ViolationStatisticsResponse getViolationStatistics(Long userId, String fileId,
|
public ViolationStatisticsResponse getViolationStatistics(Long userId, String fileId,
|
||||||
|
|||||||
Reference in New Issue
Block a user