This commit is contained in:
akulikov 2023-05-30 13:34:46 +03:00
parent 23efed8caa
commit c505292247
3 changed files with 317 additions and 244 deletions

View file

@ -60,25 +60,42 @@ public abstract class ExecutedDealReportBuilderCommon<T> extends CSVReportBuilde
lines = new ArrayList<>(executionFonds.size()); lines = new ArrayList<>(executionFonds.size());
for (ExecutionFond executionFond : executionFonds) { for (ExecutionFond executionFond : executionFonds) {
try {
Company company = companyImdg.getSingleObjectByID(executionFond.getCompanyId()); Company company = companyImdg.getSingleObjectByID(executionFond.getCompanyId());
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue; if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
STrades sTrade = sTradesImdg.getSingleObjectByFieldValues(
STrades sTrade = null;
if (executionFond.getSide() != null && executionFond.getExchangeExecutionId() != null) {
sTrade = sTradesImdg.getSingleObjectByFieldValues(
Map.of( Map.of(
"tradeNum", executionFond.getExchangeExecutionId(), "tradeNum", executionFond.getExchangeExecutionId(),
"operation", executionFond.getSide() "operation", executionFond.getSide()
) )
); );
}
String id = String.valueOf(executionFond.getId()); String id = String.valueOf(executionFond.getId());
String securityId = String.valueOf(executionFond.getSecurityId()); String securityId = String.valueOf(executionFond.getSecurityId());
String tradeNo = String.valueOf(executionFond.getExchangeExecutionId()); String tradeNo = String.valueOf(executionFond.getExchangeExecutionId());
String tradeDate = dateFormatter.format(executionFond.getTradingDate()); String tradeDate = "";
String tradeTime = dateFormatter.format(LocalDate.ofInstant(executionFond.getCreated(), ZoneId.systemDefault())); String tradeTime = "";
String settleDate = dateFormatter.format(executionFond.getSettlementDate()); String settleDate = "";
if (executionFond.getTradingDate() != null) {
tradeDate = dateFormatter.format(executionFond.getTradingDate());
}
if (executionFond.getCreated() != null) {
tradeTime = dateFormatter.format(LocalDate.ofInstant(executionFond.getCreated(), ZoneId.systemDefault()));
}
if (executionFond.getSettlementDate() != null) {
settleDate = dateFormatter.format(executionFond.getSettlementDate());
}
String settleCode = sTrade != null ? sTrade.getSettleCode() : ""; String settleCode = sTrade != null ? sTrade.getSettleCode() : "";
String quantity = String.valueOf(executionFond.getQuantity()); String quantity = String.valueOf(executionFond.getQuantity());
String value = String.valueOf(executionFond.getSettlementAmount()); String value = String.valueOf(executionFond.getSettlementAmount());
String price = String.valueOf(executionFond.getSettlementAmount().divide(executionFond.getQuantity(), RoundingMode.HALF_UP)); String price = "";
if (executionFond.getSettlementAmount() != null && executionFond.getQuantity() != null) {
price = String.valueOf(executionFond.getSettlementAmount().divide(executionFond.getQuantity(), RoundingMode.HALF_UP));
}
int valueIdx = 0; int valueIdx = 0;
String[] line = new String[getHeaders().length]; String[] line = new String[getHeaders().length];
@ -93,6 +110,9 @@ public abstract class ExecutedDealReportBuilderCommon<T> extends CSVReportBuilde
line[valueIdx++] = quantity; line[valueIdx++] = quantity;
line[valueIdx++] = value; line[valueIdx++] = value;
lines.add(line); lines.add(line);
} catch (Throwable e) {
log.error("Can't create report row for execution_fond (id = %d), skipped".formatted(executionFond.getId()), e);
}
} }
} }

View file

@ -89,6 +89,7 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
lines = new ArrayList<>(executions.size()); lines = new ArrayList<>(executions.size());
for (ExecutionCommon execution : executions) { for (ExecutionCommon execution : executions) {
try {
Company company = companyImdg.getSingleObjectByID(execution.getCompanyId()); Company company = companyImdg.getSingleObjectByID(execution.getCompanyId());
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue; if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
@ -96,14 +97,24 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
log.warn("On Execution[{}] sessionId was null. Skip in report.", execution.getId()); log.warn("On Execution[{}] sessionId was null. Skip in report.", execution.getId());
continue; continue;
} }
Registry registry = registryImdg.getSingleObjectByFieldValues(Map.of("companyId", execution.getCompanyId())); Registry registry = null;
Collection<Registry> registriesForSessionId = registryImdg.getCollectionObjectsByFieldValues( if (execution.getCompanyId() != null) {
registry = registryImdg.getSingleObjectByFieldValues(Map.of("companyId", execution.getCompanyId()));
}
Collection<Registry> registriesForSessionId = null;
if (execution.getSessionId() != null) {
registriesForSessionId = registryImdg.getCollectionObjectsByFieldValues(
Map.of("sessionId", execution.getSessionId()) Map.of("sessionId", execution.getSessionId())
); );
Listing listing = listingImdg.getSingleObjectByFieldValues(Map.of("securityId", execution.getSecurityId())); }
FixedIncomeSecurity fixedIncomeSecurity = fixedIncomeSecurityImdg.getSingleObjectByFieldValues( Listing listing = null;
FixedIncomeSecurity fixedIncomeSecurity = null;
if (execution.getSecurityId() != null) {
listing = listingImdg.getSingleObjectByFieldValues(Map.of("securityId", execution.getSecurityId()));
fixedIncomeSecurity = fixedIncomeSecurityImdg.getSingleObjectByFieldValues(
Map.of("securityId", execution.getSecurityId()) Map.of("securityId", execution.getSecurityId())
); );
}
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryImdg.getSingleObjectByID( TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryImdg.getSingleObjectByID(
execution.getTradingClearingRegistryId() execution.getTradingClearingRegistryId()
); );
@ -122,7 +133,7 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
String sessionId = String.valueOf(execution.getSessionId()); String sessionId = String.valueOf(execution.getSessionId());
String clearingDate = dateFormatter.format(execution.getClearingDate()); String clearingDate = dateFormatter.format(execution.getClearingDate());
String clearingTime = dateFormatter.format(execution.getClearingDate()); String clearingTime = dateFormatter.format(execution.getClearingDate());
String trdAccId = registry == null? null : registry.getTradingClearingRegistry(); String trdAccId = registry == null ? null : registry.getTradingClearingRegistry();
String account = String.valueOf(tradingClearingRegistry.getMoneyAccountId()); String account = String.valueOf(tradingClearingRegistry.getMoneyAccountId());
String depoAccount = String.valueOf(tradingClearingRegistry.getDepoAccountId()); String depoAccount = String.valueOf(tradingClearingRegistry.getDepoAccountId());
String currency = execution.getSettlementCurrency(); String currency = execution.getSettlementCurrency();
@ -164,22 +175,31 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
} else if (execution instanceof ExecutionFond executionFond) { } else if (execution instanceof ExecutionFond executionFond) {
trExecDate = dateFormatter.format(executionFond.getSettlementDate()); trExecDate = dateFormatter.format(executionFond.getSettlementDate());
if (Market.fond.equalsByKey(execution.getMarket())) { if (Market.fond.equalsByKey(execution.getMarket())) {
if (executionFond.getSettlementAmount() != null && executionFond.getQuantity() != null) {
trPrice = String.valueOf( trPrice = String.valueOf(
executionFond.getSettlementAmount().divide(executionFond.getQuantity(), RoundingMode.HALF_UP) executionFond.getSettlementAmount().divide(executionFond.getQuantity(), RoundingMode.HALF_UP)
); );
}
trQuantity = String.valueOf(executionFond.getQuantity()); trQuantity = String.valueOf(executionFond.getQuantity());
if (fixedIncomeSecurity != null) {
nominal = String.valueOf(fixedIncomeSecurity.getNominalValue()); nominal = String.valueOf(fixedIncomeSecurity.getNominalValue());
trValue = String.valueOf(executionFond.getSettlementAmount()); if (executionFond.getQuantity() != null) {
trAccruedInt = String.valueOf(fixedIncomeSecurity.getCoupon());
accruedInt = String.valueOf( accruedInt = String.valueOf(
fixedIncomeSecurity.getCoupon().divide(executionFond.getQuantity(), RoundingMode.HALF_UP) fixedIncomeSecurity.getCoupon().divide(executionFond.getQuantity(), RoundingMode.HALF_UP)
); );
}
trAccruedInt = String.valueOf(fixedIncomeSecurity.getCoupon());
}
trValue = String.valueOf(executionFond.getSettlementAmount());
cashLiability = String.valueOf(executionFond.getSettlementAmount()); cashLiability = String.valueOf(executionFond.getSettlementAmount());
depoLiability = String.valueOf(executionFond.getQuantity()); depoLiability = String.valueOf(executionFond.getQuantity());
} }
} }
String lotValue = String.valueOf(listing.getLotSize()); String lotValue = "";
if (listing != null) {
lotValue = String.valueOf(listing.getLotSize());
}
String trLot = String.valueOf(execution.getLots()); String trLot = String.valueOf(execution.getLots());
String trClrComm = ""; String trClrComm = "";
String trExhComm = ""; String trExhComm = "";
@ -188,27 +208,33 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
Registry om_tRegistry = null; Registry om_tRegistry = null;
Registry ts_tRegistry = null; Registry ts_tRegistry = null;
Registry os_tRegistry = null; Registry os_tRegistry = null;
if (registriesForSessionId != null) {
for (Registry currRegistry : registriesForSessionId) { for (Registry currRegistry : registriesForSessionId) {
String registryCode = currRegistry.getRegistryCode(); String registryCode = currRegistry.getRegistryCode();
if (registryCode.endsWith("T")) { if (registryCode.endsWith("T")) {
if (registryCode.startsWith("TM")) { if (registryCode.startsWith("TM")) {
if (tm_tRegistry != null && tm_tRegistry.getUpdated().isAfter(currRegistry.getUpdated())) continue; if (tm_tRegistry != null && tm_tRegistry.getUpdated().isAfter(currRegistry.getUpdated()))
continue;
tm_tRegistry = currRegistry; tm_tRegistry = currRegistry;
} }
if (registryCode.startsWith("OM")) { if (registryCode.startsWith("OM")) {
if (om_tRegistry != null && om_tRegistry.getUpdated().isAfter(currRegistry.getUpdated())) continue; if (om_tRegistry != null && om_tRegistry.getUpdated().isAfter(currRegistry.getUpdated()))
continue;
om_tRegistry = currRegistry; om_tRegistry = currRegistry;
} }
if (registryCode.startsWith("TS")) { if (registryCode.startsWith("TS")) {
if (ts_tRegistry != null && ts_tRegistry.getUpdated().isAfter(currRegistry.getUpdated())) continue; if (ts_tRegistry != null && ts_tRegistry.getUpdated().isAfter(currRegistry.getUpdated()))
continue;
ts_tRegistry = currRegistry; ts_tRegistry = currRegistry;
} }
if (registryCode.startsWith("OS")) { if (registryCode.startsWith("OS")) {
if (os_tRegistry != null && os_tRegistry.getUpdated().isAfter(currRegistry.getUpdated())) continue; if (os_tRegistry != null && os_tRegistry.getUpdated().isAfter(currRegistry.getUpdated()))
continue;
os_tRegistry = currRegistry; os_tRegistry = currRegistry;
} }
} }
} }
}
String cashNetto = ""; String cashNetto = "";
if (tm_tRegistry != null && om_tRegistry != null) { if (tm_tRegistry != null && om_tRegistry != null) {
cashNetto = String.valueOf(tm_tRegistry.getBalance().subtract(om_tRegistry.getBalance())); cashNetto = String.valueOf(tm_tRegistry.getBalance().subtract(om_tRegistry.getBalance()));
@ -259,7 +285,11 @@ public abstract class LiabilitiesClaimsReportBuilder<P> extends CSVReportBuilder
line[valueIdx++] = cashNetto; line[valueIdx++] = cashNetto;
line[valueIdx] = depoNetto; line[valueIdx] = depoNetto;
lines.add(line); lines.add(line);
} catch (Throwable e) {
log.error("Can't create report row for execution (id = %d), skipped".formatted(execution.getId()), e);
} }
} }
}
} }

View file

@ -66,17 +66,29 @@ public abstract class MoneyChangeReportBuilder<P> extends CSVReportBuilder<P> {
LocalTime nowTime = LocalTime.now(); LocalTime nowTime = LocalTime.now();
lines = new ArrayList<>(registries.size()); lines = new ArrayList<>(registries.size());
for (Registry registry : registries) { for (Registry registry : registries) {
try {
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId()); Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue; if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
Listing listing = listingImdg.getSingleObjectByFieldValues(Map.of("securityId", registry.getSecurityId())); Listing listing = null;
Statement statement = statementImdg.getSingleObjectByFieldValues(Map.of("addresseeId", registry.getCompanyId())); if (registry.getSecurityId() != null) {
PaymentInstruction paymentInstruction = paymentInstructionImdg.getSingleObjectByFieldValues( listing = listingImdg.getSingleObjectByFieldValues(Map.of("securityId", registry.getSecurityId()));
}
Statement statement = null;
if (registry.getCompanyId() != null) {
statement = statementImdg.getSingleObjectByFieldValues(Map.of("addresseeId", registry.getCompanyId()));
}
PaymentInstruction paymentInstruction = null;
if (registry.getPaymentId() != null) {
paymentInstruction = paymentInstructionImdg.getSingleObjectByFieldValues(
Map.of( Map.of(
"id", registry.getPaymentId(), "id", registry.getPaymentId(),
"creditLeg_direction", InOutDirection.out.getKey() "creditLeg_direction", InOutDirection.out.getKey()
) )
); );
}
String id = String.valueOf(registry.getId()); String id = String.valueOf(registry.getId());
String docDate = dateFormatter.format(nowDate); String docDate = dateFormatter.format(nowDate);
@ -87,7 +99,7 @@ public abstract class MoneyChangeReportBuilder<P> extends CSVReportBuilder<P> {
String firName = company.getFullName(); String firName = company.getFullName();
String trdAccId = registry.getTradingClearingRegistry(); String trdAccId = registry.getTradingClearingRegistry();
String account = String.valueOf(registry.getAccountId()); String account = String.valueOf(registry.getAccountId());
String currency = listing.getTradingCurrency(); String currency = listing != null ? listing.getTradingCurrency() : "";
String registryCode = String.valueOf(registry.getId()); String registryCode = String.valueOf(registry.getId());
String registryName = registry.getRegistryCode(); String registryName = registry.getRegistryCode();
String openBalance = String.valueOf(registry.getOpenBalance()); String openBalance = String.valueOf(registry.getOpenBalance());
@ -96,9 +108,17 @@ public abstract class MoneyChangeReportBuilder<P> extends CSVReportBuilder<P> {
String closeBalance = String.valueOf(registry.getCloseBalance()); String closeBalance = String.valueOf(registry.getCloseBalance());
String remarks = ""; String remarks = "";
String addSum = String.valueOf(registry.getCredit()); String addSum = String.valueOf(registry.getCredit());
String addTime = dateTimeFormatter.format(LocalDateTime.ofInstant(statement.getCreated(), ZoneId.systemDefault())); String addTime = "";
if (statement != null && statement.getCreated() != null) {
addTime = dateTimeFormatter.format(LocalDateTime.ofInstant(statement.getCreated(), ZoneId.systemDefault()));
}
String withdrawSum = String.valueOf(registry.getDebit()); String withdrawSum = String.valueOf(registry.getDebit());
String withdrawTime = dateTimeFormatter.format(LocalDateTime.ofInstant(paymentInstruction.getPaymentDate(), ZoneId.systemDefault())); String withdrawTime = "";
if (paymentInstruction != null) {
withdrawTime = dateTimeFormatter.format(LocalDateTime.ofInstant(paymentInstruction.getPaymentDate(), ZoneId.systemDefault()));
} else if (registry.getClearingDate() != null) {
withdrawTime = dateTimeFormatter.format(registry.getClearingDate());
}
int valueIdx = 0; int valueIdx = 0;
String[] line = new String[getHeaders().length]; String[] line = new String[getHeaders().length];
@ -125,6 +145,9 @@ public abstract class MoneyChangeReportBuilder<P> extends CSVReportBuilder<P> {
line[valueIdx++] = withdrawSum; line[valueIdx++] = withdrawSum;
line[valueIdx++] = withdrawTime; line[valueIdx++] = withdrawTime;
lines.add(line); lines.add(line);
} catch (Throwable e) {
log.error("Can't create report row for registry (id = %d), skipped".formatted(registry.getId()), e);
}
} }
} }