clearing-service http://jira.mfd.msk:8088/browse/CLS-290 обработчик для шага 6
This commit is contained in:
parent
4e37cf7757
commit
35a7a41091
8 changed files with 256 additions and 2 deletions
|
|
@ -13,7 +13,7 @@ import java.time.LocalDate;
|
||||||
* <p>
|
* <p>
|
||||||
* DB table: REGISTRY
|
* DB table: REGISTRY
|
||||||
**/
|
**/
|
||||||
public class Registry extends BusinessObject {
|
public class Registry extends BusinessObject implements Cloneable {
|
||||||
private static final long serialVersionUID = ConstSerializable.serialVersionUID;
|
private static final long serialVersionUID = ConstSerializable.serialVersionUID;
|
||||||
|
|
||||||
private Long companyId;
|
private Long companyId;
|
||||||
|
|
@ -412,4 +412,13 @@ public class Registry extends BusinessObject {
|
||||||
public void setPaymentId(Long paymentId) {
|
public void setPaymentId(Long paymentId) {
|
||||||
this.paymentId = paymentId;
|
this.paymentId = paymentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object clone() {
|
||||||
|
try {
|
||||||
|
return super.clone();
|
||||||
|
} catch (CloneNotSupportedException e) {
|
||||||
|
throw new RuntimeException("never", e); // it is Cloneable
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,9 @@ public enum TaskType {
|
||||||
*/
|
*/
|
||||||
InclusionToPool,
|
InclusionToPool,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Step 6
|
||||||
|
*/
|
||||||
|
CreateRegistryOnObligationsAndSettlementRequirements,
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,118 @@
|
||||||
|
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.execution.ExecutionDeposit;
|
||||||
|
import ru.clearing.classes.statics.data.execution.ExecutionFond;
|
||||||
|
import ru.clearing.classes.statics.data.registry.Registry;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
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.DealsPreparePayload;
|
||||||
|
import ru.spcex.clearing.session.stage.task.RegistryOnObligationsAndSettlementRequirementsPayload;
|
||||||
|
import ru.spcex.clearing.session.stage.util.RegistryUtil;
|
||||||
|
import ru.spcex.platform.classes.base.interfaces.IExecution;
|
||||||
|
import ru.spcex.platform.classes.base.interfaces.WithExchangeExecutionId;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryDesignation;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryStatus;
|
||||||
|
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 java.time.Instant;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CreateRegistryOnObligationsAndSettlementRequirements implements ISessionStage {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
private final ImdgId idSequence;
|
||||||
|
private final Imdg<Registry> registryImdg;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public CreateRegistryOnObligationsAndSettlementRequirements(ImdgProvider imdgProvider) {
|
||||||
|
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||||
|
this.idSequence = imdgProvider.getImdgIdGenerator();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public StageResult<?> submit(Task<?> task) {
|
||||||
|
RegistryOnObligationsAndSettlementRequirementsPayload payload = (RegistryOnObligationsAndSettlementRequirementsPayload) task.getData();
|
||||||
|
switch (task.getTaskType()) {
|
||||||
|
case CreateRegistryOnObligationsAndSettlementRequirements -> {
|
||||||
|
return createRegistryOnObligationsAndSettlementRequirements(payload.getSessionId());
|
||||||
|
}
|
||||||
|
default -> {
|
||||||
|
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Collection<Registry> selectRegistry(Long sessionId) {
|
||||||
|
String registrySQL = "sessionId = " + sessionId;
|
||||||
|
registrySQL += " and (registryDesignation=" + RegistryDesignation.O.getKey() + " or registryDesignation=" + RegistryDesignation.T.getKey() + ")";
|
||||||
|
registrySQL += " and (registryInstrumentType=" + RegistryInstrumentType.S.getKey() + " or registryInstrumentType=" + RegistryInstrumentType.M.getKey() + ")";
|
||||||
|
registrySQL += " and (registryUnit=" + RegistryUnit.T.getKey() + ")";
|
||||||
|
registrySQL += " and registryStatus=" + RegistryStatus.OK.getKey() + ")";
|
||||||
|
// registryCode = [O/T][S/M][*][T] & registryStatus=OK
|
||||||
|
Collection<Registry> result = registryImdg.getCollectionObjectsBySQL(registrySQL);
|
||||||
|
log.trace("Selected {} registry's by sql: {}", result.size(), registrySQL);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private StageResult<?> createRegistryOnObligationsAndSettlementRequirements(Long sessionId) {
|
||||||
|
Collection<Registry> forRegistries = selectRegistry(sessionId);
|
||||||
|
ArrayList<Registry> newRegistries = new ArrayList<>();
|
||||||
|
|
||||||
|
//todo oreder by обрабатываться группами по полю registry.groupId
|
||||||
|
|
||||||
|
for (Registry registry : forRegistries) {
|
||||||
|
Registry newRegistry = createRegistryFor(registry);
|
||||||
|
newRegistries.add(newRegistry);
|
||||||
|
registryImdg.insert(newRegistry);
|
||||||
|
log.trace("For registry {} (registryCode={}) make new registry {} (registryCode={})",
|
||||||
|
registry.getId(), registry.getRegistryCode(), newRegistry.getId(), newRegistry.getRegistryCode());
|
||||||
|
}
|
||||||
|
|
||||||
|
StageResult<Collection<Registry>> res = new StageResult<>(null, true);
|
||||||
|
res.setStageResult(newRegistries);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
Registry createRegistryFor(Registry forRegistry) {
|
||||||
|
Registry newRegistry = (Registry) forRegistry.clone();// cloneable
|
||||||
|
newRegistry.setId(idSequence.nextId());
|
||||||
|
newRegistry.setCreated(Instant.now());
|
||||||
|
newRegistry.setUpdated(newRegistry.getCreated());
|
||||||
|
|
||||||
|
String newRegDestination;
|
||||||
|
if (RegistryDesignation.O.equalsByKey(forRegistry.getRegistryDesignation())) {
|
||||||
|
newRegDestination = RegistryDesignation.L.getKey();
|
||||||
|
} else if (RegistryDesignation.T.equalsByKey(forRegistry.getRegistryDesignation())) {
|
||||||
|
newRegDestination = RegistryDesignation.C.getKey();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("RegistryDesignation=" + forRegistry.getRegistryDesignation());
|
||||||
|
}
|
||||||
|
newRegistry.setRegistryDesignation(newRegDestination);
|
||||||
|
|
||||||
|
String newRegistryInstrumentType; // по ТЗ не меняется
|
||||||
|
if (RegistryInstrumentType.S.equalsByKey(forRegistry.getRegistryInstrumentType())) {
|
||||||
|
newRegistryInstrumentType = RegistryInstrumentType.S.getKey();
|
||||||
|
} else if (RegistryInstrumentType.M.equalsByKey(forRegistry.getRegistryInstrumentType())) {
|
||||||
|
newRegistryInstrumentType = RegistryInstrumentType.M.getKey();
|
||||||
|
} else {
|
||||||
|
throw new IllegalArgumentException("RegistryInstrumentType=" + forRegistry.getRegistryInstrumentType());
|
||||||
|
}
|
||||||
|
newRegistry.setRegistryInstrumentType(newRegistryInstrumentType);
|
||||||
|
|
||||||
|
newRegistry.setRegistryCode(RegistryUtil.clearingCode(newRegistry));
|
||||||
|
return newRegistry;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
package ru.spcex.clearing.session.stage.task;
|
||||||
|
|
||||||
|
public class RegistryOnObligationsAndSettlementRequirementsPayload {
|
||||||
|
private Long sessionId;
|
||||||
|
// private Long companyId;
|
||||||
|
// private Long securityId;
|
||||||
|
|
||||||
|
public Long getSessionId() {
|
||||||
|
return sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSessionId(Long sessionId) {
|
||||||
|
this.sessionId = sessionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// public Long getCompanyId() {
|
||||||
|
// return companyId;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setCompanyId(Long companyId) {
|
||||||
|
// this.companyId = companyId;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Long getSecurityId() {
|
||||||
|
// return securityId;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void setSecurityId(Long securityId) {
|
||||||
|
// this.securityId = securityId;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package ru.spcex.clearing.session.stage.util;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import ru.clearing.classes.statics.data.registry.Registry;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryCapacity;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryDesignation;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||||
|
import ru.spcex.platform.enumeration.RegistryUnit;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class RegistryUtil {
|
||||||
|
|
||||||
|
|
||||||
|
public static String clearingCode(Registry ofRegistry) {
|
||||||
|
return clearingCode(ofRegistry.getRegistryDesignation(), ofRegistry.getRegistryInstrumentType(), ofRegistry.getRegistryCapacity(), ofRegistry.getRegistryUnit());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String clearingCode(String registryDesignation, String registryInstrumentType, String registryCapacity, String registryUnit) {
|
||||||
|
if (StringUtils.isEmpty(registryDesignation)) registryDesignation = "-";
|
||||||
|
if (StringUtils.isEmpty(registryInstrumentType)) registryInstrumentType = "-";
|
||||||
|
if (StringUtils.isEmpty(registryCapacity)) registryCapacity = "-";
|
||||||
|
if (StringUtils.isEmpty(registryUnit)) registryUnit = "-";
|
||||||
|
return registryDesignation + registryInstrumentType + registryCapacity + registryUnit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String clearingCode(RegistryDesignation registryDesignation, RegistryInstrumentType registryInstrumentType, RegistryCapacity registryCapacity, RegistryUnit registryUnit) {
|
||||||
|
return registryDesignation.getKey() + registryInstrumentType.getKey() + registryCapacity.getKey() + registryUnit.getKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Map<Long, List<Registry>> groupByGroupId(Collection<Registry> registries) {
|
||||||
|
HashMap<Long, List<Registry>> groups = new HashMap<>();
|
||||||
|
for (Registry reg : registries) {
|
||||||
|
List<Registry> lst = groups.get(reg.getGroupId());
|
||||||
|
if (lst == null) {
|
||||||
|
lst = new ArrayList<>();
|
||||||
|
groups.put(reg.getGroupId(), lst);
|
||||||
|
}
|
||||||
|
lst.add(reg);
|
||||||
|
}
|
||||||
|
return groups;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ru.spcex.clearing.session.stage.util;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import ru.clearing.classes.statics.data.registry.Registry;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class RegistryUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void clearingCode1() {
|
||||||
|
assertEquals("OMAT", RegistryUtil.clearingCode("O", "M", "A", "T"));
|
||||||
|
assertEquals("O-A-", RegistryUtil.clearingCode("O", "", "A", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void clearingCode2() {
|
||||||
|
Registry reg = new Registry();
|
||||||
|
reg.setRegistryDesignation("O");
|
||||||
|
reg.setRegistryInstrumentType("M");
|
||||||
|
reg.setRegistryCapacity("A");
|
||||||
|
reg.setRegistryUnit("T");
|
||||||
|
assertEquals("OMAT", RegistryUtil.clearingCode(reg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,7 +3,11 @@ package ru.spcex.platform.enumeration;
|
||||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
|
|
||||||
public enum RegistryDesignation implements IEnumKey {
|
public enum RegistryDesignation implements IEnumKey {
|
||||||
A("A")
|
A("A"),
|
||||||
|
O("O"),
|
||||||
|
T("T"),
|
||||||
|
L("L"),
|
||||||
|
C("C")
|
||||||
;
|
;
|
||||||
|
|
||||||
private final String key;
|
private final String key;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
package ru.spcex.platform.enumeration;
|
||||||
|
|
||||||
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
|
|
||||||
|
public enum RegistryStatus implements IEnumKey {
|
||||||
|
OK("OK"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String key;
|
||||||
|
|
||||||
|
RegistryStatus(String key) {
|
||||||
|
this.key = key;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue