diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionAssets.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionAssets.java index 77985d7b9..971a62869 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionAssets.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionAssets.java @@ -295,7 +295,7 @@ public class FormingPaymentInstructionAssets implements ISessionStage { } - Collection sdfTables = sendSdfs(paymentInstructions); + Collection sdfTables = sendSdfs(paymentInstructions, sessionId); StageResult stageResult = new StageResult<>(null, true); stageResult.setStageResult(new PaymentInfo(paymentInstructions, sdfTables)); return stageResult; @@ -307,7 +307,7 @@ public class FormingPaymentInstructionAssets implements ISessionStage { registryImdg.update(rgs); } - private Collection sendSdfs(List formedPaymentInstructions) { + private Collection sendSdfs(List formedPaymentInstructions, Long sessionId) { Collection sentSdfs = new ArrayList<>(); List sDf03Created = new ArrayList<>(); List sDf12Created = new ArrayList<>(); @@ -360,6 +360,7 @@ public class FormingPaymentInstructionAssets implements ISessionStage { SwtExporterRequest swtExporterRequest = new SwtExporterRequest(); swtExporterRequest.setType("SDF_12"); swtExporterRequest.setGroupId(sdf12GroupId); + swtExporterRequest.setSessionId(sessionId); kafkaSender.sendRequestToQueue(Consts.SWT_EXPORTER, swtExporterRequest); } if (sdf03GroupId != null) sentSdfs.add(SdfTable.SDF_03); diff --git a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java index 0f0b6c448..8ce018370 100644 --- a/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java +++ b/clearing-parent/clearing-service/src/main/java/ru/spcex/clearing/session/stage/impl/FormingPaymentInstructionSecondaryT0.java @@ -216,7 +216,7 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { paymentInstructionReturns.size(), paymentInstructionDeals.size()); List returnsAndDeals = Stream.concat(paymentInstructionReturns.stream(), paymentInstructionDeals.stream()).toList(); - sendSdfs(returnsAndDeals); + sendSdfs(returnsAndDeals, sessionId); StageResult> stageResult = new StageResult<>(null, true); stageResult.setStageResult(returnsAndDeals); return stageResult; @@ -228,7 +228,7 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { registryImdg.update(rgs); } - private void sendSdfs(List formedPaymentInstructions) { + private void sendSdfs(List formedPaymentInstructions, Long sessionId) { List sDf03Created = new ArrayList<>(); List sDf12Created = new ArrayList<>(); for (PaymentInstruction paymentInstruction : formedPaymentInstructions) { @@ -279,6 +279,7 @@ public class FormingPaymentInstructionSecondaryT0 implements ISessionStage { SwtExporterRequest swtExporterRequest = new SwtExporterRequest(); swtExporterRequest.setType("SDF_12"); swtExporterRequest.setGroupId(sdf12GroupId); + swtExporterRequest.setSessionId(sessionId); kafkaSender.sendRequestToQueue(Consts.SWT_EXPORTER, swtExporterRequest); } } diff --git a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/AbstractExporterService.java b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/AbstractExporterService.java index c823c4688..db82e9b22 100644 --- a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/AbstractExporterService.java +++ b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/AbstractExporterService.java @@ -2,6 +2,8 @@ package ru.spcex.clearing.swt.exporter.services; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import ru.clearing.classes.statics.data.misc.Session; +import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.platform.messaging.domain.cud.importexport.SwtExporterRequest; import ru.spcex.clearing.platform.messaging.domain.cud.utilities.JournalEventExportedRequest; import ru.spcex.clearing.platform.messaging.serialization.LogFormatter; @@ -36,6 +38,7 @@ public abstract class AbstractExporterService { private final KafkaSender kafkaSender; protected final FileStorage fileStorage; protected final Class mapClass; + private final Imdg sessionImdg; protected AbstractExporterService(FileStorage fileStorage, KafkaSender kafkaSender, ImdgProvider imdgProvider, @@ -47,6 +50,7 @@ public abstract class AbstractExporterService { this.mapClass = mapClass; Objects.requireNonNull(type, "SWT table type not set"); this.sdfImdg = imdgProvider.getImdg(mapName, mapClass); + this.sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class); } public SwtTable getType() { @@ -156,4 +160,11 @@ public abstract class AbstractExporterService { protected abstract void writeFooter(PrintWriter out, Collection records, int counter); + protected Session session(SwtExporterRequest req) { + Long sessionId = req.getSessionId(); + Objects.requireNonNull(sessionId, "cannot process %s without session id".formatted(typeForFileName())); + Session session = sessionImdg.getSingleObjectByID(sessionId); + Objects.requireNonNull(session, "cannot process %s: couldn't find session.id=%d".formatted(typeForFileName(), sessionId)); + return session; + } } diff --git a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF12Exporter.java b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF12Exporter.java index d06478265..3ffcf1729 100644 --- a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF12Exporter.java +++ b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF12Exporter.java @@ -2,6 +2,7 @@ package ru.spcex.clearing.swt.exporter.services.exportimpl; import com.hazelcast.aws.utility.StringUtil; import org.springframework.stereotype.Service; +import ru.clearing.classes.statics.data.misc.Session; import ru.clearing.classes.statics.data.sdf.SDf12; import ru.spcex.clearing.imdg.IMDGDistributedNames; import ru.spcex.clearing.platform.messaging.domain.cud.importexport.SwtExporterRequest; @@ -10,6 +11,8 @@ import ru.spcex.clearing.swt.exporter.services.AbstractExporterService; import ru.spcex.clearing.swt.exporter.services.FileStorage; import ru.spcex.clearing.swt.exporter.util.ConvertionContext; import ru.spcex.clearing.swt.exporter.util.SWTHeaderData; +import ru.spcex.platform.enumeration.Section; +import ru.spcex.platform.enumeration.SessionType; import ru.spcex.platform.enumeration.SwtTable; import ru.spcex.platform.imdg.api.ImdgProvider; @@ -37,7 +40,14 @@ public class DF12Exporter extends AbstractExporterService { @Override protected String sectionForFileName(SwtExporterRequest req) { - return "bond"; // todo bond / fund + Session session = session(req); + if (!Section.FOND.equalsByKey(session.getSection())) { + throw new IllegalStateException("%s is only processed for FOND section".formatted(typeForFileName())); + } + if (SessionType.TRDT.equalsByKey(session.getSessionType())) { + return "fund"; + } + return "bond"; } @Override diff --git a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF14Exporter.java b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF14Exporter.java index 7e9356ec9..9341ce0a6 100644 --- a/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF14Exporter.java +++ b/clearing-parent/swt-exporter/src/main/java/ru/spcex/clearing/swt/exporter/services/exportimpl/DF14Exporter.java @@ -15,12 +15,10 @@ import ru.spcex.platform.enumeration.SessionType; import ru.spcex.platform.enumeration.SwtTable; import ru.spcex.platform.imdg.api.Imdg; import ru.spcex.platform.imdg.api.ImdgProvider; -import ru.spcex.platform.utils.enumeration.IEnumKey; import java.io.PrintWriter; import java.time.LocalDateTime; import java.util.Collection; -import java.util.Objects; @Service @@ -45,16 +43,11 @@ public class DF14Exporter extends AbstractExporterService { @Override protected String sectionForFileName(SwtExporterRequest req) { - Long sessionId = req.getSessionId(); - Objects.requireNonNull(sessionId, "cannot process DF-14 without session id"); - Session session = sessionImdg.getSingleObjectByID(sessionId); - Objects.requireNonNull(session, "cannot process DF-14: couldn't find session.id=%d".formatted(sessionId)); - SessionType type = IEnumKey.getEnumByKey(SessionType.class, session.getSessionType()); - Objects.requireNonNull(type, "cannot process DF-14: session.id=%d couldn't determine session type %s".formatted(sessionId, session.getSessionType())); + Session session = session(req); if (!Section.FOND.equalsByKey(session.getSection())) { - throw new IllegalStateException("DF-14 is only processed for FOND section"); + throw new IllegalStateException("%s is only processed for FOND section".formatted(typeForFileName())); } - if (type == SessionType.TRDT) { + if (SessionType.TRDT.equalsByKey(session.getSessionType())) { return "fund"; } return "bond";