http://jira.mfd.msk:8088/browse/CLS-301 fix bad logic and search company for company symbols, if company not found in request
This commit is contained in:
parent
f99398ea12
commit
587da25d0c
5 changed files with 192 additions and 209 deletions
|
|
@ -61,6 +61,21 @@
|
||||||
<groupId>ru.spcex.clearing</groupId>
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
<artifactId>clearing-validation</artifactId>
|
<artifactId>clearing-validation</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.junit.jupiter</groupId>
|
||||||
|
<artifactId>junit-jupiter</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework</groupId>
|
||||||
|
<artifactId>spring-test</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ru.spcex.clearing</groupId>
|
||||||
|
<artifactId>test-clearing</artifactId>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,12 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
|
|
@ -52,109 +53,35 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
List<MemberCompany> companyList = param.getMemberCompanyList();
|
List<MemberCompany> companyList = param.getMemberCompanyList();
|
||||||
|
|
||||||
for (MemberCompany company : companyList) {
|
for (MemberCompany company : companyList) {
|
||||||
boolean companyFound = false;
|
|
||||||
List<MemberCompanySymbols> companySymbolsList = company.getMemberCompanySymbolsList();
|
List<MemberCompanySymbols> companySymbolsList = company.getMemberCompanySymbolsList();
|
||||||
|
|
||||||
// Пытаемся найти компанию по UUID
|
Map<CompanySymbol, String> companySymbolMap = new HashMap<>();
|
||||||
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
for (MemberCompanySymbols memberCompanySymbol : companySymbolsList) {
|
||||||
Map.of(
|
if (
|
||||||
"companySymbol", "UUID",
|
!memberCompanySymbol.isInvalidData() &&
|
||||||
"companySymbolValue", company.getId()
|
!CompanySymbol.CIO.equalsByKey(memberCompanySymbol.getCompanySymbol()) &&
|
||||||
)
|
!CompanySymbol.INN.equalsByKey(memberCompanySymbol.getCompanySymbol())
|
||||||
);
|
) continue;
|
||||||
if (!companySymbolsFromImdg.isEmpty()) {
|
companySymbolMap.put(IEnumKey.getEnumByKey(CompanySymbol.class, memberCompanySymbol.getCompanySymbol()), memberCompanySymbol.getCompanySymbolValue());
|
||||||
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
|
||||||
if (companySymbolsFromImdg.size() > 1) {
|
|
||||||
log.warn("For UUID = {} > 1 company_symbols, update first (id = {})", company.getId(), companySymbolFromImdg.getId());
|
|
||||||
}
|
|
||||||
companyFound = true;
|
|
||||||
company.setAlreadyExist(true);
|
|
||||||
company.setMapId(companySymbolFromImdg.getId());
|
|
||||||
}
|
}
|
||||||
|
Long companyId = getCompanyIdForCompanySymbols(company.getId().toString(), companySymbolMap);
|
||||||
|
|
||||||
// Если по UUID не нашли, пытаемся найти по INN или CIO
|
if (companyId != null) {
|
||||||
List<MemberCompanySymbols> companySymbolsListINNorCIO = companySymbolsList.stream()
|
company.setAlreadyExist(true);
|
||||||
.filter(issuerCompanySymbols ->
|
company.setMapId(companyId);
|
||||||
!issuerCompanySymbols.isInvalidData() &&
|
} else {
|
||||||
(
|
|
||||||
CompanySymbol.CIO.equalsByKey(issuerCompanySymbols.getCompanySymbol()) ||
|
|
||||||
CompanySymbol.INN.equalsByKey(issuerCompanySymbols.getCompanySymbol())
|
|
||||||
)
|
|
||||||
).collect(Collectors.toList());
|
|
||||||
|
|
||||||
// Для компании не найдены реквизиты, значит создаем новую компанию
|
|
||||||
if (companySymbolsListINNorCIO.isEmpty()) {
|
|
||||||
company.setAlreadyExist(false);
|
company.setAlreadyExist(false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Реквизиты найдены, ищем по ним company.id
|
// Проверяем реквизиты на необходимость обновления
|
||||||
for (MemberCompanySymbols companySymbols : companySymbolsListINNorCIO) {
|
for (MemberCompanySymbols companySymbols : companySymbolsList) {
|
||||||
if (companySymbols.isInvalidData()) continue;
|
if (companySymbols.isInvalidData()) continue;
|
||||||
|
|
||||||
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"companySymbol", companySymbols.getCompanySymbol(),
|
"companyId", companyId,
|
||||||
"companySymbolValue", companySymbols.getCompanySymbolValue()
|
"companySymbol", companySymbols.getCompanySymbol()
|
||||||
)
|
|
||||||
);
|
|
||||||
if (companySymbolsFromImdg.isEmpty()) {
|
|
||||||
companySymbols.setAlreadyExist(false);
|
|
||||||
} else {
|
|
||||||
if (companySymbolsFromImdg.size() > 1)
|
|
||||||
log.warn("For {} found > 1 company_symbols, use first", companySymbols.getCompanySymbol());
|
|
||||||
|
|
||||||
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
|
||||||
Company companyFromImdg = companyImdg.getSingleObjectByID(companySymbolFromImdg.getCompanyId());
|
|
||||||
if (companyFromImdg == null) {
|
|
||||||
|
|
||||||
// Случай, когда реквизиты есть, а компании нет (по сути данных ошибка в мапе)
|
|
||||||
log.warn("For own company_symbols (id = {}) company not found", companySymbolFromImdg.getId());
|
|
||||||
companySymbols.setAlreadyExist(false);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
} else if (companyFound) {
|
|
||||||
|
|
||||||
// Случай, когда по переданным реквизитам найдено несколько компании
|
|
||||||
if (!Objects.equals(company.getMapId(), companyFromImdg.getId())) {
|
|
||||||
log.warn("For company_symbols (company.UUID = {}, {} = {}) found > 1 company (company.id = {}), " +
|
|
||||||
"company_symbols skipped",
|
|
||||||
company.getId(),
|
|
||||||
companySymbols.getCompanySymbol(),
|
|
||||||
companySymbols.getCompanySymbolValue(),
|
|
||||||
companyFromImdg.getId());
|
|
||||||
companySymbols.setInvalidData(true);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Самый вероятный случай: компания найдена по реквизитам
|
|
||||||
companyFound = true;
|
|
||||||
company.setAlreadyExist(true);
|
|
||||||
company.setMapId(companyFromImdg.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
companySymbols.setAlreadyExist(true);
|
|
||||||
companySymbols.setMapId(companySymbolsFromImdg.iterator().next().getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Если компания реквизиты есть, а компании нет. Маловероятный кейс
|
|
||||||
if (!companyFound) {
|
|
||||||
company.setAlreadyExist(false);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверяем оставшиеся реквизиты на необходимость обновления
|
|
||||||
for (MemberCompanySymbols companySymbols : companySymbolsList) {
|
|
||||||
if (companySymbols.isInvalidData() || companySymbols.getMapId() == null) continue;
|
|
||||||
|
|
||||||
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
|
||||||
Map.of(
|
|
||||||
"companyId", company.getMapId(),
|
|
||||||
"companySymbol", companySymbols.getCompanySymbol(),
|
|
||||||
"companySymbolValue", companySymbols.getCompanySymbolValue()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (companySymbolsFromImdg.isEmpty()) {
|
if (companySymbolsFromImdg.isEmpty()) {
|
||||||
|
|
@ -181,7 +108,7 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
|
|
||||||
Collection<Contact> contactsFromImdg = contactImdg.getCollectionObjectsByFieldValues(
|
Collection<Contact> contactsFromImdg = contactImdg.getCollectionObjectsByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"companyId", company.getMapId(),
|
"companyId", companyId,
|
||||||
"contactType", contact.getContactType()
|
"contactType", contact.getContactType()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -205,7 +132,7 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
|
|
||||||
Collection<ProfileDocument> profileDocumentsFromImdg = profileDocumentImdg.getCollectionObjectsByFieldValues(
|
Collection<ProfileDocument> profileDocumentsFromImdg = profileDocumentImdg.getCollectionObjectsByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"companyId", company.getMapId(),
|
"companyId", companyId,
|
||||||
"documentType", memberProfileDocument.getDocumentType()
|
"documentType", memberProfileDocument.getDocumentType()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -216,7 +143,7 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
if (profileDocumentsFromImdg.size() > 1) {
|
if (profileDocumentsFromImdg.size() > 1) {
|
||||||
log.warn("Found profile_document > 1 for document_type {} (company.id {}), update first (id = {})",
|
log.warn("Found profile_document > 1 for document_type {} (company.id {}), update first (id = {})",
|
||||||
memberProfileDocument.getDocumentType(),
|
memberProfileDocument.getDocumentType(),
|
||||||
company.getMapId(),
|
companyId,
|
||||||
profileDocument.getId());
|
profileDocument.getId());
|
||||||
}
|
}
|
||||||
memberProfileDocument.setAlreadyExist(true);
|
memberProfileDocument.setAlreadyExist(true);
|
||||||
|
|
@ -230,7 +157,7 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
|
|
||||||
Collection<ClientCode> clientCodesFromImdg = clientCodeImdg.getCollectionObjectsByFieldValues(
|
Collection<ClientCode> clientCodesFromImdg = clientCodeImdg.getCollectionObjectsByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"companyId", company.getMapId(),
|
"companyId", companyId,
|
||||||
"code", memberClient.getClientCode()
|
"code", memberClient.getClientCode()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
@ -241,7 +168,7 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
if (clientCodesFromImdg.size() > 1) {
|
if (clientCodesFromImdg.size() > 1) {
|
||||||
log.warn("Found client_code > 1 for code {} (company.id {}), update first (id = {})",
|
log.warn("Found client_code > 1 for code {} (company.id {}), update first (id = {})",
|
||||||
clientCode.getCode(),
|
clientCode.getCode(),
|
||||||
company.getMapId(),
|
companyId,
|
||||||
clientCode.getId());
|
clientCode.getId());
|
||||||
}
|
}
|
||||||
memberClient.setAlreadyExist(true);
|
memberClient.setAlreadyExist(true);
|
||||||
|
|
@ -256,11 +183,9 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
}
|
}
|
||||||
|
|
||||||
List<MemberCompany> filteredMemberCompany = companyList.stream()
|
List<MemberCompany> filteredMemberCompany = companyList.stream()
|
||||||
.filter(issuerCompany -> !issuerCompany.isInvalidData())
|
.filter(memberCompany -> !memberCompany.isInvalidData())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// todo check list is empty
|
|
||||||
|
|
||||||
param.setMemberCompanyList(filteredMemberCompany);
|
param.setMemberCompanyList(filteredMemberCompany);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -319,4 +244,50 @@ public class CheckMemberCompanyExist extends Stage<CompaniesRequestParam> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Long getCompanyIdForCompanySymbols(String uuid, Map<CompanySymbol, String> INNorCIO) {
|
||||||
|
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of(
|
||||||
|
"companySymbol", CompanySymbol.UUID.getKey(),
|
||||||
|
"companySymbolValue", uuid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!companySymbolsFromImdg.isEmpty()) {
|
||||||
|
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
||||||
|
if (companySymbolsFromImdg.size() > 1) {
|
||||||
|
log.warn("For UUID found > 1 company_symbols, use first (id = {})", companySymbolFromImdg.getId());
|
||||||
|
}
|
||||||
|
return companySymbolFromImdg.getCompanyId();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<CompanySymbol, String> entry : INNorCIO.entrySet()) {
|
||||||
|
CompanySymbol companySymbol = entry.getKey();
|
||||||
|
String companySymbolValue = entry.getValue();
|
||||||
|
|
||||||
|
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of(
|
||||||
|
"companySymbol", companySymbol.getKey(),
|
||||||
|
"companySymbolValue", companySymbolValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!companySymbolsFromImdg.isEmpty()) {
|
||||||
|
if (companySymbolsFromImdg.size() > 1)
|
||||||
|
log.warn("For {} = {} found > 1 company_symbols, use first", companySymbol.getKey(), companySymbolValue);
|
||||||
|
|
||||||
|
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
||||||
|
Company companyFromImdg = companyImdg.getSingleObjectByID(companySymbolFromImdg.getCompanyId());
|
||||||
|
|
||||||
|
if (companyFromImdg == null) {
|
||||||
|
// Случай, когда реквизиты есть, а компании нет (по сути данных ошибка в мапе)
|
||||||
|
log.error("For own company_symbols (id = {}) company not found (map error)", companySymbolFromImdg.getId());
|
||||||
|
} else {
|
||||||
|
return companyFromImdg.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,12 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class CheckIssuerCompanyExist extends Stage<FondListingsRequestParam> {
|
public class CheckIssuerCompanyExist extends Stage<FondListingsRequestParam> {
|
||||||
|
|
@ -39,109 +40,35 @@ public class CheckIssuerCompanyExist extends Stage<FondListingsRequestParam> {
|
||||||
List<IssuerCompany> companyList = param.getIssuerCompanyList();
|
List<IssuerCompany> companyList = param.getIssuerCompanyList();
|
||||||
|
|
||||||
for (IssuerCompany company : companyList) {
|
for (IssuerCompany company : companyList) {
|
||||||
boolean companyFound = false;
|
|
||||||
List<IssuerCompanySymbols> companySymbolsList = company.getIssuerCompanySymbolsList();
|
List<IssuerCompanySymbols> companySymbolsList = company.getIssuerCompanySymbolsList();
|
||||||
|
|
||||||
// Пытаемся найти компанию по UUID
|
Map<CompanySymbol, String> companySymbolMap = new HashMap<>();
|
||||||
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
for (IssuerCompanySymbols issuerCompanySymbol : companySymbolsList) {
|
||||||
Map.of(
|
if (
|
||||||
"companySymbol", "UUID",
|
!issuerCompanySymbol.isInvalidData() &&
|
||||||
"companySymbolValue", company.getId()
|
!CompanySymbol.CIO.equalsByKey(issuerCompanySymbol.getCompanySymbol()) &&
|
||||||
)
|
!CompanySymbol.INN.equalsByKey(issuerCompanySymbol.getCompanySymbol())
|
||||||
);
|
) continue;
|
||||||
if (!companySymbolsFromImdg.isEmpty()) {
|
companySymbolMap.put(IEnumKey.getEnumByKey(CompanySymbol.class, issuerCompanySymbol.getCompanySymbol()), issuerCompanySymbol.getCompanySymbolValue());
|
||||||
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
|
||||||
if (companySymbolsFromImdg.size() > 1) {
|
|
||||||
log.warn("For UUID found > 1 company_symbols, update first (id = {})", companySymbolFromImdg.getId());
|
|
||||||
}
|
|
||||||
companyFound = true;
|
|
||||||
company.setAlreadyExist(true);
|
|
||||||
company.setMapId(companySymbolFromImdg.getId());
|
|
||||||
}
|
}
|
||||||
|
Long companyId = getCompanyIdForCompanySymbols(company.getId().toString(), companySymbolMap);
|
||||||
|
|
||||||
// Если по UUID не нашли, пытаемся найти по INN или CIO
|
if (companyId != null) {
|
||||||
List<IssuerCompanySymbols> companySymbolsListINNorCIO = companySymbolsList.stream()
|
company.setAlreadyExist(true);
|
||||||
.filter(issuerCompanySymbols ->
|
company.setMapId(companyId);
|
||||||
!issuerCompanySymbols.isInvalidData() &&
|
} else {
|
||||||
(
|
|
||||||
CompanySymbol.CIO.equalsByKey(issuerCompanySymbols.getCompanySymbol()) ||
|
|
||||||
CompanySymbol.INN.equalsByKey(issuerCompanySymbols.getCompanySymbol())
|
|
||||||
)
|
|
||||||
).collect(Collectors.toList());
|
|
||||||
|
|
||||||
// Для компании не найдены реквизиты, значит создаем новую компанию
|
|
||||||
if (companySymbolsListINNorCIO.isEmpty()) {
|
|
||||||
company.setAlreadyExist(false);
|
company.setAlreadyExist(false);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Реквизиты найдены, ищем по ним company.id
|
// Проверяем реквизиты на необходимость обновления
|
||||||
for (IssuerCompanySymbols companySymbols : companySymbolsListINNorCIO) {
|
for (IssuerCompanySymbols companySymbols : companySymbolsList) {
|
||||||
if (companySymbols.isInvalidData()) continue;
|
if (companySymbols.isInvalidData()) continue;
|
||||||
|
|
||||||
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
Map.of(
|
Map.of(
|
||||||
"companySymbol", companySymbols.getCompanySymbol(),
|
"companyId", companyId,
|
||||||
"companySymbolValue", companySymbols.getCompanySymbolValue()
|
"companySymbol", companySymbols.getCompanySymbol()
|
||||||
)
|
|
||||||
);
|
|
||||||
if (companySymbolsFromImdg.isEmpty()) {
|
|
||||||
companySymbols.setAlreadyExist(false);
|
|
||||||
} else {
|
|
||||||
if (companySymbolsFromImdg.size() > 1)
|
|
||||||
log.warn("For {} found > 1 company_symbols, use first", companySymbols.getCompanySymbol());
|
|
||||||
|
|
||||||
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
|
||||||
Company companyFromImdg = companyImdg.getSingleObjectByID(companySymbolFromImdg.getCompanyId());
|
|
||||||
if (companyFromImdg == null) {
|
|
||||||
|
|
||||||
// Случай, когда реквизиты есть, а компании нет (по сути данных ошибка в мапе)
|
|
||||||
log.warn("For own company_symbols (id = {}) company not found", companySymbolFromImdg.getId());
|
|
||||||
companySymbols.setAlreadyExist(false);
|
|
||||||
continue;
|
|
||||||
|
|
||||||
} else if (companyFound) {
|
|
||||||
|
|
||||||
// Случай, когда по переданным реквизитам найдено несколько компании
|
|
||||||
if (!Objects.equals(company.getMapId(), companyFromImdg.getId())) {
|
|
||||||
log.warn("For company_symbols (company.id = {}, {} = {}) found > 1 company (company.id = {}), " +
|
|
||||||
"company_symbols skipped",
|
|
||||||
company.getId(),
|
|
||||||
companySymbols.getCompanySymbol(),
|
|
||||||
companySymbols.getCompanySymbolValue(),
|
|
||||||
companyFromImdg.getId());
|
|
||||||
companySymbols.setInvalidData(true);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Самый вероятный случай: компания найдена по реквизитам
|
|
||||||
companyFound = true;
|
|
||||||
company.setAlreadyExist(true);
|
|
||||||
company.setMapId(companyFromImdg.getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
companySymbols.setAlreadyExist(true);
|
|
||||||
companySymbols.setMapId(companySymbolsFromImdg.iterator().next().getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Если компания реквизиты есть, а компании нет. Маловероятный кейс
|
|
||||||
if (!companyFound) {
|
|
||||||
company.setAlreadyExist(false);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Проверяем оставшиеся реквизиты на необходимость обновления
|
|
||||||
for (IssuerCompanySymbols companySymbols : companySymbolsList) {
|
|
||||||
if (companySymbols.isInvalidData() || companySymbols.getMapId() == null) continue;
|
|
||||||
|
|
||||||
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
|
||||||
Map.of(
|
|
||||||
"companyId", company.getMapId(),
|
|
||||||
"companySymbol", companySymbols.getCompanySymbol(),
|
|
||||||
"companySymbolValue", companySymbols.getCompanySymbolValue()
|
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
if (companySymbolsFromImdg.isEmpty()) {
|
if (companySymbolsFromImdg.isEmpty()) {
|
||||||
|
|
@ -193,10 +120,53 @@ public class CheckIssuerCompanyExist extends Stage<FondListingsRequestParam> {
|
||||||
.filter(issuerCompany -> !issuerCompany.isInvalidData())
|
.filter(issuerCompany -> !issuerCompany.isInvalidData())
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
// todo check list is empty
|
|
||||||
|
|
||||||
param.setIssuerCompanyList(filteredIssuerCompany);
|
param.setIssuerCompanyList(filteredIssuerCompany);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Long getCompanyIdForCompanySymbols(String uuid, Map<CompanySymbol, String> INNorCIO) {
|
||||||
|
Collection<CompanySymbols> companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of(
|
||||||
|
"companySymbol", CompanySymbol.UUID.getKey(),
|
||||||
|
"companySymbolValue", uuid
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!companySymbolsFromImdg.isEmpty()) {
|
||||||
|
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
||||||
|
if (companySymbolsFromImdg.size() > 1) {
|
||||||
|
log.warn("For UUID found > 1 company_symbols, use first (id = {})", companySymbolFromImdg.getId());
|
||||||
|
}
|
||||||
|
return companySymbolFromImdg.getCompanyId();
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<CompanySymbol, String> entry : INNorCIO.entrySet()) {
|
||||||
|
CompanySymbol companySymbol = entry.getKey();
|
||||||
|
String companySymbolValue = entry.getValue();
|
||||||
|
|
||||||
|
companySymbolsFromImdg = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of(
|
||||||
|
"companySymbol", companySymbol.getKey(),
|
||||||
|
"companySymbolValue", companySymbolValue
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (!companySymbolsFromImdg.isEmpty()) {
|
||||||
|
if (companySymbolsFromImdg.size() > 1)
|
||||||
|
log.warn("For {} = {} found > 1 company_symbols, use first", companySymbol.getKey(), companySymbolValue);
|
||||||
|
|
||||||
|
CompanySymbols companySymbolFromImdg = companySymbolsFromImdg.iterator().next();
|
||||||
|
Company companyFromImdg = companyImdg.getSingleObjectByID(companySymbolFromImdg.getCompanyId());
|
||||||
|
|
||||||
|
if (companyFromImdg == null) {
|
||||||
|
// Случай, когда реквизиты есть, а компании нет (по сути данных ошибка в мапе)
|
||||||
|
log.error("For own company_symbols (id = {}) company not found (map error)", companySymbolFromImdg.getId());
|
||||||
|
} else {
|
||||||
|
return companyFromImdg.getId();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@ package ru.spcex.clearing.gatewayapi.logic.listings_fond;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
import ru.clearing.classes.statics.data.instrument.issue.EquitySecurity;
|
import ru.clearing.classes.statics.data.instrument.issue.EquitySecurity;
|
||||||
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurity;
|
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurity;
|
||||||
import ru.spcex.clearing.gatewayapi.logic.ProcessResult;
|
import ru.spcex.clearing.gatewayapi.logic.ProcessResult;
|
||||||
|
|
@ -14,12 +16,15 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.securitites.*;
|
import ru.spcex.clearing.platform.messaging.domain.cud.securitites.*;
|
||||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
|
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||||
import ru.spcex.platform.enumeration.InstrumentType;
|
import ru.spcex.platform.enumeration.InstrumentType;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondListingsRequestParam> {
|
public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondListingsRequestParam> {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
@ -27,12 +32,16 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
private final KafkaSender kafkaSender;
|
private final KafkaSender kafkaSender;
|
||||||
private final Imdg<FixedIncomeSecurity> fixedIncomeSecurityImdg;
|
private final Imdg<FixedIncomeSecurity> fixedIncomeSecurityImdg;
|
||||||
private final Imdg<EquitySecurity> equitySecurityImdg;
|
private final Imdg<EquitySecurity> equitySecurityImdg;
|
||||||
|
private final Imdg<CompanySymbols> companySymbolsImdg;
|
||||||
|
private final Imdg<Company> companyImdg;
|
||||||
|
|
||||||
|
|
||||||
public SendMessageToSecurityServiceWithFondSecurities(KafkaSender kafkaSender, ImdgProvider imdgProvider) {
|
public SendMessageToSecurityServiceWithFondSecurities(KafkaSender kafkaSender, ImdgProvider imdgProvider) {
|
||||||
this.kafkaSender = kafkaSender;
|
this.kafkaSender = kafkaSender;
|
||||||
this.fixedIncomeSecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_FixedIncomeSecurity, FixedIncomeSecurity.class);
|
this.fixedIncomeSecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_FixedIncomeSecurity, FixedIncomeSecurity.class);
|
||||||
this.equitySecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_EquitySecurity, EquitySecurity.class);
|
this.equitySecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_EquitySecurity, EquitySecurity.class);
|
||||||
|
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
this.companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -40,10 +49,34 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
List<FondSecurity> securityList = param.getSecurities();
|
List<FondSecurity> securityList = param.getSecurities();
|
||||||
for (FondSecurity security : securityList) {
|
for (FondSecurity security : securityList) {
|
||||||
if (security.isInvalidData()) continue;
|
if (security.isInvalidData()) continue;
|
||||||
|
Long companyId;
|
||||||
if (security.getIssuerCompany() == null || security.getIssuerCompany().getMapId() == null) {
|
if (security.getIssuerCompany() == null || security.getIssuerCompany().getMapId() == null) {
|
||||||
log.warn("Can't insert security.UUID {}, company not found for parameter issuerId", security.getId());
|
// Пытаемся найти компанию по UUID
|
||||||
security.setInvalidData(true);
|
UUID companyUUID = security.getIssuerId();
|
||||||
continue;
|
Collection<CompanySymbols> companySymbols = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of(
|
||||||
|
"companySymbol", CompanySymbol.UUID.getKey(),
|
||||||
|
"companySymbolValue", companyUUID.toString()
|
||||||
|
)
|
||||||
|
);
|
||||||
|
if (companySymbols.isEmpty()) {
|
||||||
|
log.warn("Can't insert security.id {}, company not found for parameter issuerId", security.getId());
|
||||||
|
security.setInvalidData(true);
|
||||||
|
continue;
|
||||||
|
} else if (companySymbols.size() > 1) {
|
||||||
|
log.warn("For {} = {} found > 1 company_symbol, use first", CompanySymbol.UUID.getKey(), companyUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Проверяем, что в базе помимо реквизита есть компания
|
||||||
|
companyId = companySymbols.iterator().next().getCompanyId();
|
||||||
|
Company company = companyImdg.getSingleObjectByID(companyId);
|
||||||
|
if (company == null) {
|
||||||
|
log.warn("Can't insert security: not found company with id {}", companyId);
|
||||||
|
security.setInvalidData(true);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
companyId = security.getIssuerCompany().getMapId();
|
||||||
}
|
}
|
||||||
Long securityId;
|
Long securityId;
|
||||||
if (InstrumentType.BOND.equalsByKey(security.getInstrumentType())) {
|
if (InstrumentType.BOND.equalsByKey(security.getInstrumentType())) {
|
||||||
|
|
@ -58,7 +91,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
fixedIncomeSecurityNewRequest.setNominalCurrency(security.getNominalCurrency());
|
fixedIncomeSecurityNewRequest.setNominalCurrency(security.getNominalCurrency());
|
||||||
fixedIncomeSecurityNewRequest.setMaturityDate(security.getMaturityDate());
|
fixedIncomeSecurityNewRequest.setMaturityDate(security.getMaturityDate());
|
||||||
fixedIncomeSecurityNewRequest.setCouponFrequency(security.getCouponFrequency());
|
fixedIncomeSecurityNewRequest.setCouponFrequency(security.getCouponFrequency());
|
||||||
fixedIncomeSecurityNewRequest.setIssuerId(security.getIssuerCompany().getMapId());
|
fixedIncomeSecurityNewRequest.setIssuerId(companyId);
|
||||||
fixedIncomeSecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
fixedIncomeSecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
||||||
fixedIncomeSecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
fixedIncomeSecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
||||||
fixedIncomeSecurityNewRequest.setWorkflowStatus(security.getWorkflowStatus());
|
fixedIncomeSecurityNewRequest.setWorkflowStatus(security.getWorkflowStatus());
|
||||||
|
|
@ -76,7 +109,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
fixedIncomeSecurityUpdateRequest.setNominalCurrency(security.getNominalCurrency());
|
fixedIncomeSecurityUpdateRequest.setNominalCurrency(security.getNominalCurrency());
|
||||||
fixedIncomeSecurityUpdateRequest.setMaturityDate(security.getMaturityDate());
|
fixedIncomeSecurityUpdateRequest.setMaturityDate(security.getMaturityDate());
|
||||||
fixedIncomeSecurityUpdateRequest.setCouponFrequency(security.getCouponFrequency());
|
fixedIncomeSecurityUpdateRequest.setCouponFrequency(security.getCouponFrequency());
|
||||||
fixedIncomeSecurityUpdateRequest.setIssuerId(security.getIssuerCompany().getMapId());
|
fixedIncomeSecurityUpdateRequest.setIssuerId(companyId);
|
||||||
fixedIncomeSecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
fixedIncomeSecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
||||||
fixedIncomeSecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
fixedIncomeSecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
||||||
fixedIncomeSecurityUpdateRequest.setWorkflowStatus(security.getWorkflowStatus());
|
fixedIncomeSecurityUpdateRequest.setWorkflowStatus(security.getWorkflowStatus());
|
||||||
|
|
@ -91,7 +124,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
equitySecurityNewRequest.setFullName(security.getFullName());
|
equitySecurityNewRequest.setFullName(security.getFullName());
|
||||||
equitySecurityNewRequest.setIsin(security.getIsin());
|
equitySecurityNewRequest.setIsin(security.getIsin());
|
||||||
equitySecurityNewRequest.setShareType(security.getShareType());
|
equitySecurityNewRequest.setShareType(security.getShareType());
|
||||||
equitySecurityNewRequest.setIssuerId(security.getIssuerCompany().getMapId());
|
equitySecurityNewRequest.setIssuerId(companyId);
|
||||||
equitySecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
equitySecurityNewRequest.setShortNameEng(security.getShortNameEng());
|
||||||
equitySecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
equitySecurityNewRequest.setFullNameEng(security.getFullNameEng());
|
||||||
equitySecurityNewRequest.setWorkflowStatus(security.getWorkflowStatus());
|
equitySecurityNewRequest.setWorkflowStatus(security.getWorkflowStatus());
|
||||||
|
|
@ -105,7 +138,7 @@ public class SendMessageToSecurityServiceWithFondSecurities extends Stage<FondLi
|
||||||
equitySecurityUpdateRequest.setFullName(security.getFullName());
|
equitySecurityUpdateRequest.setFullName(security.getFullName());
|
||||||
equitySecurityUpdateRequest.setIsin(security.getIsin());
|
equitySecurityUpdateRequest.setIsin(security.getIsin());
|
||||||
equitySecurityUpdateRequest.setShareType(security.getShareType());
|
equitySecurityUpdateRequest.setShareType(security.getShareType());
|
||||||
equitySecurityUpdateRequest.setIssuerId(security.getIssuerCompany().getMapId());
|
equitySecurityUpdateRequest.setIssuerId(companyId);
|
||||||
equitySecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
equitySecurityUpdateRequest.setShortNameEng(security.getShortNameEng());
|
||||||
equitySecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
equitySecurityUpdateRequest.setFullNameEng(security.getFullNameEng());
|
||||||
equitySecurityUpdateRequest.setWorkflowStatus(security.getWorkflowStatus());
|
equitySecurityUpdateRequest.setWorkflowStatus(security.getWorkflowStatus());
|
||||||
|
|
|
||||||
|
|
@ -29,12 +29,6 @@ public class ValidateIncomeSecurities extends Stage<FondListingsRequestParam> {
|
||||||
for (FondSecurity fondSecurity : securities) {
|
for (FondSecurity fondSecurity : securities) {
|
||||||
if (fondSecurity.isInvalidData()) continue;
|
if (fondSecurity.isInvalidData()) continue;
|
||||||
|
|
||||||
if (fondSecurity.getIssuerCompany() == null) {
|
|
||||||
log.warn("For security.id {} not found company, skipped", fondSecurity.getId());
|
|
||||||
fondSecurity.setInvalidData(true);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
String instrumentTypeStr = fondSecurity.getInstrumentType();
|
String instrumentTypeStr = fondSecurity.getInstrumentType();
|
||||||
InstrumentType instrumentType = IEnumKey.getEnumByKey(InstrumentType.class, instrumentTypeStr);
|
InstrumentType instrumentType = IEnumKey.getEnumByKey(InstrumentType.class, instrumentTypeStr);
|
||||||
if (instrumentType != InstrumentType.BOND && instrumentType != InstrumentType.EQTY) {
|
if (instrumentType != InstrumentType.BOND && instrumentType != InstrumentType.EQTY) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue