/
linto
/
opensearch-example
Обзор
Документация
Войти
/
linto
/
opensearch-example
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/main/java/com/example/demo/service/IndexUpdateService.java
64 строки
2 KB
linto
init
30 июл 2025, 11:44
30 июл 2025, 11:44
dc5aaf3
Код
Авторство
О чём код?
package com.example.demo.service; import java.util.List; import com.example.demo.opensearch.model.Root; public interface IndexUpdateService { void update(List<Root> entities); // private final SubjectRepository subjectRepository; // private final SubjectIndexedRepository subjectIndexedRepository; // @Scheduled(fixedDelay = 60000) // public void sync() { // LocalDateTime fromDate; // Page<Subject> page = subjectRepository // .findAll(PageRequest.of(0, 1, Sort.by(Direction.DESC, "updatedat"))); // fromDate = page.hasContent() // ? page.getContent().iterator().next().getCreatedat().minusSeconds(1) // : LocalDateTime.now().minusSeconds(1); // Specification<Subject> spec = (root, query, builder) -> builder.greaterThan(root.get(Subject_.createdat), // fromDate); // Page<Subject> subjectsPage = subjectRepository.findAll(spec, // PageRequest.of(0, 500, Sort.by("updatedat"))); // long indexed = 0; // while (subjectsPage.hasContent()) { // subjectIndexedRepository.saveAll( // subjectsPage.getContent().stream().filter(c -> c.getDeleted() == 0).map(this::toIndexedDocument) // .collect(Collectors.toList())); // subjectIndexedRepository.deleteAll( // subjectsPage.getContent().stream().filter(c -> c.getDeleted() == 1).map(this::toIndexedDocument) // .collect(Collectors.toList())); // indexed += subjectsPage.getTotalElements(); // if (!subjectsPage.hasNext()) { // break; // } // subjectsPage = subjectRepository.findAll(spec, subjectsPage.nextPageable()); // } // log.info("{} subjects indexed", indexed); // } // private SubjectIndexed toIndexedDocument(Subject dto) { // SubjectIndexed entity = new SubjectIndexed(); // entity.setId(dto.getId()); // entity.setInn(dto.getInn()); // entity.setKpp(dto.getKpp()); // entity.setName(dto.getName()); // entity.setOgrn(dto.getOgrn()); // entity.setCreatedat(dto.getCreatedat().atZone(ZoneId.systemDefault()).toInstant()); // entity.setUpdatedat(dto.getUpdatedat().atZone(ZoneId.systemDefault()).toInstant()); // return entity; // } }