remove sneaky exceptions

This commit is contained in:
RM
2026-10-01 21:29:56 +03:00
parent 01ea006d95
commit c6183a88ef
2 changed files with 28 additions and 25 deletions

View File

@@ -8,7 +8,6 @@ import com.pledge.torgi.service.DownloadHeadlessService;
import com.pledge.torgi.service.Lot;
import com.pledge.torgi.service.SendEmailService;
import com.pledge.torgi.utils.StartParams;
import lombok.SneakyThrows;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
@@ -139,29 +138,32 @@ public class DownloadHeadlessController {
fis.close();
}
@SneakyThrows
public void richData() {
List<MissedData> all = missedDataRepository.findAll(PageRequest.of(0, 10)).toList();
DownloadHeadlessService downloadHeadlessService = new DownloadHeadlessService();
for (MissedData missedCadastral : all) {
Map<String, Lot> currentContent = downloadHeadlessService.downloadExcel(0, String.format(CUSTOM_EXCEL_LINK, missedCadastral.getCadastral()));
logger.error("get content by cadastral {} {}", missedCadastral.getCadastral(), currentContent.size());
if (!currentContent.isEmpty()) {
List<TorgiEvent> newEvents = new ArrayList<>();
Set<String> contentByCadastral = new HashSet<>();
eventRepository.findAllByFullInfoLikeOrderByCreatedAtDesc("%" + missedCadastral.getCadastral() + "%").forEach(event -> contentByCadastral.add(event.getKey()));
try {
List<MissedData> all = missedDataRepository.findAll(PageRequest.of(0, 10)).toList();
DownloadHeadlessService downloadHeadlessService = new DownloadHeadlessService();
for (MissedData missedCadastral : all) {
Map<String, Lot> currentContent = downloadHeadlessService.downloadExcel(0, String.format(CUSTOM_EXCEL_LINK, missedCadastral.getCadastral()));
logger.error("get content by cadastral {} {}", missedCadastral.getCadastral(), currentContent.size());
if (!currentContent.isEmpty()) {
List<TorgiEvent> newEvents = new ArrayList<>();
Set<String> contentByCadastral = new HashSet<>();
eventRepository.findAllByFullInfoLikeOrderByCreatedAtDesc("%" + missedCadastral.getCadastral() + "%").forEach(event -> contentByCadastral.add(event.getKey()));
for (String key : currentContent.keySet()) {
if (!contentByCadastral.contains(key)) {
newEvents.add(new TorgiEvent(key, currentContent.get(key)));
content.add(key);
logger.error("added new missed content");
for (String key : currentContent.keySet()) {
if (!contentByCadastral.contains(key)) {
newEvents.add(new TorgiEvent(key, currentContent.get(key)));
content.add(key);
logger.error("added new missed content");
}
}
eventRepository.saveAll(newEvents);
}
eventRepository.saveAll(newEvents);
missedDataRepository.delete(missedCadastral);
Thread.sleep(5000);
}
missedDataRepository.delete(missedCadastral);
Thread.sleep(5000);
} catch (Exception ex) {
logger.error("Exception during rich data", ex);
}
}
}

View File

@@ -3,7 +3,6 @@ package com.pledge.torgi.service;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.pledge.torgi.model.TorgiEvent;
import com.pledge.torgi.repositories.TorgiEventRepository;
import lombok.SneakyThrows;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
@@ -12,9 +11,7 @@ import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.PageRequest;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.net.HttpURLConnection;
@@ -43,7 +40,6 @@ public class DownloadHeadlessService {
private static final int COL_FINAL_PRICE = 27;
private static final int COL_FULL_INFO = 29;
@SneakyThrows
public Map<String, Lot> downloadExcel(int retryCount, String link) {
try {
HttpURLConnection connection = (HttpURLConnection) new URL(link).openConnection();
@@ -85,8 +81,13 @@ public class DownloadHeadlessService {
return new HashMap<>();
}
}
Thread.sleep(1000);
return downloadExcel(retryCount + 1, link);
try {
Thread.sleep(1000);
return downloadExcel(retryCount + 1, link);
} catch (Exception ex) {
logger.error("Exception during retry downloadExcel by link {}", link, ex);
return new HashMap<>();
}
}
private Lot extractDataFromRow(Row row, String cadastral) {