This commit is contained in:
parent
5ba662b11a
commit
64a28bc5a5
3 changed files with 112 additions and 54 deletions
|
|
@ -9,7 +9,7 @@ import ru.clearing.classes.statics.data.registry.Registry;
|
|||
import ru.clearing.classes.statics.data.statement.Statement;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.Sdf56Request;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.Sdf56And51Request;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.clearing.session.stage.ISessionStage;
|
||||
import ru.spcex.clearing.session.stage.StageResult;
|
||||
|
|
@ -28,7 +28,6 @@ import java.time.Instant;
|
|||
import java.time.LocalDate;
|
||||
import java.time.Month;
|
||||
import java.util.Collection;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static ru.spcex.clearing.error.ClearingErrorInternal.SessionGeneralError;
|
||||
|
||||
|
|
@ -59,7 +58,8 @@ public class BalanceRevise implements ISessionStage {
|
|||
return sendSdfs();
|
||||
}
|
||||
case ContinueRevise -> {
|
||||
return revise(); //((SdfClearingRequest) task.getData()).getGroupId() if needed
|
||||
cashFlow(); //((SdfClearingRequest) task.getData()).getGroupId() if needed
|
||||
revise();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
|
@ -70,11 +70,14 @@ public class BalanceRevise implements ISessionStage {
|
|||
Collection<Long> currencies = currencyImdg.projectSingleAttribute("id");
|
||||
Statement statement = statementImdg.aggregateByMax("created", StatementRevisePredicate.get(statementImdg, currencies));
|
||||
|
||||
Sdf56Request sdf56Request = new Sdf56Request();
|
||||
sdf56Request.setNumber(idGenerator.nextId()); //fixme day scope id generator
|
||||
Instant now = Instant.now();
|
||||
Sdf56And51Request sdf56Request = new Sdf56And51Request();
|
||||
sdf56Request.setDf56Number(idGenerator.nextId()); //fixme day scope id generator
|
||||
sdf56Request.setsDateTime(statement != null ?
|
||||
statement.getCreated() : TimeUtil.localDateToInstant(LocalDate.of(2023, Month.JANUARY, 1))); //fixme default sDate
|
||||
sdf56Request.seteDateTime(Instant.now());
|
||||
sdf56Request.seteDateTime(now);
|
||||
sdf56Request.setDf51Number(idGenerator.nextId()); //fixme day scope id generator
|
||||
sdf56Request.setDateTime(now);
|
||||
Long msgKey = kafkaSender.sendRequestToQueue(Consts.SDF56_PROCESS, sdf56Request);
|
||||
if (msgKey == null) {
|
||||
log.error("failed to put SDF56 request to kafka queue");
|
||||
|
|
@ -83,11 +86,10 @@ public class BalanceRevise implements ISessionStage {
|
|||
return new StageResult(null, true);
|
||||
}
|
||||
|
||||
private StageResult revise() {
|
||||
Collection<Statement> stmts;
|
||||
private StageResult cashFlow() {
|
||||
String statementSQL = String.format("inOutSDfType = %s and operationStatus = %s and statementType = %s",
|
||||
InOutSDfType.type57, OperationStatus.Pending.getKey(), StatementType.incr.getKey());
|
||||
stmts = statementImdg.getCollectionObjectsBySQL(statementSQL);
|
||||
InOutSDfType.type57.getKey(), OperationStatus.Pending.getKey(), StatementType.incr.getKey());
|
||||
Collection<Statement> stmts = statementImdg.getCollectionObjectsBySQL(statementSQL);
|
||||
|
||||
for (Statement stmt : stmts) {
|
||||
String unformatted = "registry_designation = '%s' " +
|
||||
|
|
@ -120,20 +122,19 @@ public class BalanceRevise implements ISessionStage {
|
|||
Registry rgsAMF = registryImdg.getSingleObjectBySQL(registrySqlAMF);
|
||||
Registry rgsAMB = registryImdg.getSingleObjectBySQL(registrySqlAMB);
|
||||
InOutDirection direction = IEnumKey.getEnumByKey(InOutDirection.class, stmt.getInOutDirection());
|
||||
UnaryOperator<BigDecimal> safe = (BigDecimal value) -> value != null ? value : BigDecimal.ZERO;
|
||||
if (direction == null) throw new IllegalStateException("null direction");
|
||||
switch (direction) {
|
||||
case out -> {
|
||||
rgsAMT.setBalance(safe.apply(rgsAMT.getBalance()).subtract(safe.apply(stmt.getAmount())));
|
||||
rgsAMT.setDebit(safe.apply(rgsAMT.getDebit()).add(safe.apply(stmt.getAmount())));
|
||||
rgsAMT.setBalance(safeBD(rgsAMT.getBalance()).subtract(safeBD(stmt.getAmount())));
|
||||
rgsAMT.setDebit(safeBD(rgsAMT.getDebit()).add(safeBD(stmt.getAmount())));
|
||||
}
|
||||
case in -> {
|
||||
rgsAMT.setBalance(safe.apply(rgsAMT.getBalance()).add(safe.apply(stmt.getAmount())));
|
||||
rgsAMT.setCredit(safe.apply(rgsAMT.getCredit()).add(safe.apply(stmt.getAmount())));
|
||||
rgsAMT.setBalance(safeBD(rgsAMT.getBalance()).add(safeBD(stmt.getAmount())));
|
||||
rgsAMT.setCredit(safeBD(rgsAMT.getCredit()).add(safeBD(stmt.getAmount())));
|
||||
}
|
||||
default -> {throw new IllegalStateException("null direction");}
|
||||
}
|
||||
rgsAMF.setBalance(safe.apply(rgsAMT.getBalance()).subtract(safe.apply(rgsAMB.getBalance())));
|
||||
rgsAMF.setBalance(safeBD(rgsAMT.getBalance()).subtract(safeBD(rgsAMB.getBalance())));
|
||||
registryImdg.update(rgsAMT);
|
||||
registryImdg.update(rgsAMF);
|
||||
registryImdg.update(rgsAMB);
|
||||
|
|
@ -142,4 +143,31 @@ public class BalanceRevise implements ISessionStage {
|
|||
//todoSdf1
|
||||
return new StageResult(null, true);
|
||||
}
|
||||
|
||||
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);
|
||||
for (Statement stmt : stmts) {
|
||||
String registrySqlAMT = String.format("registry_designation = '%s' " +
|
||||
"and registry_instrument_type = '%s' " +
|
||||
"and registry_unit = '%s' " +
|
||||
"and account = '%s' " +
|
||||
"and securityId = %d",
|
||||
RegistryDesignation.A.getKey(),
|
||||
RegistryInstrumentType.M.getKey(),
|
||||
RegistryUnit.T.getKey(),
|
||||
stmt.getAccount(),
|
||||
stmt.getSecurityId()
|
||||
);
|
||||
Registry rgsAMT = registryImdg.getSingleObjectBySQL(registrySqlAMT);
|
||||
rgsAMT.setCheckBalance(stmt.getAmount());
|
||||
rgsAMT.setDiffBalance(safeBD(rgsAMT.getBalance()).subtract(safeBD(rgsAMT.getCheckBalance())));
|
||||
}
|
||||
return new StageResult(null, true);
|
||||
}
|
||||
|
||||
private BigDecimal safeBD(BigDecimal value) {
|
||||
return value != null ? value : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
package ru.spcex.clearing.platform.messaging.domain.cud.clearing;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
/**
|
||||
* попросили сделать максимально одновременные запросы
|
||||
*/
|
||||
public class Sdf56And51Request {
|
||||
/**
|
||||
* поля для DF-16
|
||||
*/
|
||||
@JsonProperty
|
||||
private Long df56Number;
|
||||
@JsonProperty
|
||||
private Instant sDateTime;
|
||||
@JsonProperty
|
||||
private Instant eDateTime;
|
||||
|
||||
/**
|
||||
* поля для DF-51
|
||||
*/
|
||||
@JsonProperty
|
||||
private Long df51Number;
|
||||
@JsonProperty
|
||||
private Instant dateTime;
|
||||
|
||||
public Long getDf56Number() {
|
||||
return df56Number;
|
||||
}
|
||||
|
||||
public void setDf56Number(Long df56Number) {
|
||||
this.df56Number = df56Number;
|
||||
}
|
||||
|
||||
public Instant getsDateTime() {
|
||||
return sDateTime;
|
||||
}
|
||||
|
||||
public void setsDateTime(Instant sDateTime) {
|
||||
this.sDateTime = sDateTime;
|
||||
}
|
||||
|
||||
public Instant geteDateTime() {
|
||||
return eDateTime;
|
||||
}
|
||||
|
||||
public void seteDateTime(Instant eDateTime) {
|
||||
this.eDateTime = eDateTime;
|
||||
}
|
||||
|
||||
public Long getDf51Number() {
|
||||
return df51Number;
|
||||
}
|
||||
|
||||
public void setDf51Number(Long df51Number) {
|
||||
this.df51Number = df51Number;
|
||||
}
|
||||
|
||||
public Instant getDateTime() {
|
||||
return dateTime;
|
||||
}
|
||||
|
||||
public void setDateTime(Instant dateTime) {
|
||||
this.dateTime = dateTime;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,38 +0,0 @@
|
|||
package ru.spcex.clearing.platform.messaging.domain.cud.clearing;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
public class Sdf56Request {
|
||||
@JsonProperty
|
||||
private Long number;
|
||||
@JsonProperty
|
||||
private Instant sDateTime;
|
||||
@JsonProperty
|
||||
private Instant eDateTime;
|
||||
|
||||
public Long getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(Long number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public Instant getsDateTime() {
|
||||
return sDateTime;
|
||||
}
|
||||
|
||||
public void setsDateTime(Instant sDateTime) {
|
||||
this.sDateTime = sDateTime;
|
||||
}
|
||||
|
||||
public Instant geteDateTime() {
|
||||
return eDateTime;
|
||||
}
|
||||
|
||||
public void seteDateTime(Instant eDateTime) {
|
||||
this.eDateTime = eDateTime;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue