clearing-service CLS-290 рефакторинг stage 6, 8
This commit is contained in:
parent
8755f3e1ca
commit
b80431f22e
6 changed files with 80 additions and 93 deletions
|
|
@ -9,7 +9,7 @@ import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.session.stage.ISessionStage;
|
import ru.spcex.clearing.session.stage.ISessionStage;
|
||||||
import ru.spcex.clearing.session.stage.StageResult;
|
import ru.spcex.clearing.session.stage.StageResult;
|
||||||
import ru.spcex.clearing.session.stage.Task;
|
import ru.spcex.clearing.session.stage.Task;
|
||||||
import ru.spcex.clearing.session.stage.task.RegistryOnObligationsAndSettlementRequirementsPayload;
|
import ru.spcex.clearing.session.stage.task.FormingRegistersOnOSPayload;
|
||||||
import ru.spcex.clearing.session.stage.util.RegistryUtil;
|
import ru.spcex.clearing.session.stage.util.RegistryUtil;
|
||||||
import ru.spcex.platform.enumeration.RegistryDesignation;
|
import ru.spcex.platform.enumeration.RegistryDesignation;
|
||||||
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||||
|
|
@ -39,10 +39,10 @@ public class FormingRegistersOnOS implements ISessionStage {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StageResult<?> submit(Task<?> task) {
|
public StageResult<?> submit(Task<?> task) {
|
||||||
RegistryOnObligationsAndSettlementRequirementsPayload payload = (RegistryOnObligationsAndSettlementRequirementsPayload) task.getData();
|
FormingRegistersOnOSPayload payload = (FormingRegistersOnOSPayload) task.getData();
|
||||||
switch (task.getTaskType()) {
|
switch (task.getTaskType()) {
|
||||||
case FormingRegistersOnOS -> {
|
case FormingRegistersOnOS -> {
|
||||||
return createRegistryOnObligationsAndSettlementRequirements(payload.getSessionId());
|
return createRegistryOnObligationsAndSettlementRequirements();
|
||||||
}
|
}
|
||||||
default -> {
|
default -> {
|
||||||
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||||
|
|
@ -53,12 +53,10 @@ public class FormingRegistersOnOS implements ISessionStage {
|
||||||
/**
|
/**
|
||||||
* Select Registry by: registryCode = [O/T][S/M][*][T] & registryStatus=OK
|
* Select Registry by: registryCode = [O/T][S/M][*][T] & registryStatus=OK
|
||||||
*
|
*
|
||||||
* @param sessionId
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected Collection<Registry> selectRegistry(Long sessionId) {
|
protected Collection<Registry> selectRegistry() {
|
||||||
String registrySQL = "sessionId = " + sessionId;
|
String registrySQL = "(registryDesignation=" + RegistryDesignation.O.getKey() + " or registryDesignation=" + RegistryDesignation.T.getKey() + ")";
|
||||||
registrySQL += " and (registryDesignation=" + RegistryDesignation.O.getKey() + " or registryDesignation=" + RegistryDesignation.T.getKey() + ")";
|
|
||||||
registrySQL += " and (registryInstrumentType=" + RegistryInstrumentType.S.getKey() + " or registryInstrumentType=" + RegistryInstrumentType.M.getKey() + ")";
|
registrySQL += " and (registryInstrumentType=" + RegistryInstrumentType.S.getKey() + " or registryInstrumentType=" + RegistryInstrumentType.M.getKey() + ")";
|
||||||
registrySQL += " and (registryUnit=" + RegistryUnit.T.getKey() + ")";
|
registrySQL += " and (registryUnit=" + RegistryUnit.T.getKey() + ")";
|
||||||
registrySQL += " and registryStatus=" + RegistryStatus.OK.getKey() + ")";
|
registrySQL += " and registryStatus=" + RegistryStatus.OK.getKey() + ")";
|
||||||
|
|
@ -67,8 +65,8 @@ public class FormingRegistersOnOS implements ISessionStage {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected StageResult<?> createRegistryOnObligationsAndSettlementRequirements(Long sessionId) {
|
protected StageResult<?> createRegistryOnObligationsAndSettlementRequirements() {
|
||||||
Collection<Registry> forRegistries = selectRegistry(sessionId);
|
Collection<Registry> forRegistries = selectRegistry();
|
||||||
ArrayList<Registry> newRegistries = new ArrayList<>();
|
ArrayList<Registry> newRegistries = new ArrayList<>();
|
||||||
|
|
||||||
//todo oreder by обрабатываться группами по полю registry.groupId
|
//todo oreder by обрабатываться группами по полю registry.groupId
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ import ru.spcex.platform.enumeration.RegistryInstrumentType;
|
||||||
import ru.spcex.platform.enumeration.RegistryUnit;
|
import ru.spcex.platform.enumeration.RegistryUnit;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
|
|
||||||
|
|
@ -26,10 +27,12 @@ import java.util.Collection;
|
||||||
public class UnlockResources implements ISessionStage {
|
public class UnlockResources implements ISessionStage {
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
|
||||||
|
protected final ImdgProvider imdgProvider;
|
||||||
private final Imdg<Registry> registryImdg;
|
private final Imdg<Registry> registryImdg;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UnlockResources(ImdgProvider imdgProvider) {
|
public UnlockResources(ImdgProvider imdgProvider) {
|
||||||
|
this.imdgProvider = imdgProvider;
|
||||||
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
this.registryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -39,7 +42,7 @@ public class UnlockResources implements ISessionStage {
|
||||||
switch (task.getTaskType()) {
|
switch (task.getTaskType()) {
|
||||||
case UnlockResources -> {
|
case UnlockResources -> {
|
||||||
UnlockResourcesPayload payload = (UnlockResourcesPayload) task.getData();
|
UnlockResourcesPayload payload = (UnlockResourcesPayload) task.getData();
|
||||||
return unlockResources(payload.getSdfMode(), payload.getSessionId(),
|
return unlockResources(payload.getSdfMode(),
|
||||||
payload.getAccount(),
|
payload.getAccount(),
|
||||||
payload.getSecurityId(),
|
payload.getSecurityId(),
|
||||||
payload.getFullNames(),
|
payload.getFullNames(),
|
||||||
|
|
@ -52,26 +55,18 @@ public class UnlockResources implements ISessionStage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected Collection<Registry> selectRegistryForSDF04(String account, Collection<String> fullNames) {
|
||||||
* Select Registry by: account; fullName* / securityId
|
|
||||||
*/
|
|
||||||
protected Collection<Registry> selectRegistry(Long sessionId, String account, Long securityId, Collection<String> fullNames) {
|
|
||||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||||
ImdgPredicate queryPart;
|
|
||||||
if (securityId != null) {
|
|
||||||
queryPart = pb.in("securityId", securityId);
|
|
||||||
} else if (fullNames != null && !fullNames.isEmpty()) {
|
|
||||||
queryPart = pb.in("fullName", fullNames.toArray(new String[fullNames.size()]));
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException("Required securityId or fullNames");
|
|
||||||
}
|
|
||||||
ImdgPredicate query = pb.and(
|
ImdgPredicate query = pb.and(
|
||||||
pb.and(
|
pb.and(
|
||||||
pb.equals("sessionId", sessionId),
|
pb.equals("registryDesignation", RegistryDesignation.A.getKey()),
|
||||||
pb.equals("registryDesignation", RegistryDesignation.A.getKey()) // не все нужны, только с этим кодом отфильтруем.
|
pb.equals("registryInstrumentType", RegistryInstrumentType.M.getKey()),
|
||||||
|
// pb.equals("registryCapacity", *),
|
||||||
|
pb.or(pb.equals("registryUnit", RegistryUnit.F.getKey()),
|
||||||
|
pb.equals("registryUnit", RegistryUnit.B.getKey()))
|
||||||
),
|
),
|
||||||
pb.equals("account", account),
|
pb.equals("account", account),
|
||||||
queryPart
|
pb.in("fullName", fullNames.toArray(new String[fullNames.size()]))
|
||||||
);
|
);
|
||||||
|
|
||||||
Collection<Registry> result = registryImdg.getCollectionObjectsByPredicate(query);
|
Collection<Registry> result = registryImdg.getCollectionObjectsByPredicate(query);
|
||||||
|
|
@ -79,50 +74,74 @@ public class UnlockResources implements ISessionStage {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Select Registry by: account; fullName* / securityId
|
||||||
|
*/
|
||||||
|
protected Collection<Registry> selectRegistryForSDF12(String account, Long securityId) {
|
||||||
|
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||||
|
ImdgPredicate query = pb.and(
|
||||||
|
pb.and(
|
||||||
|
pb.equals("registryDesignation", RegistryDesignation.A.getKey()),
|
||||||
|
pb.equals("registryInstrumentType", RegistryInstrumentType.S.getKey()),
|
||||||
|
// pb.equals("registryCapacity", *),
|
||||||
|
pb.or(pb.equals("registryUnit", RegistryUnit.F.getKey()),
|
||||||
|
pb.equals("registryUnit", RegistryUnit.B.getKey()))
|
||||||
|
),
|
||||||
|
pb.equals("account", account),
|
||||||
|
pb.in("securityId", securityId)
|
||||||
|
);
|
||||||
|
|
||||||
|
Collection<Registry> result = registryImdg.getCollectionObjectsByPredicate(query);
|
||||||
|
log.trace("Selected {} registry's by sql: {}", result.size(), query);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param sdfMode UnlockResourcesPayload.sdfMode
|
* @param sdfMode UnlockResourcesPayload.sdfMode
|
||||||
* @param sessionId
|
|
||||||
* @param account
|
* @param account
|
||||||
* @param securityId
|
* @param securityId
|
||||||
* @param fullNames
|
* @param fullNames
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
protected StageResult<?> unlockResources(String sdfMode, Long sessionId, String account, Long securityId, Collection<String> fullNames, BigDecimal value) {
|
protected StageResult<?> unlockResources(String sdfMode, String account, Long securityId, Collection<String> fullNames, BigDecimal value) {
|
||||||
Collection<Registry> forRegistries = selectRegistry(sessionId, account, securityId, fullNames);
|
Collection<Registry> forRegistries;
|
||||||
|
|
||||||
//todo при перезапуске после незапланированного завершения стадии: надо ли проверять уже созданные регистры и не создавать дубликаты?
|
|
||||||
if (UnlockResourcesPayload.MODE_SDF04.equals(sdfMode)) {
|
if (UnlockResourcesPayload.MODE_SDF04.equals(sdfMode)) {
|
||||||
forRegistries = forRegistries.stream().filter(
|
forRegistries = selectRegistryForSDF04(account, fullNames);
|
||||||
(Registry r) ->
|
|
||||||
RegistryDesignation.A.equalsByKey(r.getRegistryDesignation())
|
|
||||||
&&
|
|
||||||
RegistryInstrumentType.M.equalsByKey(r.getRegistryInstrumentType())
|
|
||||||
&&
|
|
||||||
(RegistryUnit.F.equalsByKey(r.getRegistryUnit()) || RegistryUnit.B.equalsByKey(r.getRegistryUnit()))
|
|
||||||
).toList();
|
|
||||||
} else if (UnlockResourcesPayload.MODE_SDF12.equals(sdfMode)) {
|
} else if (UnlockResourcesPayload.MODE_SDF12.equals(sdfMode)) {
|
||||||
forRegistries = forRegistries.stream().filter(
|
forRegistries = selectRegistryForSDF12(account, securityId);
|
||||||
(Registry r) ->
|
|
||||||
RegistryDesignation.A.equalsByKey(r.getRegistryDesignation())
|
|
||||||
&&
|
|
||||||
RegistryInstrumentType.S.equalsByKey(r.getRegistryInstrumentType())
|
|
||||||
&&
|
|
||||||
(RegistryUnit.F.equalsByKey(r.getRegistryUnit()) || RegistryUnit.B.equalsByKey(r.getRegistryUnit()))
|
|
||||||
).toList();
|
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("Mode not support: " + sdfMode);
|
throw new IllegalArgumentException("Mode not support: " + sdfMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (Registry registry : forRegistries) {
|
ImdgTransaction tx = imdgProvider.newTransaction();
|
||||||
boolean modified = unlockRegistry(registry, value);
|
boolean txOk = false;
|
||||||
if (modified) {
|
try {
|
||||||
registry.setUpdated(Instant.now());
|
log.debug("Processing transaction {}, input {} registers.", tx, forRegistries.size());
|
||||||
registryImdg.update(registry);
|
Imdg<Registry> registryTxImdg = tx.getImdg(IMDGDistributedNames.Map_Registry, Registry.class);
|
||||||
log.trace("Registry {} changed; value +- registry",
|
int nUpdates = 0;
|
||||||
registry.getId(), registry.getRegistryCode(), value);
|
for (Registry registry : forRegistries) {
|
||||||
|
boolean modified = unlockRegistry(registry, value);
|
||||||
|
if (modified) {
|
||||||
|
registry.setUpdated(Instant.now());
|
||||||
|
registryTxImdg.update(registry);
|
||||||
|
nUpdates++;
|
||||||
|
log.trace("Registry {} (registryCode={}) changed; value +- {}",
|
||||||
|
registry.getId(), registry.getRegistryCode(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("Updated {} registry's (under transaction {}", nUpdates, tx);
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk) {
|
||||||
|
log.debug("Commit transaction {}.", tx);
|
||||||
|
tx.commitTransaction();
|
||||||
|
} else {
|
||||||
|
log.info("Rollback transaction {}", tx);
|
||||||
|
tx.rollbackTransaction();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//todo рекомендуется делать транзакцией.
|
|
||||||
|
|
||||||
StageResult<Collection<Registry>> res = new StageResult<>(null, true);
|
StageResult<Collection<Registry>> res = new StageResult<>(null, true);
|
||||||
res.setStageResult(forRegistries);
|
res.setStageResult(forRegistries);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,5 @@
|
||||||
|
package ru.spcex.clearing.session.stage.task;
|
||||||
|
|
||||||
|
public class FormingRegistersOnOSPayload {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,31 +0,0 @@
|
||||||
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;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
@ -12,8 +12,6 @@ public class UnlockResourcesPayload {
|
||||||
*/
|
*/
|
||||||
private String sdfMode;
|
private String sdfMode;
|
||||||
|
|
||||||
private Long sessionId;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* sDf04.c_acc_cred
|
* sDf04.c_acc_cred
|
||||||
* sDf12.depoCodeSender
|
* sDf12.depoCodeSender
|
||||||
|
|
@ -46,13 +44,6 @@ public class UnlockResourcesPayload {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Long getSessionId() {
|
|
||||||
return sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSessionId(Long sessionId) {
|
|
||||||
this.sessionId = sessionId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAccount() {
|
public String getAccount() {
|
||||||
return account;
|
return account;
|
||||||
|
|
|
||||||
|
|
@ -68,4 +68,9 @@ public class ImdgTransactionProviderHazelcast implements ImdgTransaction {
|
||||||
public void setHz(HazelcastInstance hz) {
|
public void setHz(HazelcastInstance hz) {
|
||||||
this.hz = hz;
|
this.hz = hz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "ImdgTransaction{" + (ctx == null ? null : ctx.getTxnId()) + "}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue