InspectionObligationsDepositReturn local store registries
This commit is contained in:
parent
80c9870282
commit
1defffc0a1
2 changed files with 46 additions and 20 deletions
|
|
@ -64,6 +64,9 @@ public class AssetTBFProcessing {
|
|||
return a___;
|
||||
}
|
||||
|
||||
public void process(Registry am_b, Registry am_t, Registry am_f, BigDecimal sum) {
|
||||
process(am_b, am_t, am_f, sum, true);
|
||||
}
|
||||
/**
|
||||
* пересчитывает A**F = A**T - A**B + D**I - D**V
|
||||
* учитываются только D**I с отрицательным balance.
|
||||
|
|
@ -72,7 +75,7 @@ public class AssetTBFProcessing {
|
|||
* @param am_f регистр свободных средств
|
||||
* @param sum отнимается от блокировки.
|
||||
*/
|
||||
public void process(Registry am_b, Registry am_t, Registry am_f, BigDecimal sum) {
|
||||
public void process(Registry am_b, Registry am_t, Registry am_f, BigDecimal sum, boolean isFireUpdate) {
|
||||
boolean am_bExists = am_b != null;
|
||||
if (!am_bExists) {
|
||||
am_b = new Registry();
|
||||
|
|
@ -105,11 +108,15 @@ public class AssetTBFProcessing {
|
|||
am_f.setBalance(am_t.getBalance().subtract(am_b.getBalance()).add(d__iSum).subtract(d__vSum));
|
||||
if (am_bExists) {
|
||||
am_b.setUpdated(now);
|
||||
rgsImdg.update(am_b);
|
||||
if (isFireUpdate) {
|
||||
rgsImdg.update(am_b);
|
||||
}
|
||||
}
|
||||
am_f.setUpdated(now);
|
||||
|
||||
rgsImdg.update(am_f);
|
||||
if (isFireUpdate) {
|
||||
rgsImdg.update(am_f);
|
||||
}
|
||||
log.debug("assets processing [{}#id={}#balance={} | {}#id={}#balance={} | {}#id={}#balance={}] " +
|
||||
"D**I.size={} D**V.size={}. {}.balance -> {}, {}.balance -> {}",
|
||||
am_f.getRegistryCode(), am_f.getId(), am_fBalanceForLoging,
|
||||
|
|
@ -166,6 +173,9 @@ public class AssetTBFProcessing {
|
|||
}
|
||||
|
||||
public Optional<AssetTrio> processByAm_f(Registry am_f, BigDecimal sum) {
|
||||
return processByAm_f(am_f, sum, true);
|
||||
}
|
||||
public Optional<AssetTrio> processByAm_f(Registry am_f, BigDecimal sum, boolean isFireUpdate) {
|
||||
Optional<Registry> am_b = rgsMng.findRegByUnit(am_f.getCompanyId(),
|
||||
am_f.getAccountId(),
|
||||
am_f.getContract(),
|
||||
|
|
@ -177,7 +187,7 @@ public class AssetTBFProcessing {
|
|||
am_f,
|
||||
RegistryUnit.T);
|
||||
if (am_b.isPresent() && am_t.isPresent()) {
|
||||
process(am_b.get(), am_t.get(), am_f, sum);
|
||||
process(am_b.get(), am_t.get(), am_f, sum, isFireUpdate);
|
||||
return Optional.of(new AssetTrio(am_f, am_b.get(), am_t.get()));
|
||||
} else {
|
||||
return Optional.empty();
|
||||
|
|
|
|||
|
|
@ -2,6 +2,8 @@ package ru.spcex.clearing.session.state.action;
|
|||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
|
@ -74,8 +76,10 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
RegistryCodeSqlBuilder.getInstance(OS_T, OM_T, TS_T, TM_T).build(),
|
||||
RegistryStatus.POOL.getKey());
|
||||
|
||||
List<Map.Entry<Long, List<Registry>>> registriesByGroupSorted = registryImdg.getCollectionObjectsBySQL(sqlCondition)
|
||||
.stream()
|
||||
Collection<Registry> registriesToProcess = registryImdg.getCollectionObjectsBySQL(sqlCondition);
|
||||
Map<Long, Registry> rgssToStore = new HashMap<>(registriesToProcess.size()); //вторые ноги у сделок - нужна ли оптимизация?
|
||||
|
||||
List<Map.Entry<Long, List<Registry>>> registriesByGroupSorted = registriesToProcess.stream()
|
||||
.collect(Collectors.groupingBy(Registry::getGroupId))
|
||||
.entrySet()
|
||||
.stream()
|
||||
|
|
@ -89,7 +93,7 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
Optional<Registry> tmtInGroupO = group.stream().filter(registry -> equalByRgs(TM_T, registry)).findFirst();
|
||||
if (omtInGroupO.isEmpty() || tmtInGroupO.isEmpty()) {
|
||||
log.error("groupId {} failed to find OM*T/TM*T registry", entry.getKey());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(), rgssToStore)); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
Registry omtRgs = omtInGroupO.get();
|
||||
|
|
@ -114,12 +118,12 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
dmxBalance, omtBalance
|
||||
);
|
||||
if (dmxBalance.compareTo(omtBalance) >= 0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, RegistryStatus.OK, rgssToStore));
|
||||
// updateStatus(dmx.get(), RegistryStatus.POOL);
|
||||
} else {
|
||||
//для OM*T uncovered остальным фейл
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed(rgs)));
|
||||
updateStatus(dmx.get(), RegistryStatus.UNCV);
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(rgs), rgssToStore));
|
||||
updateRegistryStatus(dmx.get(), RegistryStatus.UNCV, rgssToStore);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
|
@ -128,12 +132,12 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
Optional<Registry> amfAssetReceiverO = searchAssetByOMT(tmtRgs);
|
||||
if (amfAssetO.isEmpty()) {
|
||||
log.error("OM*T register.id={} groupId={} failed to find AM*F asset", omtRgs.getId(), entry.getKey());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(), rgssToStore)); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
if (amfAssetReceiverO.isEmpty()) {
|
||||
log.error("TM*T register.id={} groupId={} failed to find AM*F asset", tmtRgs.getId(), entry.getKey());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed())); // FAIL or MNG
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(), rgssToStore)); // FAIL or MNG
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
@ -141,10 +145,12 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
log.debug("groupId={}, AM*F.id={}", entry.getKey(), amfAsset.getId());
|
||||
BigDecimal amfBalance = safeBD(amfAsset.getBalance());
|
||||
BiConsumer<Registry, BigDecimal> processAssetsAndSetSessionId = (amf, amount) -> {
|
||||
Optional<AssetTrio> asts = assets.processByAm_f(amf, amount);
|
||||
Optional<AssetTrio> asts = assets.processByAm_f(amf, amount, false);
|
||||
if (asts.isPresent()) {
|
||||
asts.get().a__b().setSessionId(sessionId);
|
||||
registryImdg.update(asts.get().a__b());
|
||||
rgssToStore.put(asts.get().a__b().getId(), asts.get().a__b());
|
||||
rgssToStore.put(asts.get().a__f().getId(), asts.get().a__f());
|
||||
// registryImdg.update(asts.get().a__b());
|
||||
}
|
||||
};
|
||||
Optional<Registry> dmtInfo = rgsMng.searchDmtInfo(omtRgs);
|
||||
|
|
@ -156,13 +162,13 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
dmtBalance, omtBalance, amfBalance
|
||||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >= 0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, RegistryStatus.OK, rgssToStore));
|
||||
processAssetsAndSetSessionId.accept(amfAsset, omtBalance.negate());
|
||||
processAssetsAndSetSessionId.accept(amfAssetReceiverO.get(), omtBalance);
|
||||
// updateStatus(dmtInfo.get(), RegistryStatus.POOL);
|
||||
continue;
|
||||
} else if (SessionType.XDEP.equals(sessionType)) {
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed(rgs))); // для финальной UNCV or FAIL ; другие MNG
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(rgs), rgssToStore)); // для финальной UNCV or FAIL ; другие MNG
|
||||
// updateStatus(dmtInfo.get(), RegistryStatus.UNCV); не меняет статус, статус определяется OM*T
|
||||
continue;
|
||||
}
|
||||
|
|
@ -176,12 +182,12 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
dmtBalance, omtBalance, amfBalance
|
||||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >= 0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, RegistryStatus.OK, rgssToStore));
|
||||
processAssetsAndSetSessionId.accept(amfAsset, omtBalance.negate());
|
||||
processAssetsAndSetSessionId.accept(amfAssetReceiverO.get(), omtBalance);
|
||||
continue;
|
||||
} else if (SessionType.XDEP.equals(sessionType)) {
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed(rgs)));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(rgs), rgssToStore));
|
||||
// updateStatus(dmtClnr.get(), RegistryStatus.UNCV); не меняет статус, статус определяется OM*T
|
||||
continue;
|
||||
}
|
||||
|
|
@ -193,15 +199,17 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
log.debug("OM*T.id={} -> no DM*X/DM*T(INFO/CLRN) registry found. " +
|
||||
"FINL, initiator.category='V' and am*f > om*t: setting OK status to group",
|
||||
omtRgs.getId());
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, RegistryStatus.OK, rgssToStore));
|
||||
processAssetsAndSetSessionId.accept(amfAsset, omtBalance.negate());
|
||||
processAssetsAndSetSessionId.accept(amfAssetReceiverO.get(), omtBalance);
|
||||
} else {
|
||||
log.info("OM*T.id={} -> no DM*X/DM*T(INFO/CLRN) registry found. setting {} status to group",
|
||||
omtRgs.getId(), registryStatusFailed());
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed(rgs)));
|
||||
group.forEach(rgs -> updateRegistryStatus(rgs, registryStatusFailed(rgs), rgssToStore));
|
||||
}
|
||||
}
|
||||
registryImdg.putAll(rgssToStore, 200);
|
||||
|
||||
planBalanceCalc.stageRevision2(sessionId);
|
||||
}
|
||||
|
||||
|
|
@ -221,6 +229,14 @@ public class InspectionObligationsDepositReturnAction extends AbstractSessionAct
|
|||
registryImdg.update(registry);
|
||||
}
|
||||
|
||||
private void updateRegistryStatus(Registry registry, RegistryStatus registryStatus, Map<Long, Registry> rgss) {
|
||||
log.trace("Update registry.id: {} to {}", registry.getId(), registryStatus.getKey());
|
||||
registry.setRegistryStatus(registryStatus.getKey());
|
||||
registry.setUpdated(Instant.now());
|
||||
rgss.put(registry.getId(), registry);
|
||||
// registryImdg.update(registry);
|
||||
}
|
||||
|
||||
private RegistryStatus registryStatusFailed() {
|
||||
if (SessionType.FINL.equals(sessionType) || SessionType.UNIT.equals(sessionType)) {
|
||||
return RegistryStatus.FAIL;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue