This commit is contained in:
parent
6bd925c231
commit
ab98240a00
1 changed files with 112 additions and 24 deletions
|
|
@ -4,7 +4,10 @@ import java.math.BigDecimal;
|
|||
import java.time.LocalDate;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
|
|
@ -72,35 +75,73 @@ public class KSRepLccNettoReportBuilder extends CSVReportBuilder<EmptyParams, KS
|
|||
pb.equals("settlementDate", now)
|
||||
)
|
||||
);
|
||||
for (Registry registry : registries) {
|
||||
Map<SecuritySymbolSettlementDateTKR, List<Registry>> groupedRegistries = registries.stream()
|
||||
.collect(
|
||||
Collectors.groupingBy(
|
||||
registry -> new SecuritySymbolSettlementDateTKR(
|
||||
registry.getSecuritySymbol(),
|
||||
registry.getSettlementDate(),
|
||||
registry.getTradingClearingRegistry()
|
||||
),
|
||||
HashMap::new,
|
||||
Collectors.toList()
|
||||
)
|
||||
);
|
||||
|
||||
|
||||
for (Map.Entry<SecuritySymbolSettlementDateTKR, List<Registry>> entry : groupedRegistries.entrySet()) {
|
||||
List<Registry> registriesForTKR = entry.getValue();
|
||||
Registry sampleRegistry = registriesForTKR.iterator().next();
|
||||
for (Registry registry : registriesForTKR) {
|
||||
if (!sampleRegistry.getTradingCode().equalsIgnoreCase(registry.getTradingCode())) {
|
||||
log.warn(
|
||||
"For group registries (security_symbol: {}, settlement_date: {}, tkr: {}) " +
|
||||
"found registry with another trading_code (expected: {}, actual: {}). Use {} for report",
|
||||
sampleRegistry.getSecuritySymbol(),
|
||||
sampleRegistry.getSettlementDate(),
|
||||
sampleRegistry.getTradingClearingRegistry(),
|
||||
sampleRegistry.getTradingCode(),
|
||||
registry.getTradingCode(),
|
||||
sampleRegistry.getTradingCode()
|
||||
);
|
||||
}
|
||||
}
|
||||
for (DataTypes dataType : DataTypes.values()) {
|
||||
KSRepLccNettoReport ksRepLccNettoReport = new KSRepLccNettoReport();
|
||||
ksRepLccNettoReport.setFirmId(registry.getTradingCode());
|
||||
ksRepLccNettoReport.setTkr(registry.getTradingClearingRegistry());
|
||||
ksRepLccNettoReport.setCurrencyId(registry.getSecuritySymbol());
|
||||
ksRepLccNettoReport.setFirmId(sampleRegistry.getTradingCode());
|
||||
ksRepLccNettoReport.setTkr(sampleRegistry.getTradingClearingRegistry());
|
||||
ksRepLccNettoReport.setCurrencyId(sampleRegistry.getSecuritySymbol());
|
||||
ksRepLccNettoReport.setDate(now);
|
||||
RegistryStatus status = IEnumKey.getEnumByKey(RegistryStatus.class, registry.getRegistryStatus());
|
||||
RegistryDesignation designation = IEnumKey.getEnumByKey(RegistryDesignation.class, registry.getRegistryDesignation());
|
||||
|
||||
BigDecimal debit = BigDecimal.ZERO;
|
||||
BigDecimal credit = BigDecimal.ZERO;
|
||||
if (dataType == DataTypes.FX_OBLIG) {
|
||||
if (status == RegistryStatus.PROC || status == RegistryStatus.MNG) {
|
||||
if (designation == RegistryDesignation.O)
|
||||
debit = registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO;
|
||||
if (designation == RegistryDesignation.T)
|
||||
credit = registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO;
|
||||
}
|
||||
} else if (dataType == DataTypes.PR_NETTOSUM) {
|
||||
if (status == RegistryStatus.CLRD) {
|
||||
if (designation == RegistryDesignation.O)
|
||||
debit = registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO;
|
||||
if (designation == RegistryDesignation.T)
|
||||
credit = registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO;
|
||||
}
|
||||
} else if (dataType == DataTypes.FX_DEBT) {
|
||||
if (designation == RegistryDesignation.A) {
|
||||
if (registry.getBalance() != null && registry.getBalance().compareTo(BigDecimal.ZERO) < 0)
|
||||
debit = registry.getBalance();
|
||||
for (Registry registry : registriesForTKR) {
|
||||
RegistryStatus status = IEnumKey.getEnumByKey(RegistryStatus.class, registry.getRegistryStatus());
|
||||
RegistryDesignation designation = IEnumKey.getEnumByKey(RegistryDesignation.class, registry.getRegistryDesignation());
|
||||
if (dataType == DataTypes.FX_OBLIG) {
|
||||
if (status == RegistryStatus.PROC || status == RegistryStatus.MNG) {
|
||||
if (designation == RegistryDesignation.O) {
|
||||
debit = debit.add(registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO);
|
||||
}
|
||||
if (designation == RegistryDesignation.T) {
|
||||
credit = credit.add(registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
} else if (dataType == DataTypes.PR_NETTOSUM) {
|
||||
if (status == RegistryStatus.CLRD) {
|
||||
if (designation == RegistryDesignation.O) {
|
||||
debit = debit.add(registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO);
|
||||
}
|
||||
if (designation == RegistryDesignation.T) {
|
||||
credit = credit.add(registry.getBalance() != null ? registry.getBalance() : BigDecimal.ZERO);
|
||||
}
|
||||
}
|
||||
} else if (dataType == DataTypes.FX_DEBT) {
|
||||
if (designation == RegistryDesignation.A) {
|
||||
if (registry.getBalance() != null && registry.getBalance().compareTo(BigDecimal.ZERO) < 0) {
|
||||
debit = debit.add(registry.getBalance());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ksRepLccNettoReport.setDataType(dataType.value);
|
||||
|
|
@ -123,4 +164,51 @@ public class KSRepLccNettoReportBuilder extends CSVReportBuilder<EmptyParams, KS
|
|||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class SecuritySymbolSettlementDateTKR {
|
||||
private final String securitySymbol;
|
||||
private final LocalDate settlementDate;
|
||||
private final String tradingClearingRegistry;
|
||||
|
||||
private SecuritySymbolSettlementDateTKR(String securitySymbol, LocalDate settlementDate, String tradingClearingRegistry) {
|
||||
this.securitySymbol = securitySymbol;
|
||||
this.settlementDate = settlementDate;
|
||||
this.tradingClearingRegistry = tradingClearingRegistry;
|
||||
}
|
||||
|
||||
public String getSecuritySymbol() {
|
||||
return securitySymbol;
|
||||
}
|
||||
|
||||
public LocalDate getSettlementDate() {
|
||||
return settlementDate;
|
||||
}
|
||||
|
||||
public String getTradingClearingRegistry() {
|
||||
return tradingClearingRegistry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
SecuritySymbolSettlementDateTKR that = (SecuritySymbolSettlementDateTKR) o;
|
||||
|
||||
if (getSecuritySymbol() != null ? !getSecuritySymbol().equals(that.getSecuritySymbol()) : that.getSecuritySymbol() != null)
|
||||
return false;
|
||||
if (getSettlementDate() != null ? !getSettlementDate().equals(that.getSettlementDate()) : that.getSettlementDate() != null)
|
||||
return false;
|
||||
return getTradingClearingRegistry() != null ? getTradingClearingRegistry().equals(that.getTradingClearingRegistry()) : that.getTradingClearingRegistry() == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = getSecuritySymbol() != null ? getSecuritySymbol().hashCode() : 0;
|
||||
result = 31 * result + (getSettlementDate() != null ? getSettlementDate().hashCode() : 0);
|
||||
result = 31 * result + (getTradingClearingRegistry() != null ? getTradingClearingRegistry().hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue