This commit is contained in:
parent
7179c09c29
commit
e59b718eab
4 changed files with 114 additions and 0 deletions
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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<Long, List<SentAsset>> sentAssets;
|
||||
private final Map<UUID, OutboundRequest> outboundRequestByUuid;
|
||||
private final static Pattern REPORT_FILE_NAME_PATTERN = Pattern.compile("(\\S*)_(\\d{15}).csv");
|
||||
|
||||
public GatewayService(Consumer<String, Object> kafkaQueue,
|
||||
Producer<String, Object> 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<SendReportRequest> 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<String, Object> content = makeContentByReportRequest(reportPart);
|
||||
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
|
||||
.section(Section.FOND.getKey())
|
||||
.type(outboundRequestType)
|
||||
.content(content).build();
|
||||
|
||||
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
|
||||
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
|
||||
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
|
||||
SuccessResponse bodyResponse = response.getBody();
|
||||
if (bodyResponse != null) {
|
||||
log.debug("Response from service: {}", bodyResponse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected Map<String, Object> makeContentByReportRequest(ReportPart reportPart) {
|
||||
Map<String, Object> 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",
|
||||
|
|
|
|||
|
|
@ -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<String, Object> content = gatewayService.makeContentByReportRequest(reportPart);
|
||||
Assertions.assertTrue(content.containsKey("inftype_1"));
|
||||
Assertions.assertEquals("KS_BR_PFX64_INFTYPE_1_111111111111111.csv", content.get("inftype_1"));
|
||||
}
|
||||
}
|
||||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue