registry-service поправил ExecutionDepositLoader, ExecutionFondLoader
This commit is contained in:
parent
cc87b6ec1e
commit
26ce847f37
2 changed files with 145 additions and 63 deletions
|
|
@ -2,6 +2,7 @@ package ru.spcex.clearing.registry.reports.loaders;
|
|||
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.registry.conf.properties.AProperties;
|
||||
import ru.spcex.clearing.registry.reports.ReportUtils;
|
||||
|
|
@ -14,10 +15,7 @@ import ru.spcex.clearing.registry.reports.loaders.helpers.TradingClearingRegistr
|
|||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
|
@ -41,31 +39,39 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
public List<ExecutionDeposit> loadObjects() {
|
||||
try {
|
||||
List<ExecutionDeposit> executionDeposits = super.loadObjects();
|
||||
|
||||
Map<Long, List<ExecutionDeposit>> groupedExecutionDepositForTKR = executionDeposits.stream()
|
||||
.collect(Collectors.groupingBy(ExecutionDeposit::getTradingClearingRegistryId));
|
||||
if (executionDeposits.isEmpty()) {
|
||||
log.warn("ExecutionDeposit not found.");
|
||||
return new ArrayList<>();
|
||||
}
|
||||
Set<Long> tkrIds = groupedExecutionDepositForTKR.keySet();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", tkrIds);
|
||||
List<TradingClearingRegistry> tradingClearingRegistries = clearingJdbc.query(
|
||||
"select ID, CODE from TRADING_CLEARING_REGISTRY where ID in (:ids)",
|
||||
parameterSource, new TradingClearingRegistryRowMapper()
|
||||
);
|
||||
for (TradingClearingRegistry tkr : tradingClearingRegistries) {
|
||||
List<ExecutionDeposit> executionDepositList = groupedExecutionDepositForTKR.get(tkr.getId());
|
||||
for (ExecutionDeposit deposit : executionDepositList) {
|
||||
deposit.setSellerTkrCode(tkr.getCode());
|
||||
|
||||
Map<Long, TradingClearingRegistry> tradingClearingRegistryById = new HashMap<>();
|
||||
{
|
||||
Set<Long> tkrIds = executionDeposits.stream()
|
||||
.filter(eDep -> eDep.getPartyTradingClearingRegistry() == null) // оптимизация; // В execution deposit они пустые
|
||||
.map(ExecutionDeposit::getTradingClearingRegistryId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
tkrIds.addAll(executionDeposits.stream()
|
||||
.filter(eDep -> eDep.getCounterPartyTradingClearingRegistry() == null) // оптимизация // В execution deposit и fond они заполнены
|
||||
.map(ExecutionDeposit::getCounterPartyTradingClearingRegistryId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet()));
|
||||
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", tkrIds);
|
||||
List<TradingClearingRegistry> tradingClearingRegistries = clearingJdbc.query(
|
||||
"select ID, CODE from TRADING_CLEARING_REGISTRY where ID in (:ids)",
|
||||
parameterSource, new TradingClearingRegistryRowMapper()
|
||||
);
|
||||
for (TradingClearingRegistry tkr : tradingClearingRegistries) {
|
||||
tradingClearingRegistryById.put(tkr.getId(), tkr);
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, List<CompanySymbols>> companySymbolsForCompanyIdMap;
|
||||
{
|
||||
Set<Long> companyIds = executionDeposits.stream().map(ExecutionDeposit::getCompanyId).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", companyIds);
|
||||
parameterSource.addValue("cs", CompanySymbol.CLRC.getKey());
|
||||
List<CompanySymbols> companySymbolsForCompanyId = clearingJdbc.query(
|
||||
|
|
@ -78,7 +84,7 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
Map<Long, List<CompanySymbols>> companySymbolsForCounterPartyIdMap;
|
||||
{
|
||||
Set<Long> counterPartyIds = executionDeposits.stream().map(ExecutionDeposit::getCounterPartyId).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", counterPartyIds);
|
||||
parameterSource.addValue("companySymbol", CompanySymbol.CLRC.getKey());
|
||||
List<CompanySymbols> companySymbolsForCounterPartyId = clearingJdbc.query(
|
||||
|
|
@ -94,7 +100,7 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
executionDeposits.stream().map(ExecutionDeposit::getCompanyId),
|
||||
executionDeposits.stream().map(ExecutionDeposit::getCounterPartyId))
|
||||
.collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", allCompanyIds);
|
||||
List<Company> companyForCompanyId = clearingJdbc.query(
|
||||
"select ID, CLEARING_CODE, SHORT_NAME from COMPANY where ID in (:ids)",
|
||||
|
|
@ -104,15 +110,18 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
.collect(Collectors.toMap(Company::getId, o -> o));
|
||||
}
|
||||
|
||||
Set<String> coverageStatuses = executionDeposits.stream().map(ExecutionDeposit::getCoverageStatus).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("coverageStatuses", coverageStatuses);
|
||||
List<AllowedDictionary> allowedDictionaries = clearingJdbc.query(
|
||||
"select * from ALLOWED_DICTIONARY where CODE in (:coverageStatuses)",
|
||||
parameterSource, new AllowedDictionaryRowMapper()
|
||||
);
|
||||
Map<String, List<AllowedDictionary>> allowedDictionariesByCode = allowedDictionaries.stream()
|
||||
.collect(Collectors.groupingBy(AllowedDictionary::getCode));
|
||||
Map<String, List<AllowedDictionary>> allowedDictionariesByCode;
|
||||
{
|
||||
Set<String> coverageStatuses = executionDeposits.stream().map(ExecutionDeposit::getCoverageStatus).collect(Collectors.toSet());
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("coverageStatuses", coverageStatuses);
|
||||
List<AllowedDictionary> allowedDictionaries = clearingJdbc.query(
|
||||
"select * from ALLOWED_DICTIONARY where CODE in (:coverageStatuses)",
|
||||
parameterSource, new AllowedDictionaryRowMapper()
|
||||
);
|
||||
allowedDictionariesByCode = allowedDictionaries.stream()
|
||||
.collect(Collectors.groupingBy(AllowedDictionary::getCode));
|
||||
}
|
||||
|
||||
for (ExecutionDeposit executionDeposit : executionDeposits) {
|
||||
Company companyByCompanyId = companyById.get(executionDeposit.getCompanyId());
|
||||
|
|
@ -139,7 +148,17 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
executionDeposit.setBuyerCode(companySymbols.getCompanySymbolValue());
|
||||
}
|
||||
}
|
||||
executionDeposit.setBuyerTkrCode(executionDeposit.getCounterPartyTradingClearingRegistry());
|
||||
|
||||
executionDeposit.setBuyerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionDeposit.getCounterPartyTradingClearingRegistry(), // В execution deposit они заполнены
|
||||
executionDeposit.getCounterPartyTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
executionDeposit.setSellerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionDeposit.getPartyTradingClearingRegistry(),
|
||||
executionDeposit.getTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
} else if (MoneyFlowSide.BUY.equalsByKey(side) || Side.BUY.equalsByKey(side)) {
|
||||
if (companyByCompanyId != null) {
|
||||
executionDeposit.setBuyer(companyByCompanyId.getShortName());
|
||||
|
|
@ -161,7 +180,16 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
executionDeposit.setSellerCode(companySymbols.getCompanySymbolValue());
|
||||
}
|
||||
}
|
||||
executionDeposit.setBuyerTkrCode(executionDeposit.getPartyTradingClearingRegistry());
|
||||
executionDeposit.setBuyerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionDeposit.getPartyTradingClearingRegistry(),
|
||||
executionDeposit.getTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
executionDeposit.setSellerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionDeposit.getCounterPartyTradingClearingRegistry(), // В execution deposit они заполнены
|
||||
executionDeposit.getCounterPartyTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
} else {
|
||||
log.warn("Unknown executionDeposit[{}].side={}", executionDeposit.getId(), executionDeposit.getSide());
|
||||
}
|
||||
|
|
@ -178,6 +206,20 @@ public class ExecutionDepositLoader extends IDBLoader<ExecutionDeposit> {
|
|||
}
|
||||
}
|
||||
|
||||
String getTCRCodeFromValueOrById(@Nullable String tcrCode, @Nullable Long tcrId, Map<Long, TradingClearingRegistry> tradingClearingRegistryById) {
|
||||
if (tcrCode != null)
|
||||
return tcrCode;
|
||||
if (tcrId != null) {
|
||||
TradingClearingRegistry tcr = tradingClearingRegistryById.get(tcrId);
|
||||
if (tcr == null) {
|
||||
log.warn("Can not find TCR.id={}", tcrId);
|
||||
} else {
|
||||
return tcr.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ExecutionDeposit fromRS(ResultSet resultSet) throws SQLException {
|
||||
ExecutionDeposit object = new ExecutionDeposit();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.spcex.clearing.registry.reports.loaders;
|
|||
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.registry.conf.properties.AProperties;
|
||||
import ru.spcex.clearing.registry.reports.ReportUtils;
|
||||
|
|
@ -14,10 +15,7 @@ import ru.spcex.clearing.registry.reports.loaders.helpers.TradingClearingRegistr
|
|||
import java.math.BigDecimal;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
|
|
@ -37,26 +35,34 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
Map<Long, List<ExecutionFond>> groupedExecutionFondForTKR = executionFonds.stream()
|
||||
.collect(Collectors.groupingBy(ExecutionFond::getTradingClearingRegistryId));
|
||||
Set<Long> tkrIds = groupedExecutionFondForTKR.keySet();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", tkrIds);
|
||||
List<TradingClearingRegistry> tradingClearingRegistries = clearingJdbc.query(
|
||||
"select ID, CODE from TRADING_CLEARING_REGISTRY where ID in (:ids)",
|
||||
parameterSource, new TradingClearingRegistryRowMapper()
|
||||
);
|
||||
for (TradingClearingRegistry tkr : tradingClearingRegistries) {
|
||||
List<ExecutionFond> executionFondList = groupedExecutionFondForTKR.get(tkr.getId());
|
||||
for (ExecutionFond fond : executionFondList) {
|
||||
fond.setSellerTkrCode(tkr.getCode());
|
||||
Map<Long, TradingClearingRegistry> tradingClearingRegistryById = new HashMap<>();
|
||||
{
|
||||
Set<Long> tkrIds = executionFonds.stream()
|
||||
.filter(eDep -> eDep.getPartyTradingClearingRegistry() == null) // оптимизация;
|
||||
.map(ExecutionFond::getTradingClearingRegistryId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet());
|
||||
tkrIds.addAll(executionFonds.stream()
|
||||
.filter(eDep -> eDep.getCounterPartyTradingClearingRegistry() == null) // оптимизация // В execution deposit и fond они заполнены
|
||||
.map(ExecutionFond::getCounterPartyTradingClearingRegistryId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toSet()));
|
||||
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", tkrIds);
|
||||
List<TradingClearingRegistry> tradingClearingRegistries = clearingJdbc.query(
|
||||
"select ID, CODE from TRADING_CLEARING_REGISTRY where ID in (:ids)",
|
||||
parameterSource, new TradingClearingRegistryRowMapper()
|
||||
);
|
||||
for (TradingClearingRegistry tkr : tradingClearingRegistries) {
|
||||
tradingClearingRegistryById.put(tkr.getId(), tkr);
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, List<CompanySymbols>> companySymbolsForCompanyIdMap;
|
||||
{
|
||||
Set<Long> companyIds = executionFonds.stream().map(ExecutionFond::getCompanyId).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", companyIds);
|
||||
parameterSource.addValue("cs", CompanySymbol.CLRC.getKey());
|
||||
List<CompanySymbols> companySymbolsForCompanyId = clearingJdbc.query(
|
||||
|
|
@ -69,7 +75,7 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
Map<Long, List<CompanySymbols>> companySymbolsForCounterPartyIdMap;
|
||||
{
|
||||
Set<Long> counterPartyIds = executionFonds.stream().map(ExecutionFond::getCounterPartyId).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", counterPartyIds);
|
||||
parameterSource.addValue("companySymbol", CompanySymbol.CLRC.getKey());
|
||||
List<CompanySymbols> companySymbolsForCounterPartyId = clearingJdbc.query(
|
||||
|
|
@ -85,7 +91,7 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
executionFonds.stream().map(ExecutionFond::getCompanyId),
|
||||
executionFonds.stream().map(ExecutionFond::getCounterPartyId))
|
||||
.collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("ids", allCompanyIds);
|
||||
List<Company> companyForCompanyId = clearingJdbc.query(
|
||||
"select ID, CLEARING_CODE, SHORT_NAME from COMPANY where ID in (:ids)",
|
||||
|
|
@ -95,15 +101,18 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
.collect(Collectors.toMap(Company::getId, o -> o));
|
||||
}
|
||||
|
||||
Set<String> coverageStatuses = executionFonds.stream().map(ExecutionFond::getCoverageStatus).collect(Collectors.toSet());
|
||||
parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("coverageStatuses", coverageStatuses);
|
||||
List<AllowedDictionary> allowedDictionaries = clearingJdbc.query(
|
||||
"select CODE, NAME from ALLOWED_DICTIONARY where CODE in (:coverageStatuses)",
|
||||
parameterSource, new AllowedDictionaryRowMapper()
|
||||
);
|
||||
Map<String, List<AllowedDictionary>> allowedDictionariesByCode = allowedDictionaries.stream()
|
||||
.collect(Collectors.groupingBy(AllowedDictionary::getCode));
|
||||
Map<String, List<AllowedDictionary>> allowedDictionariesByCode;
|
||||
{
|
||||
Set<String> coverageStatuses = executionFonds.stream().map(ExecutionFond::getCoverageStatus).collect(Collectors.toSet());
|
||||
MapSqlParameterSource parameterSource = new MapSqlParameterSource();
|
||||
parameterSource.addValue("coverageStatuses", coverageStatuses);
|
||||
List<AllowedDictionary> allowedDictionaries = clearingJdbc.query(
|
||||
"select CODE, NAME from ALLOWED_DICTIONARY where CODE in (:coverageStatuses)",
|
||||
parameterSource, new AllowedDictionaryRowMapper()
|
||||
);
|
||||
allowedDictionariesByCode = allowedDictionaries.stream()
|
||||
.collect(Collectors.groupingBy(AllowedDictionary::getCode));
|
||||
}
|
||||
|
||||
for (ExecutionFond executionFond : executionFonds) {
|
||||
Company companyByCompanyId = companyById.get(executionFond.getCompanyId());
|
||||
|
|
@ -130,7 +139,16 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
executionFond.setBuyerCode(companySymbols.getCompanySymbolValue());
|
||||
}
|
||||
}
|
||||
executionFond.setBuyerTkrCode(executionFond.getCounterPartyTradingClearingRegistry());
|
||||
executionFond.setBuyerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionFond.getCounterPartyTradingClearingRegistry(), // В execution fond они заполнены
|
||||
executionFond.getCounterPartyTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
executionFond.setSellerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionFond.getPartyTradingClearingRegistry(),
|
||||
executionFond.getTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
} else if (MoneyFlowSide.BUY.equalsByKey(side) || Side.BUY.equalsByKey(side)) {
|
||||
if (companyByCompanyId != null) {
|
||||
executionFond.setBuyer(companyByCompanyId.getShortName());
|
||||
|
|
@ -152,7 +170,16 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
executionFond.setSellerCode(companySymbols.getCompanySymbolValue());
|
||||
}
|
||||
}
|
||||
executionFond.setBuyerTkrCode(executionFond.getPartyTradingClearingRegistry());
|
||||
executionFond.setBuyerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionFond.getPartyTradingClearingRegistry(),
|
||||
executionFond.getTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
executionFond.setSellerTkrCode(getTCRCodeFromValueOrById(
|
||||
executionFond.getCounterPartyTradingClearingRegistry(), // В execution fond они заполнены
|
||||
executionFond.getCounterPartyTradingClearingRegistryId(),
|
||||
tradingClearingRegistryById
|
||||
));
|
||||
} else {
|
||||
log.warn("Unknown executionFond[{}].side={}", executionFond.getId(), executionFond.getSide());
|
||||
}
|
||||
|
|
@ -168,6 +195,19 @@ public class ExecutionFondLoader extends IDBLoader<ExecutionFond> {
|
|||
}
|
||||
}
|
||||
|
||||
String getTCRCodeFromValueOrById(@Nullable String tcrCode, @Nullable Long tcrId, Map<Long, TradingClearingRegistry> tradingClearingRegistryById) {
|
||||
if (tcrCode != null)
|
||||
return tcrCode;
|
||||
if (tcrId != null) {
|
||||
TradingClearingRegistry tcr = tradingClearingRegistryById.get(tcrId);
|
||||
if (tcr == null) {
|
||||
log.warn("Can not find TCR.id={}", tcrId);
|
||||
} else {
|
||||
return tcr.getCode();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ExecutionFond fromRS(ResultSet resultSet) throws SQLException {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue