Added generation request logic to nbki signal service; Added type handlers for IndicDataSourceConfig;
This commit is contained in:
parent
a6110322d3
commit
ebbbd1b575
17 changed files with 654 additions and 5 deletions
71
signal-package.xsd
Normal file
71
signal-package.xsd
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="windows-1251"?>
|
||||
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||
elementFormDefault="qualified"
|
||||
attributeFormDefault="unqualified">
|
||||
|
||||
<xs:element name="Signals">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Id" type="xs:string"/>
|
||||
<xs:element name="Auth">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="User" type="xs:string"/>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="Conditions">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="Persons">
|
||||
<xs:complexType>
|
||||
<xs:sequence>
|
||||
<xs:element name="p" maxOccurs="unbounded">
|
||||
<xs:complexType>
|
||||
<xs:simpleContent>
|
||||
<xs:extension base="xs:string">
|
||||
<!-- Îáÿçàòåëüíûå áàçîâûå àòðèáóòû -->
|
||||
<xs:attribute name="uid" type="xs:string" use="required"/>
|
||||
<xs:attribute name="s" type="xs:string" use="required"/>
|
||||
<xs:attribute name="n" type="xs:string" use="required"/>
|
||||
<xs:attribute name="m" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="d" type="xs:date" use="required"/>
|
||||
<xs:attribute name="pn" type="xs:string" use="required"/>
|
||||
<xs:attribute name="pd" type="xs:date" use="required"/>
|
||||
<xs:attribute name="dt" type="xs:string" use="required"/>
|
||||
<xs:attribute name="ip" type="xs:string" use="required"/>
|
||||
|
||||
<!-- Àòðèáóòû ñîãëàñèÿ -->
|
||||
<xs:attribute name="consentDate" type="xs:date" use="optional"/>
|
||||
<xs:attribute name="consentPurpose" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="reportUser" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="liability" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentPeriod" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="agrDate" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="reportUserRegNum" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="reportUserTaxID" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentHash" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="cS" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentN" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentM" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentBd" type="xs:date" use="optional"/>
|
||||
<xs:attribute name="consentPn" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="consentPd" type="xs:date" use="optional"/>
|
||||
<xs:attribute name="consentDt" type="xs:string" use="optional"/>
|
||||
<xs:attribute name="inqPurpose" type="xs:string" use="required"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
</xs:sequence>
|
||||
<xs:attribute name="online" type="xs:string" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
|
||||
</xs:schema>
|
||||
|
|
@ -51,6 +51,7 @@ public class IndicDataSourceConfig {
|
|||
SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
|
||||
sqlSessionFactoryBean.setDataSource(dataSource);
|
||||
sqlSessionFactoryBean.setMapperLocations(resources);
|
||||
sqlSessionFactoryBean.setTypeHandlersPackage("ru.nbch.credit_tracker.config.datasource.handlers");
|
||||
return sqlSessionFactoryBean.getObject();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
package ru.nbch.credit_tracker.config.datasource.handlers;
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.sql.CallableStatement;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
@MappedTypes(BigInteger.class)
|
||||
public class BigIntegerTypeHandler extends BaseTypeHandler<BigInteger> {
|
||||
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, BigInteger parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setLong(i, parameter.longValue());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
String value = rs.getString(columnName);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return BigInteger.valueOf(Long.parseLong(value.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
String value = rs.getString(columnIndex);
|
||||
if (rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return BigInteger.valueOf(Long.parseLong(value.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigInteger getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
String value = cs.getString(columnIndex);
|
||||
if (cs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
try {
|
||||
return BigInteger.valueOf(Long.parseLong(value.trim()));
|
||||
} catch (NumberFormatException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package ru.nbch.credit_tracker.config.datasource.handlers;
|
||||
|
||||
|
||||
import org.apache.ibatis.type.BaseTypeHandler;
|
||||
import org.apache.ibatis.type.JdbcType;
|
||||
import org.apache.ibatis.type.MappedTypes;
|
||||
|
||||
import java.sql.*;
|
||||
import java.time.LocalDate;
|
||||
|
||||
@MappedTypes(LocalDate.class)
|
||||
public class LocalDateTypeHandler extends BaseTypeHandler<LocalDate> {
|
||||
@Override
|
||||
public void setNonNullParameter(PreparedStatement ps, int i, LocalDate parameter, JdbcType jdbcType) throws SQLException {
|
||||
ps.setDate(i, Date.valueOf(parameter));
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getNullableResult(ResultSet rs, String columnName) throws SQLException {
|
||||
Date date = rs.getDate(columnName);
|
||||
if(rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return date.toLocalDate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
|
||||
Date date = rs.getDate(columnIndex);
|
||||
if(rs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return date.toLocalDate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
|
||||
Date date = cs.getDate(columnIndex);
|
||||
if(cs.wasNull()) {
|
||||
return null;
|
||||
} else {
|
||||
return date.toLocalDate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
package ru.nbch.credit_tracker.config.settings;
|
||||
|
||||
public record XsdValidation (
|
||||
String monitoringRequestPath
|
||||
String monitoringRequestPath,
|
||||
String signalPackagePath
|
||||
) {}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
package ru.nbch.credit_tracker.entities.signal_package;
|
||||
|
||||
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 lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"user"
|
||||
})
|
||||
public class Auth {
|
||||
|
||||
@XmlElement(name = "User", required = true)
|
||||
protected String user;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
package ru.nbch.credit_tracker.entities.signal_package;
|
||||
|
||||
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 lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"persons"
|
||||
})
|
||||
public class Conditions {
|
||||
|
||||
@XmlElement(name = "Persons", required = true)
|
||||
protected Persons persons;
|
||||
|
||||
public Persons getPersons() {
|
||||
if (persons == null) {
|
||||
persons = new Persons();
|
||||
}
|
||||
return persons;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package ru.nbch.credit_tracker.entities.signal_package;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"value"
|
||||
})
|
||||
public class Person {
|
||||
|
||||
@XmlValue
|
||||
protected String value;
|
||||
@XmlAttribute(name = "uid", required = true)
|
||||
protected String uid;
|
||||
@XmlAttribute(name = "s", required = true)
|
||||
protected String s;
|
||||
@XmlAttribute(name = "n", required = true)
|
||||
protected String n;
|
||||
@XmlAttribute(name = "m")
|
||||
protected String m;
|
||||
@XmlAttribute(name = "d", required = true)
|
||||
@XmlSchemaType(name = "date")
|
||||
protected String d;
|
||||
@XmlAttribute(name = "pn", required = true)
|
||||
protected String pn;
|
||||
@XmlAttribute(name = "pd", required = true)
|
||||
@XmlSchemaType(name = "date")
|
||||
protected String pd;
|
||||
@XmlAttribute(name = "dt", required = true)
|
||||
protected String dt;
|
||||
@XmlAttribute(name = "ip", required = true)
|
||||
protected String ip;
|
||||
@XmlAttribute(name = "consentDate")
|
||||
@XmlSchemaType(name = "date")
|
||||
protected String consentDate;
|
||||
@XmlAttribute(name = "consentPurpose")
|
||||
protected String consentPurpose;
|
||||
@XmlAttribute(name = "reportUser")
|
||||
protected String reportUser;
|
||||
@XmlAttribute(name = "liability")
|
||||
protected String liability;
|
||||
@XmlAttribute(name = "consentPeriod")
|
||||
protected String consentPeriod;
|
||||
@XmlAttribute(name = "agrDate")
|
||||
protected String agrDate;
|
||||
@XmlAttribute(name = "reportUserRegNum")
|
||||
protected String reportUserRegNum;
|
||||
@XmlAttribute(name = "reportUserTaxID")
|
||||
protected String reportUserTaxID;
|
||||
@XmlAttribute(name = "consentHash")
|
||||
protected String consentHash;
|
||||
@XmlAttribute(name = "cS")
|
||||
protected String cs;
|
||||
@XmlAttribute(name = "consentN")
|
||||
protected String consentN;
|
||||
@XmlAttribute(name = "consentM")
|
||||
protected String consentM;
|
||||
@XmlAttribute(name = "consentBd")
|
||||
@XmlSchemaType(name = "date")
|
||||
protected String consentBd;
|
||||
@XmlAttribute(name = "consentPn")
|
||||
protected String consentPn;
|
||||
@XmlAttribute(name = "consentPd")
|
||||
@XmlSchemaType(name = "date")
|
||||
protected String consentPd;
|
||||
@XmlAttribute(name = "consentDt")
|
||||
protected String consentDt;
|
||||
@XmlAttribute(name = "inqPurpose")
|
||||
protected String inqPurpose;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package ru.nbch.credit_tracker.entities.signal_package;
|
||||
|
||||
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 = {
|
||||
"person"
|
||||
})
|
||||
public class Persons {
|
||||
|
||||
@XmlElement(name = "p", required = true)
|
||||
protected List<Person> person;
|
||||
|
||||
public List<Person> getPerson() {
|
||||
if (person == null) {
|
||||
person = new ArrayList<>();
|
||||
}
|
||||
return this.person;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
|
||||
package ru.nbch.credit_tracker.entities.signal_package;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"id",
|
||||
"auth",
|
||||
"conditions"
|
||||
})
|
||||
@XmlRootElement(name = "Signals")
|
||||
public class Signals {
|
||||
|
||||
@XmlElement(name = "Id", required = true)
|
||||
protected String id;
|
||||
@XmlElement(name = "Auth", required = true)
|
||||
protected Auth auth;
|
||||
@XmlElement(name = "Conditions", required = true)
|
||||
protected Conditions conditions;
|
||||
@XmlAttribute(name = "online", required = true)
|
||||
protected String online;
|
||||
|
||||
public Conditions getConditions() {
|
||||
if (conditions == null) {
|
||||
conditions = new Conditions();
|
||||
}
|
||||
return conditions;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,13 +8,16 @@ import org.springframework.stereotype.Service;
|
|||
import org.springframework.web.multipart.MultipartFile;
|
||||
import ru.nbch.credit_tracker.config.settings.CreditTrackerSettings;
|
||||
import ru.nbch.credit_tracker.entities.monitoring_request.MonitoringRequest;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Signals;
|
||||
import ru.nbch.credit_tracker.enums.SignalError;
|
||||
import ru.nbch.credit_tracker.service.FailureAnswerGenerator;
|
||||
import ru.nbch.credit_tracker.service.SignalService;
|
||||
import ru.nbch.credit_tracker.service.indic.PhoneService;
|
||||
import ru.nbch.credit_tracker.service.scoring.AuthorizationService;
|
||||
import ru.nbch.credit_tracker.service.xml.IXmlProcessor;
|
||||
import ru.nbch.credit_tracker.service.xml.XmlUtilService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
|
|
@ -124,7 +127,12 @@ public class SignalFacade {
|
|||
return getBadResponse(SignalError.ERROR_007);
|
||||
}
|
||||
|
||||
signalService.registerPackage(monitoringRequest);
|
||||
List<PhoneService.FidsPhoneData> phoneFidsData = signalService.registerPackage(monitoringRequest);
|
||||
if(!phoneFidsData.isEmpty()) {
|
||||
Signals signals = signalService.setupMonitoring(monitoringRequest, phoneFidsData);
|
||||
// TODO validate?
|
||||
// TODO marshall to xml and send to nbki signal service
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
package ru.nbch.credit_tracker.mapper.indic;
|
||||
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
import ru.nbch.credit_tracker.service.indic.PersonService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface PersonMapper {
|
||||
|
||||
PersonService.NameData findNameData(@Param("fid") Integer fid);
|
||||
|
||||
List<PersonService.PassportData> findPassportData(@Param("fid") Integer fid);
|
||||
}
|
||||
|
|
@ -1,28 +1,42 @@
|
|||
package ru.nbch.credit_tracker.service;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.nbch.credit_tracker.entities.monitoring_request.MonitoringRequest;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Auth;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Person;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Signals;
|
||||
import ru.nbch.credit_tracker.enums.Status;
|
||||
import ru.nbch.credit_tracker.mapper.signal.SignalMapper;
|
||||
import ru.nbch.credit_tracker.service.indic.FlagsService;
|
||||
import ru.nbch.credit_tracker.service.indic.PersonService;
|
||||
import ru.nbch.credit_tracker.service.indic.PhoneService;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class SignalService {
|
||||
|
||||
private final static DateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy");
|
||||
|
||||
private final SignalMapper mapper;
|
||||
private final PhoneService phoneService;
|
||||
private final FlagsService flagsService;
|
||||
private final PersonService personService;
|
||||
|
||||
public SignalService(SignalMapper mapper,
|
||||
PhoneService phoneService,
|
||||
FlagsService flagsService) {
|
||||
FlagsService flagsService, PersonService personService) {
|
||||
this.mapper = mapper;
|
||||
this.phoneService = phoneService;
|
||||
this.flagsService = flagsService;
|
||||
this.personService = personService;
|
||||
}
|
||||
|
||||
public boolean isPackageNotUnique(MonitoringRequest request) {
|
||||
|
|
@ -30,7 +44,7 @@ public class SignalService {
|
|||
return mapper.isPackageNotUnique(userId.substring(0, 6), request.getPackageName());
|
||||
}
|
||||
|
||||
public void registerPackage(MonitoringRequest request) {
|
||||
public List<PhoneService.FidsPhoneData> registerPackage(MonitoringRequest request) {
|
||||
Integer packageId = mapper.registerPackage(request, LocalDateTime.now(), Status.PROCESSING.name());
|
||||
mapper.registerSubjects(request.getSubjects().getSubject(), packageId);
|
||||
List<PhoneService.FidsPhoneData> fidsPhoneDataList = phoneService.findFidsPhoneData(request.getSubjects().getSubject());
|
||||
|
|
@ -39,10 +53,88 @@ public class SignalService {
|
|||
mapper.registerSubjectsFidAndDebts(phoneData.getId(), phoneData.getFid(), flagsData.getFlagDebt5000(), flagsData.getFlag90days(), packageId);
|
||||
});
|
||||
|
||||
return fidsPhoneDataList;
|
||||
}
|
||||
|
||||
public void rejectPackage(MonitoringRequest request) {
|
||||
mapper.insertPackage(request, LocalDateTime.now(), Status.REJECTED.name());
|
||||
}
|
||||
|
||||
public Signals setupMonitoring(MonitoringRequest request, List<PhoneService.FidsPhoneData> fids) {
|
||||
Signals signals = new Signals();
|
||||
signals.setOnline("2"); // Всегда=2 (только онлайн-сигналы)
|
||||
signals.setId(request.getUserId().substring(0, 6) + "_" + request.getPackageName()); // <MEMBERCODE>_<PackageName>
|
||||
Auth auth = new Auth();
|
||||
auth.setUser("test_user"); // TODO from properties // Внутренний логин НБКИ
|
||||
signals.setAuth(auth);
|
||||
for (PhoneService.FidsPhoneData fidData : fids) {
|
||||
Person person = findPerson(fidData.getFid(), fidData.getId());
|
||||
if (person != null) {
|
||||
signals.getConditions().getPersons().getPerson().add(person);
|
||||
}
|
||||
}
|
||||
|
||||
return signals;
|
||||
}
|
||||
|
||||
private Person findPerson(Integer fid, String id) {
|
||||
PersonService.PersonData personData = personService.findPersonData(fid);
|
||||
if (personData == null) {
|
||||
return null;
|
||||
}
|
||||
PersonService.NameData nameData = personData.getName();
|
||||
PersonService.PassportData passportData = personData.getPassport();
|
||||
Person person = new Person();
|
||||
person.setS(nameData.getLastName());
|
||||
person.setN(nameData.getFirstName());
|
||||
person.setM(StringUtils.isNotBlank(nameData.getMiddleName()) ? nameData.getMiddleName() : null);
|
||||
person.setD(DATE_FORMAT.format(toDate(nameData.getBirthDate())));
|
||||
|
||||
person.setPn(getPn(passportData.getSerNum(), passportData.getIdNum()));
|
||||
person.setPd(passportData.getIssDate() != null ? DATE_FORMAT.format(toDate(passportData.getIssDate())) : "01.01.2000");
|
||||
person.setDt(StringUtils.isNotBlank(passportData.getIdType2()) ? passportData.getIdType2() : passportData.getIdType());
|
||||
person.setIp("0");
|
||||
person.setUid(id);
|
||||
person.setConsentDate(DATE_FORMAT.format(toDate(LocalDate.now())));
|
||||
person.setConsentPurpose("16");
|
||||
person.setReportUser("АО «НБКИ»");
|
||||
person.setLiability("1");
|
||||
person.setConsentPeriod("3");
|
||||
person.setAgrDate(DATE_FORMAT.format(toDate(LocalDate.now())));
|
||||
person.setReportUserRegNum("1057746710713");
|
||||
person.setReportUserTaxID("7703548386");
|
||||
person.setConsentHash("hash");
|
||||
|
||||
person.setCs(person.getS());
|
||||
person.setConsentN(person.getN());
|
||||
person.setConsentM(person.getM());
|
||||
person.setConsentBd(person.getD());
|
||||
person.setConsentPn(person.getPn());
|
||||
person.setConsentPd(person.getPd());
|
||||
person.setConsentDt(person.getDt());
|
||||
person.setInqPurpose("16");
|
||||
return person;
|
||||
}
|
||||
|
||||
private String getPn(String serNum, String idNum) {
|
||||
String normSerNum = normalize(serNum);
|
||||
String normIdNum = normalize(idNum);
|
||||
return StringUtils.isNotBlank(normSerNum) ? normSerNum + normIdNum : normIdNum;
|
||||
}
|
||||
|
||||
// TODO move to utility service
|
||||
private String normalize(String value) {
|
||||
if (value == null)
|
||||
return null;
|
||||
value = value.replaceAll("[^А-Яа-яA-Za-z0-9]", "");
|
||||
return value.replaceFirst("^0+", "");
|
||||
}
|
||||
|
||||
// TODO move to utility service
|
||||
private Date toDate(LocalDate date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
return Date.from(date.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,127 @@
|
|||
package ru.nbch.credit_tracker.service.indic;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.nbch.credit_tracker.mapper.indic.PersonMapper;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
@Service
|
||||
public class PersonService {
|
||||
|
||||
private final PersonMapper mapper;
|
||||
|
||||
public PersonService(PersonMapper mapper) {
|
||||
this.mapper = mapper;
|
||||
}
|
||||
|
||||
public PersonData findPersonData(Integer fid) {
|
||||
NameData person = mapper.findNameData(fid);
|
||||
PassportData passort = findPassportData(fid);
|
||||
|
||||
if (person != null && passort != null && requiredFieldPresent(person, passort)) {
|
||||
return new PersonData(person, passort);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private PassportData findPassportData(Integer fid) {
|
||||
List<PassportData> passports = mapper.findPassportData(fid);
|
||||
|
||||
List<PassportData> documents = passports.stream().filter(this::isDUL).toList(); // берем только ДУЛ
|
||||
|
||||
if (documents.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Отдаем приоритет паспортам РФ
|
||||
PassportData passport = documents.stream()
|
||||
.filter(p -> "21".equals(p.getIdType2()) || "21".equals(p.getIdType()))
|
||||
.sorted(
|
||||
Comparator.comparing(
|
||||
PassportData::getIssDate,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())
|
||||
)
|
||||
)
|
||||
.sorted(
|
||||
Comparator.comparing(
|
||||
PassportData::getFileSinceDate,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())
|
||||
)
|
||||
).findFirst().orElse(null);
|
||||
|
||||
if (passport != null) {
|
||||
return passport;
|
||||
}
|
||||
|
||||
// Если паспорт РФ не найден, смотри остальные ДУЛ'ы и берем первый
|
||||
passport = documents.stream()
|
||||
.sorted(
|
||||
Comparator.comparing(
|
||||
PassportData::getIssDate,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())
|
||||
)
|
||||
)
|
||||
.sorted(
|
||||
Comparator.comparing(
|
||||
PassportData::getFileSinceDate,
|
||||
Comparator.nullsLast(Comparator.reverseOrder())
|
||||
)
|
||||
).findFirst().orElse(null);
|
||||
return passport;
|
||||
}
|
||||
|
||||
private boolean isDUL(PassportData p) {
|
||||
Integer idType;
|
||||
Double idType2;
|
||||
try {
|
||||
idType = p.getIdType() != null ? Integer.parseInt(p.getIdType()) : null;
|
||||
} catch (NumberFormatException e) {
|
||||
idType = null;
|
||||
}
|
||||
try {
|
||||
idType2 = p.getIdType2() != null ? Double.valueOf(p.getIdType2()) : null;
|
||||
} catch (NumberFormatException e) {
|
||||
idType2 = null;
|
||||
}
|
||||
return (idType != null && idType <= 30) || (idType2 != null && (idType2 >= 1 || idType2 <= 999));
|
||||
}
|
||||
|
||||
private boolean requiredFieldPresent(NameData nameData, PassportData passportData) {
|
||||
boolean isDocTypeNotNull = StringUtils.isNotBlank(passportData.idType) || StringUtils.isNotBlank(passportData.idType2);
|
||||
return !StringUtils.isAllBlank(nameData.firstName, nameData.lastName, passportData.idNum) && nameData.birthDate != null && isDocTypeNotNull;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public static class PersonData {
|
||||
private NameData name;
|
||||
private PassportData passport;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class NameData {
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
private String middleName;
|
||||
private LocalDate birthDate;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class PassportData {
|
||||
private String serNum;
|
||||
private String idNum;
|
||||
private LocalDate issDate;
|
||||
private String idType;
|
||||
private String idType2;
|
||||
private LocalDate fileSinceDate;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import org.springframework.stereotype.Service;
|
|||
import org.xml.sax.SAXException;
|
||||
import ru.nbch.credit_tracker.entities.monitoring_request.MonitoringRequest;
|
||||
import ru.nbch.credit_tracker.entities.response.errors.MonitoringError;
|
||||
import ru.nbch.credit_tracker.entities.signal_package.Signals;
|
||||
|
||||
import javax.xml.XMLConstants;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
|
|
@ -29,6 +30,7 @@ public class XmlUtilService {
|
|||
// unmarshalling classes
|
||||
MonitoringRequest.class,
|
||||
// marshalling classes
|
||||
Signals.class,
|
||||
MonitoringError.class);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,5 @@ ct.scoring-data-source-settings.password=tester
|
|||
#spring.servlet.multipart.max-request-size=10MB
|
||||
|
||||
# xsd paths
|
||||
ct.xsd-validation.monitoring-request-path=monitoring-request.xsd
|
||||
ct.xsd-validation.monitoring-request-path=monitoring-request.xsd
|
||||
ct.xsd-validation.signal-package-path=signal-package.xsd
|
||||
38
src/main/resources/mybatis/mapper/indic/PersonMapper.xml
Normal file
38
src/main/resources/mybatis/mapper/indic/PersonMapper.xml
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
|
||||
<mapper namespace="ru.nbch.credit_tracker.mapper.indic.PersonMapper">
|
||||
|
||||
<resultMap id="nameDataResultMap" type="ru.nbch.credit_tracker.service.indic.PersonService$NameData">
|
||||
<result property="firstName" column="FIRST" />
|
||||
<result property="lastName" column="NAME_1" />
|
||||
<result property="middleName" column="MIDDLE" />
|
||||
<result property="birthDate" column="BIRTH_DT" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="passportDataResultMap" type="ru.nbch.credit_tracker.service.indic.PersonService$PassportData">
|
||||
<result property="serNum" column="SER_NUM" />
|
||||
<result property="idNum" column="ID_NUM" />
|
||||
<result property="issDate" column="ISS_DTE" />
|
||||
<result property="fileSinceDate" column="FILE_SINCE_DT" />
|
||||
<result property="idType" column="ID_TYPE" />
|
||||
<result property="idType2" column="ID_TYPE2" />
|
||||
</resultMap>
|
||||
|
||||
<select id="findNameData" resultMap="nameDataResultMap">
|
||||
SELECT FIRST, NAME_1, MIDDLE, BIRTH_DT
|
||||
FROM NAME
|
||||
WHERE FID = #{fid}
|
||||
ORDER BY FILE_SINCE_DT DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<select id="findPassportData" resultMap="passportDataResultMap" resultType="java.util.List">
|
||||
SELECT SER_NUM, ID_NUM, ISS_DTE, FILE_SINCE_DT, ID_TYPE, ID_TYPE2
|
||||
FROM ID
|
||||
WHERE FID = #{fid}
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
Loading…
Add table
Reference in a new issue