GatewayRequester 5 шаг сессий
This commit is contained in:
parent
8cd1bda1ed
commit
08271d7e36
3 changed files with 64 additions and 8 deletions
|
|
@ -24,7 +24,6 @@ import ru.spcex.clearing.service.integration.GatewayRequestCreator;
|
|||
import ru.spcex.platform.enumeration.InOutDirection;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
|
@ -80,7 +79,7 @@ public class GatewayRequester extends QueueConsumer implements InitializingBean
|
|||
AssetOperationRequest req = GatewayRequestCreator.gatewayRequestPart(
|
||||
om_t.getId(),
|
||||
null,
|
||||
BigDecimal.ONE,
|
||||
om_t.getBalance(),
|
||||
InOutDirection.out,
|
||||
om_t.getTradingCode(),
|
||||
om_t.getTradingClearingRegistry());
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import ru.spcex.clearing.error.ClearingError;
|
|||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.service.registry.AssetTBFProcessing;
|
||||
import ru.spcex.clearing.service.registry.RegistryManager;
|
||||
import ru.spcex.clearing.service.schedule.TradingTimeService;
|
||||
import ru.spcex.clearing.session.stage.ISessionStage;
|
||||
import ru.spcex.clearing.session.stage.StageResult;
|
||||
import ru.spcex.clearing.session.stage.Task;
|
||||
|
|
@ -48,12 +49,19 @@ public class InspectionObligations implements ISessionStage {
|
|||
private SessionType sessionType;
|
||||
private Section section;
|
||||
private final AssetTBFProcessing assets;
|
||||
private final GatewayRequester gateway;
|
||||
private final TradingTimeService tradingTimeService;
|
||||
|
||||
@Autowired
|
||||
public InspectionObligations(ImdgProvider imdgProvider, RegistryManager registryManager, AssetTBFProcessing assets) {
|
||||
public InspectionObligations(ImdgProvider imdgProvider,
|
||||
RegistryManager registryManager,
|
||||
AssetTBFProcessing assets,
|
||||
GatewayRequester gateway) {
|
||||
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
this.registryManager = registryManager;
|
||||
this.assets = assets;
|
||||
this.gateway = gateway;
|
||||
this.tradingTimeService = new TradingTimeService(imdgProvider);
|
||||
}
|
||||
|
||||
public void setSessionType(SessionType sessionType) {
|
||||
|
|
@ -118,6 +126,20 @@ public class InspectionObligations implements ISessionStage {
|
|||
checkResults.add(new CheckResult(obligation, isUncovered));
|
||||
isUncovered = false;
|
||||
}
|
||||
|
||||
Optional<Registry> omt = group.stream().filter(rgs -> RegistryManager.equalsByCode(OM_T, rgs)).findFirst();
|
||||
if (SessionType.FINL.equals(sessionType) && tradingTimeService.isTradingTime() && omt.isPresent()) {
|
||||
Optional<Boolean> gatewayReceived = gateway.gatewayRequestAndWait(omt.get());
|
||||
if (gatewayReceived.isEmpty()) {
|
||||
log.error("Gateway not received response for groupId: {}. ", entry.getKey());
|
||||
}
|
||||
if (!gatewayReceived.orElse(false)) {
|
||||
checkResults.stream()
|
||||
.filter(chk -> chk.registry().getId().equals(omt.get().getId()))
|
||||
.findFirst()
|
||||
.ifPresent(chk -> chk.isUncovered = true);
|
||||
}
|
||||
}
|
||||
defineStatusAndUpdateRegistry(checkResults, group);
|
||||
if (checkResults.stream().noneMatch(checkResult -> checkResult.isUncovered)) {
|
||||
Instant now = Instant.now();
|
||||
|
|
@ -302,7 +324,22 @@ foreach( at: rgsAT)
|
|||
registryImdg.update(registry);
|
||||
}
|
||||
|
||||
private record CheckResult(Registry registry, boolean isUncovered) {
|
||||
private static final class CheckResult {
|
||||
private final Registry registry;
|
||||
private boolean isUncovered;
|
||||
|
||||
private CheckResult(Registry registry, boolean isUncovered) {
|
||||
this.registry = registry;
|
||||
this.isUncovered = isUncovered;
|
||||
}
|
||||
|
||||
public Registry registry() {
|
||||
return registry;
|
||||
}
|
||||
|
||||
public boolean isUncovered() {
|
||||
return isUncovered;
|
||||
}
|
||||
}
|
||||
|
||||
private RegistryStatus uncvStatus() {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import ru.clearing.classes.statics.data.registry.Registry;
|
|||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.service.registry.AssetTBFProcessing;
|
||||
import ru.spcex.clearing.service.registry.RegistryManager;
|
||||
import ru.spcex.clearing.service.schedule.TradingTimeService;
|
||||
import ru.spcex.clearing.session.stage.ISessionStage;
|
||||
import ru.spcex.clearing.session.stage.StageResult;
|
||||
import ru.spcex.clearing.session.stage.Task;
|
||||
|
|
@ -40,13 +41,17 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
private SessionType sessionType;
|
||||
private final RegistryManager rgsMng;
|
||||
private final AssetTBFProcessing assets;
|
||||
private final TradingTimeService tradingTimeService;
|
||||
private final GatewayRequester gateway;
|
||||
|
||||
@Autowired
|
||||
public InspectionObligationsDepositReturn(ImdgProvider imdgProvider, RegistryManager rgsMng, AssetTBFProcessing assets) {
|
||||
public InspectionObligationsDepositReturn(ImdgProvider imdgProvider, RegistryManager rgsMng, AssetTBFProcessing assets, TradingTimeService tradingTimeService, GatewayRequester gateway) {
|
||||
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
this.categoryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||
this.rgsMng = rgsMng;
|
||||
this.assets = assets;
|
||||
this.tradingTimeService = tradingTimeService;
|
||||
this.gateway = gateway;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -59,6 +64,21 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
}
|
||||
}
|
||||
|
||||
private boolean gatewayIfNeeded(Registry omt) {
|
||||
if (SessionType.FINL.equals(sessionType) && tradingTimeService.isTradingTime()) {
|
||||
Optional<Boolean> gatewayReceived = gateway.gatewayRequestAndWait(omt);
|
||||
if (gatewayReceived.isEmpty()) {
|
||||
log.error("gateway not received response for om*t.id: {}. ", omt.getId());
|
||||
} else {
|
||||
log.debug("gateway response for om*t.id {}: approved {}", omt.getId(), gatewayReceived.get());
|
||||
}
|
||||
return gatewayReceived.orElse(false);
|
||||
} else {
|
||||
log.trace("gateway not needed for om*t.id: {}", omt.getId());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private StageResult<?> inspectionObligations() {
|
||||
String sqlCondition = String.format("(%s) and registryStatus = '%s'",
|
||||
RegistryCodeSqlBuilder.getInstance(OS_T, OM_T, TS_T, TM_T).build(),
|
||||
|
|
@ -130,7 +150,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
dmtInfo.get().getId(),
|
||||
dmtBalance, omtBalance, amfBalance
|
||||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >=0) {
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >=0 && gatewayIfNeeded(omtRgs)) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
assets.processByAm_f(amfAsset, omtBalance.negate());
|
||||
// updateStatus(dmtInfo.get(), RegistryStatus.POOL);
|
||||
|
|
@ -149,7 +169,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
dmtClnr.get().getId(),
|
||||
dmtBalance, omtBalance, amfBalance
|
||||
);
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >= 0) {
|
||||
if (dmtBalance.compareTo(omtBalance) >= 0 && amfBalance.compareTo(omtBalance) >= 0 && gatewayIfNeeded(omtRgs)) {
|
||||
group.forEach(rgs -> updateStatus(rgs, RegistryStatus.OK));
|
||||
assets.processByAm_f(amfAsset, omtBalance.negate());
|
||||
continue;
|
||||
|
|
@ -162,7 +182,7 @@ public class InspectionObligationsDepositReturn implements ISessionStage {
|
|||
|
||||
if (SessionType.FINL.equals(sessionType)
|
||||
&& amfBalance.compareTo(omtBalance) >= 0
|
||||
&& initiatorV(omtRgs)) {
|
||||
&& initiatorV(omtRgs) && gatewayIfNeeded(omtRgs)) {
|
||||
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());
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue