This commit is contained in:
@@ -135,23 +135,32 @@ public class ViolationHandler implements RequestHandler {
|
||||
.messageBody(groupedData)
|
||||
.build();
|
||||
} else {
|
||||
Page<Violation> violationPage;
|
||||
|
||||
if (startDate != null && endDate != null) {
|
||||
violationPage = violationService.getViolationsByFilesAndDateRange(
|
||||
targetFiles, startDate, endDate,
|
||||
violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||
);
|
||||
} else if (violationRequest.getStatus() != null && !violationRequest.getStatus().isEmpty()) {
|
||||
violationPage = violationService.getViolationsByFilesAndStatus(
|
||||
targetFiles, violationRequest.getStatus(),
|
||||
violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||
);
|
||||
} else {
|
||||
violationPage = violationService.getViolationsByFiles(
|
||||
targetFiles, violationRequest.getPage(), violationRequest.getSize(),
|
||||
violationRequest.getSortDirection());
|
||||
}
|
||||
// Page<Violation> violationPage;
|
||||
//
|
||||
// if (startDate != null && endDate != null) {
|
||||
// violationPage = violationService.getViolationsByFilesAndDateRange(
|
||||
// targetFiles, startDate, endDate,
|
||||
// violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||
// );
|
||||
// } else if (violationRequest.getStatus() != null && !violationRequest.getStatus().isEmpty()) {
|
||||
// violationPage = violationService.getViolationsByFilesAndStatus(
|
||||
// targetFiles, violationRequest.getStatus(),
|
||||
// violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||
// );
|
||||
// } else {
|
||||
// violationPage = violationService.getViolationsByFiles(
|
||||
// targetFiles, violationRequest.getPage(), violationRequest.getSize(),
|
||||
// violationRequest.getSortDirection());
|
||||
// }
|
||||
Page<Violation> violationPage = violationService.getViolationsByFilesAndFilters(
|
||||
targetFiles,
|
||||
startDate,
|
||||
endDate,
|
||||
violationRequest.getStatus(),
|
||||
violationRequest.getPage(),
|
||||
violationRequest.getSize(),
|
||||
violationRequest.getSortDirection()
|
||||
);
|
||||
|
||||
ViolationResponse.ViolationDto firstShowViolation = null;
|
||||
List<Violation> content = violationPage.getContent();
|
||||
|
||||
@@ -4,6 +4,7 @@ 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.JpaSpecificationExecutor;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.stereotype.Repository;
|
||||
@@ -15,7 +16,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface ViolationRepository extends JpaRepository<Violation, Long> {
|
||||
public interface ViolationRepository extends JpaRepository<Violation, Long>, JpaSpecificationExecutor<Violation> {
|
||||
|
||||
Page<Violation> findByFileEntity(FileEntity file, Pageable pageable);
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.codec.digest.DigestUtils;
|
||||
import org.springframework.data.domain.*;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import ru.soune.nocopy.dto.file.YandexSearchResponse;
|
||||
@@ -71,6 +72,34 @@ public class ViolationService {
|
||||
}
|
||||
}
|
||||
|
||||
public Page<Violation> getViolationsByFilesAndFilters(
|
||||
List<FileEntity> targetFiles,
|
||||
LocalDateTime startDate,
|
||||
LocalDateTime endDate,
|
||||
String status,
|
||||
int page, int size, String sortDirection) {
|
||||
Specification<Violation> spec = (root, query, cb) -> cb.conjunction();
|
||||
|
||||
if (targetFiles != null && !targetFiles.isEmpty()) {
|
||||
spec = spec.and((root, query, cb) -> root.get("file").in(targetFiles));
|
||||
}
|
||||
|
||||
if (startDate != null && endDate != null) {
|
||||
spec = spec.and((root, query, cb) ->
|
||||
cb.between(root.get("violationDate"), startDate, endDate));
|
||||
}
|
||||
|
||||
if (status != null && !status.isEmpty()) {
|
||||
spec = spec.and((root, query, cb) ->
|
||||
cb.equal(root.get("status"), status));
|
||||
}
|
||||
|
||||
Sort sort = Sort.by("ASC".equalsIgnoreCase(sortDirection) ?
|
||||
Sort.Direction.ASC : Sort.Direction.DESC, "violationDate");
|
||||
|
||||
return violationRepository.findAll(spec, PageRequest.of(page, size, sort));
|
||||
}
|
||||
|
||||
public Violation getById(Long violationId) {
|
||||
return violationRepository.findById(violationId).orElse(null);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user