This commit is contained in:
parent
c1519a2d7a
commit
fc82c9817c
11 changed files with 159 additions and 13 deletions
|
|
@ -1,12 +1,13 @@
|
|||
package ru.clearing.classes.statics.data.execution;
|
||||
|
||||
import ru.clearing.classes.objects.BusinessObject;
|
||||
import ru.spcex.platform.classes.base.interfaces.IExecution;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class ExecutionDeposit extends BusinessObject {
|
||||
public class ExecutionDeposit extends BusinessObject implements IExecution {
|
||||
private Long exchangeExecutionId;
|
||||
private Instant exchangeExecutionTime;
|
||||
private LocalDate tradingDate;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package ru.clearing.classes.statics.data.execution;
|
|||
|
||||
import ru.clearing.classes.ConstSerializable;
|
||||
import ru.clearing.classes.objects.BusinessObject;
|
||||
import ru.spcex.platform.classes.base.interfaces.IExecution;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
|
|
@ -12,7 +13,7 @@ import java.time.LocalDate;
|
|||
* <p>
|
||||
* DB table: EXECUTION_FOND
|
||||
**/
|
||||
public class ExecutionFond extends BusinessObject {
|
||||
public class ExecutionFond extends BusinessObject implements IExecution {
|
||||
private static final long serialVersionUID = ConstSerializable.serialVersionUID;
|
||||
|
||||
private LocalDate clearingDate;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ru.spcex.clearing.session.stage;
|
||||
|
||||
public interface ISessionStage {
|
||||
StageResult submit(Task<?> task);
|
||||
StageResult<?> submit(Task<?> task);
|
||||
// StageStatus getInitStatus(); пока не нужно
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ package ru.spcex.clearing.session.stage;
|
|||
|
||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||
|
||||
public class StageResult {
|
||||
public class StageResult<T> {
|
||||
EnumMessage error;
|
||||
boolean success;
|
||||
T stageResult;
|
||||
|
||||
public StageResult(EnumMessage error, boolean success) {
|
||||
this.error = error;
|
||||
|
|
@ -26,4 +27,12 @@ public class StageResult {
|
|||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public T getStageResult() {
|
||||
return stageResult;
|
||||
}
|
||||
|
||||
public void setStageResult(T stageResult) {
|
||||
this.stageResult = stageResult;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,15 @@
|
|||
package ru.spcex.clearing.session.stage;
|
||||
|
||||
public enum TaskType {
|
||||
/**
|
||||
* step 0
|
||||
*/
|
||||
StartRevise,
|
||||
ContinueRevise
|
||||
ContinueRevise,
|
||||
|
||||
/**
|
||||
* step 1
|
||||
*/
|
||||
DealsPrepare,
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class BalanceRevise implements ISessionStage {
|
|||
}
|
||||
|
||||
@Override
|
||||
public StageResult submit(Task<?> task) {
|
||||
public StageResult<?> submit(Task<?> task) {
|
||||
switch (task.getTaskType()) {
|
||||
case StartRevise -> {
|
||||
return sendSdfs();
|
||||
|
|
@ -66,7 +66,7 @@ public class BalanceRevise implements ISessionStage {
|
|||
}
|
||||
|
||||
|
||||
private StageResult sendSdfs() {
|
||||
private StageResult<?> sendSdfs() {
|
||||
Collection<Long> currencies = currencyImdg.projectSingleAttribute("id");
|
||||
Statement statement = statementImdg.aggregateByMax("created", StatementRevisePredicate.get(statementImdg, currencies));
|
||||
|
||||
|
|
@ -81,12 +81,12 @@ public class BalanceRevise implements ISessionStage {
|
|||
Long msgKey = kafkaSender.sendRequestToQueue(Consts.SDF56_PROCESS, sdf56Request);
|
||||
if (msgKey == null) {
|
||||
log.error("failed to put SDF56 request to kafka queue");
|
||||
return new StageResult(new EnumMessage(SessionGeneralError), false);
|
||||
return new StageResult<>(new EnumMessage(SessionGeneralError), false);
|
||||
}
|
||||
return new StageResult(null, true);
|
||||
return new StageResult<>(null, true);
|
||||
}
|
||||
|
||||
private StageResult cashFlow() {
|
||||
private StageResult<?> cashFlow() {
|
||||
String statementSQL = String.format("inOutSDfType = %s and operationStatus = %s and statementType = %s",
|
||||
InOutSDfType.type57.getKey(), OperationStatus.Pending.getKey(), StatementType.incr.getKey());
|
||||
Collection<Statement> stmts = statementImdg.getCollectionObjectsBySQL(statementSQL);
|
||||
|
|
@ -141,10 +141,10 @@ public class BalanceRevise implements ISessionStage {
|
|||
//todo create if needed?
|
||||
}
|
||||
//todoSdf1
|
||||
return new StageResult(null, true);
|
||||
return new StageResult<>(null, true);
|
||||
}
|
||||
|
||||
private StageResult revise() {
|
||||
private StageResult<?> revise() {
|
||||
String statementSQL = String.format("inOutSDfType = %s and operationStatus = %s and statementType = %s",
|
||||
InOutSDfType.type1.getKey(), OperationStatus.Pending.getKey(), StatementType.full.getKey());
|
||||
Collection<Statement> stmts = statementImdg.getCollectionObjectsBySQL(statementSQL);
|
||||
|
|
@ -164,7 +164,7 @@ public class BalanceRevise implements ISessionStage {
|
|||
rgsAMT.setCheckBalance(stmt.getAmount());
|
||||
rgsAMT.setDiffBalance(safeBD(rgsAMT.getBalance()).subtract(safeBD(rgsAMT.getCheckBalance())));
|
||||
}
|
||||
return new StageResult(null, true);
|
||||
return new StageResult<>(null, true);
|
||||
}
|
||||
|
||||
private BigDecimal safeBD(BigDecimal value) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,80 @@
|
|||
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.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.platform.classes.base.interfaces.IExecution;
|
||||
import ru.spcex.platform.classes.base.interfaces.WithExchangeExecutionId;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Service
|
||||
public class DealsPrepare implements ISessionStage {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<ExecutionDeposit> executionDepositImdg;
|
||||
private final Imdg<ExecutionFond> executionFondImdg;
|
||||
|
||||
@Autowired
|
||||
public DealsPrepare(ImdgProvider imdgProvider) {
|
||||
this.executionDepositImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionDeposit, ExecutionDeposit.class);
|
||||
this.executionFondImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public StageResult<?> submit(Task<?> task) {
|
||||
DealsPreparePayload payload = (DealsPreparePayload) task.getData();
|
||||
switch (task.getTaskType()) {
|
||||
case DealsPrepare -> {
|
||||
return prepareDeals(payload.getSessionId(), payload.getCompanyId(), payload.getSecurityId());
|
||||
}
|
||||
default -> {
|
||||
throw new IllegalStateException("Unknown task type: " + task.getTaskType());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private StageResult<?> prepareDeals(Long sessionId, Long companyId, Long securityId) {
|
||||
StringBuilder executionDepositSQL = new StringBuilder("sessionId = null");
|
||||
if (companyId != null) {
|
||||
executionDepositSQL.append(" and companyId = ").append(companyId);
|
||||
}
|
||||
if (securityId != null) {
|
||||
executionDepositSQL.append(" and securityId = ").append(securityId);
|
||||
}
|
||||
Collection<ExecutionDeposit> excDpsts = executionDepositImdg.getCollectionObjectsBySQL(executionDepositSQL.toString());
|
||||
Collection<ExecutionFond> excFonds = executionFondImdg.getCollectionObjectsBySQL(executionDepositSQL.toString());
|
||||
List<IExecution> excs = Stream.concat(excDpsts.stream().map(execToInterface()),
|
||||
excFonds.stream().map(execToInterface()))
|
||||
.sorted(Comparator.comparing(WithExchangeExecutionId::getExchangeExecutionId))
|
||||
.toList();
|
||||
for (IExecution exc : excs) {
|
||||
exc.setSessionId(sessionId);
|
||||
if (exc instanceof ExecutionDeposit) {
|
||||
executionDepositImdg.update((ExecutionDeposit) exc);
|
||||
} else if (exc instanceof ExecutionFond) {
|
||||
executionFondImdg.update((ExecutionFond) exc);
|
||||
}
|
||||
}
|
||||
StageResult<Collection<IExecution>> res = new StageResult<>(null, true);
|
||||
res.setStageResult(excs);
|
||||
return res;
|
||||
}
|
||||
|
||||
private static <E extends IExecution> Function<E, IExecution> execToInterface() {
|
||||
return (e) -> e;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package ru.spcex.clearing.session.stage.task;
|
||||
|
||||
public class DealsPreparePayload {
|
||||
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,4 @@
|
|||
package ru.spcex.platform.classes.base.interfaces;
|
||||
|
||||
public interface IExecution extends WithSessionId, WithExchangeExecutionId {
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package ru.spcex.platform.classes.base.interfaces;
|
||||
|
||||
public interface WithExchangeExecutionId {
|
||||
Long getExchangeExecutionId();
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package ru.spcex.platform.classes.base.interfaces;
|
||||
|
||||
public interface WithSessionId {
|
||||
Long getSessionId();
|
||||
void setSessionId(Long sessionId);
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue