This commit is contained in:
parent
e04460b194
commit
0b2bef797e
9 changed files with 69 additions and 58 deletions
|
|
@ -1,12 +1,13 @@
|
|||
package ru.spcex.clearing.reports.builders;
|
||||
|
||||
import com.opencsv.CSVWriterBuilder;
|
||||
import com.opencsv.CSVWriter;
|
||||
import com.opencsv.ICSVWriter;
|
||||
import com.opencsv.bean.*;
|
||||
import com.opencsv.exceptions.CsvBadConverterException;
|
||||
import com.opencsv.exceptions.CsvChainedException;
|
||||
import com.opencsv.exceptions.CsvFieldAssignmentException;
|
||||
import com.opencsv.exceptions.CsvRequiredFieldEmptyException;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
|
|
@ -91,23 +92,6 @@ public abstract class CSVReportBuilder<P, R> {
|
|||
*/
|
||||
protected abstract void collect(P params);
|
||||
|
||||
/**
|
||||
* Создает CSVWriter. Если требуется изменить параметры выходного CSV файла, этот метод следует переопределить.
|
||||
*
|
||||
* @param file Файл отчета
|
||||
* @return Созданный CSVWriter
|
||||
* <p>
|
||||
* todo check it
|
||||
*/
|
||||
protected ICSVWriter createCsvWriter(File file) throws IOException {
|
||||
Writer writer = new FileWriter(file);
|
||||
CSVWriterBuilder csvWriterBuilder = new CSVWriterBuilder(writer)
|
||||
.withLineEnd("\n")
|
||||
.withSeparator(',')
|
||||
.withQuoteChar('\"');
|
||||
return csvWriterBuilder.build();
|
||||
}
|
||||
|
||||
public File createReport(P params, File outFolder) {
|
||||
assert outFolder != null && outFolder.isDirectory();
|
||||
|
||||
|
|
@ -118,10 +102,11 @@ public abstract class CSVReportBuilder<P, R> {
|
|||
|
||||
assert rows != null;
|
||||
|
||||
try (Writer writer = new FileWriter(reportFile)) {
|
||||
try (Writer writer = new FileWriter(reportFile);
|
||||
ICSVWriter icsvWriter = new CustomCSVWriter(writer)) {
|
||||
CustomStrategy<R> customStrategy = new CustomStrategy<>();
|
||||
customStrategy.setType(getReportClass());
|
||||
StatefulBeanToCsv<R> sbc = new StatefulBeanToCsvBuilder<R>(writer)
|
||||
StatefulBeanToCsv<R> sbc = new StatefulBeanToCsvBuilder<R>(icsvWriter)
|
||||
.withMappingStrategy(customStrategy)
|
||||
.withLineEnd("\n")
|
||||
.withSeparator(',')
|
||||
|
|
@ -160,6 +145,24 @@ public abstract class CSVReportBuilder<P, R> {
|
|||
return sessionIds.stream().toList();
|
||||
}
|
||||
|
||||
static class CustomCSVWriter extends CSVWriter {
|
||||
public CustomCSVWriter(Writer writer) {
|
||||
super(writer);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNext(String[] nextLine, boolean applyQuotesToAll, Appendable appendable) throws IOException {
|
||||
if (nextLine != null) {
|
||||
for (int i = 0; i < nextLine.length; i++) {
|
||||
if (StringUtils.isEmpty(nextLine[i])) {
|
||||
nextLine[i] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
super.writeNext(nextLine, applyQuotesToAll, appendable);
|
||||
}
|
||||
}
|
||||
|
||||
static class CustomStrategy<T> extends ColumnPositionMappingStrategy<T> {
|
||||
public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException {
|
||||
super.generateHeader(bean);
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ 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.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -105,8 +104,8 @@ public class KSCommissionTradesReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
continue;
|
||||
}
|
||||
|
||||
String firmId = "";
|
||||
String firmIdInitiator = "";
|
||||
String firmId = null;
|
||||
String firmIdInitiator = null;
|
||||
if (registryUnit == RegistryUnit.X) {
|
||||
firmIdInitiator = registry.getTradingCode();
|
||||
} else if (registryUnit == RegistryUnit.T) {
|
||||
|
|
@ -122,7 +121,7 @@ public class KSCommissionTradesReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
}
|
||||
}
|
||||
|
||||
String execStatus = "";
|
||||
String execStatus = null;
|
||||
RegistryStatus registryStatus = IEnumKey.getEnumByKey(RegistryStatus.class, registry.getRegistryStatus());
|
||||
if (registryStatus == RegistryStatus.CLRD) execStatus = "Исполнен";
|
||||
else if (registryStatus == RegistryStatus.FAIL) execStatus = "Не исполнен";
|
||||
|
|
@ -160,7 +159,7 @@ public class KSCommissionTradesReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
ksCommissionTradesReport.setAgreementNumber(agreementNumber);
|
||||
ksCommissionTradesReport.setAgreementNumberPostfix(agreementNumberPostfix);
|
||||
ksCommissionTradesReport.setAgreementDate(registry.getTradingDate());
|
||||
ksCommissionTradesReport.setSum(registry.getBalance() != null ? registry.getBalance().negate() : BigDecimal.ZERO);
|
||||
ksCommissionTradesReport.setSum(registry.getBalance() != null ? registry.getBalance().negate() : null);
|
||||
ksCommissionTradesReport.setRepaymDate(registry.getRefundDate());
|
||||
ksCommissionTradesReport.setExecStatus(execStatus);
|
||||
ksCommissionTradesReport.setAgreementSettlementDate(registry.getValueDate());
|
||||
|
|
|
|||
|
|
@ -111,8 +111,8 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
|
||||
boolean invalid = false;
|
||||
if (!cmtRegistries.isEmpty() || !lmtRegistries.isEmpty()) {
|
||||
String sourceTradingCode = "";
|
||||
String sourceTkr = "";
|
||||
String sourceTradingCode = null;
|
||||
String sourceTkr = null;
|
||||
if (!cmtRegistries.isEmpty()) {
|
||||
Registry next = cmtRegistries.iterator().next();
|
||||
sourceTradingCode = next.getTradingCode();
|
||||
|
|
@ -160,7 +160,7 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ksRepCashNettoReport.setSessionDate(LocalDateTime.ofInstant(session.getCreated(), getReportZoneId()));
|
||||
|
||||
|
||||
String account = "";
|
||||
String account = null;
|
||||
AccountType accountType = IEnumKey.getEnumByKey(AccountType.class, registry.getAccountType());
|
||||
if (accountType == AccountType.Clrn) {
|
||||
account = registry.getAccount();
|
||||
|
|
@ -175,12 +175,10 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ksRepCashNettoReport.setTkr(registry.getTradingClearingRegistry());
|
||||
ksRepCashNettoReport.setDate(nowDate);
|
||||
|
||||
BigDecimal cmtBalance = BigDecimal.ZERO;
|
||||
BigDecimal lmtBalance = BigDecimal.ZERO;
|
||||
BigDecimal oblValue = BigDecimal.ZERO;
|
||||
BigDecimal reqValue = BigDecimal.ZERO;
|
||||
boolean withValue = false;
|
||||
boolean withOblReqValue = false;
|
||||
BigDecimal cmtBalance = null;
|
||||
BigDecimal lmtBalance = null;
|
||||
BigDecimal oblValue = null;
|
||||
BigDecimal reqValue = null;
|
||||
Set<SessionType> sessionTypeForValue = Set.of(
|
||||
SessionType.IPOT,
|
||||
SessionType.TRDT,
|
||||
|
|
@ -198,12 +196,12 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
SessionType sessionType = IEnumKey.getEnumByKey(SessionType.class, cmtRegistry.getSessionType());
|
||||
if (sessionType == null) continue;
|
||||
if (sessionTypeForValue.contains(sessionType)) {
|
||||
if (cmtBalance == null) cmtBalance = BigDecimal.ZERO;
|
||||
cmtBalance = cmtBalance.add(cmtRegistry.getBalance());
|
||||
withValue = true;
|
||||
}
|
||||
if (sessionTypeForOblReqValue.contains(sessionType)) {
|
||||
if (reqValue == null) reqValue = BigDecimal.ZERO;
|
||||
reqValue = reqValue.add(cmtRegistry.getBalance());
|
||||
withOblReqValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -212,18 +210,26 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
SessionType sessionType = IEnumKey.getEnumByKey(SessionType.class, lmtRegistry.getSessionType());
|
||||
if (sessionType == null) continue;
|
||||
if (sessionTypeForValue.contains(sessionType)) {
|
||||
if (lmtBalance == null) lmtBalance = BigDecimal.ZERO;
|
||||
lmtBalance = lmtBalance.add(lmtRegistry.getBalance());
|
||||
withValue = true;
|
||||
}
|
||||
if (sessionTypeForOblReqValue.contains(sessionType)) {
|
||||
if (oblValue == null) oblValue = BigDecimal.ZERO;
|
||||
oblValue = oblValue.add(lmtRegistry.getBalance());
|
||||
withOblReqValue = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
ksRepCashNettoReport.setValue(withValue ? cmtBalance.subtract(lmtBalance) : null);
|
||||
ksRepCashNettoReport.setOblValue(withOblReqValue ? oblValue : null);
|
||||
ksRepCashNettoReport.setReqValue(withOblReqValue ? reqValue : null);
|
||||
BigDecimal value;
|
||||
if (cmtBalance != null) {
|
||||
value = cmtBalance.subtract(Objects.requireNonNullElse(lmtBalance, BigDecimal.ZERO));
|
||||
}
|
||||
else {
|
||||
if (lmtBalance != null) value = lmtBalance.negate();
|
||||
else value = null;
|
||||
}
|
||||
ksRepCashNettoReport.setValue(value);
|
||||
ksRepCashNettoReport.setOblValue(oblValue);
|
||||
ksRepCashNettoReport.setReqValue(reqValue);
|
||||
|
||||
rows.add(ksRepCashNettoReport);
|
||||
} catch (Throwable e) {
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
|
||||
String firmId = registry.getTradingCode();
|
||||
String tkr = registry.getTradingClearingRegistry();
|
||||
String tradeNum = "";
|
||||
String tradeNum = null;
|
||||
String registerCode = pairRegistry != null ? pairRegistry.getRegistryCode() : "";
|
||||
BigDecimal addSum = registry.getBalance() != null ? registry.getBalance() :BigDecimal.ZERO;
|
||||
Instant addTime = registry.getUpdated();
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
String account = "";
|
||||
String account = null;
|
||||
AccountType accountType = IEnumKey.getEnumByKey(AccountType.class, registry.getAccountType());
|
||||
if (accountType == AccountType.Clrn) {
|
||||
account = registry.getAccount();
|
||||
|
|
@ -110,7 +110,8 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
"accountType", AccountType.Anlt.getKey()
|
||||
));
|
||||
if (accountFromIMDG != null) account = accountFromIMDG.getAccount();
|
||||
} KSRepCashRegistersReport ksRepCashRegistersReport = new KSRepCashRegistersReport();
|
||||
}
|
||||
KSRepCashRegistersReport ksRepCashRegistersReport = new KSRepCashRegistersReport();
|
||||
|
||||
ksRepCashRegistersReport.setFirmId(registry.getTradingCode());
|
||||
ksRepCashRegistersReport.setAccount(account);
|
||||
|
|
@ -121,7 +122,8 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
BigDecimal openBalance = registry.getOpenBalance() != null ? registry.getOpenBalance() : BigDecimal.ZERO;
|
||||
ksRepCashRegistersReport.setOpenBalance(openBalance);
|
||||
|
||||
ksRepCashRegistersReport.setRemarks("");
|
||||
ksRepCashRegistersReport.setRemarks(null);
|
||||
ksRepCashRegistersReport.setTradeNum(null);
|
||||
|
||||
RegistryCodeDictionary registryCodeDictionary = registryCodeDictionaryImdg.getFirstObjectByFieldValues(Map.of("code", registry.getRegistryCode()));
|
||||
if (registryCodeDictionary != null) ksRepCashRegistersReport.setRegisterName(registryCodeDictionary.getName());
|
||||
|
|
@ -170,7 +172,9 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
)
|
||||
);
|
||||
BigDecimal addWithdraw = BigDecimal.ZERO;
|
||||
for (Registry currRegistry : registriesForAddWithdraw) addWithdraw = addWithdraw.add(currRegistry.getBalance());
|
||||
for (Registry currRegistry : registriesForAddWithdraw) {
|
||||
addWithdraw = addWithdraw.add(currRegistry.getBalance());
|
||||
}
|
||||
ksRepCashRegistersReport.setAddWithdraw(addWithdraw);
|
||||
|
||||
BigDecimal closeBalance = ksRepCashRegistersReport.getOpenBalance()
|
||||
|
|
|
|||
|
|
@ -90,9 +90,8 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
List<Registry> groupedRegistry = entry.getValue();
|
||||
try {
|
||||
if (groupedRegistry.isEmpty()) {
|
||||
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(", "))
|
||||
log.warn("Empty LS_T and CS_T registries for {}",
|
||||
pairRegistryId
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
|
@ -110,7 +109,7 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
|
||||
boolean invalid = false;
|
||||
if (!cstRegistries.isEmpty() || !lstRegistries.isEmpty()) {
|
||||
String sourceTradingCode = "";
|
||||
String sourceTradingCode = null;
|
||||
if (!cstRegistries.isEmpty()) sourceTradingCode = cstRegistries.iterator().next().getTradingCode();
|
||||
if (!lstRegistries.isEmpty()) sourceTradingCode = lstRegistries.iterator().next().getTradingCode();
|
||||
for (Registry currRegistry : cstRegistries) {
|
||||
|
|
|
|||
|
|
@ -120,10 +120,10 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
|||
|
||||
String firmId = registry.getTradingCode();
|
||||
String tkr = registry.getTradingClearingRegistry();
|
||||
String tradeNum = "";
|
||||
String tradeNum = null;
|
||||
String securityId = registry.getSecuritySymbol();
|
||||
String registerCode = pairRegistry != null ? pairRegistry.getRegistryCode() : "";
|
||||
BigDecimal addQuantity = registry.getBalance() != null ? registry.getBalance() :BigDecimal.ZERO;
|
||||
String registerCode = pairRegistry != null ? pairRegistry.getRegistryCode() : null;
|
||||
BigDecimal addQuantity = registry.getBalance();
|
||||
Instant addTime = registry.getUpdated();
|
||||
LocalDate addDate = LocalDate.now();
|
||||
|
||||
|
|
|
|||
|
|
@ -108,10 +108,11 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
ksRepDepoRegistersReport.setSecurityId(registry.getSecuritySymbol());
|
||||
ksRepDepoRegistersReport.setRegisterCode(registry.getRegistryCode());
|
||||
|
||||
BigDecimal openBalance = registry.getOpenBalance() != null ? registry.getOpenBalance() : BigDecimal.ZERO;
|
||||
BigDecimal openBalance = registry.getOpenBalance();
|
||||
ksRepDepoRegistersReport.setOpenQuantity(openBalance);
|
||||
|
||||
ksRepDepoRegistersReport.setRemarks(null);
|
||||
ksRepDepoRegistersReport.setTradeNum(null);
|
||||
|
||||
RegistryCodeDictionary registryCodeDescription = registryCodeDictionaryImdg.getFirstObjectByFieldValues(Map.of("code", registry.getRegistryCode()));
|
||||
if (registryCodeDescription != null) ksRepDepoRegistersReport.setRegisterName(registryCodeDescription.getName());
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams, KSRe
|
|||
Map<ExecutionKey, String> statusForExecution = new HashMap<>();
|
||||
executions.forEach(execution -> {
|
||||
if (Set.of("S", "SELL").contains(execution.getSide())) {
|
||||
String status = "";
|
||||
String status = null;
|
||||
if (execution.getCoverageStatus() != null) {
|
||||
Long groupId = execution.getExchangeExecutionId();
|
||||
String coverageStatus = execution.getCoverageStatus().toUpperCase();
|
||||
|
|
@ -190,8 +190,8 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams, KSRe
|
|||
continue;
|
||||
}
|
||||
|
||||
String depoAccount = "";
|
||||
String agreementNumber = "";
|
||||
String depoAccount = null;
|
||||
String agreementNumber = null;
|
||||
if (execution instanceof ExecutionDeposit executionDeposit) {
|
||||
agreementNumber = executionDeposit.getContract();
|
||||
BigDecimal firstLegAmount = executionDeposit.getFirstLegAmount() != null ? executionDeposit.getFirstLegAmount() : BigDecimal.ZERO;
|
||||
|
|
@ -253,7 +253,6 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams, KSRe
|
|||
executionFond.getExchangeExecutionId());
|
||||
continue;
|
||||
}
|
||||
agreementNumber = null;
|
||||
|
||||
BigDecimal quantity = executionFond.getQuantity() != null ? executionFond.getQuantity() : BigDecimal.ZERO;
|
||||
if (Arrays.asList(Side.SELL.getKey(), "S", "SELL").contains((executionFond.getSide())))
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue