Added generating MonitoringSignalResponse
This commit is contained in:
parent
a9332dd71e
commit
76525b3f8b
11 changed files with 205 additions and 8 deletions
|
|
@ -0,0 +1,21 @@
|
|||
package ru.nbch.credit_tracker.entities.response.monitoring_signal_response;
|
||||
|
||||
import jakarta.xml.bind.annotation.*;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"packageName",
|
||||
"subjects"
|
||||
})
|
||||
@XmlRootElement(name = "MonitoringSignalResponse")
|
||||
public class MonitoringSignalResponse {
|
||||
|
||||
@XmlElement(name = "PackageName", required = true)
|
||||
protected String packageName;
|
||||
@XmlElement(name = "Subjects", required = true)
|
||||
protected Subjects subjects;
|
||||
}
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
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.XmlType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"signalType",
|
||||
"inquiryDate",
|
||||
"inquiryPurpose"
|
||||
})
|
||||
public class Signal {
|
||||
@XmlAttribute(name = "SignalType", required = true)
|
||||
protected Integer signalType;
|
||||
@XmlAttribute(name = "InquiryDate", required = true)
|
||||
protected String inquiryDate;
|
||||
@XmlAttribute(name = "InquiryPurpose", required = true)
|
||||
protected Integer inquiryPurpose;
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
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.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"signals"
|
||||
})
|
||||
public class Signals {
|
||||
|
||||
@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,35 @@
|
|||
|
||||
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.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "SubjectType", propOrder = {
|
||||
"id",
|
||||
"clientId",
|
||||
"flagDebt5000",
|
||||
"flag9012"
|
||||
})
|
||||
public class Subject {
|
||||
|
||||
@XmlElement(name = "Id", required = true)
|
||||
protected String id;
|
||||
@XmlElement(name = "ClientId", required = true)
|
||||
protected String clientId;
|
||||
@XmlElement(name = "FlagDebt5000", required = true)
|
||||
protected Integer flagDebt5000;
|
||||
@XmlElement(name = "Flag90_12", required = true)
|
||||
protected Integer flag9012;
|
||||
@XmlElement(name = "Signals", required = true)
|
||||
protected Signals signals;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
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.XmlElement;
|
||||
import jakarta.xml.bind.annotation.XmlType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
@XmlType(name = "", propOrder = {
|
||||
"subject"
|
||||
})
|
||||
public class Subjects {
|
||||
|
||||
@XmlElement(name = "Subject", required = true)
|
||||
protected List<Subject> subjects;
|
||||
|
||||
public List<Subject> getSubjects() {
|
||||
if (subjects == null) {
|
||||
subjects = new ArrayList<>();
|
||||
}
|
||||
return this.subjects;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ public class Inquiry {
|
|||
@XmlAttribute(name = "own", required = true)
|
||||
protected String own;
|
||||
@XmlAttribute(name = "inq_p", required = true)
|
||||
protected String inqP;
|
||||
protected Integer inqP;
|
||||
@XmlAttribute(name = "currency", required = true)
|
||||
protected String currency;
|
||||
@XmlAttribute(name = "serial_num", required = true)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,14 @@ 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 = {
|
||||
"inquiry"
|
||||
"inquiries"
|
||||
})
|
||||
public class Person {
|
||||
|
||||
|
|
@ -16,6 +19,12 @@ public class Person {
|
|||
protected String uid;
|
||||
|
||||
@XmlElement(name = "Inquiry", required = true)
|
||||
protected Inquiry inquiry;
|
||||
protected List<Inquiry> inquiries;
|
||||
|
||||
public List<Inquiry> getInquiries() {
|
||||
if (inquiries == null) {
|
||||
inquiries = new ArrayList<>();
|
||||
}
|
||||
return this.inquiries;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ public interface SignalMapper {
|
|||
|
||||
List<SignalService.SubjectData> findSubjectsData(@Param("packageId") Integer packageId);
|
||||
|
||||
List<SignalService.SubjectData> findFullSubjectsData(@Param("packageId") Integer packageId);
|
||||
|
||||
SignalService.PackageData findPackageData(@Param("id") Integer id);
|
||||
|
||||
List<SignalService.PackageData> findPackageDataList(@Param("userId") String userId);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package ru.nbch.credit_tracker.service;
|
|||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
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;
|
||||
import ru.nbch.credit_tracker.entities.response.online_download.Person;
|
||||
import ru.nbch.credit_tracker.entities.response.online_report.Report;
|
||||
|
|
@ -63,16 +65,45 @@ public class MonitoringService {
|
|||
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();
|
||||
MonitoringSignalResponse response = generateResponse(packageData, report.getPersons().getPersons());
|
||||
|
||||
createRsponse(packageData, validPersons);
|
||||
}
|
||||
}
|
||||
|
||||
private void createRsponse(SignalService.PackageData packageData, List<Person> validPersons) {
|
||||
private MonitoringSignalResponse generateResponse(SignalService.PackageData packageData, List<Person> persons) {
|
||||
MonitoringSignalResponse response = new MonitoringSignalResponse();
|
||||
response.setPackageName(packageData.getPackageName()); // Имя пакета, переданного при установке
|
||||
Subjects subjects = new Subjects();
|
||||
List<SignalService.SubjectData> subjectDataList = signalService.findFullSubjectsData(packageData.getId());
|
||||
for (Person person : persons) {
|
||||
Signals signals = new Signals();
|
||||
for (Inquiry inquiry : person.getInquiries()) {
|
||||
// Отбираем только тех фл, у которых bus_category in (MFO, MKK, MFK) и есть сигналы с кодом 16
|
||||
if (!CTUtil.checkBusCategory(inquiry.getBusCategory()) && inquiry.getSignals().stream().anyMatch(signal -> signal.getN().equals(16))) {
|
||||
continue;
|
||||
}
|
||||
Signal signal = new Signal();
|
||||
signal.setSignalType(1); // Код типа сигнала по внутреннему справочнику. В текущей версии: 1 = сигнал 16 от MFO/MKK/MFK
|
||||
signal.setInquiryDate(inquiry.getDate()); // Дата и время запроса КИ
|
||||
signal.setInquiryPurpose(inquiry.getInqP()); // Цель запроса КИ
|
||||
signals.getSignals().add(signal);
|
||||
}
|
||||
|
||||
// Если есть хотя бы один заполненный сигнал, значит заполняем остальные данные
|
||||
if (!signals.getSignals().isEmpty()) {
|
||||
subjectDataList.stream().filter(p -> p.getSubjectId().equals(person.getUid())).findFirst().ifPresent(subjectData -> {
|
||||
Subject subject = new Subject();
|
||||
subject.setId(subjectData.getSubjectId()); // Уникальный идентификатор субъекта (равен Id из XML-пакета при установке мониторинга)
|
||||
subject.setClientId(subjectData.getPhone());
|
||||
subject.setFlagDebt5000(subjectData.getFlagDebt5000());
|
||||
subject.setFlag9012(subjectData.getFlag90days());
|
||||
subject.setSignals(signals);
|
||||
subjects.getSubjects().add(subject);
|
||||
});
|
||||
}
|
||||
}
|
||||
response.setSubjects(subjects);
|
||||
return response;
|
||||
}
|
||||
|
||||
private OnlineDownloadReport loadReport(String reportName) {
|
||||
|
|
|
|||
|
|
@ -200,6 +200,10 @@ public class SignalService {
|
|||
return mapper.findPackagesByStatus(Status.ON_MONITORING.name());
|
||||
}
|
||||
|
||||
public List<SubjectData> findFullSubjectsData(Integer packageId) {
|
||||
return mapper.findFullSubjectsData(packageId);
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class PackageData {
|
||||
|
|
@ -215,7 +219,12 @@ public class SignalService {
|
|||
@Setter
|
||||
public static class SubjectData {
|
||||
private Integer id;
|
||||
private Integer packageId;
|
||||
private String subjectId;
|
||||
private String phone;
|
||||
private Integer fid;
|
||||
private Integer flagDebt5000;
|
||||
private Integer flag90days;
|
||||
private LocalDateTime calculatedAt;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,8 +7,13 @@
|
|||
|
||||
<resultMap id="subjectDataResultMap" type="ru.nbch.credit_tracker.service.SignalService$SubjectData">
|
||||
<result property="id" column="id" />
|
||||
<result property="packageId" column="package_id" />
|
||||
<result property="subjectId" column="subject_id" />
|
||||
<result property="phone" column="phone" />
|
||||
<result property="fid" column="fid" />
|
||||
<result property="flagDebt5000" column="flag_debt5000" />
|
||||
<result property="flag90days" column="flag_90_12" />
|
||||
<result property="calculatedAt" column="calculated_at" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap id="packageDataResultMap" type="ru.nbch.credit_tracker.service.SignalService$PackageData">
|
||||
|
|
@ -75,6 +80,12 @@
|
|||
WHERE package_id = #{packageId}
|
||||
</select>
|
||||
|
||||
<select id="findFullSubjectsData" resultMap="subjectDataResultMap" resultType="java.util.List">
|
||||
SELECT id, package_id, subject_id, phone, fid, flag_90_12, flag_debt5000, calculated_at
|
||||
FROM signals_phone_fid_map
|
||||
WHERE package_id = #{packageId}
|
||||
</select>
|
||||
|
||||
<select id="findPackageData" resultMap="packageDataResultMap" resultType="ru.nbch.credit_tracker.service.SignalService$PackageData">
|
||||
SELECT membercode, package_name
|
||||
FROM signals_user_packages
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue