reports-service http://jira.mfd.msk:8088/browse/CLS-497 ksRepCashRegisterSums

This commit is contained in:
AKurakin 2023-09-22 12:39:56 +03:00
parent 334e01d02d
commit 5b85844e5e
2 changed files with 118 additions and 47 deletions

View file

@ -1,6 +1,7 @@
package ru.spcex.clearing.reports.reports.ks;
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.registry.Registry;
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
@ -21,16 +22,14 @@ import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.temporal.ChronoUnit;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.*;
@Component
public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyParams, KSRepCashRegisterSumsReport> {
private final Imdg<Statement> statementImdg;
private final Imdg<Registry> registryImdg;
private final Imdg<Company> companyImdg;
private final Imdg<Account> accountImdg;
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
private List<KSRepCashRegisterSumsReport> rows = null;
@ -40,6 +39,7 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
}
@Override
@ -77,69 +77,140 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
pb.greatEqual("created", instantNow.truncatedTo(ChronoUnit.DAYS)),
pb.less("created", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
pb.equals("inOutSDfType", InOutSDfType.type57.getKey()),
pb.equals("operationStatus", OperationStatus.Executed.getKey()),
pb.notNull("amount")
pb.equals("operationStatus", OperationStatus.Executed.getKey())
// ,pb.notNull("amount")
);
Collection<Statement> statements = statementImdg.getCollectionObjectsByPredicate(finalPredicate);
rows = new ArrayList<>(statements.size());
for (Statement statement : statements) {
try {
Company 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;
// Company 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())) 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;
Long accountId = statement.getAccountId();
if (accountId == null) {
log.warn("For statement id = {} empty accountId, statement was skipped", statement.getId());
continue;
}
TradingClearingRegistry tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(
Map.of("moneyAccountId", accountId)
);
if (tkr == null) {
log.warn(
"For statement id = {} and accountId = {} not found TradingClearingRegistry",
statement.getId(),
accountId
);
continue;
TradingClearingRegistry tkr;
if (searchTCRAsInfo) {
String code = statement.getComment();
int i = code.lastIndexOf("ТКР");
if (i >= 0) {
code = code.substring(i + 3).trim();
}
if (i<0 || code.isBlank()) {
log.warn("For statement id = {} empty or unparseable code=\"{}\" (comment \"{}\"), statement was skipped",
code, statement.getComment(), statement.getId());
continue;
}
log.debug("Search TCR by code={}", code);
tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("code", code));
if (tkr == null) {
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();
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(
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)
)
);
ImdgPredicate registryQuery;
if (searchTCRAsInfo) {
registryQuery = pbRegistry.and(
pbRegistry.equals("tradingClearingRegistry", tkr.getCode()),
pbRegistry.in("accountType", AccountType.Clrn.getKey(), AccountType.Info.getKey()),
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()) {
log.warn(
"Can't find registry for companyId = {} and account: {}. Statement id = {} skipped",
statement.getAddresseeId(),
statement.getAccount(),
"Can't find registry for {}. Statement id = {} skipped",
registryQuery,
statement.getId()
);
continue;
} else if (registries.size() > 1) {
log.warn(
"More then one AM_T registry found for companyId = {} and account: {}, statement id {}. Use first",
statement.getAddresseeId(),
statement.getAccount(),
"More then one AM_T registry found for {}, statement id {}. Use first",
registryQuery,
statement.getId()
);
}
Registry registry = registries.iterator().next();
KSRepCashRegisterSumsReport ksRepCashRegisterSumsReport = new KSRepCashRegisterSumsReport();
ksRepCashRegisterSumsReport.setFirmId(String.valueOf(statement.getAddresseeId()));
ksRepCashRegisterSumsReport.setAccount(statement.getAccount());
ksRepCashRegisterSumsReport.setTkr(registry.getTradingClearingRegistry());
ksRepCashRegisterSumsReport.setFirmId(company.getTradingCode());
if (searchTCRAsInfo) {
ksRepCashRegisterSumsReport.setAccount(company.getTradingCode());
} else {
ksRepCashRegisterSumsReport.setAccount(statement.getAccount());
}
ksRepCashRegisterSumsReport.setTkr(tkr.getCode());
ksRepCashRegisterSumsReport.setRegisterCode(registry.getRegistryCode());
ksRepCashRegisterSumsReport.setAddDate(nowDate);
if (statement.getCreated() != null)

View file

@ -144,8 +144,8 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
ksRepDepoRegisterQuantitiesReport.setSecurityId(security.getSecuritySymbol());
ksRepDepoRegisterQuantitiesReport.setRegisterCode(registry.getRegistryCode());
ksRepDepoRegisterQuantitiesReport.setAddDate(nowDate);
if (statement.getUpdated() != null)
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(statement.getUpdated(), getReportZoneId()));
if (statement.getCreated() != null)
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(statement.getCreated(), getReportZoneId()));
InOutDirection inOutDirection = IEnumKey.getEnumByKey(InOutDirection.class, statement.getInOutDirection());
if (inOutDirection == InOutDirection.in) {