This commit is contained in:
@@ -135,23 +135,32 @@ public class ViolationHandler implements RequestHandler {
|
|||||||
.messageBody(groupedData)
|
.messageBody(groupedData)
|
||||||
.build();
|
.build();
|
||||||
} else {
|
} else {
|
||||||
Page<Violation> violationPage;
|
// Page<Violation> violationPage;
|
||||||
|
//
|
||||||
if (startDate != null && endDate != null) {
|
// if (startDate != null && endDate != null) {
|
||||||
violationPage = violationService.getViolationsByFilesAndDateRange(
|
// violationPage = violationService.getViolationsByFilesAndDateRange(
|
||||||
targetFiles, startDate, endDate,
|
// targetFiles, startDate, endDate,
|
||||||
violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
// violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||||
);
|
// );
|
||||||
} else if (violationRequest.getStatus() != null && !violationRequest.getStatus().isEmpty()) {
|
// } else if (violationRequest.getStatus() != null && !violationRequest.getStatus().isEmpty()) {
|
||||||
violationPage = violationService.getViolationsByFilesAndStatus(
|
// violationPage = violationService.getViolationsByFilesAndStatus(
|
||||||
targetFiles, violationRequest.getStatus(),
|
// targetFiles, violationRequest.getStatus(),
|
||||||
violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
// violationRequest.getPage(), violationRequest.getSize(), violationRequest.getSortDirection()
|
||||||
);
|
// );
|
||||||
} else {
|
// } else {
|
||||||
violationPage = violationService.getViolationsByFiles(
|
// violationPage = violationService.getViolationsByFiles(
|
||||||
targetFiles, violationRequest.getPage(), violationRequest.getSize(),
|
// targetFiles, violationRequest.getPage(), violationRequest.getSize(),
|
||||||
violationRequest.getSortDirection());
|
// violationRequest.getSortDirection());
|
||||||
}
|
// }
|
||||||
|
Page<Violation> violationPage = violationService.getViolationsByFilesAndFilters(
|
||||||
|
targetFiles,
|
||||||
|
startDate,
|
||||||
|
endDate,
|
||||||
|
violationRequest.getStatus(),
|
||||||
|
violationRequest.getPage(),
|
||||||
|
violationRequest.getSize(),
|
||||||
|
violationRequest.getSortDirection()
|
||||||
|
);
|
||||||
|
|
||||||
ViolationResponse.ViolationDto firstShowViolation = null;
|
ViolationResponse.ViolationDto firstShowViolation = null;
|
||||||
List<Violation> content = violationPage.getContent();
|
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.Pageable;
|
||||||
import org.springframework.data.domain.Sort;
|
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.JpaSpecificationExecutor;
|
||||||
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;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
@@ -15,7 +16,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface ViolationRepository extends JpaRepository<Violation, Long> {
|
public interface ViolationRepository extends JpaRepository<Violation, Long>, JpaSpecificationExecutor<Violation> {
|
||||||
|
|
||||||
Page<Violation> findByFileEntity(FileEntity file, Pageable pageable);
|
Page<Violation> findByFileEntity(FileEntity file, Pageable pageable);
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
import org.springframework.data.domain.*;
|
import org.springframework.data.domain.*;
|
||||||
|
import org.springframework.data.jpa.domain.Specification;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import ru.soune.nocopy.dto.file.YandexSearchResponse;
|
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) {
|
public Violation getById(Long violationId) {
|
||||||
return violationRepository.findById(violationId).orElse(null);
|
return violationRepository.findById(violationId).orElse(null);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user