This commit is contained in:
parent
ea4ef2f09c
commit
d0a74989a4
5 changed files with 150 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ public enum ClearingError implements IErrorEnumId {
|
|||
SecurityNotFound(5416L),
|
||||
TradingClearingRegistryNotFound(5418L),
|
||||
TradingClearingRegistryNotActive(5419L),
|
||||
InsecurityObligation(5422L),
|
||||
NewDealsNotFound(5423L),
|
||||
;
|
||||
private final Long id;
|
||||
|
|
|
|||
|
|
@ -9,4 +9,8 @@ public record RegistryInfo(RegistryDesignation registryDesignation,
|
|||
RegistryInstrumentType registryInstrumentType,
|
||||
RegistryCapacity registryCapacity,
|
||||
RegistryUnit registryUnit) {
|
||||
|
||||
public String buildSqlCondition(){
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,15 +53,18 @@ public class InclusionObligations implements ISessionStage {
|
|||
|
||||
|
||||
private StageResult inclusionToPool(String sessionType, Long counterPartyId) {
|
||||
String sqlCondition = String.format("registryCode like '%s' and " +
|
||||
String sqlCondition = String.format("registryDesignation in ('%s', '%s') and " +
|
||||
"registryInstrumentType in ('%s', '%s') and " +
|
||||
"registryUnit = '%s' and " +
|
||||
"registryStatus = '%s' and " +
|
||||
"settlementDate = '%s' and " +
|
||||
"sessionType = '%s'",
|
||||
"[O/T][S/M][*][T]",
|
||||
"O", "T",
|
||||
"S", "M",
|
||||
"T",
|
||||
"PROC",
|
||||
LocalDate.now(),
|
||||
sessionType);
|
||||
|
||||
Collection<Registry> obligations = registryImdg.getCollectionObjectsBySQL(sqlCondition);
|
||||
Map<Long, List<Registry>> registryByGroupId = obligations.stream().
|
||||
filter(registry -> registry.getCompanyId().equals(counterPartyId)).
|
||||
|
|
@ -69,7 +72,7 @@ public class InclusionObligations implements ISessionStage {
|
|||
|
||||
for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupId.entrySet()) {
|
||||
log.debug("Processing set of registry with groupId: {}", entrySet.getKey());
|
||||
for (Registry registry : entrySet.getValue()){
|
||||
for (Registry registry : entrySet.getValue()) {
|
||||
registry.setRegistryStatus("POOL");
|
||||
registryImdg.update(registry);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,125 @@
|
|||
package ru.spcex.clearing.session.stage.impl;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.clearing.classes.statics.data.registry.Registry;
|
||||
import ru.spcex.clearing.error.ClearingError;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.session.stage.ISessionStage;
|
||||
import ru.spcex.clearing.session.stage.StageResult;
|
||||
import ru.spcex.clearing.session.stage.Task;
|
||||
import ru.spcex.clearing.session.stage.task.InspectionPoolPayload;
|
||||
import ru.spcex.platform.enumeration.RegistryDesignation;
|
||||
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||
import ru.spcex.platform.enumeration.RegistryUnit;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||
import ru.spcex.platform.utils.enumeration.SimpleMessageResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
|
||||
@Service
|
||||
public class InspectionObligations implements ISessionStage {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
//todo remove (set all in single method setImdg(provider -> setImdg1();setIdGenerator();...)
|
||||
private ImdgProvider imdgProvider;
|
||||
private ImdgId idGenerator;
|
||||
private Imdg<Registry> registryImdg;
|
||||
private KafkaSender kafkaSender;
|
||||
private final IMessageResolver msgResolver = new SimpleMessageResolver();
|
||||
|
||||
@Autowired
|
||||
public InspectionObligations(ImdgProvider imdgProvider) {
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StageResult submit(Task<?> task) {
|
||||
InspectionPoolPayload payload = (InspectionPoolPayload) task.getData();
|
||||
switch (task.getTaskType()) {
|
||||
case InclusionToPool -> {
|
||||
return inspectionPool(payload.getProcessedCompanyId());
|
||||
}
|
||||
default -> {
|
||||
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private StageResult inspectionPool(Long processedCompanyId) {
|
||||
String sqlCondition = String.format("registryDesignation in ('%s', '%s') and " +
|
||||
"registryInstrumentType in ('%s', '%s') and " +
|
||||
"registryUnit = '%s' and " +
|
||||
"registryStatus = '%s' and " +
|
||||
"settlementDate = '%s'",
|
||||
RegistryDesignation.O.getKey(), RegistryDesignation.T.getKey(),
|
||||
RegistryInstrumentType.S.getKey(), RegistryInstrumentType.M.getKey(),
|
||||
RegistryUnit.T.getKey(),
|
||||
"POOL");
|
||||
|
||||
Collection<Registry> obligations = registryImdg.getCollectionObjectsBySQL(sqlCondition);
|
||||
Map<Long, Map<Long, List<Registry>>> registryByGroupIdAndCompanyId = obligations.stream().
|
||||
collect(Collectors.groupingBy(Registry::getGroupId, Collectors.groupingBy(Registry::getCompanyId)));
|
||||
|
||||
List<Long> insecurityGroups = new ArrayList<>();
|
||||
for (Registry currentRegistry : obligations) {
|
||||
if (insecurityGroups.contains(currentRegistry.getGroupId())) {
|
||||
log.debug("Skip insecurity groupId: {}", currentRegistry.getGroupId());
|
||||
continue;
|
||||
}
|
||||
if (IEnumKey.getEnumByKey(RegistryDesignation.class, currentRegistry.getRegistryDesignation()) == RegistryDesignation.A) {
|
||||
String sqlCounterRegistryCondition = String.format("registryDesignation = '%s' and " +
|
||||
"registryInstrumentType in ('%s', '%s') and " +
|
||||
"registryUnit = '%s' and " +
|
||||
"tradingClearingRegistryId = '%s' and " +
|
||||
"companyId = '%s' and ",
|
||||
RegistryDesignation.A,
|
||||
RegistryInstrumentType.S.getKey(), RegistryInstrumentType.M.getKey(),
|
||||
RegistryUnit.F.getKey(),
|
||||
currentRegistry.getTradingClearingRegistryId(),
|
||||
currentRegistry.getCompanyId());
|
||||
Registry counterRegistry = registryImdg.getSingleObjectBySQL(sqlCounterRegistryCondition);
|
||||
if (currentRegistry.getBalance().compareTo(counterRegistry.getBalance()) > 0) {
|
||||
log.warn("{}", msgResolver.resolve(new EnumMessage(ClearingError.InsecurityObligation, currentRegistry.getCompanyId())));
|
||||
insecurityGroups.add(currentRegistry.getGroupId());
|
||||
break;
|
||||
}
|
||||
currentRegistry.setRegistryStatus("OK");
|
||||
registryImdg.update(counterRegistry);
|
||||
}
|
||||
}
|
||||
|
||||
for (Long insecuritiesGroupId : insecurityGroups) {
|
||||
for (Map.Entry<Long, List<Registry>> entrySet : registryByGroupIdAndCompanyId.get(insecuritiesGroupId).entrySet()) {
|
||||
if (entrySet.getKey().equals(processedCompanyId)) {
|
||||
for (Registry registry : entrySet.getValue()) {
|
||||
registry.setRegistryStatus("UNCV");
|
||||
registryImdg.update(registry);
|
||||
}
|
||||
} else {
|
||||
for (Registry registry : entrySet.getValue()) {
|
||||
registry.setRegistryStatus("FAIL");
|
||||
registryImdg.update(registry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new StageResult(null, true);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
package ru.spcex.clearing.session.stage.task;
|
||||
|
||||
public class InspectionPoolPayload {
|
||||
private Long processedCompanyId;
|
||||
|
||||
public Long getProcessedCompanyId() {
|
||||
return processedCompanyId;
|
||||
}
|
||||
|
||||
public void setProcessedCompanyId(Long processedCompanyId) {
|
||||
this.processedCompanyId = processedCompanyId;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue