This commit is contained in:
parent
4da67d145d
commit
e99311b582
14 changed files with 294 additions and 467 deletions
|
|
@ -66,7 +66,7 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
LocalDate nowDate = LocalDate.now();
|
||||
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TM_T, RegistryTradingParams.OM_T).build();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.CM_T, RegistryTradingParams.LM_T).build();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
|
|
@ -89,7 +89,7 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
List<Registry> groupedRegistry = entry.getValue();
|
||||
try {
|
||||
if (groupedRegistry.isEmpty()) {
|
||||
log.warn("Empty OM_T and TM_T registries for account = {} and session_id = {}. Registries with id = [{}] was skipped",
|
||||
log.warn("Empty LM_T and CM_T registries for account = {} and session_id = {}. Registries with id = [{}] was skipped",
|
||||
pairRegistryId.getAccount(),
|
||||
pairRegistryId.getSessionId(),
|
||||
groupedRegistry.stream().map(r -> String.valueOf(r.getId())).collect(Collectors.joining(", "))
|
||||
|
|
@ -97,32 +97,32 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
continue;
|
||||
}
|
||||
|
||||
List<Registry> tmtRegistries = new ArrayList<>();
|
||||
List<Registry> omtRegistries = new ArrayList<>();
|
||||
List<Registry> cmtRegistries = new ArrayList<>();
|
||||
List<Registry> lmtRegistries = new ArrayList<>();
|
||||
Registry registry = null;
|
||||
for (Registry currRegistry : groupedRegistry) {
|
||||
registry = currRegistry;
|
||||
if (RegistryDesignation.O.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
omtRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.T.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
tmtRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.L.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
lmtRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.C.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
cmtRegistries.add(currRegistry);
|
||||
}
|
||||
|
||||
boolean invalid = false;
|
||||
if (!tmtRegistries.isEmpty() || !omtRegistries.isEmpty()) {
|
||||
if (!cmtRegistries.isEmpty() || !lmtRegistries.isEmpty()) {
|
||||
String sourceTradingCode = "";
|
||||
if (!tmtRegistries.isEmpty()) sourceTradingCode = tmtRegistries.iterator().next().getTradingCode();
|
||||
if (!omtRegistries.isEmpty()) sourceTradingCode = omtRegistries.iterator().next().getTradingCode();
|
||||
for (Registry currRegistry : tmtRegistries) {
|
||||
if (!cmtRegistries.isEmpty()) sourceTradingCode = cmtRegistries.iterator().next().getTradingCode();
|
||||
if (!lmtRegistries.isEmpty()) sourceTradingCode = lmtRegistries.iterator().next().getTradingCode();
|
||||
for (Registry currRegistry : cmtRegistries) {
|
||||
if (sourceTradingCode.equals(currRegistry.getTradingCode())) continue;
|
||||
invalid = true;
|
||||
log.warn("Invalid TM_T registries set, tradingCode not equals. Registries was skipped");
|
||||
log.warn("Invalid CM_T registries set, tradingCode not equals. Registries was skipped");
|
||||
break;
|
||||
}
|
||||
for (Registry currRegistry : omtRegistries) {
|
||||
for (Registry currRegistry : lmtRegistries) {
|
||||
if (sourceTradingCode.equals(currRegistry.getTradingCode())) continue;
|
||||
invalid = true;
|
||||
log.warn("Invalid OM_T registries set, tradingCode not equals. Registries was skipped");
|
||||
log.warn("Invalid LM_T registries set, tradingCode not equals. Registries was skipped");
|
||||
break;
|
||||
}
|
||||
if (invalid) continue;
|
||||
|
|
@ -140,15 +140,15 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ksRepCashNettoReport.setAccount(registry.getAccount());
|
||||
ksRepCashNettoReport.setDate(nowDate);
|
||||
|
||||
BigDecimal tmtBalance = BigDecimal.ZERO;
|
||||
BigDecimal omtBalance = BigDecimal.ZERO;
|
||||
for (Registry tmtRegistry : tmtRegistries) {
|
||||
if (tmtRegistry.getBalance() != null) tmtBalance = tmtBalance.add(tmtRegistry.getBalance());
|
||||
BigDecimal cmtBalance = BigDecimal.ZERO;
|
||||
BigDecimal lmtBalance = BigDecimal.ZERO;
|
||||
for (Registry cmtRegistry : cmtRegistries) {
|
||||
if (cmtRegistry.getBalance() != null) cmtBalance = cmtBalance.add(cmtRegistry.getBalance());
|
||||
}
|
||||
for (Registry omtRegistry : omtRegistries) {
|
||||
if (omtRegistry.getBalance() != null) omtBalance = omtBalance.add(omtRegistry.getBalance());
|
||||
for (Registry lmtRegistry : lmtRegistries) {
|
||||
if (lmtRegistry.getBalance() != null) lmtBalance = lmtBalance.add(lmtRegistry.getBalance());
|
||||
}
|
||||
ksRepCashNettoReport.setValue(tmtBalance.subtract(omtBalance));
|
||||
ksRepCashNettoReport.setValue(cmtBalance.subtract(lmtBalance));
|
||||
|
||||
rows.add(ksRepCashNettoReport);
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
|
|
@ -1,11 +1,8 @@
|
|||
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;
|
||||
import ru.clearing.classes.statics.data.statement.Statement;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.reports.reports.CSVReportBuilder;
|
||||
import ru.spcex.clearing.reports.reports.EmptyParams;
|
||||
|
|
@ -16,30 +13,26 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@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 final Imdg<Registry> registryImdg;
|
||||
|
||||
private List<KSRepCashRegisterSumsReport> rows = null;
|
||||
|
||||
public KSRepCashRegisterSumsReportBuilder(ImdgProvider imdgProvider) {
|
||||
statementImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Statement, Statement.class);
|
||||
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);
|
||||
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -69,196 +62,51 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
|
||||
@Override
|
||||
protected void collect(EmptyParams params) {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
Instant instantNow = Instant.now();
|
||||
|
||||
ImdgPredicateBuilder pb = statementImdg.predicateBuilder();
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
ImdgPredicate registryPredicate = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.DM_I).buildPredicate(pb);
|
||||
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
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.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("registryStatus", RegistryStatus.OK.getKey()),
|
||||
pb.notNull("tradingClearingRegistry"),
|
||||
registryPredicate
|
||||
|
||||
);
|
||||
Collection<Statement> statements = statementImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
log.debug("Found {} Statements by query: {}", statements.size(), finalPredicate);
|
||||
rows = new ArrayList<>(statements.size());
|
||||
for (Statement statement : statements) {
|
||||
if (statement.getAmount() == null) {
|
||||
log.warn("Statement id={} has null amount, statement was skipped", statement.getId());
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
log.debug("Found {} registries by query: {}", registries.size(), finalPredicate);
|
||||
rows = new ArrayList<>(registries.size());
|
||||
for (Registry registry : registries) {
|
||||
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For registry id = {} company with id = {} not found, registry was skipped",
|
||||
registry.getId(),
|
||||
registry.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
try {
|
||||
boolean searchTCRAsInfo;
|
||||
if (Arrays.asList(1L, 2L).contains(statement.getAccountId())) {
|
||||
searchTCRAsInfo = true;
|
||||
} else {
|
||||
Account account = accountImdg.getSingleObjectByID(statement.getAccountId());
|
||||
if (account == null) {
|
||||
log.warn("Unexpected state: for statement (id = {}) not found account for accountId = {}. Statement was skipped",
|
||||
statement.getId(),
|
||||
statement.getAccountId());
|
||||
continue;
|
||||
}
|
||||
searchTCRAsInfo = AccountType.Info.equalsByKey(account.getAccountType());
|
||||
if (!searchTCRAsInfo && !AccountType.Clrn.equalsByKey(account.getAccountType())) {
|
||||
log.warn("Unexpected account[{}] type {}", account.getId(), account.getAccountType());
|
||||
}
|
||||
}
|
||||
TradingClearingRegistry tkr;
|
||||
if (searchTCRAsInfo) {
|
||||
String code = parseCodeFromStatementComment(statement.getComment());
|
||||
if (code == null || code.isBlank()) {
|
||||
log.warn("For statement id = {} empty or unparseable code=\"{}\" (comment \"{}\"), statement was skipped",
|
||||
code, statement.getComment(), statement.getId());
|
||||
continue;
|
||||
}
|
||||
log.debug("Search TradingClearingRegistry by code={}", code);
|
||||
tkr = tradingClearingRegistryImdg.getFirstObjectByFieldValues(Map.of("code", code));
|
||||
if (tkr == null) {
|
||||
log.warn(
|
||||
"For statement id = {} and code = {} (or unparseable comment=\"{}\") not found TradingClearingRegistry, statement was skipped",
|
||||
statement.getId(),
|
||||
code, statement.getComment()
|
||||
);
|
||||
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 was skipped",
|
||||
statement.getId(),
|
||||
accountId
|
||||
);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) 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;
|
||||
}
|
||||
String firmId = registry.getTradingCode();
|
||||
String account = registry.getAccount();
|
||||
String tkr = registry.getTradingClearingRegistry();
|
||||
String tradeNum = "";
|
||||
String registerCode = registry.getRegistryCode();
|
||||
BigDecimal addSum = registry.getBalance() != null ? registry.getBalance() :BigDecimal.ZERO;
|
||||
Instant addTime = registry.getUpdated();
|
||||
LocalDate addDate = LocalDate.now();
|
||||
|
||||
|
||||
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
||||
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 {}. Statement id = {} skipped",
|
||||
registryQuery,
|
||||
statement.getId()
|
||||
);
|
||||
continue;
|
||||
} else if (registries.size() > 1) {
|
||||
log.warn(
|
||||
"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(company.getTradingCode());
|
||||
if (searchTCRAsInfo) {
|
||||
Account account = accountImdg.getSingleObjectByID(tkr.getMoneyAccountId());
|
||||
if (account == null) {
|
||||
log.debug("statement id={}, moneyAccount not found with id={}",
|
||||
statement.getId(), tkr.getMoneyAccountId());
|
||||
} else {
|
||||
ksRepCashRegisterSumsReport.setAccount(account.getAccount());
|
||||
}
|
||||
} else {
|
||||
ksRepCashRegisterSumsReport.setAccount(statement.getAccount());
|
||||
}
|
||||
ksRepCashRegisterSumsReport.setTkr(tkr.getCode());
|
||||
ksRepCashRegisterSumsReport.setRegisterCode(registry.getRegistryCode());
|
||||
ksRepCashRegisterSumsReport.setAddDate(nowDate);
|
||||
if (statement.getCreated() != null)
|
||||
ksRepCashRegisterSumsReport.setAddTime(LocalTime.ofInstant(statement.getCreated(), getReportZoneId()));
|
||||
|
||||
InOutDirection inOutDirection = IEnumKey.getEnumByKey(InOutDirection.class, statement.getInOutDirection());
|
||||
if (inOutDirection == InOutDirection.in) {
|
||||
ksRepCashRegisterSumsReport.setAddSum(statement.getAmount());
|
||||
} else if (inOutDirection == InOutDirection.out) {
|
||||
ksRepCashRegisterSumsReport.setAddSum(statement.getAmount().negate());
|
||||
} else {
|
||||
log.warn(
|
||||
"Invalid statement.in_out_direction ({}). Statement id = {} skipped",
|
||||
statement.getInOutDirection(),
|
||||
statement.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
rows.add(ksRepCashRegisterSumsReport);
|
||||
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(statement.getId()), e);
|
||||
}
|
||||
KSRepCashRegisterSumsReport ksRepCashRegisterSumsReport = new KSRepCashRegisterSumsReport();
|
||||
ksRepCashRegisterSumsReport.setFirmId(firmId);
|
||||
ksRepCashRegisterSumsReport.setAccount(account);
|
||||
ksRepCashRegisterSumsReport.setTkr(tkr);
|
||||
ksRepCashRegisterSumsReport.setTradeNum(tradeNum);
|
||||
ksRepCashRegisterSumsReport.setRegisterCode(registerCode);
|
||||
ksRepCashRegisterSumsReport.setAddSum(addSum);
|
||||
ksRepCashRegisterSumsReport.setAddTime(LocalTime.ofInstant(addTime, getReportZoneId()));
|
||||
ksRepCashRegisterSumsReport.setAddDate(addDate);
|
||||
rows.add(ksRepCashRegisterSumsReport);
|
||||
}
|
||||
}
|
||||
|
||||
protected String parseCodeFromStatementComment(String comment) {
|
||||
if (comment == null)
|
||||
return null;
|
||||
int i = comment.lastIndexOf("ТКР");
|
||||
String code = comment;
|
||||
if (i >= 0) {
|
||||
code = code.substring(i + 3).trim();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
i = -1;
|
||||
for (String end : Arrays.asList(".", ";", " ")) {
|
||||
int p = code.indexOf(end);
|
||||
if (p > 0 && (i <= 0 || i > p)) i = p;
|
||||
}
|
||||
if (i > 0) {
|
||||
code = code.substring(0, i);
|
||||
}
|
||||
return code;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -114,9 +114,22 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
BigDecimal settleDebit = registry.getSettledDebit() != null ? registry.getSettledDebit() : BigDecimal.ZERO;
|
||||
ksRepCashRegistersReport.setChangeBalance(settleCredit.subtract(settleDebit));
|
||||
|
||||
BigDecimal credit = registry.getCredit() != null ? registry.getCredit() : BigDecimal.ZERO;
|
||||
BigDecimal debit = registry.getDebit() != null ? registry.getDebit() : BigDecimal.ZERO;
|
||||
ksRepCashRegistersReport.setAddWithdraw(credit.subtract(debit));
|
||||
registryPredicate = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.DMAI).buildPredicate(pb);
|
||||
Collection<Registry> registriesForAddWithdraw = registryImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
registryPredicate,
|
||||
pb.equals("securityId", registry.getSecurityId()),
|
||||
pb.equals("accountId", registry.getAccountId()),
|
||||
pb.equals("companyId", registry.getCompanyId()),
|
||||
pb.equals("registryStatus", RegistryStatus.OK.getKey()),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.notNull("balance")
|
||||
)
|
||||
);
|
||||
BigDecimal addWithdraw = BigDecimal.ZERO;
|
||||
for (Registry currRegistry : registriesForAddWithdraw) addWithdraw = addWithdraw.add(currRegistry.getBalance());
|
||||
ksRepCashRegistersReport.setAddWithdraw(addWithdraw);
|
||||
|
||||
BigDecimal closeBalance = ksRepCashRegistersReport.getOpenBalance()
|
||||
.add(ksRepCashRegistersReport.getChangeBalance())
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TS_T, RegistryTradingParams.OS_T).build();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.CS_T, RegistryTradingParams.LS_T).build();
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.in("sessionId", sessionIds.toArray(new Long[0])),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
|
|
@ -86,39 +86,39 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
List<Registry> groupedRegistry = entry.getValue();
|
||||
try {
|
||||
if (groupedRegistry.isEmpty()) {
|
||||
log.warn("Empty OS_T and TS_T registries for {}. Registries with id = [{}] was skipped",
|
||||
log.warn("Empty LS_T and CS_T registries for {}. Registries with id = [{}] was skipped",
|
||||
pairRegistryId,
|
||||
groupedRegistry.stream().map(r -> String.valueOf(r.getId())).collect(Collectors.joining(", "))
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
List<Registry> tstRegistries = new ArrayList<>();
|
||||
List<Registry> ostRegistries = new ArrayList<>();
|
||||
List<Registry> cstRegistries = new ArrayList<>();
|
||||
List<Registry> lstRegistries = new ArrayList<>();
|
||||
Registry registry = null;
|
||||
for (Registry currRegistry : groupedRegistry) {
|
||||
registry = currRegistry;
|
||||
if (RegistryDesignation.O.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
ostRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.T.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
tstRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.L.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
lstRegistries.add(currRegistry);
|
||||
if (RegistryDesignation.C.equalsByKey(currRegistry.getRegistryDesignation()))
|
||||
cstRegistries.add(currRegistry);
|
||||
}
|
||||
|
||||
boolean invalid = false;
|
||||
if (!tstRegistries.isEmpty() || !ostRegistries.isEmpty()) {
|
||||
if (!cstRegistries.isEmpty() || !lstRegistries.isEmpty()) {
|
||||
String sourceTradingCode = "";
|
||||
if (!tstRegistries.isEmpty()) sourceTradingCode = tstRegistries.iterator().next().getTradingCode();
|
||||
if (!ostRegistries.isEmpty()) sourceTradingCode = ostRegistries.iterator().next().getTradingCode();
|
||||
for (Registry currRegistry : tstRegistries) {
|
||||
if (!cstRegistries.isEmpty()) sourceTradingCode = cstRegistries.iterator().next().getTradingCode();
|
||||
if (!lstRegistries.isEmpty()) sourceTradingCode = lstRegistries.iterator().next().getTradingCode();
|
||||
for (Registry currRegistry : cstRegistries) {
|
||||
if (sourceTradingCode.equals(currRegistry.getTradingCode())) continue;
|
||||
invalid = true;
|
||||
log.warn("Invalid TS_T registries set, tradingCode not equals. Registries was skipped");
|
||||
log.warn("Invalid CS_T registries set, tradingCode not equals. Registries was skipped");
|
||||
break;
|
||||
}
|
||||
for (Registry currRegistry : ostRegistries) {
|
||||
for (Registry currRegistry : lstRegistries) {
|
||||
if (sourceTradingCode.equals(currRegistry.getTradingCode())) continue;
|
||||
invalid = true;
|
||||
log.warn("Invalid OS_T registries set, tradingCode not equals. Registries was skipped");
|
||||
log.warn("Invalid LS_T registries set, tradingCode not equals. Registries was skipped");
|
||||
break;
|
||||
}
|
||||
if (invalid) continue;
|
||||
|
|
@ -135,15 +135,15 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
if (session != null && session.getCreated() != null)
|
||||
ksRepDepoNettoReport.setSessionDate(LocalDateTime.ofInstant(session.getCreated(), getReportZoneId()));
|
||||
|
||||
BigDecimal tstBalance = BigDecimal.ZERO;
|
||||
BigDecimal ostBalance = BigDecimal.ZERO;
|
||||
for (Registry tstRegistry : tstRegistries) {
|
||||
if (tstRegistry.getBalance() != null) tstBalance = tstBalance.add(tstRegistry.getBalance());
|
||||
BigDecimal cstBalance = BigDecimal.ZERO;
|
||||
BigDecimal lstBalance = BigDecimal.ZERO;
|
||||
for (Registry cstRegistry : cstRegistries) {
|
||||
if (cstRegistry.getBalance() != null) cstBalance = cstBalance.add(cstRegistry.getBalance());
|
||||
}
|
||||
for (Registry ostRegistry : ostRegistries) {
|
||||
if (ostRegistry.getBalance() != null) ostBalance = ostBalance.add(ostRegistry.getBalance());
|
||||
for (Registry lstRegistry : lstRegistries) {
|
||||
if (lstRegistry.getBalance() != null) lstBalance = lstBalance.add(lstRegistry.getBalance());
|
||||
}
|
||||
ksRepDepoNettoReport.setValue(tstBalance.subtract(ostBalance));
|
||||
ksRepDepoNettoReport.setValue(cstBalance.subtract(lstBalance));
|
||||
|
||||
rows.add(ksRepDepoNettoReport);
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
|
|
@ -2,12 +2,7 @@ package ru.spcex.clearing.reports.reports.ks;
|
|||
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.instrument.issue.EquitySecurity;
|
||||
import ru.clearing.classes.statics.data.instrument.issue.FixedIncomeSecurity;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.clearing.classes.statics.data.security.MoneyMarketSecurity;
|
||||
import ru.clearing.classes.statics.data.security.Security;
|
||||
import ru.clearing.classes.statics.data.statement.Statement;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.reports.reports.CSVReportBuilder;
|
||||
import ru.spcex.clearing.reports.reports.EmptyParams;
|
||||
|
|
@ -18,8 +13,8 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
|
@ -30,22 +25,14 @@ import java.util.List;
|
|||
|
||||
@Component
|
||||
public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<EmptyParams, KSRepDepoRegisterQuantitiesReport> {
|
||||
private final Imdg<Statement> statementImdg;
|
||||
private final Imdg<Registry> registryImdg;
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<FixedIncomeSecurity> fixedIncomeSecurityImdg;
|
||||
private final Imdg<EquitySecurity> equitySecurityImdg;
|
||||
private final Imdg<MoneyMarketSecurity> moneyMarketSecurityImdg;
|
||||
|
||||
private List<KSRepDepoRegisterQuantitiesReport> rows = null;
|
||||
|
||||
public KSRepDepoRegisterQuantitiesReportBuilder(ImdgProvider imdgProvider) {
|
||||
statementImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Statement, Statement.class);
|
||||
registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
fixedIncomeSecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_FixedIncomeSecurity, FixedIncomeSecurity.class);
|
||||
equitySecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_EquitySecurity, EquitySecurity.class);
|
||||
moneyMarketSecurityImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_MoneyMarketSecurity, MoneyMarketSecurity.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -75,126 +62,55 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
|||
|
||||
@Override
|
||||
protected void collect(EmptyParams params) {
|
||||
LocalDate nowDate = LocalDate.now();
|
||||
Instant instantNow = Instant.now();
|
||||
|
||||
ImdgPredicateBuilder pb = statementImdg.predicateBuilder();
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
ImdgPredicate registryPredicate = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.DS_I).buildPredicate(pb);
|
||||
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.greatEqual("created", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("created", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("inOutSDfType", InOutSDfType.type21.getKey()),
|
||||
pb.equals("operationStatus", OperationStatus.Executed.getKey()),
|
||||
pb.notNull("amount")
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("registryStatus", RegistryStatus.OK.getKey()),
|
||||
pb.notNull("tradingClearingRegistry"),
|
||||
registryPredicate
|
||||
|
||||
);
|
||||
Collection<Statement> statements = statementImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
log.debug("Found {} Statement by query: {}", statements.size(), 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;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(
|
||||
pbRegistry.and(
|
||||
pbRegistry.equals("companyId", statement.getAddresseeId()),
|
||||
pbRegistry.equals("account", statement.getAccount()),
|
||||
pbRegistry.equals("accountType", AccountType.Depo.getKey()),
|
||||
RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AS_T).buildPredicate(pbRegistry),
|
||||
pbRegistry.equals("securityId", statement.getSecurityId())
|
||||
)
|
||||
);
|
||||
if (registries.isEmpty()) {
|
||||
log.warn(
|
||||
"Can't find registry for companyId = {}, securityId = {} and account: {}. Statement id = {} skipped",
|
||||
statement.getAddresseeId(),
|
||||
statement.getSecurityId(),
|
||||
statement.getAccount(),
|
||||
statement.getId()
|
||||
);
|
||||
continue;
|
||||
} else if (registries.size() > 1) {
|
||||
log.warn(
|
||||
"More then one AS_T registry found for companyId = {}, securityId = {} and account: {}, statement id {}. Use first",
|
||||
statement.getAddresseeId(),
|
||||
statement.getSecurityId(),
|
||||
statement.getAccount(),
|
||||
statement.getId()
|
||||
);
|
||||
}
|
||||
Registry registry = registries.iterator().next();
|
||||
|
||||
Security security = getSecurityWithSecuritySymbolForId(statement.getSecurityId());
|
||||
if (security == null) {
|
||||
log.warn(
|
||||
"Can't find security for securityId = {}. Statement id = {} skipped",
|
||||
statement.getSecurityId(),
|
||||
statement.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
KSRepDepoRegisterQuantitiesReport ksRepDepoRegisterQuantitiesReport = new KSRepDepoRegisterQuantitiesReport();
|
||||
ksRepDepoRegisterQuantitiesReport.setFirmId(company.getTradingCode());
|
||||
ksRepDepoRegisterQuantitiesReport.setAccount(statement.getAccount());
|
||||
ksRepDepoRegisterQuantitiesReport.setTkr(registry.getTradingClearingRegistry());
|
||||
ksRepDepoRegisterQuantitiesReport.setSecurityId(security.getSecuritySymbol());
|
||||
ksRepDepoRegisterQuantitiesReport.setRegisterCode(registry.getRegistryCode());
|
||||
ksRepDepoRegisterQuantitiesReport.setAddDate(nowDate);
|
||||
if (statement.getCreated() != null)
|
||||
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(statement.getCreated(), getReportZoneId()));
|
||||
|
||||
InOutDirection inOutDirection = IEnumKey.getEnumByKey(InOutDirection.class, statement.getInOutDirection());
|
||||
if (inOutDirection == InOutDirection.in) {
|
||||
ksRepDepoRegisterQuantitiesReport.setAddQuantity(statement.getAmount());
|
||||
} else if (inOutDirection == InOutDirection.out) {
|
||||
ksRepDepoRegisterQuantitiesReport.setAddQuantity(statement.getAmount().negate());
|
||||
} else {
|
||||
log.warn(
|
||||
"Invalid statement.in_out_direction ({}). Statement id = {} skipped",
|
||||
statement.getInOutDirection(),
|
||||
statement.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
rows.add(ksRepDepoRegisterQuantitiesReport);
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(statement.getId()), e);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
log.debug("Found {} registries by query: {}", registries.size(), finalPredicate);
|
||||
rows = new ArrayList<>(registries.size());
|
||||
for (Registry registry : registries) {
|
||||
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For registry id = {} company with id = {} not found, registry was skipped",
|
||||
registry.getId(),
|
||||
registry.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
String firmId = registry.getTradingCode();
|
||||
String account = registry.getAccount();
|
||||
String tkr = registry.getTradingClearingRegistry();
|
||||
String tradeNum = "";
|
||||
String securityId = registry.getSecuritySymbol();
|
||||
String registerCode = registry.getRegistryCode();
|
||||
BigDecimal addQuantity = registry.getBalance() != null ? registry.getBalance() :BigDecimal.ZERO;
|
||||
Instant addTime = registry.getUpdated();
|
||||
LocalDate addDate = LocalDate.now();
|
||||
|
||||
KSRepDepoRegisterQuantitiesReport ksRepDepoRegisterQuantitiesReport = new KSRepDepoRegisterQuantitiesReport();
|
||||
ksRepDepoRegisterQuantitiesReport.setFirmId(firmId);
|
||||
ksRepDepoRegisterQuantitiesReport.setAccount(account);
|
||||
ksRepDepoRegisterQuantitiesReport.setTkr(tkr);
|
||||
ksRepDepoRegisterQuantitiesReport.setTradeNum(tradeNum);
|
||||
ksRepDepoRegisterQuantitiesReport.setSecurityId(securityId);
|
||||
ksRepDepoRegisterQuantitiesReport.setRegisterCode(registerCode);
|
||||
ksRepDepoRegisterQuantitiesReport.setAddQuantity(addQuantity);
|
||||
ksRepDepoRegisterQuantitiesReport.setAddTime(LocalTime.ofInstant(addTime, getReportZoneId()));
|
||||
ksRepDepoRegisterQuantitiesReport.setAddDate(addDate);
|
||||
rows.add(ksRepDepoRegisterQuantitiesReport);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Security getSecurityWithSecuritySymbolForId(Long securityId) {
|
||||
Security security;
|
||||
security = equitySecurityImdg.getFirstObjectByPredicate(
|
||||
equitySecurityImdg.predicateBuilder().and(
|
||||
equitySecurityImdg.predicateBuilder().equals("securityId", securityId),
|
||||
equitySecurityImdg.predicateBuilder().notNull("securitySymbol")
|
||||
)
|
||||
);
|
||||
if (security == null) {
|
||||
security = fixedIncomeSecurityImdg.getFirstObjectByPredicate(
|
||||
fixedIncomeSecurityImdg.predicateBuilder().and(
|
||||
fixedIncomeSecurityImdg.predicateBuilder().equals("securityId", securityId),
|
||||
fixedIncomeSecurityImdg.predicateBuilder().notNull("securitySymbol")
|
||||
)
|
||||
);
|
||||
}
|
||||
if (security == null)
|
||||
security = moneyMarketSecurityImdg.getFirstObjectByPredicate(
|
||||
moneyMarketSecurityImdg.predicateBuilder().and(
|
||||
moneyMarketSecurityImdg.predicateBuilder().equals("securityId", securityId),
|
||||
moneyMarketSecurityImdg.predicateBuilder().notNull("securitySymbol")
|
||||
)
|
||||
);
|
||||
return security;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,9 +69,9 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
Instant instantNow = Instant.now();
|
||||
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AS_T).build();
|
||||
ImdgPredicate registryPredicate = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.AS_T).buildPredicate(pb);
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.sql(sql),
|
||||
registryPredicate,
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("accountType", AccountType.Depo.getKey()),
|
||||
|
|
@ -112,9 +112,22 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
BigDecimal settledDebit = registry.getSettledDebit() != null ? registry.getSettledDebit() : BigDecimal.ZERO;
|
||||
ksRepDepoRegistersReport.setChangeQuantity(settledCredit.subtract(settledDebit));
|
||||
|
||||
BigDecimal credit = registry.getCredit() != null ? registry.getCredit() : BigDecimal.ZERO;
|
||||
BigDecimal debit = registry.getDebit() != null ? registry.getDebit() : BigDecimal.ZERO;
|
||||
ksRepDepoRegistersReport.setAddWithdrawDepo(credit.subtract(debit));
|
||||
registryPredicate = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.DMAI).buildPredicate(pb);
|
||||
Collection<Registry> registriesForAddWithdraw = registryImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
registryPredicate,
|
||||
pb.equals("securityId", registry.getSecurityId()),
|
||||
pb.equals("accountId", registry.getAccountId()),
|
||||
pb.equals("companyId", registry.getCompanyId()),
|
||||
pb.equals("registryStatus", RegistryStatus.OK.getKey()),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.notNull("balance")
|
||||
)
|
||||
);
|
||||
BigDecimal addWithdraw = BigDecimal.ZERO;
|
||||
for (Registry currRegistry : registriesForAddWithdraw) addWithdraw = addWithdraw.add(currRegistry.getBalance());
|
||||
ksRepDepoRegistersReport.setAddWithdrawDepo(addWithdraw);
|
||||
|
||||
BigDecimal closeBalance = ksRepDepoRegistersReport.getOpenQuantity()
|
||||
.add(ksRepDepoRegistersReport.getChangeQuantity())
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
package ru.spcex.clearing.reports.reports.ks;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class KSRepCashRegisterSumsReportBuilderTest {
|
||||
|
||||
@Test
|
||||
void parseCodeFromStatementComment() {
|
||||
KSRepCashRegisterSumsReportBuilder reportB = new KSRepCashRegisterSumsReportBuilder(Mockito.mock(ImdgProvider.class));
|
||||
assertNull(reportB.parseCodeFromStatementComment(null));
|
||||
assertEquals(null, reportB.parseCodeFromStatementComment(""));
|
||||
assertEquals(null, reportB.parseCodeFromStatementComment(" TTTAAA "));
|
||||
assertEquals("0045CAT00001", reportB.parseCodeFromStatementComment("Возврат на депозит №DSTAA10S003/150923/45/23091500000008 по ТКР 0045CAT00001"));
|
||||
assertEquals("0574MAT00001", reportB.parseCodeFromStatementComment("Вывод средств по ТКР 0574MAT00001. Поручения 777."));
|
||||
assertEquals("0574MAT00001", reportB.parseCodeFromStatementComment("ТКР 0574MAT00001"));
|
||||
assertEquals("0574MAT00001", reportB.parseCodeFromStatementComment("ТКР0574MAT00001"));
|
||||
assertEquals("", reportB.parseCodeFromStatementComment("ТКР"));
|
||||
}
|
||||
}
|
||||
|
|
@ -129,6 +129,8 @@ public class ReportServiceTest_KS {
|
|||
|
||||
Registry registry = new Registry();
|
||||
registry.setCompanyId(COMPANY_ID);
|
||||
registry.setSecurityId(777L);
|
||||
registry.setAccountId(888L);
|
||||
registry.setRegistryCode("AM_T");
|
||||
registry.setRegistryDesignation(RegistryDesignation.A.getKey());
|
||||
registry.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
|
|
@ -146,6 +148,48 @@ public class ReportServiceTest_KS {
|
|||
registry.setCloseBalance(BigDecimal.valueOf(11.11111111));
|
||||
registryImdg.insert(registry);
|
||||
|
||||
Registry addWithdrawRegistry_1 = new Registry();
|
||||
addWithdrawRegistry_1.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_1.setSecurityId(777L);
|
||||
addWithdrawRegistry_1.setAccountId(888L);
|
||||
addWithdrawRegistry_1.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_1.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_1.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_1.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_1.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_1.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_1.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_1.setBalance(BigDecimal.TEN);
|
||||
registryImdg.insert(addWithdrawRegistry_1);
|
||||
|
||||
Registry addWithdrawRegistry_2 = new Registry();
|
||||
addWithdrawRegistry_2.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_2.setSecurityId(777L);
|
||||
addWithdrawRegistry_2.setAccountId(888L);
|
||||
addWithdrawRegistry_2.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_2.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_2.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_2.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_2.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_2.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_2.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_2.setBalance(BigDecimal.ONE);
|
||||
registryImdg.insert(addWithdrawRegistry_2);
|
||||
|
||||
Registry addWithdrawRegistry_3 = new Registry();
|
||||
addWithdrawRegistry_3.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_3.setSecurityId(777L);
|
||||
addWithdrawRegistry_3.setAccountId(888L);
|
||||
addWithdrawRegistry_3.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_3.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_3.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_3.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_3.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_3.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_3.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_3.setBalance(BigDecimal.valueOf(100L));
|
||||
registryImdg.insert(addWithdrawRegistry_3);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) reportService.getConsumer(),
|
||||
|
|
@ -162,6 +206,9 @@ public class ReportServiceTest_KS {
|
|||
|
||||
registryCodeDictionaryImdg.delete(registryCodeDictionary);
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(addWithdrawRegistry_1);
|
||||
registryImdg.delete(addWithdrawRegistry_2);
|
||||
registryImdg.delete(addWithdrawRegistry_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -173,39 +220,18 @@ public class ReportServiceTest_KS {
|
|||
reportRequest.setReportId(ReportBuilderType.KS_REP_CASH_REGISTER_SUMS.getKey());
|
||||
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setUpdated(Instant.now());
|
||||
registry_1.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setTradingClearingRegistry("0008CAT00001");
|
||||
registry_1.setCompanyId(COMPANY_ID);
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setAccountType(AccountType.Clrn.getKey());
|
||||
registry_1.setRegistryCode("AM_T");
|
||||
registry_1.setRegistryDesignation("A");
|
||||
registry_1.setRegistryCode("DM_I");
|
||||
registry_1.setRegistryDesignation("D");
|
||||
registry_1.setRegistryInstrumentType("M");
|
||||
registry_1.setRegistryUnit("T");
|
||||
registry_1.setTradingClearingRegistry("0008CAT00001");
|
||||
registry_1.setRegistryUnit("I");
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
TradingClearingRegistry tkr = new TradingClearingRegistry();
|
||||
tkr.setMoneyAccountId(777L);
|
||||
tkr.setCode("0008CAT00001");
|
||||
tkr.setCompanyId(COMPANY_ID);
|
||||
tradingClearingRegistryImdg.insert(tkr);
|
||||
|
||||
Account account = new Account();
|
||||
account.setAccountType(AccountType.Info.getKey());
|
||||
account.setAccount("ACCOUNT");
|
||||
Long accountId = accountImdg.insert(account);
|
||||
|
||||
Statement statement_1 = new Statement();
|
||||
statement_1.setAddresseeId(COMPANY_ID);
|
||||
statement_1.setAccount("ACCOUNT");
|
||||
statement_1.setAccountId(accountId);
|
||||
statement_1.setInOutDirection(InOutDirection.in.getKey());
|
||||
statement_1.setInOutSDfType(InOutSDfType.type57.getKey());
|
||||
statement_1.setOperationStatus(OperationStatus.Executed.getKey());
|
||||
statement_1.setAmount(BigDecimal.valueOf(7777.777777777));
|
||||
statement_1.setCreated(Instant.now());
|
||||
statement_1.setComment("Зачислить на ТКР 0008CAT00001");
|
||||
statementImdg.insert(statement_1);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) reportService.getConsumer(),
|
||||
|
|
@ -221,9 +247,6 @@ public class ReportServiceTest_KS {
|
|||
compareCSVFiles(expectedFile, outFile, Arrays.asList("FIRMID", "ADD_DATE", "ADD_TIME"));
|
||||
|
||||
registryImdg.delete(registry_1);
|
||||
statementImdg.delete(statement_1);
|
||||
tradingClearingRegistryImdg.delete(tkr);
|
||||
accountImdg.delete(account);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -241,7 +264,10 @@ public class ReportServiceTest_KS {
|
|||
|
||||
Registry registry = new Registry();
|
||||
registry.setCompanyId(COMPANY_ID);
|
||||
registry.setSecurityId(777L);
|
||||
registry.setAccountId(888L);
|
||||
registry.setRegistryCode("AS_T");
|
||||
registry.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry.setRegistryDesignation(RegistryDesignation.A.getKey());
|
||||
registry.setRegistryInstrumentType(RegistryInstrumentType.S.getKey());
|
||||
registry.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
|
|
@ -258,6 +284,48 @@ public class ReportServiceTest_KS {
|
|||
registry.setCloseBalance(BigDecimal.valueOf(11.11111111));
|
||||
registryImdg.insert(registry);
|
||||
|
||||
Registry addWithdrawRegistry_1 = new Registry();
|
||||
addWithdrawRegistry_1.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_1.setSecurityId(777L);
|
||||
addWithdrawRegistry_1.setAccountId(888L);
|
||||
addWithdrawRegistry_1.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_1.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_1.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_1.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_1.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_1.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_1.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_1.setBalance(BigDecimal.TEN);
|
||||
registryImdg.insert(addWithdrawRegistry_1);
|
||||
|
||||
Registry addWithdrawRegistry_2 = new Registry();
|
||||
addWithdrawRegistry_2.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_2.setSecurityId(777L);
|
||||
addWithdrawRegistry_2.setAccountId(888L);
|
||||
addWithdrawRegistry_2.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_2.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_2.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_2.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_2.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_2.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_2.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_2.setBalance(BigDecimal.ONE);
|
||||
registryImdg.insert(addWithdrawRegistry_2);
|
||||
|
||||
Registry addWithdrawRegistry_3 = new Registry();
|
||||
addWithdrawRegistry_3.setCompanyId(COMPANY_ID);
|
||||
addWithdrawRegistry_3.setSecurityId(777L);
|
||||
addWithdrawRegistry_3.setAccountId(888L);
|
||||
addWithdrawRegistry_3.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
addWithdrawRegistry_3.setRegistryCode("DMAI");
|
||||
addWithdrawRegistry_3.setRegistryDesignation(RegistryDesignation.D.getKey());
|
||||
addWithdrawRegistry_3.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
addWithdrawRegistry_3.setRegistryCapacity(RegistryCapacity.A.getKey());
|
||||
addWithdrawRegistry_3.setRegistryUnit(RegistryUnit.I.getKey());
|
||||
addWithdrawRegistry_3.setUpdated(Instant.now());
|
||||
addWithdrawRegistry_3.setBalance(BigDecimal.valueOf(100L));
|
||||
registryImdg.insert(addWithdrawRegistry_3);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) reportService.getConsumer(),
|
||||
|
|
@ -274,6 +342,9 @@ public class ReportServiceTest_KS {
|
|||
|
||||
registryCodeDictionaryImdg.delete(registryCodeDictionary);
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(addWithdrawRegistry_1);
|
||||
registryImdg.delete(addWithdrawRegistry_2);
|
||||
registryImdg.delete(addWithdrawRegistry_3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -285,34 +356,20 @@ public class ReportServiceTest_KS {
|
|||
reportRequest.setReportId(ReportBuilderType.KS_REP_DEPO_REGISTER_QUANTITIES.getKey());
|
||||
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setUpdated(Instant.now());
|
||||
registry_1.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry_1.setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setTradingClearingRegistry("0008CAT00001");
|
||||
registry_1.setCompanyId(COMPANY_ID);
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setTradingClearingRegistry("TRADING_CLEARING_REGISTRY");
|
||||
registry_1.setAccountType(AccountType.Depo.getKey());
|
||||
registry_1.setRegistryCode("AS_T");
|
||||
registry_1.setRegistryDesignation("A");
|
||||
registry_1.setRegistryCode("DS_I");
|
||||
registry_1.setRegistryDesignation("D");
|
||||
registry_1.setRegistryInstrumentType("S");
|
||||
registry_1.setRegistryUnit("T");
|
||||
registry_1.setSecurityId(777L);
|
||||
|
||||
registry_1.setRegistryUnit("I");
|
||||
registry_1.setBalance(BigDecimal.TEN);
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
EquitySecurity equitySecurity = new EquitySecurity();
|
||||
equitySecurity.setSecuritySymbol("value");
|
||||
equitySecurity.setSecurityId(777L);
|
||||
equitySecurityImdg.insert(equitySecurity);
|
||||
|
||||
Statement statement_1 = new Statement();
|
||||
statement_1.setAddresseeId(COMPANY_ID);
|
||||
statement_1.setAccount("ACCOUNT");
|
||||
statement_1.setInOutDirection(InOutDirection.in.getKey());
|
||||
statement_1.setInOutSDfType(InOutSDfType.type21.getKey());
|
||||
statement_1.setOperationStatus(OperationStatus.Executed.getKey());
|
||||
statement_1.setAmount(BigDecimal.valueOf(7777.777777777));
|
||||
statement_1.setCreated(Instant.now());
|
||||
statement_1.setSecurityId(777L);
|
||||
statementImdg.insert(statement_1);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
TestUtils.addRecordToKafka((MockConsumer) reportService.getConsumer(),
|
||||
|
|
@ -328,8 +385,6 @@ public class ReportServiceTest_KS {
|
|||
compareCSVFiles(expectedFile, outFile, Arrays.asList("FIRMID", "ADD_DATE", "ADD_TIME"));
|
||||
|
||||
registryImdg.delete(registry_1);
|
||||
equitySecurityImdg.delete(equitySecurity);
|
||||
statementImdg.delete(statement_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -434,9 +489,9 @@ public class ReportServiceTest_KS {
|
|||
registry_1.setSettlementDate(LocalDate.now());
|
||||
registry_1.setGroupId(Long.MAX_VALUE);
|
||||
registry_1.setClearingDate(LocalDate.now());
|
||||
registry_1.setRegistryCode("OM_T");
|
||||
registry_1.setRegistryCode("LM_T");
|
||||
registry_1.setRegistryStatus(RegistryStatus.PROC.getKey());
|
||||
registry_1.setRegistryDesignation(RegistryDesignation.O.getKey());
|
||||
registry_1.setRegistryDesignation(RegistryDesignation.L.getKey());
|
||||
registry_1.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
registry_1.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
registry_1.setSessionId(sessionId);
|
||||
|
|
@ -450,9 +505,9 @@ public class ReportServiceTest_KS {
|
|||
registry_2.setSettlementDate(LocalDate.now());
|
||||
registry_2.setGroupId(Long.MAX_VALUE);
|
||||
registry_2.setClearingDate(LocalDate.now());
|
||||
registry_2.setRegistryCode("TM_T");
|
||||
registry_2.setRegistryCode("CM_T");
|
||||
registry_2.setRegistryStatus(RegistryStatus.PROC.getKey());
|
||||
registry_2.setRegistryDesignation(RegistryDesignation.T.getKey());
|
||||
registry_2.setRegistryDesignation(RegistryDesignation.C.getKey());
|
||||
registry_2.setRegistryInstrumentType(RegistryInstrumentType.M.getKey());
|
||||
registry_2.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
registry_2.setSessionId(sessionId);
|
||||
|
|
@ -498,8 +553,8 @@ public class ReportServiceTest_KS {
|
|||
registry_1.setClearingDate(LocalDate.now());
|
||||
registry_1.setGroupId(Long.MAX_VALUE);
|
||||
registry_1.setSettlementDate(LocalDate.now());
|
||||
registry_1.setRegistryCode("TS_T");
|
||||
registry_1.setRegistryDesignation(RegistryDesignation.T.getKey());
|
||||
registry_1.setRegistryCode("CS_T");
|
||||
registry_1.setRegistryDesignation(RegistryDesignation.C.getKey());
|
||||
registry_1.setRegistryInstrumentType(RegistryInstrumentType.S.getKey());
|
||||
registry_1.setRegistryStatus(RegistryStatus.PROC.getKey());
|
||||
registry_1.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
|
|
@ -515,8 +570,8 @@ public class ReportServiceTest_KS {
|
|||
registry_2.setClearingDate(LocalDate.now());
|
||||
registry_2.setGroupId(Long.MAX_VALUE);
|
||||
registry_2.setSettlementDate(LocalDate.now());
|
||||
registry_2.setRegistryCode("OS_T");
|
||||
registry_2.setRegistryDesignation(RegistryDesignation.O.getKey());
|
||||
registry_2.setRegistryCode("LS_T");
|
||||
registry_2.setRegistryDesignation(RegistryDesignation.L.getKey());
|
||||
registry_2.setRegistryInstrumentType(RegistryInstrumentType.S.getKey());
|
||||
registry_2.setRegistryUnit(RegistryUnit.T.getKey());
|
||||
registry_2.setRegistryStatus(RegistryStatus.PROC.getKey());
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
"FIRMID","SESSION_ID","SESSION_DATE","ACCOUNT","VALUE","DATE"
|
||||
"TRADING_CODE","2","20.01.1970T02:49:58","ACCOUNT","22.22","07.07.2023"
|
||||
"TRADING_CODE","2","20.01.1970T02:49:58","ACCOUNT","22.22","02.10.2023"
|
||||
|
|
|
|||
|
|
|
@ -1,2 +1,2 @@
|
|||
"FIRMID","ACCOUNT","TKR","DATE","REGISTER_CODE","REGISTER_NAME","OPEN_BALANCE","CHANGE_BALANCE","ADD_WITHDRAW","CLOSE_BALANCE","REMARKS","TRADE_NUM"
|
||||
"TRADING_CODE","ACCOUNT","TRADING_CLEARING_REGISTRY","01.08.2023","AM_T","AM_T_NAME","77.78","66.67","66.67","211.11","",""
|
||||
"TRADING_CODE","ACCOUNT","TRADING_CLEARING_REGISTRY","02.10.2023","AM_T","AM_T_NAME","77.78","66.67","111.00","255.44","",""
|
||||
|
|
|
|||
|
|
|
@ -1,2 +1,2 @@
|
|||
"FIRMID","ACCOUNT","TKR","REGISTER_CODE","ADD_SUM","ADD_TIME","ADD_DATE","TRADE_NUM"
|
||||
"1","","0008CAT00001","AM_T","7777.78","15:49:30","01.08.2023",""
|
||||
"TRADING_CODE","ACCOUNT","0008CAT00001","DM_I","0.00","13:02:50","02.10.2023",""
|
||||
|
|
|
|||
|
|
|
@ -1,2 +1,2 @@
|
|||
"FIRMID","ACCOUNT","TKR","DATE","SECURITYID","REGISTER_CODE","REGISTER_NAME","OPEN_QUANTITY","CHANGE_QUANTITY","ADD_WITHDRAW_DEPO","CLOSE_QUANTITY","REMARKS","TRADE_NUM"
|
||||
"TRADING_CODE","ACCOUNT","TRADING_CLEARING_REGISTRY","01.08.2023","","AS_T","AS_T_NAME","78","67","67","211","",""
|
||||
"TRADING_CODE","ACCOUNT","TRADING_CLEARING_REGISTRY","02.10.2023","SECURITY_SYMBOL","AS_T","AS_T_NAME","78","67","111","255","",""
|
||||
|
|
|
|||
|
|
|
@ -1,2 +1,2 @@
|
|||
"FIRMID","ACCOUNT","TKR","SECURITYID","REGISTER_CODE","ADD_QUANTITY","ADD_TIME","ADD_DATE","TRADE_NUM"
|
||||
"1","ACCOUNT","TRADING_CLEARING_REGISTRY","value","AS_T","7778","15:52:33","01.08.2023",""
|
||||
"TRADING_CODE","ACCOUNT","0008CAT00001","SECURITY_SYMBOL","DS_I","10","13:55:53","02.10.2023",""
|
||||
|
|
|
|||
|
|
|
@ -105,6 +105,7 @@ public record RegistryTradingParams(RegistryDesignation registryDesignation,
|
|||
public final static RegistryTradingParams CM__;
|
||||
public final static RegistryTradingParams LM__;
|
||||
public final static RegistryTradingParams DMAU;
|
||||
public final static RegistryTradingParams DMAI;
|
||||
public final static RegistryTradingParams D__I;
|
||||
public final static RegistryTradingParams D__V;
|
||||
|
||||
|
|
@ -218,6 +219,10 @@ public record RegistryTradingParams(RegistryDesignation registryDesignation,
|
|||
RegistryInstrumentType.M,
|
||||
RegistryCapacity.A,
|
||||
RegistryUnit.U);
|
||||
DMAI = new RegistryTradingParams(RegistryDesignation.D,
|
||||
RegistryInstrumentType.M,
|
||||
RegistryCapacity.A,
|
||||
RegistryUnit.I);
|
||||
DS_I = new RegistryTradingParams(RegistryDesignation.D,
|
||||
RegistryInstrumentType.S,
|
||||
null,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue