reports-service http://jira.mfd.msk:8088/browse/CLS-497 ksRepCashRegisterSums
This commit is contained in:
parent
334e01d02d
commit
5b85844e5e
2 changed files with 118 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.spcex.clearing.reports.reports.ks;
|
package ru.spcex.clearing.reports.reports.ks;
|
||||||
|
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
import ru.clearing.classes.statics.data.registry.Registry;
|
import ru.clearing.classes.statics.data.registry.Registry;
|
||||||
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||||
|
|
@ -21,16 +22,14 @@ import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.time.temporal.ChronoUnit;
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyParams, KSRepCashRegisterSumsReport> {
|
public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyParams, KSRepCashRegisterSumsReport> {
|
||||||
private final Imdg<Statement> statementImdg;
|
private final Imdg<Statement> statementImdg;
|
||||||
private final Imdg<Registry> registryImdg;
|
private final Imdg<Registry> registryImdg;
|
||||||
private final Imdg<Company> companyImdg;
|
private final Imdg<Company> companyImdg;
|
||||||
|
private final Imdg<Account> accountImdg;
|
||||||
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||||
|
|
||||||
private List<KSRepCashRegisterSumsReport> rows = null;
|
private List<KSRepCashRegisterSumsReport> rows = null;
|
||||||
|
|
@ -40,6 +39,7 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
||||||
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||||
tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||||
|
accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -77,69 +77,140 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
||||||
pb.greatEqual("created", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
pb.greatEqual("created", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||||
pb.less("created", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
pb.less("created", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||||
pb.equals("inOutSDfType", InOutSDfType.type57.getKey()),
|
pb.equals("inOutSDfType", InOutSDfType.type57.getKey()),
|
||||||
pb.equals("operationStatus", OperationStatus.Executed.getKey()),
|
pb.equals("operationStatus", OperationStatus.Executed.getKey())
|
||||||
pb.notNull("amount")
|
// ,pb.notNull("amount")
|
||||||
);
|
);
|
||||||
Collection<Statement> statements = statementImdg.getCollectionObjectsByPredicate(finalPredicate);
|
Collection<Statement> statements = statementImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||||
rows = new ArrayList<>(statements.size());
|
rows = new ArrayList<>(statements.size());
|
||||||
for (Statement statement : statements) {
|
for (Statement statement : statements) {
|
||||||
try {
|
try {
|
||||||
Company company = companyImdg.getSingleObjectByID(statement.getAddresseeId());
|
// Company company = companyImdg.getSingleObjectByID(statement.getAddresseeId());
|
||||||
if (company == null) {
|
// if (company == null) {
|
||||||
log.warn("For statement id = {} company with id = {} not found, statement was skipped",
|
// log.warn("For statement id = {} company with id = {} not found, statement was skipped",
|
||||||
statement.getId(),
|
// statement.getId(),
|
||||||
statement.getAddresseeId());
|
// statement.getAddresseeId());
|
||||||
continue;
|
// continue;
|
||||||
|
// }
|
||||||
|
// if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||||
|
// Long accountId = statement.getAccountId();
|
||||||
|
boolean searchTCRAsInfo=false;
|
||||||
|
if (Arrays.asList(1L,2L).contains(statement.getAccountId())) {
|
||||||
|
searchTCRAsInfo = true;
|
||||||
|
} else {
|
||||||
|
Account account = accountImdg.getSingleObjectByID(statement.getAccountId());
|
||||||
|
searchTCRAsInfo = AccountType.Info.equalsByKey(account.getAccountType());
|
||||||
|
if (!searchTCRAsInfo && !AccountType.Clrn.equalsByKey(account.getAccountType())) {
|
||||||
|
log.warn("Unexpected account[{}] type {}", account.getId(), account.getAccountType());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
TradingClearingRegistry tkr;
|
||||||
Long accountId = statement.getAccountId();
|
if (searchTCRAsInfo) {
|
||||||
if (accountId == null) {
|
String code = statement.getComment();
|
||||||
log.warn("For statement id = {} empty accountId, statement was skipped", statement.getId());
|
int i = code.lastIndexOf("ТКР");
|
||||||
continue;
|
if (i >= 0) {
|
||||||
}
|
code = code.substring(i + 3).trim();
|
||||||
TradingClearingRegistry tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(
|
}
|
||||||
Map.of("moneyAccountId", accountId)
|
if (i<0 || code.isBlank()) {
|
||||||
);
|
log.warn("For statement id = {} empty or unparseable code=\"{}\" (comment \"{}\"), statement was skipped",
|
||||||
if (tkr == null) {
|
code, statement.getComment(), statement.getId());
|
||||||
log.warn(
|
continue;
|
||||||
"For statement id = {} and accountId = {} not found TradingClearingRegistry",
|
}
|
||||||
statement.getId(),
|
log.debug("Search TCR by code={}", code);
|
||||||
accountId
|
tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("code", code));
|
||||||
);
|
if (tkr == null) {
|
||||||
continue;
|
log.warn(
|
||||||
|
"For statement id = {} and code = {} not found TradingClearingRegistry",
|
||||||
|
statement.getId(),
|
||||||
|
code
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Long accountId = statement.getAccountId();
|
||||||
|
if (accountId == null) {
|
||||||
|
log.warn("For statement id = {} empty accountId, statement was skipped", statement.getId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
log.debug("Search TCR by moneyAccountId={}", accountId);
|
||||||
|
tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("moneyAccountId", accountId));
|
||||||
|
if (tkr == null) {
|
||||||
|
log.warn(
|
||||||
|
"For statement id = {} and accountId = {} not found TradingClearingRegistry",
|
||||||
|
statement.getId(),
|
||||||
|
accountId
|
||||||
|
);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Company company;
|
||||||
|
if (searchTCRAsInfo) {
|
||||||
|
company = companyImdg.getSingleObjectByID(tkr.getCompanyId());
|
||||||
|
if (company == null) {
|
||||||
|
log.warn("For statement id = {}, tcr.id={}, company with id = {} not found, statement was skipped",
|
||||||
|
statement.getId(),
|
||||||
|
tkr.getId(),
|
||||||
|
tkr.getCompanyId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
company = companyImdg.getSingleObjectByID(statement.getAddresseeId());
|
||||||
|
if (company == null) {
|
||||||
|
log.warn("For statement id = {}, company with id = {} not found, statement was skipped",
|
||||||
|
statement.getId(),
|
||||||
|
statement.getAddresseeId());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) {
|
||||||
|
log.debug("For statement id = {}, company with id = {} not active",
|
||||||
|
statement.getId(), company.getId());
|
||||||
|
//continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
||||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(
|
ImdgPredicate registryQuery;
|
||||||
pbRegistry.and(
|
if (searchTCRAsInfo) {
|
||||||
pbRegistry.equals("companyId", statement.getAddresseeId()),
|
registryQuery = pbRegistry.and(
|
||||||
pbRegistry.equals("account", statement.getAccount()),
|
pbRegistry.equals("tradingClearingRegistry", tkr.getCode()),
|
||||||
pbRegistry.in("accountType", AccountType.Clrn.getKey(), AccountType.Info.getKey()),
|
pbRegistry.in("accountType", AccountType.Clrn.getKey(), AccountType.Info.getKey()),
|
||||||
RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AM_T).buildPredicate(pbRegistry)
|
RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AM_T).buildPredicate(pbRegistry)
|
||||||
)
|
);
|
||||||
);
|
} else {
|
||||||
|
registryQuery = pbRegistry.and(
|
||||||
|
pbRegistry.equals("companyId", statement.getAddresseeId()),
|
||||||
|
pbRegistry.equals("account", statement.getAccount()),
|
||||||
|
pbRegistry.in("accountType", AccountType.Clrn.getKey(), AccountType.Info.getKey()),
|
||||||
|
RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AM_T).buildPredicate(pbRegistry)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
log.trace("For statement id={} search registry query: {}", statement.getId(), registryQuery);
|
||||||
|
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(registryQuery);
|
||||||
if (registries.isEmpty()) {
|
if (registries.isEmpty()) {
|
||||||
log.warn(
|
log.warn(
|
||||||
"Can't find registry for companyId = {} and account: {}. Statement id = {} skipped",
|
"Can't find registry for {}. Statement id = {} skipped",
|
||||||
statement.getAddresseeId(),
|
registryQuery,
|
||||||
statement.getAccount(),
|
|
||||||
statement.getId()
|
statement.getId()
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
} else if (registries.size() > 1) {
|
} else if (registries.size() > 1) {
|
||||||
log.warn(
|
log.warn(
|
||||||
"More then one AM_T registry found for companyId = {} and account: {}, statement id {}. Use first",
|
"More then one AM_T registry found for {}, statement id {}. Use first",
|
||||||
statement.getAddresseeId(),
|
registryQuery,
|
||||||
statement.getAccount(),
|
|
||||||
statement.getId()
|
statement.getId()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Registry registry = registries.iterator().next();
|
Registry registry = registries.iterator().next();
|
||||||
|
|
||||||
KSRepCashRegisterSumsReport ksRepCashRegisterSumsReport = new KSRepCashRegisterSumsReport();
|
KSRepCashRegisterSumsReport ksRepCashRegisterSumsReport = new KSRepCashRegisterSumsReport();
|
||||||
ksRepCashRegisterSumsReport.setFirmId(String.valueOf(statement.getAddresseeId()));
|
ksRepCashRegisterSumsReport.setFirmId(company.getTradingCode());
|
||||||
ksRepCashRegisterSumsReport.setAccount(statement.getAccount());
|
if (searchTCRAsInfo) {
|
||||||
ksRepCashRegisterSumsReport.setTkr(registry.getTradingClearingRegistry());
|
ksRepCashRegisterSumsReport.setAccount(company.getTradingCode());
|
||||||
|
} else {
|
||||||
|
ksRepCashRegisterSumsReport.setAccount(statement.getAccount());
|
||||||
|
}
|
||||||
|
ksRepCashRegisterSumsReport.setTkr(tkr.getCode());
|
||||||
ksRepCashRegisterSumsReport.setRegisterCode(registry.getRegistryCode());
|
ksRepCashRegisterSumsReport.setRegisterCode(registry.getRegistryCode());
|
||||||
ksRepCashRegisterSumsReport.setAddDate(nowDate);
|
ksRepCashRegisterSumsReport.setAddDate(nowDate);
|
||||||
if (statement.getCreated() != null)
|
if (statement.getCreated() != null)
|
||||||
|
|
|
||||||
|
|
@ -144,8 +144,8 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
||||||
ksRepDepoRegisterQuantitiesReport.setSecurityId(security.getSecuritySymbol());
|
ksRepDepoRegisterQuantitiesReport.setSecurityId(security.getSecuritySymbol());
|
||||||
ksRepDepoRegisterQuantitiesReport.setRegisterCode(registry.getRegistryCode());
|
ksRepDepoRegisterQuantitiesReport.setRegisterCode(registry.getRegistryCode());
|
||||||
ksRepDepoRegisterQuantitiesReport.setAddDate(nowDate);
|
ksRepDepoRegisterQuantitiesReport.setAddDate(nowDate);
|
||||||
if (statement.getUpdated() != null)
|
if (statement.getCreated() != null)
|
||||||
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(statement.getUpdated(), getReportZoneId()));
|
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(statement.getCreated(), getReportZoneId()));
|
||||||
|
|
||||||
InOutDirection inOutDirection = IEnumKey.getEnumByKey(InOutDirection.class, statement.getInOutDirection());
|
InOutDirection inOutDirection = IEnumKey.getEnumByKey(InOutDirection.class, statement.getInOutDirection());
|
||||||
if (inOutDirection == InOutDirection.in) {
|
if (inOutDirection == InOutDirection.in) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue