формирование PaymentInstruction, пропуск при наличии DM*X
This commit is contained in:
parent
679a64bd85
commit
81a39b9dbe
1 changed files with 64 additions and 22 deletions
|
|
@ -189,7 +189,20 @@ public class FormingPaymentInstructionAssetsAction extends AbstractSessionAction
|
|||
Account debitLegAccount;
|
||||
Account creditLegAccount;
|
||||
BigDecimal amount;
|
||||
amount = safeBD(registry.getBalance()).add(adjustAmountByReturns(registry, sessionId));
|
||||
Collection<Registry> oAndT = loadLiabilitiesAndClaims(registry, sessionId);
|
||||
Optional<Registry> dmx = searchDmx(registry, oAndT);
|
||||
if (dmx.isPresent()) {
|
||||
log.debug("{}.id={} found {}.id={}, skipping PaymentInstruction creation",
|
||||
registry.getRegistryCode(), registry.getId(),
|
||||
dmx.get().getRegistryCode(), dmx.get().getId());
|
||||
continue;
|
||||
}
|
||||
BigDecimal adjustByReturns = adjustAmountByReturns(oAndT);
|
||||
log.debug("{}.id={} adjust by returns value {}",
|
||||
registry.getRegistryCode(),
|
||||
registry.getId(),
|
||||
adjustByReturns);
|
||||
amount = safeBD(registry.getBalance()).add(adjustByReturns);
|
||||
boolean isPositiveBalance = amount.compareTo(BigDecimal.ZERO) > 0;
|
||||
if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
||||
continue;
|
||||
|
|
@ -349,6 +362,30 @@ public class FormingPaymentInstructionAssetsAction extends AbstractSessionAction
|
|||
}
|
||||
}
|
||||
|
||||
private Optional<Registry> searchDmx(Registry asset, Collection<Registry> oAndT) {
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
Registry tOrO = oAndT
|
||||
.stream()
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (tOrO == null) {
|
||||
log.debug("couldn't find O/T for {}.id={}, not searching DM*X", asset.getRegistryCode(), asset.getId());
|
||||
return Optional.empty();
|
||||
}
|
||||
ImdgPredicate dmxPrdct = pb.and(
|
||||
pb.sql(RegistryCodeSqlBuilder.getInstance(DM_X).build()),
|
||||
pb.equals("companyId", tOrO.getCounterPartyId()),
|
||||
pb.equals("contract", tOrO.getContract()),
|
||||
pb.equals("registryStatus", RegistryStatus.OK.getKey())
|
||||
);
|
||||
log.debug("{}.id={}, searching DM*X by {}", asset.getRegistryCode(), asset.getId(), dmxPrdct);
|
||||
Registry dmx = registryImdg.getSingleObjectByPredicate(dmxPrdct);
|
||||
if (dmx == null) {
|
||||
log.debug("{}.id={}, didn't find DM*X", asset.getRegistryCode(), asset.getId());
|
||||
}
|
||||
return Optional.ofNullable(dmx);
|
||||
}
|
||||
|
||||
private Collection<Registry> selectAMBRegistries(Long sessionId) {
|
||||
ImdgPredicateBuilder rgsPb = registryImdg.predicateBuilder();
|
||||
RegistryCodeSqlBuilder registryCodeSqlBuilder = RegistryCodeSqlBuilder.getInstance(
|
||||
|
|
@ -373,8 +410,7 @@ public class FormingPaymentInstructionAssetsAction extends AbstractSessionAction
|
|||
return registryImdg.getCollectionObjectsByPredicate(rgsCodePrdct);
|
||||
}
|
||||
|
||||
private BigDecimal adjustAmountByReturns(Registry amb, Long sessionId) {//companyid, tcr/account, sessionId, RUB
|
||||
if (SessionType.UNIT.equals(sessionType)) return BigDecimal.ZERO;
|
||||
private Collection<Registry> loadLiabilitiesAndClaims(Registry amb, Long sessionId) {
|
||||
Long companyId = amb.getCompanyId();
|
||||
Long tradingClearingRegistryId = amb.getTradingClearingRegistryId();
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
|
|
@ -388,26 +424,32 @@ public class FormingPaymentInstructionAssetsAction extends AbstractSessionAction
|
|||
pb.sql(RegistryCodeSqlBuilder.getInstance(TM_T).build())
|
||||
)
|
||||
);
|
||||
BigDecimal reduce = registryImdg.getCollectionObjectsByPredicate(cL)
|
||||
.stream()
|
||||
.filter(rgs -> rgs.getValueDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate().isAfter(rgs.getValueDate()))
|
||||
.map(rgs -> {
|
||||
if (RegistryDesignation.T.equalsByKey(rgs.getRegistryDesignation())) {
|
||||
return rgs.getBalance();
|
||||
} else {
|
||||
return rgs.getBalance().abs().negate();
|
||||
}
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
log.debug("{}.id={} {} adjust value {}",
|
||||
amb.getRegistryCode(),
|
||||
amb.getId(),
|
||||
cL,
|
||||
reduce);
|
||||
return reduce;
|
||||
log.debug("{}.id={} search adjust O/T: {}", amb.getRegistryCode(), amb.getId(), cL);
|
||||
List<Registry> list = registryImdg
|
||||
.getCollectionObjectsByPredicate(cL)
|
||||
.stream()
|
||||
.filter(rgs -> rgs.getValueDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate().isAfter(rgs.getValueDate()))
|
||||
.toList();
|
||||
log.debug("{}.id={} adjust O/T found: {}", amb.getRegistryCode(), amb.getId(), list.size());
|
||||
return list;
|
||||
}
|
||||
|
||||
private BigDecimal adjustAmountByReturns(Collection<Registry> lAndC) {//companyid, tcr/account, sessionId, RUB
|
||||
if (SessionType.UNIT.equals(sessionType)) return BigDecimal.ZERO;
|
||||
return lAndC.stream()
|
||||
.filter(rgs -> rgs.getValueDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate() != null)
|
||||
.filter(rgs -> rgs.getSettlementDate().isAfter(rgs.getValueDate()))
|
||||
.map(rgs -> {
|
||||
if (RegistryDesignation.T.equalsByKey(rgs.getRegistryDesignation())) {
|
||||
return rgs.getBalance();
|
||||
} else {
|
||||
return rgs.getBalance().abs().negate();
|
||||
}
|
||||
})
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
private void setUpdatedStoreInImdg(Registry rgs, Instant now) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue