dev add violation notion
Test Workflow / test (push) Successful in 4s

This commit is contained in:
vladp
2026-03-18 17:55:14 +07:00
parent 02b8d3ee6d
commit c7660c30de
3 changed files with 38 additions and 3 deletions
@@ -72,7 +72,8 @@ public class ViolationHandler implements RequestHandler {
violationRequest.getGroupBy(), violationRequest.getGroupBy(),
violationRequest.getStatus(), violationRequest.getStatus(),
startDate, startDate,
endDate); endDate,
violationRequest.getSortDirection());
return BaseResponse.builder() return BaseResponse.builder()
.msgId(request.getMsgId()) .msgId(request.getMsgId())
@@ -2,6 +2,7 @@ package ru.soune.nocopy.repository;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; 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.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; 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") @Query("SELECT COUNT(v) FROM Violation v WHERE v.globalSearchResult.taskId = :taskId")
long countByGlobalSearchResultTaskId(@Param("taskId") String 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() return violations.stream()
.collect(Collectors.groupingBy( .collect(Collectors.groupingBy(
v -> extractGroupKey(v.getPageUrl(), groupBy), 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, public ViolationStatisticsResponse getViolationStatistics(Long userId, String fileId,