Added zip response
This commit is contained in:
parent
76525b3f8b
commit
d43a95e564
8 changed files with 62 additions and 15 deletions
|
|
@ -31,3 +31,5 @@ ct.xsd-validation.signal-package-path=signal-package.xsd
|
|||
ct.signals-root-uri=http://10.230.227.102:11094/signalRUalfa/
|
||||
ct.signals-token=gttcHxwcGojoAvZK
|
||||
ct.signals-user=0001ZZ000001
|
||||
|
||||
ct.load-dir=D:\\folder_name\\signals
|
||||
|
|
@ -26,4 +26,6 @@ public class CreditTrackerSettings {
|
|||
private String signalsToken;
|
||||
private String signalsuser;
|
||||
|
||||
private String loadDir;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ package ru.nbch.credit_tracker.entities.response.monitoring_signal_response;
|
|||
|
||||
import jakarta.xml.bind.annotation.XmlAccessType;
|
||||
import jakarta.xml.bind.annotation.XmlAccessorType;
|
||||
import jakarta.xml.bind.annotation.XmlAttribute;
|
||||
import jakarta.xml.bind.annotation.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
|
@ -16,10 +16,10 @@ import lombok.Setter;
|
|||
"inquiryPurpose"
|
||||
})
|
||||
public class Signal {
|
||||
@XmlAttribute(name = "SignalType", required = true)
|
||||
@XmlElement(name = "SignalType", required = true)
|
||||
protected Integer signalType;
|
||||
@XmlAttribute(name = "InquiryDate", required = true)
|
||||
@XmlElement(name = "InquiryDate", required = true)
|
||||
protected String inquiryDate;
|
||||
@XmlAttribute(name = "InquiryPurpose", required = true)
|
||||
@XmlElement(name = "InquiryPurpose", required = true)
|
||||
protected Integer inquiryPurpose;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,11 +12,12 @@ import lombok.Setter;
|
|||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "SubjectType", propOrder = {
|
||||
@XmlType(name = "", propOrder = {
|
||||
"id",
|
||||
"clientId",
|
||||
"flagDebt5000",
|
||||
"flag9012"
|
||||
"flag9012",
|
||||
"signals"
|
||||
})
|
||||
public class Subject {
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"subject"
|
||||
"subjects"
|
||||
})
|
||||
public class Subjects {
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.nbch.credit_tracker.service;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.nbch.credit_tracker.config.settings.CreditTrackerSettings;
|
||||
import ru.nbch.credit_tracker.entities.response.monitoring_signal_response.*;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.Inquiry;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.OnlineDownloadReport;
|
||||
|
|
@ -14,12 +15,17 @@ import ru.nbch.credit_tracker.service.xml.jaxb.XmlUtilService;
|
|||
import ru.nbch.credit_tracker.utils.CTUtil;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.nio.charset.Charset;
|
||||
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;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
|
|
@ -28,14 +34,16 @@ public class MonitoringService {
|
|||
private final SignalRestService signalRestService;
|
||||
private final SignalService signalService;
|
||||
private final XmlUtilService xmlUtilService;
|
||||
private final CreditTrackerSettings config;
|
||||
|
||||
public MonitoringService(SignalRestService signalRestService,
|
||||
SignalService signalService,
|
||||
XmlUtilService xmlUtilService) {
|
||||
XmlUtilService xmlUtilService,
|
||||
CreditTrackerSettings config) {
|
||||
this.signalRestService = signalRestService;
|
||||
this.signalService = signalService;
|
||||
this.xmlUtilService = xmlUtilService;
|
||||
monitor();
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public void monitor() {
|
||||
|
|
@ -66,7 +74,7 @@ public class MonitoringService {
|
|||
}
|
||||
|
||||
MonitoringSignalResponse response = generateResponse(packageData, report.getPersons().getPersons());
|
||||
|
||||
createResponseFile(packageData, response);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -106,6 +114,33 @@ public class MonitoringService {
|
|||
return response;
|
||||
}
|
||||
|
||||
private void createResponseFile(SignalService.PackageData packageData, MonitoringSignalResponse response) {
|
||||
try {
|
||||
String fileName = CTUtil.generateResponseReportFileName(packageData.getUserId(), packageData.getPackageName());
|
||||
String filePath = config.getLoadDir() + File.separator + packageData.getUserId().substring(0, 6) + File.separator;
|
||||
|
||||
File folder = new File(filePath);
|
||||
if (!folder.exists()) {
|
||||
folder.mkdir();
|
||||
}
|
||||
|
||||
IXmlProcessor processor = xmlUtilService.createJaxbProcessor();
|
||||
String xmlStr = processor.asString(response, true);
|
||||
|
||||
byte[] xmlBytes = xmlStr.getBytes(Charset.forName("windows-1251"));
|
||||
try (FileOutputStream fos = new FileOutputStream(filePath + fileName + ".zip");
|
||||
ZipOutputStream zos = new ZipOutputStream(fos)) {
|
||||
|
||||
ZipEntry zipEntry = new ZipEntry(fileName + ".xml");
|
||||
zos.putNextEntry(zipEntry);
|
||||
zos.write(xmlBytes);
|
||||
zos.closeEntry();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("Ошибка при записи отчета пользователя в файл: ", e);
|
||||
}
|
||||
}
|
||||
|
||||
private OnlineDownloadReport loadReport(String reportName) {
|
||||
byte[] archive = signalRestService.downloadReport(reportName);
|
||||
if (archive == null) {
|
||||
|
|
|
|||
|
|
@ -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.monitoring_signal_response.MonitoringSignalResponse;
|
||||
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;
|
||||
|
|
@ -35,7 +36,8 @@ public class XmlUtilService {
|
|||
// marshalling classes
|
||||
Signals.class,
|
||||
MonitoringError.class,
|
||||
MonitoringResponse.class);
|
||||
MonitoringResponse.class,
|
||||
MonitoringSignalResponse.class);
|
||||
}
|
||||
|
||||
public void validateXMLByXSD(InputStream xmlStream, String xsdPath) throws IOException, XMLStreamException, SAXException {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import java.util.regex.Pattern;
|
|||
public class CTUtil {
|
||||
|
||||
private static DateTimeFormatter onlineReportDateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH-mm-ss");
|
||||
private static DateTimeFormatter responseReportDateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMdd_HHmmss");
|
||||
|
||||
|
||||
public static LocalDateTime parseDateFromReportFileName(String reportFileName) {
|
||||
|
|
@ -35,4 +36,8 @@ public class CTUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static String generateResponseReportFileName(String userId, String packageName) {
|
||||
return userId.substring(0,6) + "_" + packageName + "_" + LocalDateTime.now().format(responseReportDateTimeFormatter);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue