@@ -72,7 +72,8 @@ public class ViolationHandler implements RequestHandler {
|
||||
violationRequest.getGroupBy(),
|
||||
violationRequest.getStatus(),
|
||||
startDate,
|
||||
endDate);
|
||||
endDate,
|
||||
violationRequest.getSortDirection());
|
||||
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
|
||||
@@ -2,6 +2,7 @@ package ru.soune.nocopy.repository;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
@@ -62,4 +63,15 @@ public interface ViolationRepository extends JpaRepository<Violation, Long> {
|
||||
|
||||
@Query("SELECT COUNT(v) FROM Violation v WHERE v.globalSearchResult.taskId = :taskId")
|
||||
long countByGlobalSearchResultTaskId(@Param("taskId") String taskId);
|
||||
|
||||
List<Violation> findByFileEntityIn(List<FileEntity> files, Sort sort);
|
||||
|
||||
List<Violation> findByFileEntityInAndStatus(List<FileEntity> files, String status, Sort sort);
|
||||
|
||||
List<Violation> findByFileEntityInAndCreatedDateBetween(List<FileEntity> files, LocalDateTime startDate,
|
||||
LocalDateTime endDate, Sort sort);
|
||||
|
||||
List<Violation> findByFileEntityInAndStatusAndCreatedDateBetween(List<FileEntity> files, String status,
|
||||
LocalDateTime startDate, LocalDateTime endDate,
|
||||
Sort sort);
|
||||
}
|
||||
@@ -182,8 +182,30 @@ public class ViolationService {
|
||||
return violations.stream()
|
||||
.collect(Collectors.groupingBy(
|
||||
v -> extractGroupKey(v.getPageUrl(), groupBy),
|
||||
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 ViolationStatisticsResponse getViolationStatistics(Long userId, String fileId,
|
||||
|
||||
Reference in New Issue
Block a user