fix balance and credit for T and F registry
This commit is contained in:
parent
873123cb9c
commit
99004e0c47
1 changed files with 45 additions and 6 deletions
|
|
@ -165,6 +165,16 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
if (err.isEmpty()) {
|
if (err.isEmpty()) {
|
||||||
Consumer<Registry> update = rgs -> {
|
Consumer<Registry> update = rgs -> {
|
||||||
updateReg(stmt, rgs);
|
updateReg(stmt, rgs);
|
||||||
|
|
||||||
|
Optional<Registry> registryUnitBOpt = findRegByUnit(stmt, rgs, RegistryUnit.B);
|
||||||
|
Optional<Registry> registryUnitFOpt = findRegByUnit(stmt, rgs, RegistryUnit.F);
|
||||||
|
if (registryUnitFOpt.isPresent() && registryUnitBOpt.isPresent()) {
|
||||||
|
Registry registryUnitF = registryUnitFOpt.get();
|
||||||
|
Registry registryUnitB = registryUnitBOpt.get();
|
||||||
|
registryUnitF.setBalance(rgs.getBalance().subtract(registryUnitB.getBalance()));
|
||||||
|
registryUnitF.setUpdated(Instant.now());
|
||||||
|
registryImdg.update(registryUnitF);
|
||||||
|
}
|
||||||
registryImdg.update(rgs);
|
registryImdg.update(rgs);
|
||||||
};
|
};
|
||||||
Consumer<RegistryDesignation> create = (dsgn) -> {
|
Consumer<RegistryDesignation> create = (dsgn) -> {
|
||||||
|
|
@ -190,10 +200,10 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
};
|
};
|
||||||
|
|
||||||
//todo понять что происходит со инициатором/контрагентом, особенно если у нас только один Statement
|
//todo понять что происходит со инициатором/контрагентом, особенно если у нас только один Statement
|
||||||
findReg(stmt, RegistryDesignation.A).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.A));
|
findRegByDesignation(stmt, RegistryDesignation.A).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.A));
|
||||||
if (!StringUtils.isEmpty(sdf57.getSpecif()) && sdf57.getSpecif().contains("№")) {
|
if (!StringUtils.isEmpty(sdf57.getSpecif()) && sdf57.getSpecif().contains("№")) {
|
||||||
//todo доделать 11. Идентификация средств УК на клиринговом счете
|
//todo доделать 11. Идентификация средств УК на клиринговом счете
|
||||||
findReg(stmt, RegistryDesignation.D).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.D));
|
findRegByDesignation(stmt, RegistryDesignation.D).ifPresentOrElse(update, () -> create.accept(RegistryDesignation.D));
|
||||||
}
|
}
|
||||||
stmt.setOperationStatus(OperationStatus.Executed.getKey());
|
stmt.setOperationStatus(OperationStatus.Executed.getKey());
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -237,7 +247,7 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
statement.setInOutDirection(inOutDirection.getKey());
|
statement.setInOutDirection(inOutDirection.getKey());
|
||||||
statement.setSettlementDate(payDate(sdf57.getPay_date()));
|
statement.setSettlementDate(payDate(sdf57.getPay_date()));
|
||||||
statement.setAmount(TextUtil.isEmpty(sdf57.getSum_deb()) ? null : new BigDecimal(sdf57.getSum_deb()));
|
statement.setAmount(TextUtil.isEmpty(sdf57.getSum_deb()) ? null : new BigDecimal(sdf57.getSum_deb()));
|
||||||
statement.setOperationStatus(OperationStatus.Pending.getKey());
|
statement.setOperationStatus(OperationStatus.Pending.getKey());//todo тут что-то с апдейтом статуса на EXEC когда создались регистры с нулевым диффом?
|
||||||
statement.setInSDfId(sdf57.getId());
|
statement.setInSDfId(sdf57.getId());
|
||||||
statement.setInOutSDfType(InOutSDfType.type57.getKey());
|
statement.setInOutSDfType(InOutSDfType.type57.getKey());
|
||||||
|
|
||||||
|
|
@ -317,13 +327,19 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
private void updateReg(Statement s, Registry r) {
|
private void updateReg(Statement s, Registry r) {
|
||||||
InOutDirection direction = IEnumKey.getEnumByKey(InOutDirection.class, s.getInOutDirection());
|
InOutDirection direction = IEnumKey.getEnumByKey(InOutDirection.class, s.getInOutDirection());
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case in -> r.setBalance(r.getBalance().add(s.getAmount()));
|
case in -> {
|
||||||
case out -> r.setBalance(r.getBalance().subtract(s.getAmount()));
|
r.setBalance(r.getBalance().add(s.getAmount()));
|
||||||
|
r.setCredit(safeBD(r.getCredit()).add(safeBD(s.getAmount())));
|
||||||
|
}
|
||||||
|
case out -> {
|
||||||
|
r.setBalance(r.getBalance().subtract(s.getAmount()));
|
||||||
|
r.setDebit(safeBD(r.getDebit()).add(safeBD(s.getAmount())));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
r.setUpdated(Instant.now());
|
r.setUpdated(Instant.now());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Registry> findReg(Statement s, RegistryDesignation des) {
|
private Optional<Registry> findRegByDesignation(Statement s, RegistryDesignation des) {
|
||||||
RegistryTradingParams p = new RegistryTradingParams(
|
RegistryTradingParams p = new RegistryTradingParams(
|
||||||
des, RegistryInstrumentType.M, RegistryCapacity.A, RegistryUnit.T
|
des, RegistryInstrumentType.M, RegistryCapacity.A, RegistryUnit.T
|
||||||
);
|
);
|
||||||
|
|
@ -339,6 +355,25 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
return Optional.ofNullable(registryImdg.getSingleObjectByPredicate(rgstrPredicate));
|
return Optional.ofNullable(registryImdg.getSingleObjectByPredicate(rgstrPredicate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Optional<Registry> findRegByUnit(Statement s, Registry registry, RegistryUnit unit) {
|
||||||
|
RegistryTradingParams p = new RegistryTradingParams(
|
||||||
|
RegistryDesignation.valueOf(registry.getRegistryDesignation()),
|
||||||
|
RegistryInstrumentType.valueOf(registry.getRegistryInstrumentType()),
|
||||||
|
RegistryCapacity.valueOf(registry.getRegistryCapacity()),
|
||||||
|
unit
|
||||||
|
);
|
||||||
|
String sql = RegistryCodeSqlBuilder.getInstance(p).build();
|
||||||
|
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||||
|
ImdgPredicate rgstrPredicate = pb.and(pb.sql(sql),
|
||||||
|
pb.sql(sql),
|
||||||
|
pb.equals("companyId", s.getAddresseeId()) //fixme companyId?
|
||||||
|
);
|
||||||
|
if (RegistryDesignation.D.equalsByKey(registry.getRegistryDesignation()) && !TextUtil.isEmpty(s.getContract())) {
|
||||||
|
rgstrPredicate = pb.and(rgstrPredicate, pb.equals("contract", s.getContract()));
|
||||||
|
}
|
||||||
|
return Optional.ofNullable(registryImdg.getSingleObjectByPredicate(rgstrPredicate));
|
||||||
|
}
|
||||||
|
|
||||||
DateTimeFormatter payDateFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
|
DateTimeFormatter payDateFormatter = DateTimeFormatter.ofPattern("dd.MM.yy");
|
||||||
|
|
||||||
private LocalDate payDate(String payDate) {
|
private LocalDate payDate(String payDate) {
|
||||||
|
|
@ -363,4 +398,8 @@ public class Sdf57Executor extends AbstractExecutor<SDf57> {
|
||||||
private static interface TriFunction<T1, T2, T3, R> {
|
private static interface TriFunction<T1, T2, T3, R> {
|
||||||
R apply(T1 arg1, T2 arg2, T3 arg3);
|
R apply(T1 arg1, T2 arg2, T3 arg3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigDecimal safeBD(BigDecimal value) {
|
||||||
|
return value != null ? value : BigDecimal.ZERO;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue