etreschenkov 2024-05-27 16:23:59 +03:00
parent a35b19467a
commit e00cc21a58
7 changed files with 81 additions and 85 deletions

View file

@ -0,0 +1,22 @@
package ru.spcex.clearing.gatewayapi.config.deserializers;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
public class LocalDateTimeDeserializer extends JsonDeserializer<LocalDateTime> {
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy HH:mm:ss:SSS");
@Override
public LocalDateTime deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
String date = p.getText();
if (date == null || date.trim().length() == 0) {
return null;
}
return LocalDateTime.parse(date, formatter);
}
}

View file

@ -4,10 +4,13 @@ import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import ru.spcex.clearing.gatewayapi.config.deserializers.LocalDateTimeDeserializer;
public class TkrRequest {
@JsonProperty("id")
private UUID id;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@JsonProperty("datetime")
private LocalDateTime datetime;
@JsonProperty("type")

View file

@ -11,6 +11,7 @@ public enum OutboundRequestType implements IEnumKey {
PFX65("PFX65"),
REPORT_KS_TMP("REPORT_KS_TMP"),
REPORT_KS_FINAL("REPORT_KS_FINAL"),
MEMBER_RESPONSE_TKR("MEMBER_RESPONSE_TKR"),
;
private final String key;

View file

@ -40,6 +40,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.clearing.AssetOperationRe
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.gateway.SendTkrRequest;
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;
@ -84,20 +85,23 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
@Override
public void afterPropertiesSet() throws Exception {
callback(GatewayTaskRequest.class)
.setConsumer(this::requestOnDemandCompany)
.forDestination(Task.loadParty_LOCM.topic(), callbacks::put);
.setConsumer(this::requestOnDemandCompany)
.forDestination(Task.loadParty_LOCM.topic(), callbacks::put);
callback(GatewayTaskRequest.class)
.setConsumer(this::requestOnDemandSecurity)
.forDestination(Task.loadIssue_LOSC.topic(), callbacks::put);
.setConsumer(this::requestOnDemandSecurity)
.forDestination(Task.loadIssue_LOSC.topic(), callbacks::put);
callback(LimExportedRequest.class)
.setConsumer(this::requestOnLimit)
.forDestination(Consts.LIM_EXPORTED, callbacks::put);
.setConsumer(this::requestOnLimit)
.forDestination(Consts.LIM_EXPORTED, callbacks::put);
callback(AssetOperationListRequest.class)
.setConsumer(this::requestOnAsset)
.forDestination(Consts.ASSET_OPERATION, callbacks::put);
.setConsumer(this::requestOnAsset)
.forDestination(Consts.ASSET_OPERATION, callbacks::put);
callback(SendReportRequest.class)
.setConsumer(this::requestOnReport)
.forDestination(Consts.REPORTS_TO_GATEWAY, callbacks::put);
.setConsumer(this::requestOnReport)
.forDestination(Consts.REPORTS_TO_GATEWAY, callbacks::put);
callback(SendTkrRequest.class)
.setConsumer(this::requestOnTkr)
.forDestination(Consts.ACCOUNTS_TO_GATEWAY, callbacks::put);
init();
}
@ -112,8 +116,8 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
.type(OutboundRequestType.MEMBER_ON_DEMAND.getKey())
.build();
.type(OutboundRequestType.MEMBER_ON_DEMAND.getKey())
.build();
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest);
@ -131,10 +135,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
Map<String, Object> content = Map.of("file", exportedRequest.getLimFileName());
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
.section(exportedRequest.getSection())
.type(OutboundRequestType.FILL_LIMITS.getKey())
.content(content)
.build();
.section(exportedRequest.getSection())
.type(OutboundRequestType.FILL_LIMITS.getKey())
.content(content)
.build();
HttpEntity<OutboundRequest> request = makeDefaultRequest(outboundFondRequest);
outboundRequestByUuid.put(outboundFondRequest.getId(), outboundFondRequest);
@ -157,19 +161,19 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
OutboundRequest outboundFondRequest = OutboundRequestBuilder.builder()
.section(Section.FOND.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
.section(Section.FOND.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
OutboundRequest outboundMkrRequest = OutboundRequestBuilder.builder()
.section(Section.MKR.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
.section(Section.MKR.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
OutboundRequest outboundCurrRequest = OutboundRequestBuilder.builder()
.section(Section.CURR.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
.section(Section.CURR.getKey())
.type(OutboundRequestType.ON_DEMAND.getKey())
.build();
HttpEntity<OutboundRequest> requestFond = makeDefaultRequest(outboundFondRequest);
HttpEntity<OutboundRequest> requestMKR = makeDefaultRequest(outboundMkrRequest);
@ -215,9 +219,9 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
}
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
.section(assetOperation.getAmount() != null ? Section.MKR.getKey() : Section.FOND.getKey())
.type(OutboundRequestType.ASSET_OPERATION.getKey())
.content(content).build();
.section(assetOperation.getAmount() != null ? Section.MKR.getKey() : Section.FOND.getKey())
.type(OutboundRequestType.ASSET_OPERATION.getKey())
.content(content).build();
gatewayBuilder.outboundRequest(outboundRequest);
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
@ -254,9 +258,9 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
Map<String, Object> content = new HashMap<>();
reportRequest.getReports().forEach(reportPart -> makeContentByReportRequest(content, reportPart));
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
.section(Section.FOND.getKey())
.type(reportType.getKey())
.content(content).build();
.section(Section.FOND.getKey())
.type(reportType.getKey())
.content(content).build();
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
@ -267,21 +271,17 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
}
}
public void requestOnTkr(BaseRequest<SendReportRequest> request) {
SendReportRequest reportRequest = request.getRequestPayload();
ReportType reportType = IEnumKey.getEnumByKey(ReportType.class, reportRequest.getType());
if (reportType == null) {
log.warn("Undefined type of request: {}; skip", reportRequest.getType());
return;
}
public void requestOnTkr(BaseRequest<SendTkrRequest> request) {
SendTkrRequest reportRequest = request.getRequestPayload();
Map<String, Object> content = new HashMap<>();
reportRequest.getReports().forEach(reportPart -> makeContentByReportRequest(content, reportPart));
content.put("tkr_list", reportRequest.getTkrs());
OutboundRequest outboundRequest = OutboundRequestBuilder.builder()
.section(Section.FOND.getKey())
.type(reportType.getKey())
.content(content).build();
.type(OutboundRequestType.MEMBER_RESPONSE_TKR.getKey())
.content(content)
.build();
if (reportRequest.getRequestId() != null) {
outboundRequest.setId(reportRequest.getRequestId());
}
String url = formingInboundUrl(inboundServerSettings.getPathLOCM());
HttpEntity<OutboundRequest> r = makeDefaultRequest(outboundRequest);
ResponseEntity<SuccessResponse> response = restTemplate.exchange(url, HttpMethod.POST, r, SuccessResponse.class);
@ -322,10 +322,10 @@ public class GatewayService extends QueueConsumer implements InitializingBean {
public String formingInboundUrl(String path) {
return "%s://%s:%s/%s".formatted(
inboundServerSettings.getEnableSsl() ? "https" : "http",
inboundServerSettings.getHost(),
inboundServerSettings.getPort(),
path
inboundServerSettings.getEnableSsl() ? "https" : "http",
inboundServerSettings.getHost(),
inboundServerSettings.getPort(),
path
);
}

View file

@ -5,8 +5,8 @@ import org.springframework.stereotype.Service;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.TkrRequest;
import ru.spcex.clearing.gatewayapi.service.adapter.TkrAdapter;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.TkrAccount;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.TkrAccountsResponse;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccountsCheckRequest;
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
@Service
@ -23,8 +23,9 @@ public class TkrService {
public void processedTkrRequest(TkrRequest tkrRequest) {
List<TkrAccount> tkrAccounts = tkrRequest.getInfoAccount().stream()
.map(tkrAdapter::toTkrResponse).toList();
TkrAccountsResponse tkrAccountsResponse = new TkrAccountsResponse();
tkrAccountsResponse.setAccounts(tkrAccounts);
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_CHECK, tkrAccountsResponse);
TkrAccountsCheckRequest tkrAccountsCheckRequest = new TkrAccountsCheckRequest();
tkrAccountsCheckRequest.setRequestId(tkrRequest.getId());
tkrAccountsCheckRequest.setAccounts(tkrAccounts);
kafkaSender.sendRequestToQueue(Consts.DESTINATION_TRADING_CLEARING_REGISTRY_CHECK, tkrAccountsCheckRequest);
}
}

View file

@ -5,7 +5,7 @@ import org.springframework.stereotype.Service;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.InfoAccount;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.MoneyAccount;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsg;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.TkrAccount;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
@Service
public class TkrAdapter {

View file

@ -1,31 +0,0 @@
package ru.spcex.clearing.gatewayapi.service.builders;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.response.TkrElemResponse;
public class TkrListResultBuilder {
private final List<TkrElemResponse> tkrElems;
private TkrListResultBuilder() {
this.tkrElems = new ArrayList<>();
}
public static TkrListResultBuilder builder() {
return new TkrListResultBuilder();
}
public TkrListResultBuilder elemOfList() {
TkrElemResponse tkrElemResponse = new TkrElemResponse();
tkrElems.add(tkrElemResponse);
return this;
}
public Map<String, List<TkrElemResponse>> build() {
Map<String, List<TkrElemResponse>> map = new HashMap<>();
map.put("tkr_list", this.tkrElems);
return map;
}
}