This commit is contained in:
@@ -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