Merge branch 'ReturnDepositSessionFix' into CLNRWORM
This commit is contained in:
commit
8ea1ba2e79
5 changed files with 61 additions and 13 deletions
|
|
@ -43,6 +43,17 @@ public class RegistryManager {
|
|||
return Optional.ofNullable(dmx);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchDmxByCounterPartyNotOk(Registry rgs) {
|
||||
if (TextUtil.isEmpty(rgs.getContract())) return Optional.empty();
|
||||
String sqlCondition = String.format("(%s) and companyId = %d and contract = '%s' and registryStatus != '%s'",
|
||||
RegistryCodeSqlBuilder.getInstance(DM_X).build(),
|
||||
rgs.getCounterPartyId(),
|
||||
rgs.getContract(),
|
||||
RegistryStatus.OK.getKey());
|
||||
Registry dmx = rgsImdg.getFirstObjectBySQL(sqlCondition);
|
||||
return Optional.ofNullable(dmx);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchDmxByCompanyId(Registry rgs) {
|
||||
if (TextUtil.isEmpty(rgs.getContract())) return Optional.empty();
|
||||
String sqlCondition = String.format("(%s) and companyId = %d and contract = '%s'",
|
||||
|
|
@ -65,6 +76,19 @@ public class RegistryManager {
|
|||
return Optional.ofNullable(dmt);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchDmtInfoNotOk(Registry rgs) {
|
||||
if (TextUtil.isEmpty(rgs.getContract())) return Optional.empty();
|
||||
String sqlCondition = String.format("(%s) and accountType='%s' and companyId = %d and counterPartyId = %d and contract = '%s' and registryStatus != '%s'",
|
||||
RegistryCodeSqlBuilder.getInstance(DM_T).build(),
|
||||
AccountType.Info.getKey(),
|
||||
rgs.getCompanyId(),
|
||||
rgs.getCounterPartyId(),
|
||||
rgs.getContract(),
|
||||
RegistryStatus.OK.getKey());
|
||||
Registry dmt = rgsImdg.getFirstObjectBySQL(sqlCondition);
|
||||
return Optional.ofNullable(dmt);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchDmtClrn(Registry rgs) {
|
||||
ImdgPredicate dmtClrnPrdct = RegistryDm_tClrnPredicate
|
||||
.instance(rgs.getCompanyId(), rgs.getCounterPartyId())
|
||||
|
|
@ -75,6 +99,18 @@ public class RegistryManager {
|
|||
return Optional.ofNullable(dmt);
|
||||
}
|
||||
|
||||
public Optional<Registry> searchDmtClrnNotOk(Registry rgs) {
|
||||
ImdgPredicate dmtClrnPrdct = RegistryDm_tClrnPredicate
|
||||
.instance(rgs.getCompanyId(), rgs.getCounterPartyId())
|
||||
.apply(rgsImdg);
|
||||
ImdgPredicateBuilder rgsPb = rgsImdg.predicateBuilder();
|
||||
dmtClrnPrdct = rgsPb.and(dmtClrnPrdct,
|
||||
rgsPb.equals("contract", rgs.getContract()),
|
||||
rgsPb.not(rgsPb.equals("registryStatus", RegistryStatus.OK.getKey())));
|
||||
Registry dmt = rgsImdg.getSingleObjectByPredicate(dmtClrnPrdct);
|
||||
return Optional.ofNullable(dmt);
|
||||
}
|
||||
|
||||
public Optional<Registry> findRelatedAsset(Long tradingClearingRegistryId,
|
||||
Long companyId,
|
||||
String securitySymbol,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import ru.spcex.clearing.session.stage.task.FormingPaymentInstructionPayload;
|
|||
import ru.spcex.platform.enumeration.AccountStatus;
|
||||
import ru.spcex.platform.enumeration.AccountType;
|
||||
import ru.spcex.platform.enumeration.Allowed;
|
||||
import ru.spcex.platform.enumeration.RegistryStatus;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
|
@ -98,6 +99,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
|||
//CM_T LM_T CS_T LS_T
|
||||
|
||||
private StageResult formingPaymentInstruction(Long sessionId) {
|
||||
Instant now = Instant.now();
|
||||
|
||||
RegistryCodeSqlBuilder registryCodeSqlBuilder = RegistryCodeSqlBuilder.getInstance(LM_T,CM_T, LS_T, CS_T);
|
||||
String registryCodeCondition = registryCodeSqlBuilder.build();
|
||||
|
|
@ -125,24 +127,28 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
|||
}
|
||||
Registry lm_t = lmtO.get(); //obligation by money
|
||||
Registry cm_t = cmtO.get();
|
||||
Optional<Registry> dmx = rgsMng.searchDmxByCounterParty(lm_t);
|
||||
Optional<Registry> dmx = rgsMng.searchDmxByCounterPartyNotOk(lm_t);
|
||||
if (dmx.isPresent()) {
|
||||
log.debug("LM*T#id={}, DM*X#id={} found, no action needed for group {}, skipping liability",
|
||||
lm_t.getId(), dmx.get().getId(), lm_t.getGroupId());
|
||||
dmx.get().setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
setUpdatedStoreInImdg(dmx.get(), now);
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<Registry> dmtInfo = rgsMng.searchDmtInfo(lm_t);
|
||||
Optional<Registry> dmtInfo = rgsMng.searchDmtInfoNotOk(lm_t);
|
||||
if (dmtInfo.isPresent()) {
|
||||
BigDecimal balance = safeBD(lm_t.getBalance()).add(safeBD(cm_t.getBalance())); //fixme????
|
||||
PaymentInstruction payInstr = createPaymentInstruction(List.of(lm_t, cm_t), balance, sessionId);
|
||||
lm_t.setPaymentId(payInstr.getId());
|
||||
lm_t.setUpdated(Instant.now());
|
||||
registryImdg.update(lm_t);
|
||||
dmtInfo.get().setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
setUpdatedStoreInImdg(dmtInfo.get(), now);
|
||||
continue;
|
||||
}
|
||||
|
||||
Optional<Registry> dmtClnr = rgsMng.searchDmtClrn(lm_t);
|
||||
Optional<Registry> dmtClnr = rgsMng.searchDmtClrnNotOk(lm_t);
|
||||
if (dmtClnr.isPresent()) {
|
||||
Account tranAcc = accountImdg.getFirstObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'"
|
||||
.formatted(AccountType.Tran.getKey(), AccountStatus.ACTIVE.getKey(), Allowed.ALLOWED.getKey()));
|
||||
|
|
@ -165,7 +171,6 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
|||
ambO.map(Registry::getId).orElse(null),
|
||||
receiverAmtO.map(Registry::getId).orElse(null)
|
||||
);
|
||||
Instant now = Instant.now();
|
||||
amfO.ifPresent(amf -> {
|
||||
amf.setBalance(safeBD(amf.getBalance()).subtract(safeBD(lm_t.getBalance())));
|
||||
setUpdatedStoreInImdg(amf, now);
|
||||
|
|
@ -197,6 +202,8 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
|||
lm_t.getId(), cm_t.getId(), pmts.getFirst().getId(), pmts.getSecond().getId());
|
||||
pmtCreated.add(pmts.getFirst());
|
||||
pmtCreated.add(pmts.getSecond());
|
||||
dmtClnr.get().setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
setUpdatedStoreInImdg(dmtClnr.get(), now);
|
||||
}
|
||||
}
|
||||
sendSdfs(pmtCreated);
|
||||
|
|
|
|||
|
|
@ -96,6 +96,7 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage {
|
|||
|
||||
|
||||
private StageResult formingPaymentInstruction(Long sessionId) {
|
||||
Instant now = Instant.now();
|
||||
RegistryCodeSqlBuilder registryCodeSqlBuilder = RegistryCodeSqlBuilder.getInstance(LM_T, CM_T);
|
||||
String registryCodeCondition = registryCodeSqlBuilder.build();
|
||||
|
||||
|
|
@ -142,13 +143,15 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage {
|
|||
}
|
||||
Registry lm_t = lmtO.get(); //obligation by money
|
||||
Registry cm_t = cmtO.get();
|
||||
Optional<Registry> dmx = rgsMng.searchDmxByCounterParty(lm_t);
|
||||
Optional<Registry> dmx = rgsMng.searchDmxByCounterPartyNotOk(lm_t);
|
||||
if (dmx.isPresent()) {
|
||||
log.debug("LM*T#id={}, DM*X#id={} found, no action needed for group {}, skipping liability",
|
||||
lm_t.getId(), dmx.get().getId(), lm_t.getGroupId());
|
||||
dmx.get().setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
setUpdatedStoreInImdg(dmx.get(), now);
|
||||
continue;
|
||||
}
|
||||
Optional<Registry> dmtClnr = rgsMng.searchDmtClrn(lm_t);
|
||||
Optional<Registry> dmtClnr = rgsMng.searchDmtClrnNotOk(lm_t);
|
||||
if (dmtClnr.isPresent()) {
|
||||
Account tranAcc = accountImdg.getFirstObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'"
|
||||
.formatted(AccountType.Tran.getKey(), AccountStatus.ACTIVE.getKey(), Allowed.ALLOWED.getKey()));
|
||||
|
|
@ -171,7 +174,6 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage {
|
|||
ambO.map(Registry::getId).orElse(null),
|
||||
receiverAmtO.map(Registry::getId).orElse(null)
|
||||
);
|
||||
Instant now = Instant.now();
|
||||
amfO.ifPresent(amf -> {
|
||||
amf.setBalance(safeBD(amf.getBalance()).subtract(safeBD(lm_t.getBalance())));
|
||||
setUpdatedStoreInImdg(amf, now);
|
||||
|
|
@ -203,6 +205,8 @@ public class FormingPaymentInstructionReturnMkr implements ISessionStage {
|
|||
lm_t.getId(), cm_t.getId(), pmts.getFirst().getId(), pmts.getSecond().getId());
|
||||
pmtCreated.add(pmts.getFirst());
|
||||
pmtCreated.add(pmts.getSecond());
|
||||
dmtClnr.get().setRegistryStatus(RegistryStatus.OK.getKey());
|
||||
setUpdatedStoreInImdg(dmtClnr.get(), now);
|
||||
}
|
||||
}
|
||||
StageResult<Collection<PaymentInstruction>> stageResult = new StageResult(null, true);
|
||||
|
|
|
|||
|
|
@ -137,10 +137,11 @@ public class InclusionObligations implements ISessionStage {
|
|||
|
||||
private ImdgPredicate sessionTypePredicate() {
|
||||
if (this.sessionType != null) {
|
||||
if (SessionType.FINL.equals(sessionType)) {
|
||||
if (SessionType.FINL.equals(sessionType) || SessionType.MEDM.equals(sessionType)) {
|
||||
return rgsPb.or(
|
||||
rgsPb.equals("sessionType", sessionType.getKey()),
|
||||
rgsPb.equals("sessionType", SessionType.MEDM.getKey())
|
||||
rgsPb.equals("sessionType", SessionType.FINL.getKey()),
|
||||
rgsPb.equals("sessionType", SessionType.MEDM.getKey()),
|
||||
rgsPb.equals("sessionType", SessionType.XDEP.getKey())
|
||||
);
|
||||
} else {
|
||||
return rgsPb.equals("sessionType", sessionType.getKey());
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
);
|
||||
if (dmxBalance.compareTo(omtBalance) >= 0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
updateStatus(dmx.get(), RegistryStatus.OK);
|
||||
// updateStatus(dmx.get(), RegistryStatus.POOL);
|
||||
} else {
|
||||
//для OM*T uncovered остальным фейл
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed(rgs)));
|
||||
|
|
@ -126,7 +126,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >=0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
updateStatus(dmtInfo.get(), RegistryStatus.OK);
|
||||
// updateStatus(dmtInfo.get(), RegistryStatus.POOL);
|
||||
} else {
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed()));
|
||||
updateStatus(dmtInfo.get(), RegistryStatus.UNCV);
|
||||
|
|
@ -143,7 +143,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >= 0) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
updateStatus(dmtClnr.get(), RegistryStatus.OK);
|
||||
// updateStatus(dmtClnr.get(), RegistryStatus.POOL);
|
||||
} else {
|
||||
group.forEach(rgs -> updateStatus(rgs, registryStatusFailed()));
|
||||
updateStatus(dmtClnr.get(), RegistryStatus.UNCV);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue