http://jira.mfd.msk:8088/browse/BKI-3199 Added MonitoringReportErrorsStaxtReader and updating error_text column
This commit is contained in:
parent
6a350bfd17
commit
d4bef965c3
8 changed files with 192 additions and 5 deletions
|
|
@ -38,6 +38,7 @@ public class XmlConfig {
|
|||
staxReader.add(MonitoringRequestStaxReader::new);
|
||||
staxReader.add(OnlineDownloadReportPersonsStaxReader::new);
|
||||
staxReader.add(MonitoringSignalResponseStaxXmlReader::new);
|
||||
staxReader.add(MonitoringReportErrorsStaxtReader::new);
|
||||
return new XmlProcessorStaxImpl(staxReader);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package ru.nbch.credit_tracker.entities.external_response.monitoring_report_error;
|
||||
|
||||
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 = {
|
||||
"id",
|
||||
"version",
|
||||
"user",
|
||||
"reportCreated"
|
||||
})
|
||||
@XmlRootElement(name = "Errors")
|
||||
public class MonitoringReportErrors {
|
||||
|
||||
@XmlElement(name = "Id")
|
||||
protected String id;
|
||||
|
||||
@XmlElement(name = "Version")
|
||||
protected String version;
|
||||
|
||||
@XmlElement(name = "User")
|
||||
protected String user;
|
||||
|
||||
@XmlElement(name = "ReportCreated")
|
||||
protected String reportCreated;
|
||||
|
||||
@XmlElement(name = "p")
|
||||
protected List<P> persons;
|
||||
|
||||
public List<P> getPersons() {
|
||||
if (persons == null) {
|
||||
persons = new ArrayList<>();
|
||||
}
|
||||
return this.persons;
|
||||
}
|
||||
|
||||
private P currentPerson;
|
||||
|
||||
public void createCurrentPerson() {
|
||||
currentPerson = new P();
|
||||
}
|
||||
|
||||
public P getCurrentPerson() {
|
||||
return currentPerson;
|
||||
}
|
||||
|
||||
public void finalizePerson() {
|
||||
getPersons().add(currentPerson);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
})
|
||||
public static class P {
|
||||
|
||||
@XmlAttribute(name = "uid")
|
||||
protected Integer uid;
|
||||
|
||||
@XmlValue
|
||||
protected String value;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ public class SignalFacade {
|
|||
}
|
||||
request.getSubjects().getSubject().clear();
|
||||
},
|
||||
request-> request.getSubjects().getSubject().isEmpty()
|
||||
request -> request.getSubjects().getSubject().isEmpty()
|
||||
,
|
||||
40000, "/MonitoringRequest/Subjects/Subject");
|
||||
} catch (IOException e) {
|
||||
|
|
@ -248,7 +248,13 @@ public class SignalFacade {
|
|||
if (StringUtils.isNotBlank(fileName)) {
|
||||
String filePath = signalRestService.loadErrorFile(packageId, fileName);
|
||||
if (StringUtils.isNotBlank(filePath)) {
|
||||
signalService.updateSubjectsErrors(filePath);
|
||||
try {
|
||||
signalService.updateSubjectsErrors(filePath, packageId);
|
||||
CTUtil.removeFile(filePath);
|
||||
} catch (Exception e) {
|
||||
log.error("Ошибка при записи сообщений об ошибках в сформированных субъектах для мониторинга. Файл ошибок не будет удален. filePath = {}, Package_id = {}",
|
||||
fileName, packageId, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,8 @@ public interface PhoneFidMapMapper {
|
|||
|
||||
void updatePhoneFidMaps(@Param("subjects") List<PhoneFidMap> subjects);
|
||||
|
||||
void updatePhoneFidMapsErrors(@Param("subjects") List<PhoneFidMap> subjects);
|
||||
|
||||
PhoneFidMap findPhoneFidMapById(@Param("id") Integer packageId);
|
||||
|
||||
boolean hasNonNullFids(@Param("packageId") Integer packageId);
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import ru.nbch.credit_tracker.entities.dto.UserPackage;
|
|||
import ru.nbch.credit_tracker.entities.external_request.signals.Auth;
|
||||
import ru.nbch.credit_tracker.entities.external_request.signals.Person;
|
||||
import ru.nbch.credit_tracker.entities.external_request.signals.Signals;
|
||||
import ru.nbch.credit_tracker.entities.external_response.monitoring_report_error.MonitoringReportErrors;
|
||||
import ru.nbch.credit_tracker.entities.user_request.monitoring_request.MonitoringRequest;
|
||||
import ru.nbch.credit_tracker.enums.Status;
|
||||
import ru.nbch.credit_tracker.service.indic.FlagsService;
|
||||
|
|
@ -174,7 +175,7 @@ public class SignalService {
|
|||
subjectToUpdate.add(subject);
|
||||
});
|
||||
|
||||
int updateBatchSize = batchSize / 8; // 8 параметров на одну запись для обновления. Максимальное количество параметров ~65000
|
||||
int updateBatchSize = batchSize / 9; // 9 параметров на одну запись для обновления. Максимальное количество параметров ~65000
|
||||
for (int j = 0; j < subjectToUpdate.size(); j += updateBatchSize) {
|
||||
int endIndex = Math.min(j + updateBatchSize, subjectToUpdate.size());
|
||||
phoneFidMapService.updatePhoneFidMaps(subjectToUpdate.subList(j, endIndex));
|
||||
|
|
@ -202,6 +203,7 @@ public class SignalService {
|
|||
|
||||
/**
|
||||
* Формирует файл запроса в официальный сервис сигналов, выгружая паспортные данные пачками и сразу записывая их в файл
|
||||
*
|
||||
* @return Путь к файлу запроса к официальному сервису сигналов на постановку на мониторинг
|
||||
*/
|
||||
public String writeSignals(Integer packageId) {
|
||||
|
|
@ -277,8 +279,31 @@ public class SignalService {
|
|||
return persons;
|
||||
}
|
||||
|
||||
public void updateSubjectsErrors(String filePath) {
|
||||
|
||||
public void updateSubjectsErrors(String filePath, Integer packageId) {
|
||||
log.info("Start updating subjects errors. PackageId: {}", packageId);
|
||||
try (BufferedInputStream in = new BufferedInputStream(Files.newInputStream(Path.of(filePath)), 8 * 1024 * 1024)) {
|
||||
staxXmlProcessor.read(in, MonitoringReportErrors.class,
|
||||
request -> {
|
||||
if (!request.getPersons().isEmpty()) {
|
||||
List<PhoneFidMap> subjects = request.getPersons().stream().map(p -> {
|
||||
log.error("Ошибка при формировании субъекта. package_id = {}, id = {}. Описание: {}", packageId, p.getUid(), p.getValue());
|
||||
return PhoneFidMap.builder()
|
||||
.id(p.getUid())
|
||||
.errorText(p.getValue())
|
||||
.build();
|
||||
}).toList();
|
||||
phoneFidMapService.updatePhoneFidMapsErrors(subjects);
|
||||
log.trace("Updated subject's batch. Total count: {}. PackageId: {}", request.getPersons().size(), packageId);
|
||||
request.getPersons().clear();
|
||||
}
|
||||
},
|
||||
request -> request.getPersons().isEmpty()
|
||||
,
|
||||
batchSize, "/Errors/p");
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Error while parsing MonitoringReportErrors", e);
|
||||
}
|
||||
log.info("Subject's errors were updated. PackageId: {}", packageId);
|
||||
}
|
||||
|
||||
public List<UserPackage> findActivePackages(String userId) {
|
||||
|
|
|
|||
|
|
@ -28,6 +28,10 @@ public class PhoneFidMapService {
|
|||
mapper.updatePhoneFidMaps(subjects);
|
||||
}
|
||||
|
||||
public void updatePhoneFidMapsErrors(List<PhoneFidMap> subjects) {
|
||||
mapper.updatePhoneFidMapsErrors(subjects);
|
||||
}
|
||||
|
||||
public PhoneFidMap findPhoneFidMapById(Integer id) {
|
||||
return mapper.findPhoneFidMapById(id);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package ru.nbch.credit_tracker.service.xml.stax;
|
||||
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import ru.nbch.credit_tracker.entities.external_response.monitoring_report_error.MonitoringReportErrors;
|
||||
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
|
||||
@Slf4j
|
||||
public class MonitoringReportErrorsStaxtReader extends BaseStaxReader<MonitoringReportErrors> {
|
||||
|
||||
@Override
|
||||
public Class<MonitoringReportErrors> type() {
|
||||
return MonitoringReportErrors.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MonitoringReportErrors createObject() {
|
||||
return new MonitoringReportErrors();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean innerProcess(XMLStreamReader reader, MonitoringReportErrors obj) throws XMLStreamException {
|
||||
String text = buffer.toString();
|
||||
String currPath = getPath();
|
||||
switch (currPath) {
|
||||
case "/Errors/Id" ->
|
||||
obj.setId(text);
|
||||
case "/Errors/Version" ->
|
||||
obj.setVersion(text);
|
||||
case "/Errors/User" ->
|
||||
obj.setUser(text);
|
||||
case "/Errors/ReportCreated" ->
|
||||
obj.setReportCreated(text);
|
||||
case "/Errors/p" -> {
|
||||
obj.getCurrentPerson().setValue(text);
|
||||
obj.finalizePerson();
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void innerProcessStartElement(XMLStreamReader reader, MonitoringReportErrors obj) throws XMLStreamException {
|
||||
String currPath = getPath();
|
||||
|
||||
switch (currPath) {
|
||||
case "/Errors/p" ->
|
||||
obj.createCurrentPerson();
|
||||
}
|
||||
|
||||
for (int i = 0; i < reader.getAttributeCount(); i++) {
|
||||
String text = reader.getAttributeValue(i);
|
||||
switch (reader.getAttributeLocalName(i)) {
|
||||
case "uid" -> {
|
||||
try {
|
||||
int uid = Integer.parseInt(text);
|
||||
obj.getCurrentPerson().setUid(uid);
|
||||
} catch (NumberFormatException e) {
|
||||
log.error("Couldn't parse uid: {}", text);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +42,15 @@
|
|||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updatePhoneFidMapsErrors" parameterType="java.util.List">
|
||||
<foreach collection="subjects" item="subject" separator=";">
|
||||
UPDATE signals_phone_fid_map
|
||||
SET
|
||||
error_text = #{subject.errorText}
|
||||
WHERE id = #{subject.id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<select id="findFullPhoneFidMap" resultMap="PhoneFidMapResultMap" resultType="java.util.List">
|
||||
SELECT id,
|
||||
package_id,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue