сессия по возврату депозитов, DM*T 'CLNR' создание PaymentInstruction
This commit is contained in:
parent
a63782a57b
commit
5c7218e7f0
1 changed files with 35 additions and 41 deletions
|
|
@ -13,12 +13,15 @@ import ru.clearing.classes.statics.data.registry.Registry;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf03;
|
import ru.clearing.classes.statics.data.sdf.SDf03;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf12;
|
import ru.clearing.classes.statics.data.sdf.SDf12;
|
||||||
import ru.clearing.classes.statics.data.security.Security;
|
import ru.clearing.classes.statics.data.security.Security;
|
||||||
|
import ru.spcex.clearing.error.ClearingError;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
|
import ru.spcex.clearing.service.Sdf03Creator;
|
||||||
import ru.spcex.clearing.service.SpecifUtil;
|
import ru.spcex.clearing.service.SpecifUtil;
|
||||||
import ru.spcex.clearing.service.builder.PaymentInstructionBuilder;
|
import ru.spcex.clearing.service.builder.PaymentInstructionBuilder;
|
||||||
|
import ru.spcex.clearing.service.builder.PaymentInstructionBuilderFinalMkrDeals;
|
||||||
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;
|
||||||
|
|
@ -27,9 +30,9 @@ import ru.spcex.platform.enumeration.*;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgId;
|
import ru.spcex.platform.imdg.api.ImdgId;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
|
||||||
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
|
||||||
import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder;
|
import ru.spcex.platform.imdg.api.predicate.specific.RegistryCodeSqlBuilder;
|
||||||
|
import ru.spcex.platform.utils.collection.Pair;
|
||||||
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||||
import ru.spcex.platform.utils.number.BigDecimalUtil;
|
import ru.spcex.platform.utils.number.BigDecimalUtil;
|
||||||
|
|
||||||
|
|
@ -55,6 +58,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
private final Imdg<SDf03> sDf03Imdg;
|
private final Imdg<SDf03> sDf03Imdg;
|
||||||
private final Imdg<SDf12> sDf12Imdg;
|
private final Imdg<SDf12> sDf12Imdg;
|
||||||
private final KafkaSender kafkaSender;
|
private final KafkaSender kafkaSender;
|
||||||
|
private final Sdf03Creator sdf03Creator;
|
||||||
private final static RegistryTradingParams OS_T;
|
private final static RegistryTradingParams OS_T;
|
||||||
private final static RegistryTradingParams OM_T;
|
private final static RegistryTradingParams OM_T;
|
||||||
private final static RegistryTradingParams TS_T;
|
private final static RegistryTradingParams TS_T;
|
||||||
|
|
@ -123,7 +127,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public FormingPaymentInstructionDepositReturn(ImdgProvider imdgProvider,
|
public FormingPaymentInstructionDepositReturn(ImdgProvider imdgProvider,
|
||||||
KafkaSender kafkaSender) {
|
KafkaSender kafkaSender, Sdf03Creator sdf03Creator) {
|
||||||
this.kafkaSender = kafkaSender;
|
this.kafkaSender = kafkaSender;
|
||||||
this.imdgProvider = imdgProvider;
|
this.imdgProvider = imdgProvider;
|
||||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||||
|
|
@ -134,6 +138,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
this.sDf03Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
|
this.sDf03Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf03, SDf03.class);
|
||||||
this.sDf12Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf12, SDf12.class);
|
this.sDf12Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf12, SDf12.class);
|
||||||
this.paymentInstructionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
this.paymentInstructionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_PaymentInstruction, PaymentInstruction.class);
|
||||||
|
this.sdf03Creator = sdf03Creator;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -164,6 +169,7 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
collect(Collectors.groupingBy(Registry::getGroupId));
|
collect(Collectors.groupingBy(Registry::getGroupId));
|
||||||
log.info("registry groups found {}", registriesByGroup.size());
|
log.info("registry groups found {}", registriesByGroup.size());
|
||||||
|
|
||||||
|
ArrayList<PaymentInstruction> pmtCreated = new ArrayList<>();
|
||||||
for (Map.Entry<Long, List<Registry>> entry : registriesByGroup.entrySet()) {
|
for (Map.Entry<Long, List<Registry>> entry : registriesByGroup.entrySet()) {
|
||||||
List<Registry> groupRgs = entry.getValue();
|
List<Registry> groupRgs = entry.getValue();
|
||||||
Optional<Registry> lmtO = groupRgs.stream().filter(rgs -> equalByRgs(LM_T, rgs)).findFirst();
|
Optional<Registry> lmtO = groupRgs.stream().filter(rgs -> equalByRgs(LM_T, rgs)).findFirst();
|
||||||
|
|
@ -193,15 +199,33 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
|
|
||||||
Optional<Registry> dmtClnr = searchDmtClrn(lmt);
|
Optional<Registry> dmtClnr = searchDmtClrn(lmt);
|
||||||
if (dmtClnr.isPresent()) {
|
if (dmtClnr.isPresent()) {
|
||||||
//todo 1.1; 1.3; 2; 3; 4
|
Account tranAcc = accountImdg.getSingleObjectBySQL("accountType = '%s' and status = '%s' and processingSign = '%s'"
|
||||||
|
.formatted(AccountType.Tran.getKey(), AccountStatus.ACTIVE.getKey(), Allowed.ALLOWED.getKey()));
|
||||||
|
if (tranAcc == null) {
|
||||||
|
return new StageResult<>(
|
||||||
|
new EnumMessage(ClearingError.AccountNotPresent, "accountType = " + AccountType.Tran.getKey()),
|
||||||
|
false);
|
||||||
|
}
|
||||||
|
Pair<PaymentInstruction, PaymentInstruction> pmts = PaymentInstructionBuilderFinalMkrDeals.builder(imdgProvider)
|
||||||
|
.lm_t(lmt)
|
||||||
|
.cm_t(cmt)
|
||||||
|
.tranAcc(tranAcc)
|
||||||
|
.sessionId(sessionId)
|
||||||
|
.paymentPurpose("Размещение депозита " + lmt.getContract() + " по ТКР " + lmt.getTradingClearingRegistry())
|
||||||
|
.build();
|
||||||
|
paymentInstructionImdg.insert(pmts.getFirst());
|
||||||
|
paymentInstructionImdg.insert(pmts.getSecond());
|
||||||
|
log.debug("LM*T#id={}, CM*T#id={} found, PaymentInstruction id={} and id={} created",
|
||||||
|
lmt.getId(), cmt.getId(), pmts.getFirst().getId(), pmts.getSecond().getId());
|
||||||
|
pmtCreated.add(pmts.getFirst());
|
||||||
|
pmtCreated.add(pmts.getSecond());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
sendSdfs(pmtCreated);
|
||||||
|
|
||||||
//todo fill result
|
//todo fill result
|
||||||
StageResult<Collection<PaymentInstruction>> stageResult = new StageResult(null, true);
|
StageResult<Collection<PaymentInstruction>> stageResult = new StageResult(null, true);
|
||||||
stageResult.setStageResult(new ArrayList<>());
|
stageResult.setStageResult(pmtCreated);
|
||||||
return stageResult;
|
return stageResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -249,16 +273,12 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
|
|
||||||
private void sendSdfs(List<PaymentInstruction> formedPaymentInstructions) {
|
private void sendSdfs(List<PaymentInstruction> formedPaymentInstructions) {
|
||||||
List<SDf03> sDf03Created = new ArrayList<>();
|
List<SDf03> sDf03Created = new ArrayList<>();
|
||||||
List<SDf12> sDf12Created = new ArrayList<>();
|
|
||||||
for (PaymentInstruction paymentInstruction : formedPaymentInstructions) {
|
for (PaymentInstruction paymentInstruction : formedPaymentInstructions) {
|
||||||
Security security = securityImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_securityId());
|
|
||||||
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
|
Account account = accountImdg.getSingleObjectByID(paymentInstruction.getCreditLeg_accountId());
|
||||||
if (InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
|
if (List.of(AccountType.Corr, AccountType.Clrn, AccountType.Tran, AccountType.Anlt, AccountType.Info)
|
||||||
List.of(AccountType.Corr, AccountType.Clrn).contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
|
.contains(IEnumKey.getEnumByKey(AccountType.class, account.getAccountType()))) {
|
||||||
sDf03Created.add(newSDf03(paymentInstruction));
|
//если info подставить anlt (единственный счет в системе)
|
||||||
} else if (!InstrumentType.CRNC.equalsByKey(security.getInstrumentType()) &&
|
sDf03Created.add(sdf03Creator.create(paymentInstruction));
|
||||||
AccountType.Depo.equalsByKey(account.getAccountType())) {
|
|
||||||
sDf12Created.add(newSDf12(paymentInstruction));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,32 +294,6 @@ public class FormingPaymentInstructionDepositReturn implements ISessionStage {
|
||||||
exportToFileRequest.setSdfGroupId(sdf03GroupId);
|
exportToFileRequest.setSdfGroupId(sdf03GroupId);
|
||||||
kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest);
|
kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest);
|
||||||
}
|
}
|
||||||
|
|
||||||
Long sdf12GroupId = null;
|
|
||||||
Long maxTxNumber = 1L;
|
|
||||||
if (!sDf12Created.isEmpty()) {
|
|
||||||
sdf12GroupId = !sDf12Created.isEmpty() ? imdgProvider.getImdgIdGenerator().nextId() : null;
|
|
||||||
ImdgPredicateBuilder predicateBuilder = sDf12Imdg.predicateBuilder();
|
|
||||||
ImdgPredicate notEmptyTransactionNum = predicateBuilder.not(predicateBuilder.equals("transaction_number", ""));
|
|
||||||
Long maxId = sDf12Imdg.aggregateLongMax("id", notEmptyTransactionNum);
|
|
||||||
if (maxId != null) {
|
|
||||||
SDf12 sDf12 = sDf12Imdg.getSingleObjectByID(maxId);
|
|
||||||
maxTxNumber = Long.parseLong(sDf12.getTransactionNumber()) + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (SDf12 sDf12 : sDf12Created) {
|
|
||||||
sDf12.setGenerationId(sdf03GroupId);
|
|
||||||
sDf12.setTransactionNumber(maxTxNumber.toString());
|
|
||||||
sDf12.setTransactionQuantity(String.valueOf(sDf12Created.size()));
|
|
||||||
sDf12Imdg.insert(sDf12);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sdf12GroupId != null) {
|
|
||||||
ExportToFileRequest exportToFileRequest = new ExportToFileRequest();
|
|
||||||
exportToFileRequest.setNameOfTable("DF-12");
|
|
||||||
exportToFileRequest.setSdfGroupId(sdf12GroupId);
|
|
||||||
kafkaSender.sendRequestToQueue(Consts.EXPORT_PROCESS, exportToFileRequest);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private PaymentInstruction createPaymentInstruction(List<Registry> registries, BigDecimal balance, Long sessionId) {
|
private PaymentInstruction createPaymentInstruction(List<Registry> registries, BigDecimal balance, Long sessionId) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue