diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/enums/OutboundRequestType.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/enums/OutboundRequestType.java index fb1f01acc..92cbed4f9 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/enums/OutboundRequestType.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/enums/OutboundRequestType.java @@ -7,6 +7,10 @@ public enum OutboundRequestType implements IEnumKey { ON_DEMAND("ON_DEMAND"), FILL_LIMITS("FILL_LIMITS"), MEMBER_ON_DEMAND("MEMBER_ON_DEMAND"), + PFX64("PFX64"), + PFX65("PFX65"), + REPORT_KS_TMP("REPORT_KS_TMP"), + REPORT_KS_FINAL("REPORT_KS_FINAL"), ; private final String key; diff --git a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java index a66b13033..9c13a7ea1 100644 --- a/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java +++ b/clearing-parent/gateway-api/src/main/java/ru/spcex/clearing/gatewayapi/service/GatewayService.java @@ -22,14 +22,20 @@ import ru.spcex.clearing.platform.messaging.domain.Consts; import ru.spcex.clearing.platform.messaging.domain.cud.clearing.AssetOperationListRequest; import ru.spcex.clearing.platform.messaging.domain.cud.clearing.AssetOperationRequest; import ru.spcex.clearing.platform.messaging.domain.cud.gateway.GatewayTaskRequest; +import ru.spcex.clearing.platform.messaging.domain.cud.gateway.ReportPart; +import ru.spcex.clearing.platform.messaging.domain.cud.gateway.SendReportRequest; import ru.spcex.clearing.platform.messaging.domain.cud.utilities.LimExportedRequest; import ru.spcex.clearing.platform.messaging.service.QueueConsumer; import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate; import ru.spcex.clearing.util.security.UserRoleVerification; +import ru.spcex.platform.enumeration.ReportKeys; import ru.spcex.platform.enumeration.Section; import ru.spcex.platform.enumeration.Task; +import ru.spcex.platform.utils.enumeration.IEnumKey; import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Service public class GatewayService extends QueueConsumer implements InitializingBean { @@ -40,6 +46,7 @@ public class GatewayService extends QueueConsumer implements InitializingBean { private final InboundServerSettings inboundServerSettings; private final Map> sentAssets; private final Map outboundRequestByUuid; + private final static Pattern REPORT_FILE_NAME_PATTERN = Pattern.compile("(\\S*)_(\\d{15}).csv"); public GatewayService(Consumer kafkaQueue, Producer kafkaProducer, @@ -70,6 +77,9 @@ public class GatewayService extends QueueConsumer implements InitializingBean { callback(AssetOperationListRequest.class) .setConsumer(this::requestOnAsset) .forDestination(Consts.ASSET_OPERATION, callbacks::put); + callback(SendReportRequest.class) + .setConsumer(this::requestOnReport) + .forDestination(Consts.REPORTS_TO_GATEWAY, callbacks::put); init(); } @@ -198,6 +208,49 @@ public class GatewayService extends QueueConsumer implements InitializingBean { sentAssets.put(requestId, assets); } + public void requestOnReport(BaseRequest request) { + SendReportRequest reportRequest = request.getRequestPayload(); + OutboundRequestType outboundRequestType = IEnumKey.getEnumByKey(OutboundRequestType.class, reportRequest.getType()); + if (outboundRequestType == null) { + log.warn("Undefined type of request: {}; skip", reportRequest.getType()); + return; + } + + for (ReportPart reportPart : reportRequest.getReports()) { + Map content = makeContentByReportRequest(reportPart); + OutboundRequest outboundRequest = OutboundRequestBuilder.builder() + .section(Section.FOND.getKey()) + .type(outboundRequestType) + .content(content).build(); + + String url = formingInboundUrl(inboundServerSettings.getPathLOCM()); + HttpEntity r = makeDefaultRequest(outboundRequest); + ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class); + SuccessResponse bodyResponse = response.getBody(); + if (bodyResponse != null) { + log.debug("Response from service: {}", bodyResponse); + } + } + } + + protected Map makeContentByReportRequest(ReportPart reportPart) { + Map content = new HashMap<>(); + Matcher matcher = REPORT_FILE_NAME_PATTERN.matcher(reportPart.getFileName()); + ReportKeys reportKeys = IEnumKey.getUndefined(ReportKeys.class); + if (matcher.matches()) { + String rowKey = matcher.group(1); + reportKeys = IEnumKey.getEnumByKeyOrUndefined(ReportKeys.class, rowKey); + } + String paramName = null; + switch (reportKeys) { + case KS_BR_PFX64_INFTYPE_1 -> paramName = "inftype_1"; + } + if (paramName != null) { + content.put(paramName, reportPart.getFileName()); + } + return content; + } + private String formingInboundUrl(String path) { return "%s://%s:%s/%s".formatted( inboundServerSettings.getEnableSsl() ? "https" : "http", diff --git a/clearing-parent/gateway-api/src/test/java/ru/spcex/clearing/gatewayapi/service/GatewayServiceTest.java b/clearing-parent/gateway-api/src/test/java/ru/spcex/clearing/gatewayapi/service/GatewayServiceTest.java new file mode 100644 index 000000000..372cbab34 --- /dev/null +++ b/clearing-parent/gateway-api/src/test/java/ru/spcex/clearing/gatewayapi/service/GatewayServiceTest.java @@ -0,0 +1,21 @@ +package ru.spcex.clearing.gatewayapi.service; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import ru.spcex.clearing.platform.messaging.domain.cud.gateway.ReportPart; + +import java.util.Map; + +public class GatewayServiceTest { + + @Test + public void makeContentByReportRequestTest() { + GatewayService gatewayService = new GatewayService(null, null, null, + null, null, null, null); + ReportPart reportPart = new ReportPart(); + reportPart.setFileName("KS_BR_PFX64_INFTYPE_1_111111111111111.csv"); + Map content = gatewayService.makeContentByReportRequest(reportPart); + Assertions.assertTrue(content.containsKey("inftype_1")); + Assertions.assertEquals("KS_BR_PFX64_INFTYPE_1_111111111111111.csv", content.get("inftype_1")); + } +} diff --git a/platform-parent/platform-enum/src/main/java/ru/spcex/platform/enumeration/ReportKeys.java b/platform-parent/platform-enum/src/main/java/ru/spcex/platform/enumeration/ReportKeys.java new file mode 100644 index 000000000..1583e5dfd --- /dev/null +++ b/platform-parent/platform-enum/src/main/java/ru/spcex/platform/enumeration/ReportKeys.java @@ -0,0 +1,36 @@ +package ru.spcex.platform.enumeration; + +import ru.spcex.platform.utils.enumeration.IEnumKey; + +public enum ReportKeys implements IEnumKey { + KS_BR_PFX64_INFTYPE_1("KS_BR_PFX64_INFTYPE_1"), + KS_BR_PFX64_INFTYPE_2("KS_BR_PFX64_INFTYPE_2"), + KS_BR_PFX64_INFTYPE_3("KS_BR_PFX64_INFTYPE_3"), + KS_BR_PFX64_INFTYPE_4("KS_BR_PFX64_INFTYPE_4"), + KS_BR_PFX65_DEALS("KS_BR_PFX65_DEALS"), + KS_REP_CASH_REGISTERS("KS_REP_CASH_REGISTERS"), + KS_REP_CASH_REGISTER_SUMS("KS_REP_CASH_REGISTER_SUMS"), + KS_REP_DEPO_REGISTERS("KS_REP_DEPO_REGISTERS"), + KS_REP_DEPO_REGISTER_QUANTITIES("KS_REP_DEPO_REGISTER_QUANTITIES"), + KS_REP_TRADES("KS_REP_TRADES"), + KS_REP_CASH_NETTO("KS_REP_CASH_NETTO"), + KS_REP_DEPO_NETTO("KS_REP_DEPO_NETTO"), + + ; + + private final String key; + + ReportKeys(String key) { + this.key = key; + } + + @Override + public String getKey() { + return this.key; + } + + @Override + public boolean equalsByKey(String key) { + return IEnumKey.super.equalsByKey(key); + } +}