CheckMoneyMarketSecurityExist
This commit is contained in:
parent
a0b8291e1d
commit
0feec2cfa2
4 changed files with 113 additions and 0 deletions
|
|
@ -0,0 +1,62 @@
|
|||
package ru.spcex.clearing.gatewayapi.logic.listings_mm;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.clearing.classes.statics.data.security.MoneyMarketSecurity;
|
||||
import ru.spcex.clearing.gatewayapi.logic.ProcessResult;
|
||||
import ru.spcex.clearing.gatewayapi.logic.Stage;
|
||||
import ru.spcex.clearing.gatewayapi.request.objects.ExchangeInstrument;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.enumeration.InstrumentType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CheckMoneyMarketSecurityExist extends Stage<MMListingsRequestParam> {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final Imdg<MoneyMarketSecurity> moneyMarketSecurityImdg;
|
||||
|
||||
public CheckMoneyMarketSecurityExist(ImdgProvider imdgProvider) {
|
||||
moneyMarketSecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_MoneyMarketSecurity, MoneyMarketSecurity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessResult process(MMListingsRequestParam param) {
|
||||
List<ExchangeInstrument> exchangeInstrumentList = param.getExchangeInstrumentsList();
|
||||
|
||||
for (ExchangeInstrument exchangeInstrument : exchangeInstrumentList) {
|
||||
String securitySymbol = extractSecuritySymbol(exchangeInstrument.getCode());
|
||||
Collection<MoneyMarketSecurity> securitiesFromImdg = moneyMarketSecurityImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"securitySymbol", securitySymbol,
|
||||
"instrumentType", InstrumentType.RATE.getKey()
|
||||
)
|
||||
);
|
||||
if (securitiesFromImdg.isEmpty()) {
|
||||
exchangeInstrument.setAlreadyExist(false);
|
||||
} else {
|
||||
MoneyMarketSecurity security = securitiesFromImdg.iterator().next();
|
||||
if (securitiesFromImdg.size() > 1) {
|
||||
log.warn("For securitySymbol = {} and instrumentType = {} found > 1 moneyMarketSecurity, update first (id = {})",
|
||||
securitySymbol,
|
||||
InstrumentType.RATE.getKey(),
|
||||
security.getId());
|
||||
}
|
||||
exchangeInstrument.setAlreadyExist(true);
|
||||
exchangeInstrument.setMapId(security.getId());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String extractSecuritySymbol(String code) {
|
||||
int firstX = code.indexOf('X');
|
||||
if (firstX == -1) return code;
|
||||
return code.substring(0, firstX);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,22 +3,60 @@ package ru.spcex.clearing.gatewayapi.logic.listings_mm;
|
|||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||
import ru.spcex.clearing.gatewayapi.logic.ProcessResult;
|
||||
import ru.spcex.clearing.gatewayapi.logic.Stage;
|
||||
import ru.spcex.clearing.gatewayapi.request.objects.ExchangeInstrument;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.platform.enumeration.CompanySymbol;
|
||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ValidateExchangeInstruments extends Stage<MMListingsRequestParam> {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<CompanySymbols> companySymbolsImdg;
|
||||
|
||||
public ValidateExchangeInstruments(ImdgProvider imdgProvider) {
|
||||
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ProcessResult process(MMListingsRequestParam param) {
|
||||
List<ExchangeInstrument> exchangeInstrumentList = param.getExchangeInstrumentsList();
|
||||
for (ExchangeInstrument exchangeInstrument : exchangeInstrumentList) {
|
||||
|
||||
Collection<CompanySymbols> companySymbols = companySymbolsImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"companySymbol", CompanySymbol.UUID.getKey(),
|
||||
"companySymbolValue", exchangeInstrument.getInitiatorId()
|
||||
)
|
||||
);
|
||||
if (companySymbols.isEmpty()) {
|
||||
log.warn("Invalid exchange_instrument.initiator_id: companySymbol.UUID = {} not found, skipped",
|
||||
exchangeInstrument.getInitiatorId());
|
||||
exchangeInstrument.setInvalidData(true);
|
||||
} else {
|
||||
CompanySymbols companySymbol = companySymbols.iterator().next();
|
||||
if (companySymbols.size() > 1) {
|
||||
log.warn("companySymbol.UUID = {} > 1, use first (id = {}, companyId = {})",
|
||||
companySymbol.getCompanySymbolValue(),
|
||||
companySymbol.getId(),
|
||||
companySymbol.getCompanyId());
|
||||
}
|
||||
exchangeInstrument.setIssuerId(companySymbol.getCompanyId());
|
||||
}
|
||||
|
||||
if (StringUtils.isEmpty(exchangeInstrument.getCode())) {
|
||||
log.warn("Invalid exchange_instrument (id = {}), code is empty or null, skipped", exchangeInstrument.getId());
|
||||
exchangeInstrument.setInvalidData(true);
|
||||
|
|
|
|||
|
|
@ -209,6 +209,10 @@ public class ExchangeInstrument extends WithMapId {
|
|||
@ApiModelProperty(hidden = true)
|
||||
private DirAuctionBiddingType dirAuctionBiddingType;
|
||||
|
||||
@JsonIgnore
|
||||
@ApiModelProperty(hidden = true)
|
||||
private Long issuerId;
|
||||
|
||||
|
||||
public UUID getId() {
|
||||
return id;
|
||||
|
|
@ -393,4 +397,12 @@ public class ExchangeInstrument extends WithMapId {
|
|||
public void setLot(Long lot) {
|
||||
this.lot = lot;
|
||||
}
|
||||
|
||||
public Long getIssuerId() {
|
||||
return issuerId;
|
||||
}
|
||||
|
||||
public void setIssuerId(Long issuerId) {
|
||||
this.issuerId = issuerId;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,6 +5,7 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
|
|||
public enum InstrumentType implements IEnumKey {
|
||||
BOND("BOND"), // Долевые ценные бумаги (акции)
|
||||
EQTY("EQTY"), // Долговые ценные бумаги (облигации)
|
||||
RATE("RATE"), // Инструмент Денежного рынка
|
||||
;
|
||||
|
||||
private final String key;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue