This commit is contained in:
parent
a529135daf
commit
a3a749f587
11 changed files with 345 additions and 118 deletions
|
|
@ -28,6 +28,7 @@ public abstract class CSVReportBuilder<P> {
|
|||
protected DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy'T'HH:mm:ss");
|
||||
protected DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
|
||||
protected DateTimeFormatter dateTimeFormatter_YYMMDDHHmmssSSS = DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
|
||||
protected DateTimeFormatter dateFormatter_yyMMdd = DateTimeFormatter.ofPattern("yyMMdd");
|
||||
protected InstantFormatter instantFormatter = new InstantFormatter();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
|
@ -59,14 +60,63 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.regex("registryCode","[T|O]M.T")
|
||||
pb.regex("registryCode","[T|O]M.T"),
|
||||
pb.or(
|
||||
pb.equals("accountType", AccountType.Clrn.getKey()),
|
||||
pb.equals("accountType", AccountType.Info.getKey())
|
||||
)
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
Map<String, Boolean> registryAlreadySaved = new HashMap<>();
|
||||
Map<String, Registry> omtRegistries = new HashMap<>();
|
||||
Map<String, Registry> tmtRegistries = new HashMap<>();
|
||||
for (Registry registry : registries) {
|
||||
if (registry.getSettlementDate() == null || registry.getGroupId() == null) continue;
|
||||
registryAlreadySaved.put(registry.getGroupId() + registry.getSettlementDate().toString(), false);
|
||||
if (registry.getRegistryCode().startsWith("O")) {
|
||||
Registry existOMTRegistry = omtRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
if (existOMTRegistry != null && existOMTRegistry.getBalance() != null) {
|
||||
log.warn("Duplicated registry OM*T (id = {} and id = {}). Use id = {}",
|
||||
registry.getId(),
|
||||
existOMTRegistry,
|
||||
existOMTRegistry);
|
||||
} else omtRegistries.put(registry.getGroupId() + registry.getSettlementDate().toString(), registry);
|
||||
}
|
||||
if (registry.getRegistryCode().startsWith("T")) {
|
||||
Registry existTMTRegistry = tmtRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
if (existTMTRegistry != null && existTMTRegistry.getBalance() != null) {
|
||||
log.warn("Duplicated registry TM*T (id = {} and id = {}). Use id = {}",
|
||||
registry.getId(),
|
||||
existTMTRegistry,
|
||||
existTMTRegistry);
|
||||
} else tmtRegistries.put(registry.getGroupId() + registry.getSettlementDate().toString(), registry);
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, String> createdAtForSessionId = new HashMap<>();
|
||||
lines = new ArrayList<>(registries.size());
|
||||
for (Registry registry : registries) {
|
||||
try {
|
||||
if (registry.getSettlementDate() == null || registry.getGroupId() == null) {
|
||||
log.warn("Registry without GroupId or SettlementDate, id = {}. Skipped", registry.getId());
|
||||
continue;
|
||||
}
|
||||
if (registryAlreadySaved.get(registry.getGroupId() + registry.getSettlementDate().toString())) continue;
|
||||
|
||||
Registry tmtRegistry = tmtRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
Registry omtRegistry = omtRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
|
||||
if (!tmtRegistry.getTradingCode().equalsIgnoreCase(omtRegistry.getTradingCode()) ||
|
||||
!tmtRegistry.getSessionId().equals(omtRegistry.getSessionId()) ||
|
||||
!tmtRegistry.getAccount().equals(omtRegistry.getAccount())) {
|
||||
log.warn("Invalid registry OM*T (id = {}) and TM*T (id = {}) registry pair: fields not equal. GroupId = {}, SettlementDate = {}. Skipped",
|
||||
omtRegistry.getId(),
|
||||
tmtRegistry.getId(),
|
||||
registry.getSettlementDate().toString(),
|
||||
registry.getGroupId());
|
||||
continue;
|
||||
}
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
String sessionId = String.valueOf(registry.getSessionId());
|
||||
|
|
@ -78,12 +128,11 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
createdAtForSessionId.put(registry.getSessionId(), sessionDate);
|
||||
}
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Info.getKey()) || registry.getAccountType().equalsIgnoreCase(AccountType.Clrn.getKey()))
|
||||
account = registry.getAccount();
|
||||
String account = registry.getAccount();
|
||||
|
||||
// todo выяснить, как заполнять
|
||||
String value = registry.getBalance() != null ? df02Format.format(registry.getBalance()) : "";
|
||||
BigDecimal tmtBalance = tmtRegistry.getBalance() != null ? tmtRegistry.getBalance() : BigDecimal.ZERO;
|
||||
BigDecimal omtBalance = omtRegistry.getBalance() != null ? omtRegistry.getBalance() : BigDecimal.ZERO;
|
||||
String value = df02Format.format(tmtBalance.subtract(omtBalance));
|
||||
|
||||
String date = dateFormatter.format(nowDate);
|
||||
|
||||
|
|
@ -96,6 +145,8 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
line[valueIdx++] = value;
|
||||
line[valueIdx++] = date;
|
||||
lines.add(line);
|
||||
|
||||
registryAlreadySaved.put(registry.getGroupId() + registry.getSettlementDate().toString(), true);
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(registry.getId()), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
|
||||
@Override
|
||||
public ReportType getReportType() {
|
||||
return ReportType.KS_REP_CASH_REGISTERS;
|
||||
return ReportType.KS_REP_CASH_REGISTER_SUMS;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -62,7 +62,11 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.regex("registryCode", "AM.."),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS))
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.or(
|
||||
pb.equals("accountType", AccountType.Clrn.getKey()),
|
||||
pb.equals("accountType", AccountType.Info.getKey())
|
||||
)
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
|
|
@ -79,30 +83,38 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
if (!activeCompany) continue;
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Info.getKey()) || registry.getAccountType().equalsIgnoreCase(AccountType.Clrn.getKey()))
|
||||
account = registry.getAccount();
|
||||
|
||||
String account = registry.getAccount();
|
||||
String registerCode = registry.getRegistryCode();
|
||||
|
||||
String addSum = "";
|
||||
if (registry.getCredit() != null) addSum = df02Format.format(registry.getCredit());
|
||||
else if (registry.getDebit() != null) addSum = df02Format.format(registry.getDebit());
|
||||
|
||||
String addTime = "";
|
||||
String addDate = dateFormatter.format(nowDate);
|
||||
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addSum;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
// Если есть одновременно registry.credit и registry.debit, записываем две записи по одному registry
|
||||
String addSum = "";
|
||||
if (registry.getCredit() != null) {
|
||||
addSum = df02Format.format(registry.getCredit());
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addSum;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
lines.add(line);
|
||||
}
|
||||
if (registry.getDebit() != null) {
|
||||
addSum = "-" + df02Format.format(registry.getDebit());
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addSum;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
lines.add(line);
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(registry.getId()), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,11 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.regex("registryCode", "AM.T"),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS))
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.or(
|
||||
pb.equals("accountType", AccountType.Clrn.getKey()),
|
||||
pb.equals("accountType", AccountType.Info.getKey())
|
||||
)
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
|
|
@ -84,10 +88,7 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
if (!activeCompany) continue;
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Info.getKey()) || registry.getAccountType().equalsIgnoreCase(AccountType.Clrn.getKey()))
|
||||
account = registry.getAccount();
|
||||
String account = registry.getAccount();
|
||||
|
||||
String date = dateFormatter.format(nowDate);
|
||||
String registerCode = registry.getRegistryCode();
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
|
|
@ -59,14 +60,60 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.equals("sessionId", params.getSessionId()),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.regex("registryCode","[T|O]S.T")
|
||||
pb.regex("registryCode","[T|O]S.T"),
|
||||
pb.equals("accountType", AccountType.Depo.getKey())
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
Map<String, Boolean> registryAlreadySaved = new HashMap<>();
|
||||
Map<String, Registry> ostRegistries = new HashMap<>();
|
||||
Map<String, Registry> tstRegistries = new HashMap<>();
|
||||
for (Registry registry : registries) {
|
||||
if (registry.getGroupId() == null || registry.getSettlementDate() == null) continue;
|
||||
registryAlreadySaved.put(registry.getGroupId() + registry.getSettlementDate().toString(), false);
|
||||
if (registry.getRegistryCode().startsWith("O")) {
|
||||
Registry existOSTRegistry = ostRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
if (existOSTRegistry != null && existOSTRegistry.getBalance() != null) {
|
||||
log.warn("Duplicated registry OM*T (id = {} and id = {}). Use id = {}",
|
||||
registry.getId(),
|
||||
existOSTRegistry,
|
||||
existOSTRegistry);
|
||||
} else ostRegistries.put(registry.getGroupId() + registry.getSettlementDate().toString(), registry);
|
||||
}
|
||||
if (registry.getRegistryCode().startsWith("T")) {
|
||||
Registry existTSTRegistry = tstRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
if (existTSTRegistry != null && existTSTRegistry.getBalance() != null) {
|
||||
log.warn("Duplicated registry TM*T (id = {} and id = {}). Use id = {}",
|
||||
registry.getId(),
|
||||
existTSTRegistry,
|
||||
existTSTRegistry);
|
||||
} else tstRegistries.put(registry.getGroupId() + registry.getSettlementDate().toString(), registry);
|
||||
}
|
||||
}
|
||||
|
||||
Map<Long, String> createdAtForSessionId = new HashMap<>();
|
||||
lines = new ArrayList<>(registries.size());
|
||||
for (Registry registry : registries) {
|
||||
try {
|
||||
if (registry.getGroupId() == null || registry.getSettlementDate() == null) {
|
||||
log.warn("Registry without GroupId or SettlementDate, id = {}. Skipped", registry.getId());
|
||||
continue;
|
||||
}
|
||||
if (registryAlreadySaved.get(registry.getGroupId() + registry.getSettlementDate().toString())) continue;
|
||||
|
||||
Registry tstRegistry = tstRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
Registry ostRegistry = ostRegistries.get(registry.getGroupId() + registry.getSettlementDate().toString());
|
||||
|
||||
if (!tstRegistry.getTradingCode().equalsIgnoreCase(ostRegistry.getTradingCode()) ||
|
||||
!tstRegistry.getSessionId().equals(ostRegistry.getSessionId()) ||
|
||||
!tstRegistry.getAccount().equals(ostRegistry.getAccount())) {
|
||||
log.warn("Invalid registry OS*T (id = {}) and TS*T (id = {}) registry pair: fields not equal. GroupId = {}, SettlementDate = {}. Skipped",
|
||||
ostRegistry.getId(),
|
||||
tstRegistry.getId(),
|
||||
registry.getSettlementDate(),
|
||||
registry.getGroupId());
|
||||
continue;
|
||||
}
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
String sessionId = String.valueOf(registry.getSessionId());
|
||||
|
|
@ -78,13 +125,12 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
createdAtForSessionId.put(registry.getSessionId(), sessionDate);
|
||||
}
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Depo.getKey())) account = registry.getAccount();
|
||||
|
||||
String account = registry.getAccount();
|
||||
String securityId = registry.getSecuritySymbol() != null ? registry.getSecuritySymbol() : "";
|
||||
|
||||
// todo выяснить, как заполнять
|
||||
String value = registry.getBalance() != null ? df02Format.format(registry.getBalance()) : "";
|
||||
BigDecimal tmtBalance = tstRegistry.getBalance() != null ? tstRegistry.getBalance() : BigDecimal.ZERO;
|
||||
BigDecimal omtBalance = ostRegistry.getBalance() != null ? ostRegistry.getBalance() : BigDecimal.ZERO;
|
||||
String value = df02Format.format(tmtBalance.subtract(omtBalance));
|
||||
|
||||
String date = dateFormatter.format(nowDate);
|
||||
|
||||
|
|
@ -98,6 +144,8 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
line[valueIdx++] = value;
|
||||
line[valueIdx++] = date;
|
||||
lines.add(line);
|
||||
|
||||
registryAlreadySaved.put(registry.getGroupId() + registry.getSettlementDate().toString(), true);
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(registry.getId()), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.regex("registryCode", "AS.."),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS))
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("accountType", AccountType.Depo.getKey())
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
|
|
@ -80,32 +81,41 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
|||
if (!activeCompany) continue;
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Depo.getKey()))
|
||||
account = registry.getAccount();
|
||||
|
||||
String account = registry.getAccount();
|
||||
String securityId = registry.getSecuritySymbol() != null ? registry.getSecuritySymbol() : "";
|
||||
String registerCode = registry.getRegistryCode();
|
||||
|
||||
String addQuantity = "";
|
||||
if (registry.getCredit() != null) addQuantity = df02Format.format(registry.getCredit());
|
||||
else if (registry.getDebit() != null) addQuantity = df02Format.format(registry.getDebit());
|
||||
|
||||
String addTime = "";
|
||||
String addDate = dateFormatter.format(nowDate);
|
||||
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = securityId;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addQuantity;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
// Если есть одновременно registry.credit и registry.debit, записываем две записи по одному registry
|
||||
String addQuantity = "";
|
||||
if (registry.getCredit() != null) {
|
||||
addQuantity = df02Format.format(registry.getCredit());
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = securityId;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addQuantity;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
lines.add(line);
|
||||
}
|
||||
if (registry.getDebit() != null) {
|
||||
addQuantity = "-" + df02Format.format(registry.getDebit());
|
||||
int valueIdx = 0;
|
||||
String[] line = new String[getHeaders().length];
|
||||
line[valueIdx++] = firmId;
|
||||
line[valueIdx++] = account;
|
||||
line[valueIdx++] = securityId;
|
||||
line[valueIdx++] = registerCode;
|
||||
line[valueIdx++] = addQuantity;
|
||||
line[valueIdx++] = addTime;
|
||||
line[valueIdx++] = addDate;
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
lines.add(line);
|
||||
} catch (Throwable e) {
|
||||
log.error("Can't create report row for registry (id = %d), skipped".formatted(registry.getId()), e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,8 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.regex("registryCode", "AS.T"),
|
||||
pb.greatEqual("updated", instantNow.truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS))
|
||||
pb.less("updated", instantNow.plus(1, ChronoUnit.DAYS).truncatedTo(ChronoUnit.DAYS)),
|
||||
pb.equals("accountType", AccountType.Depo.getKey())
|
||||
);
|
||||
Collection<Registry> registries = registryImdg.getCollectionObjectsByPredicate(finalPredicate);
|
||||
|
||||
|
|
@ -84,10 +85,7 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
if (!activeCompany) continue;
|
||||
|
||||
String firmId = registry.getTradingCode() != null ? registry.getTradingCode() : "";
|
||||
|
||||
String account = "";
|
||||
if (registry.getAccountType().equalsIgnoreCase(AccountType.Depo.getKey())) account = registry.getAccount();
|
||||
|
||||
String account = registry.getAccount();
|
||||
String date = dateFormatter.format(nowDate);
|
||||
String securityId = registry.getSecuritySymbol() != null ? registry.getSecuritySymbol() : "";
|
||||
String registerCode = registry.getRegistryCode();
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
|||
import ru.spcex.clearing.reports.reports.CSVReportBuilder;
|
||||
import ru.spcex.clearing.reports.reports.EmptyParams;
|
||||
import ru.spcex.platform.enumeration.CoverageStatus;
|
||||
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||
import ru.spcex.platform.enumeration.RegistryStatus;
|
||||
import ru.spcex.platform.enumeration.ReportType;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
|
|
@ -21,6 +22,7 @@ import java.time.LocalDate;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams> {
|
||||
private final Imdg<ExecutionDeposit> executionDepositImdg;
|
||||
|
|
@ -82,6 +84,7 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams> {
|
|||
Map<Long, String> sessionDateForSessionId = new HashMap<>();
|
||||
lines = new ArrayList<>(executions.size());
|
||||
for (ExecutionCommon execution : executions) {
|
||||
boolean brokenExecution = false;
|
||||
try {
|
||||
String sessionId = execution.getSessionId() != null ? String.valueOf(execution.getSessionId()) : "";
|
||||
|
||||
|
|
@ -97,7 +100,6 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams> {
|
|||
|
||||
String trId = String.valueOf(execution.getId());
|
||||
|
||||
// todo выяснить, так ли это
|
||||
String firmId = "";
|
||||
if (execution.getCompanyId() != null) {
|
||||
firmId = tradingCodeForCompanyId.get(execution.getCompanyId());
|
||||
|
|
@ -132,20 +134,84 @@ public class KSRepTradesReportBuilder extends CSVReportBuilder<EmptyParams> {
|
|||
} else if (coverage == CoverageStatus.ALWD) {
|
||||
status = "1";
|
||||
} else if (coverage == CoverageStatus.DNED) {
|
||||
// todo обсудить
|
||||
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
Registry registry = registryImdg.getSingleObjectByPredicate(
|
||||
String groupId = "%s%d%s".formatted(
|
||||
dateFormatter_yyMMdd.format(nowDate),
|
||||
execution.getExchangeExecutionId(),
|
||||
execution.getMarket()
|
||||
);
|
||||
Collection<Registry> registryCollection = registryImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.equals("sessionId", execution.getSessionId()),
|
||||
pb.regex("registryCode", "[O|T][S|M].[T]")
|
||||
pb.regex("registryCode", "[O|T][S|M].[T]"),
|
||||
pb.equals("groupId", groupId)
|
||||
)
|
||||
);
|
||||
if (registry.getRegistryStatus() != null) {
|
||||
String registryStatusStr = registry.getRegistryStatus().toUpperCase();
|
||||
RegistryStatus registryStatus = IEnumKey.getEnumByKey(RegistryStatus.class, registryStatusStr);
|
||||
if (registryStatus == RegistryStatus.NACC || registryStatus == RegistryStatus.NACK) status = "0";
|
||||
else if (registryStatus == RegistryStatus.FAIL) status = "3";
|
||||
if (registryCollection.isEmpty()) {
|
||||
log.warn(
|
||||
"Broken execution (empty registries). Registry for groupId = {} not found. Execution (id = {}) skipped",
|
||||
groupId,
|
||||
execution.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
Boolean fail = null;
|
||||
boolean brokenRegistries = false;
|
||||
for (Registry registry : registryCollection) {
|
||||
if (registry.getRegistryStatus() == null) continue;
|
||||
String regStatus = registry.getRegistryStatus();
|
||||
|
||||
if (regStatus.equals(RegistryStatus.NACK.getKey()) ||
|
||||
regStatus.equals(RegistryStatus.NACC.getKey())) {
|
||||
if (fail != null && fail) {
|
||||
brokenRegistries = true;
|
||||
break;
|
||||
}
|
||||
fail = false;
|
||||
} else if (regStatus.equals(RegistryStatus.FAIL.getKey()) ||
|
||||
regStatus.equals(RegistryStatus.UNCV.getKey())) {
|
||||
if (fail != null && !fail) {
|
||||
brokenRegistries = true;
|
||||
break;
|
||||
}
|
||||
fail = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (brokenRegistries || fail == null) {
|
||||
log.warn(
|
||||
"Broken execution (invalid registry statuses). Registry for groupId = {} has invalid registry set. Id = [{}]. Execution (id = {}) skipped",
|
||||
groupId,
|
||||
registryCollection.stream().map(r -> String.valueOf(r.getId())).collect(Collectors.joining(",")),
|
||||
execution.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fail) {
|
||||
boolean allS = true;
|
||||
boolean allM = true;
|
||||
for (Registry registry : registryCollection) {
|
||||
if (registry.getRegistryInstrumentType() == null) continue;
|
||||
if (registry.getRegistryInstrumentType().equals(RegistryInstrumentType.S.getKey()))
|
||||
allM = false;
|
||||
if (registry.getRegistryInstrumentType().equals(RegistryInstrumentType.M.getKey()))
|
||||
allS = false;
|
||||
}
|
||||
if (allS) status = "3";
|
||||
if (allM) status = "2";
|
||||
if (allS == allM) {
|
||||
log.warn(
|
||||
"Broken execution (different instrument types). Registry for groupId = {} has invalid registry set. Id = [{}]. Execution (id = {}) skipped",
|
||||
groupId,
|
||||
registryCollection.stream().map(r -> String.valueOf(r.getId())).collect(Collectors.joining(",")),
|
||||
execution.getId()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
} else status = "0";
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ import java.time.Instant;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
|
@ -68,6 +69,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|||
})
|
||||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
|
||||
public class ReportServiceTest_KS {
|
||||
protected DateTimeFormatter dateFormatter_yyMMdd = DateTimeFormatter.ofPattern("yyMMdd");
|
||||
private static File outFolder;
|
||||
private static int reportRequestCnt = 0;
|
||||
private static int reportRequestWithSessionIdCnt = 0;
|
||||
|
|
@ -164,15 +166,16 @@ public class ReportServiceTest_KS {
|
|||
ReportRequest reportRequest = new ReportRequest();
|
||||
reportRequest.setReportId(ReportType.KS_REP_CASH_REGISTER_SUMS.getKey());
|
||||
|
||||
Registry registry = new Registry();
|
||||
registry.setCompanyId(COMPANY_ID);
|
||||
registry.setRegistryCode("AM__");
|
||||
registry.setUpdated(Instant.now());
|
||||
registry.setTradingCode("TRADING_CODE");
|
||||
registry.setAccount("ACCOUNT");
|
||||
registry.setAccountType(AccountType.Clrn.getKey());
|
||||
registry.setDebit(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry);
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setCompanyId(COMPANY_ID);
|
||||
registry_1.setRegistryCode("AM__");
|
||||
registry_1.setUpdated(Instant.now());
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setAccountType(AccountType.Clrn.getKey());
|
||||
registry_1.setDebit(BigDecimal.valueOf(22.2222222));
|
||||
registry_1.setCredit(BigDecimal.valueOf(44.4444444));
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
|
|
@ -188,7 +191,7 @@ public class ReportServiceTest_KS {
|
|||
File expectedFile = new File(getClass().getClassLoader().getResource("expected_reports_csv/ks/KS_REP_CASH_REGISTER_SUMS_expected.csv").getFile());
|
||||
compareCSVFiles(expectedFile, outFile, Arrays.asList("ADD_DATE"));
|
||||
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(registry_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -245,16 +248,17 @@ public class ReportServiceTest_KS {
|
|||
ReportRequest reportRequest = new ReportRequest();
|
||||
reportRequest.setReportId(ReportType.KS_REP_DEPO_REGISTER_QUANTITIES.getKey());
|
||||
|
||||
Registry registry = new Registry();
|
||||
registry.setCompanyId(COMPANY_ID);
|
||||
registry.setRegistryCode("AS__");
|
||||
registry.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry.setUpdated(Instant.now());
|
||||
registry.setTradingCode("TRADING_CODE");
|
||||
registry.setAccount("ACCOUNT");
|
||||
registry.setAccountType(AccountType.Depo.getKey());
|
||||
registry.setDebit(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry);
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setCompanyId(COMPANY_ID);
|
||||
registry_1.setRegistryCode("AS__");
|
||||
registry_1.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry_1.setUpdated(Instant.now());
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setAccountType(AccountType.Depo.getKey());
|
||||
registry_1.setDebit(BigDecimal.valueOf(22.2222222));
|
||||
registry_1.setCredit(BigDecimal.valueOf(44.4444444));
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
|
|
@ -270,7 +274,7 @@ public class ReportServiceTest_KS {
|
|||
File expectedFile = new File(getClass().getClassLoader().getResource("expected_reports_csv/ks/KS_REP_DEPO_REGISTER_QUANTITIES_expected.csv").getFile());
|
||||
compareCSVFiles(expectedFile, outFile, Arrays.asList("ADD_DATE"));
|
||||
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(registry_1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -304,10 +308,13 @@ public class ReportServiceTest_KS {
|
|||
Registry registry = new Registry();
|
||||
registry.setSessionId(sessionId_2);
|
||||
registry.setRegistryCode("OM_T");
|
||||
registry.setGroupId(Long.parseLong("%s%d%s".formatted(dateFormatter_yyMMdd.format(LocalDate.now()), 222, "333")));
|
||||
registry.setRegistryStatus(RegistryStatus.FAIL.getKey());
|
||||
registry.setRegistryInstrumentType(RegistryInstrumentType.S.getKey());
|
||||
registryImdg.insert(registry);
|
||||
|
||||
ExecutionDeposit executionDeposit = new ExecutionDeposit();
|
||||
executionDeposit.setMarket("333");
|
||||
executionDeposit.setCompanyId(COMPANY_ID);
|
||||
executionDeposit.setTradingDate(LocalDate.now());
|
||||
executionDeposit.setSessionId(sessionId_2);
|
||||
|
|
@ -352,15 +359,29 @@ public class ReportServiceTest_KS {
|
|||
reportRequest.setReportId(ReportType.KS_REP_CASH_NETTO.getKey());
|
||||
reportRequest.setSessionId(sessionId);
|
||||
|
||||
Registry registry = new Registry();
|
||||
registry.setTradingCode("TRADING_CODE");
|
||||
registry.setClearingDate(LocalDate.now());
|
||||
registry.setRegistryCode("TM_T");
|
||||
registry.setSessionId(sessionId);
|
||||
registry.setAccount("ACCOUNT");
|
||||
registry.setAccountType(AccountType.Clrn.getKey());
|
||||
registry.setBalance(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry);
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setSettlementDate(LocalDate.now());
|
||||
registry_1.setGroupId(Long.MAX_VALUE);
|
||||
registry_1.setClearingDate(LocalDate.now());
|
||||
registry_1.setRegistryCode("OM_T");
|
||||
registry_1.setSessionId(sessionId);
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setAccountType(AccountType.Clrn.getKey());
|
||||
registry_1.setBalance(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
Registry registry_2 = new Registry();
|
||||
registry_2.setTradingCode("TRADING_CODE");
|
||||
registry_2.setSettlementDate(LocalDate.now());
|
||||
registry_2.setGroupId(Long.MAX_VALUE);
|
||||
registry_2.setClearingDate(LocalDate.now());
|
||||
registry_2.setRegistryCode("TM_T");
|
||||
registry_2.setSessionId(sessionId);
|
||||
registry_2.setAccount("ACCOUNT");
|
||||
registry_2.setAccountType(AccountType.Clrn.getKey());
|
||||
registry_2.setBalance(BigDecimal.valueOf(44.4444444));
|
||||
registryImdg.insert(registry_2);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
|
|
@ -376,7 +397,8 @@ public class ReportServiceTest_KS {
|
|||
File expectedFile = new File(getClass().getClassLoader().getResource("expected_reports_csv/ks/KS_REP_CASH_NETTO_expected.csv").getFile());
|
||||
compareCSVFiles(expectedFile, outFile, Arrays.asList("SESSION_ID", "DATE"));
|
||||
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(registry_1);
|
||||
registryImdg.delete(registry_2);
|
||||
sessionImdg.delete(session);
|
||||
}
|
||||
|
||||
|
|
@ -393,16 +415,31 @@ public class ReportServiceTest_KS {
|
|||
reportRequest.setReportId(ReportType.KS_REP_DEPO_NETTO.getKey());
|
||||
reportRequest.setSessionId(sessionId);
|
||||
|
||||
Registry registry = new Registry();
|
||||
registry.setTradingCode("TRADING_CODE");
|
||||
registry.setClearingDate(LocalDate.now());
|
||||
registry.setRegistryCode("TS_T");
|
||||
registry.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry.setSessionId(sessionId);
|
||||
registry.setAccount("ACCOUNT");
|
||||
registry.setAccountType(AccountType.Depo.getKey());
|
||||
registry.setBalance(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry);
|
||||
Registry registry_1 = new Registry();
|
||||
registry_1.setTradingCode("TRADING_CODE");
|
||||
registry_1.setClearingDate(LocalDate.now());
|
||||
registry_1.setGroupId(Long.MAX_VALUE);
|
||||
registry_1.setSettlementDate(LocalDate.now());
|
||||
registry_1.setRegistryCode("TS_T");
|
||||
registry_1.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry_1.setSessionId(sessionId);
|
||||
registry_1.setAccount("ACCOUNT");
|
||||
registry_1.setAccountType(AccountType.Depo.getKey());
|
||||
registry_1.setBalance(BigDecimal.valueOf(44.4444444));
|
||||
registryImdg.insert(registry_1);
|
||||
|
||||
Registry registry_2 = new Registry();
|
||||
registry_2.setTradingCode("TRADING_CODE");
|
||||
registry_2.setClearingDate(LocalDate.now());
|
||||
registry_2.setGroupId(Long.MAX_VALUE);
|
||||
registry_2.setSettlementDate(LocalDate.now());
|
||||
registry_2.setRegistryCode("OS_T");
|
||||
registry_2.setSecuritySymbol("SECURITY_SYMBOL");
|
||||
registry_2.setSessionId(sessionId);
|
||||
registry_2.setAccount("ACCOUNT");
|
||||
registry_2.setAccountType(AccountType.Depo.getKey());
|
||||
registry_2.setBalance(BigDecimal.valueOf(22.2222222));
|
||||
registryImdg.insert(registry_2);
|
||||
|
||||
String jsonString = TestUtils.getJsonStringForSystem(reportRequest, 0L);
|
||||
|
||||
|
|
@ -418,7 +455,8 @@ public class ReportServiceTest_KS {
|
|||
File expectedFile = new File(getClass().getClassLoader().getResource("expected_reports_csv/ks/KS_REP_DEPO_NETTO_expected.csv").getFile());
|
||||
compareCSVFiles(expectedFile, outFile, Arrays.asList("SESSION_ID", "DATE"));
|
||||
|
||||
registryImdg.delete(registry);
|
||||
registryImdg.delete(registry_1);
|
||||
registryImdg.delete(registry_2);
|
||||
sessionImdg.delete(session);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +1,3 @@
|
|||
FIRMID,ACCOUNT,REGISTER_CODE,ADD_SUM,ADD_TIME,ADD_DATE
|
||||
"TRADING_CODE","ACCOUNT","AM__","22,22","","30.06.2023"
|
||||
"TRADING_CODE","ACCOUNT","AM__","44,44","","04.07.2023"
|
||||
"TRADING_CODE","ACCOUNT","AM__","-22,22","","04.07.2023"
|
||||
|
|
|
|||
|
|
|
@ -1,2 +1,3 @@
|
|||
FIRMID,ACCOUNT,SECURITYID,REGISTER_CODE,ADD_QUANTITY,ADD_TIME,ADD_DATE
|
||||
"TRADING_CODE","ACCOUNT","SECURITY_SYMBOL","AS__","22,22","","30.06.2023"
|
||||
"TRADING_CODE","ACCOUNT","SECURITY_SYMBOL","AS__","44,44","","04.07.2023"
|
||||
"TRADING_CODE","ACCOUNT","SECURITY_SYMBOL","AS__","-22,22","","04.07.2023"
|
||||
|
|
|
|||
|
Loading…
Add table
Reference in a new issue