Added loading Report by fileName and parsing it
This commit is contained in:
parent
7f6e56a835
commit
a9332dd71e
9 changed files with 222 additions and 5 deletions
|
|
@ -0,0 +1,45 @@
|
|||
package ru.nbch.credit_tracker.entities.response.online_download;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"signals"
|
||||
})
|
||||
public class Inquiry {
|
||||
|
||||
@XmlAttribute(name = "own", required = true)
|
||||
protected String own;
|
||||
@XmlAttribute(name = "inq_p", required = true)
|
||||
protected String inqP;
|
||||
@XmlAttribute(name = "currency", required = true)
|
||||
protected String currency;
|
||||
@XmlAttribute(name = "serial_num", required = true)
|
||||
protected String serialNum;
|
||||
@XmlAttribute(name = "date", required = true)
|
||||
protected String date;
|
||||
@XmlAttribute(name = "bus_category", required = true)
|
||||
protected String busCategory;
|
||||
@XmlAttribute(name = "inq_t", required = true)
|
||||
protected String inqT;
|
||||
@XmlAttribute(name = "channel", required = true)
|
||||
protected String channel;
|
||||
|
||||
@XmlElement(name = "Signal", required = true)
|
||||
protected List<Signal> signals;
|
||||
|
||||
public List<Signal> getSignals() {
|
||||
if (signals == null) {
|
||||
signals = new ArrayList<>();
|
||||
}
|
||||
return this.signals;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package ru.nbch.credit_tracker.entities.response.online_download;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"id",
|
||||
"version",
|
||||
"user",
|
||||
"reportCreated",
|
||||
"persons"
|
||||
})
|
||||
@XmlRootElement(name = "Report")
|
||||
public class OnlineDownloadReport {
|
||||
|
||||
@XmlElement(name = "Id", required = true)
|
||||
protected String id;
|
||||
@XmlElement(name = "Version", required = true)
|
||||
protected String version;
|
||||
@XmlElement(name = "User", required = true)
|
||||
protected String user;
|
||||
@XmlElement(name = "ReportCreated", required = true)
|
||||
protected String reportCreated;
|
||||
@XmlElement(name = "Persons", required = true)
|
||||
protected Persons persons;
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
package ru.nbch.credit_tracker.entities.response.online_download;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"inquiry"
|
||||
})
|
||||
public class Person {
|
||||
|
||||
@XmlAttribute(name = "uid", required = true)
|
||||
protected String uid;
|
||||
|
||||
@XmlElement(name = "Inquiry", required = true)
|
||||
protected Inquiry inquiry;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package ru.nbch.credit_tracker.entities.response.online_download;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"persons"
|
||||
})
|
||||
public class Persons {
|
||||
|
||||
@XmlElement(name = "Person", required = true)
|
||||
protected List<Person> persons;
|
||||
|
||||
public List<Person> getPersons() {
|
||||
if (persons == null) {
|
||||
persons = new ArrayList<>();
|
||||
}
|
||||
return this.persons;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
package ru.nbch.credit_tracker.entities.response.online_download;
|
||||
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlAttribute;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
})
|
||||
public class Signal {
|
||||
@XmlAttribute(name = "n", required = true)
|
||||
protected Integer n;
|
||||
}
|
||||
|
|
@ -1,26 +1,39 @@
|
|||
package ru.nbch.credit_tracker.service;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.OnlineDownloadReport;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.Person;
|
||||
import ru.nbch.credit_tracker.entities.response.online_report.Report;
|
||||
import ru.nbch.credit_tracker.entities.response.online_report.SgnlOnlineReport;
|
||||
import ru.nbch.credit_tracker.service.signal.SignalRestService;
|
||||
import ru.nbch.credit_tracker.service.xml.jaxb.IXmlProcessor;
|
||||
import ru.nbch.credit_tracker.service.xml.jaxb.XmlUtilService;
|
||||
import ru.nbch.credit_tracker.utils.CTUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MonitoringService {
|
||||
|
||||
private final SignalRestService signalRestService;
|
||||
private final SignalService signalService;
|
||||
private final XmlUtilService xmlUtilService;
|
||||
|
||||
public MonitoringService(SignalRestService signalRestService, SignalService signalService) {
|
||||
public MonitoringService(SignalRestService signalRestService,
|
||||
SignalService signalService,
|
||||
XmlUtilService xmlUtilService) {
|
||||
this.signalRestService = signalRestService;
|
||||
this.signalService = signalService;
|
||||
this.xmlUtilService = xmlUtilService;
|
||||
monitor();
|
||||
}
|
||||
|
||||
public void monitor() {
|
||||
|
|
@ -37,18 +50,48 @@ public class MonitoringService {
|
|||
|
||||
LocalDateTime lastDownloadedReportDate = CTUtil.parseDateFromReportFileName(packageData.getLastDownloadedReport());
|
||||
|
||||
OnlineDownloadReport report = null;
|
||||
if (packageData.getLastDownloadedReport() == null && newReport.isPresent()) {
|
||||
loadReport(newReport.get()); // по этому пакету еще не было загруженных отчетов, продолжаем работу с полученным
|
||||
report = loadReport(newReport.get()); // по этому пакету еще не было загруженных отчетов, продолжаем работу с полученным
|
||||
} else if (lastDownloadedReportDate != null && newReport.isPresent()) {
|
||||
LocalDateTime newReportDate = CTUtil.parseDateFromReportFileName(newReport.get());
|
||||
if (newReportDate.isAfter(lastDownloadedReportDate)) {
|
||||
loadReport(newReport.get()); // полученный отчет новее записанного в базу
|
||||
report = loadReport(newReport.get()); // полученный отчет новее записанного в базу
|
||||
}
|
||||
}
|
||||
if (report == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Отбирает только тех фл, у которых bus_category in (MFO, MKK, MFK) и есть сигналы с кодом 16
|
||||
List<Person> validPersons = report.getPersons().getPersons().stream().filter(person -> CTUtil.checkBusCategory(person.getInquiry().getBusCategory()))
|
||||
.filter(person -> person.getInquiry().getSignals().stream().anyMatch(signal -> signal.getN().equals(16))).toList();
|
||||
|
||||
createRsponse(packageData, validPersons);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadReport(String report) {
|
||||
private void createRsponse(SignalService.PackageData packageData, List<Person> validPersons) {
|
||||
|
||||
}
|
||||
|
||||
private OnlineDownloadReport loadReport(String reportName) {
|
||||
byte[] archive = signalRestService.downloadReport(reportName);
|
||||
if (archive == null) {
|
||||
return null;
|
||||
}
|
||||
OnlineDownloadReport report;
|
||||
try (GZIPInputStream zipInputStream = new GZIPInputStream(new ByteArrayInputStream(archive))) {
|
||||
|
||||
IXmlProcessor processor = xmlUtilService.createJaxbProcessor();
|
||||
report = processor.read(zipInputStream, OnlineDownloadReport.class);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return report;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ public class SignalRestService {
|
|||
private static String UPDATE_URI = "update";
|
||||
private static String DELETE_URI = "delete";
|
||||
private static String GET_REPORTS_URI = "onlinereport";
|
||||
private static String DOWNLOAD_REPORT_URI = "onlinedownload";
|
||||
|
||||
private final RestTemplate restTemplate;
|
||||
private final XmlUtilService xmlUtilService;
|
||||
|
|
@ -138,6 +139,24 @@ public class SignalRestService {
|
|||
return response.getBody();
|
||||
}
|
||||
|
||||
public byte[] downloadReport(String reportName) {
|
||||
String url = DOWNLOAD_REPORT_URI + "?fNameReport=" + reportName;
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setBasicAuth(authToken);
|
||||
|
||||
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
||||
|
||||
ResponseEntity<byte[]> response = restTemplate.exchange(
|
||||
url,
|
||||
HttpMethod.GET,
|
||||
requestEntity,
|
||||
byte[].class
|
||||
);
|
||||
|
||||
return response.getBody();
|
||||
}
|
||||
|
||||
private String buildToken(String signalsToken, String signalsuser) throws Exception {
|
||||
try {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.xml.sax.SAXException;
|
||||
import ru.nbch.credit_tracker.entities.request.monitoring_request.MonitoringRequest;
|
||||
import ru.nbch.credit_tracker.entities.response.errors.MonitoringError;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.OnlineDownloadReport;
|
||||
import ru.nbch.credit_tracker.entities.response.success.MonitoringResponse;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Signals;
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ public class XmlUtilService {
|
|||
return new XmlProcessorImplAnyClasses(Charset.forName("windows-1251"),
|
||||
// unmarshalling classes
|
||||
MonitoringRequest.class,
|
||||
OnlineDownloadReport.class,
|
||||
// marshalling classes
|
||||
Signals.class,
|
||||
MonitoringError.class,
|
||||
|
|
|
|||
|
|
@ -23,5 +23,16 @@ public class CTUtil {
|
|||
return LocalDateTime.parse(dateTimeStr, onlineReportDateTimeFormatter);
|
||||
}
|
||||
return null;
|
||||
};
|
||||
}
|
||||
|
||||
public static boolean checkBusCategory(String busCategory) {
|
||||
switch (busCategory) {
|
||||
case "MFO", "MKK", "MFK", "BANK" -> { // TODO remove bank after testing
|
||||
return true;
|
||||
}
|
||||
default -> {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue