etreschenkov 2024-05-24 13:37:12 +03:00
parent 1349425e09
commit 6d47a2e322
16 changed files with 505 additions and 13 deletions

View file

@ -80,6 +80,10 @@
<artifactId>test-clearing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jakarta.validation</groupId>
<artifactId>jakarta.validation-api</artifactId>
</dependency>
</dependencies>
<build>

View file

@ -3,13 +3,23 @@ package ru.spcex.clearing.gatewayapi.controller;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.CommonRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.company.CompaniesRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.limit.LimitRequest;
@ -17,10 +27,12 @@ import ru.spcex.clearing.gatewayapi.controller.inbound.request.listing.curr.mkr.
import ru.spcex.clearing.gatewayapi.controller.inbound.request.listing.fond.FondListingsRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.listing.mkr.MMListingsRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.operations.OperationsRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.TkrRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.response.CommonResponse;
import ru.spcex.clearing.gatewayapi.exception.GatewayException;
import ru.spcex.clearing.gatewayapi.service.NotificationService;
import ru.spcex.clearing.gatewayapi.service.OperationService;
import ru.spcex.clearing.gatewayapi.service.TkrService;
import ru.spcex.clearing.gatewayapi.service.processor.CompanyProcessor;
import ru.spcex.clearing.gatewayapi.service.processor.ListingCurrProcessor;
import ru.spcex.clearing.gatewayapi.service.processor.ListingFondProcessor;
@ -28,12 +40,6 @@ import ru.spcex.clearing.gatewayapi.service.processor.ListingMMProcessor;
import ru.spcex.platform.utils.enumeration.EnumMessage;
import ru.spcex.platform.utils.enumeration.IMessageResolver;
import java.time.Instant;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@Controller
@RequestMapping("/")
public class GatewayController {
@ -47,6 +53,7 @@ public class GatewayController {
private final ExecutorService executor;
private final OperationService operationService;
private final NotificationService notificationService;
private final TkrService tkrService;
private List<String> validTypes = Arrays.asList("DAY_START", "ON_DEMAND");
@ -57,7 +64,8 @@ public class GatewayController {
ListingCurrProcessor listingCurrProcessor,
@Qualifier("gatewayExecutor") ExecutorService executor,
OperationService operationService,
NotificationService notificationService) {
NotificationService notificationService,
TkrService tkrService) {
this.messageResolver = messageResolver;
this.companiesProcessor = companiesProcessor;
this.listingFondProcessor = listingFondProcessor;
@ -66,6 +74,7 @@ public class GatewayController {
this.executor = executor;
this.operationService = operationService;
this.notificationService = notificationService;
this.tkrService = tkrService;
}
@ -182,6 +191,25 @@ public class GatewayController {
return createCommonResponse(request.getId());
}
@ApiResponses(value = {
@ApiResponse(code = 200, message = "OK", response = CommonResponse.class),
@ApiResponse(code = 400, message = "Ошибка валидации", response = CommonResponse.class)
})
@RequestMapping(
path = "/member_request_tkr",
method = RequestMethod.POST,
consumes = MediaType.APPLICATION_JSON_VALUE,
produces = MediaType.APPLICATION_JSON_VALUE
)
@ResponseBody
public CommonResponse requestTkr(@RequestBody TkrRequest request) {
log.debug("Received message: {}", request);
executor.submit(() -> {
tkrService.processedTkrRequest(request);
});
return createCommonResponse(request.getId());
}
@ResponseStatus(value = HttpStatus.BAD_REQUEST)
@ResponseBody
@ExceptionHandler(GatewayException.class)

View file

@ -0,0 +1,77 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class InfoAccount {
@JsonProperty("company_id")
private String companyId;
@JsonProperty("trading_code")
private Long tradingCode;
@JsonProperty("client_code")
private String clientCode;
@JsonProperty("enabled")
private Boolean enabled;
@JsonProperty("tkr_code")
private String tkrCode;
@JsonProperty("depo_account")
private String depoAccount;
@JsonProperty("money_account")
private List<MoneyAccount> moneyAccounts;
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public Long getTradingCode() {
return tradingCode;
}
public void setTradingCode(Long tradingCode) {
this.tradingCode = tradingCode;
}
public String getClientCode() {
return clientCode;
}
public void setClientCode(String clientCode) {
this.clientCode = clientCode;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getTkrCode() {
return tkrCode;
}
public void setTkrCode(String tkrCode) {
this.tkrCode = tkrCode;
}
public String getDepoAccount() {
return depoAccount;
}
public void setDepoAccount(String depoAccount) {
this.depoAccount = depoAccount;
}
public List<MoneyAccount> getMoneyAccounts() {
return moneyAccounts;
}
public void setMoneyAccounts(List<MoneyAccount> moneyAccounts) {
this.moneyAccounts = moneyAccounts;
}
}

View file

@ -0,0 +1,26 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request;
import com.fasterxml.jackson.annotation.JsonProperty;
public class MoneyAccount {
@JsonProperty("curr_code")
private String currCode;
@JsonProperty("account")
private String account;
public String getCurrCode() {
return currCode;
}
public void setCurrCode(String currCode) {
this.currCode = currCode;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
}

View file

@ -0,0 +1,49 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TkrRequest {
@JsonProperty("id")
private UUID id;
@JsonProperty("datetime")
private LocalDateTime datetime;
@JsonProperty("type")
private String type;
@JsonProperty("sent_info_accounts")
private List<InfoAccount> infoAccount;
public UUID getId() {
return id;
}
public void setId(UUID id) {
this.id = id;
}
public LocalDateTime getDatetime() {
return datetime;
}
public void setDatetime(LocalDateTime datetime) {
this.datetime = datetime;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<InfoAccount> getInfoAccount() {
return infoAccount;
}
public void setInfoAccount(List<InfoAccount> infoAccount) {
this.infoAccount = infoAccount;
}
}

View file

@ -0,0 +1,10 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.response;
import com.fasterxml.jackson.annotation.JsonProperty;
public class MoneyAccountResponse {
@JsonProperty("curr_code")
private String currCode;
@JsonProperty("account")
private String account;
}

View file

@ -0,0 +1,23 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.response;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TkrElemResponse {
@JsonProperty("company_id")
private String companyId;
@JsonProperty("trading_code")
private Long tradingCode;
@JsonProperty("client_code")
private String clientCode;
@JsonProperty("tkr_code")
private String tkrCode;
@JsonProperty("tkr_type")
private String tkrType;
@JsonProperty("account_type_name")
private String accountTypeName;
@JsonProperty("depo_account")
private String depoAccount;
@JsonProperty("money_account")
private List<MoneyAccountResponse> moneyAccounts;
}

View file

@ -1,5 +1,14 @@
package ru.spcex.clearing.gatewayapi.service;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.regex.Pattern;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.kafka.clients.consumer.Consumer;
import org.apache.kafka.clients.producer.Producer;
@ -7,7 +16,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.*;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import ru.clearing.classes.statics.data.register.GatewayResult;
@ -39,10 +52,6 @@ import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.utils.enumeration.IEnumKey;
import java.math.BigDecimal;
import java.util.*;
import java.util.regex.Pattern;
@Service
public class GatewayService extends QueueConsumer implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass());
@ -258,6 +267,30 @@ 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;
}
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();
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 void makeContentByReportRequest(Map<String, Object> content, ReportPart reportPart) {
ReportKeys reportKey = IEnumKey.getEnumByKey(ReportKeys.class, reportPart.getReportType());
if (reportKey == null) {

View file

@ -0,0 +1,30 @@
package ru.spcex.clearing.gatewayapi.service;
import java.util.List;
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.service.sender.KafkaSender;
@Service
public class TkrService {
private final KafkaSender kafkaSender;
private final TkrAdapter tkrAdapter;
public TkrService(KafkaSender kafkaSender,
TkrAdapter tkrAdapter) {
this.kafkaSender = kafkaSender;
this.tkrAdapter = tkrAdapter;
}
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);
}
}

View file

@ -0,0 +1,32 @@
package ru.spcex.clearing.gatewayapi.service.adapter;
import java.util.List;
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;
@Service
public class TkrAdapter {
public TkrAccount toTkrResponse(InfoAccount infoAccount) {
TkrAccount tkrResponse = new TkrAccount();
tkrResponse.setCompanyId(infoAccount.getCompanyId());
tkrResponse.setTradingCode(infoAccount.getTradingCode());
tkrResponse.setClientCode(infoAccount.getClientCode());
tkrResponse.setEnabled(infoAccount.getEnabled());
tkrResponse.setTkrCode(infoAccount.getTkrCode());
tkrResponse.setDepoAccount(infoAccount.getDepoAccount());
List<MoneyAccountMsg> moneyAccountMsgs = infoAccount.getMoneyAccounts().stream()
.map(this::toMoneyAccountMsg).toList();
tkrResponse.setMoneyAccounts(moneyAccountMsgs);
return tkrResponse;
}
private MoneyAccountMsg toMoneyAccountMsg(MoneyAccount moneyAccount) {
MoneyAccountMsg moneyAccountMsg = new MoneyAccountMsg();
moneyAccountMsg.setAccount(moneyAccount.getAccount());
moneyAccountMsg.setCurrCode(moneyAccount.getCurrCode());
return moneyAccountMsg;
}
}

View file

@ -0,0 +1,31 @@
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;
}
}

View file

@ -110,6 +110,7 @@ public interface Consts {
String DESTINATION_TRADING_CLEARING_REGISTRY_AUTO_NEW = "trading-clearing-registry-auto-new";
String DESTINATION_TRADING_CLEARING_REGISTRY_UPDATE = "trading-clearing-registry-update";
String DESTINATION_TRADING_CLEARING_REGISTRY_BLOCK = "trading-clearing-registry-block";
String DESTINATION_TRADING_CLEARING_REGISTRY_CHECK = "trading-clearing-registry-check";
String CLEARING_NOTIFICATION_FEEDBACK = "clearing-notification-feedback";
String ACCOUNT_NOTIFICATION_FEEDBACK = "account-notification-feedback";

View file

@ -0,0 +1,26 @@
package ru.spcex.clearing.platform.messaging.domain.cud.gateway;
import com.fasterxml.jackson.annotation.JsonProperty;
public class MoneyAccountMsg {
@JsonProperty("curr_code")
private String currCode;
@JsonProperty("account")
private String account;
public String getCurrCode() {
return currCode;
}
public void setCurrCode(String currCode) {
this.currCode = currCode;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
}

View file

@ -0,0 +1,28 @@
package ru.spcex.clearing.platform.messaging.domain.cud.gateway;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class SendTkrRequest {
@JsonProperty
private List<Tkr> tkrs;
public class Tkr {
@JsonProperty
private String companyId;
@JsonProperty
private Long tradingCode;
@JsonProperty
private String clientCode;
@JsonProperty
private String tkrCode;
@JsonProperty
private String tkrType;
@JsonProperty
private String accountTypeName;
@JsonProperty
private String depoAccount;
@JsonProperty
private List<MoneyAccountMsg> moneyAccounts;
}
}

View file

@ -0,0 +1,77 @@
package ru.spcex.clearing.platform.messaging.domain.cud.gateway;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TkrAccount {
@JsonProperty
private String companyId;
@JsonProperty
private Long tradingCode;
@JsonProperty
private String clientCode;
@JsonProperty
private Boolean enabled;
@JsonProperty
private String tkrCode;
@JsonProperty
private String depoAccount;
@JsonProperty
private List<MoneyAccountMsg> moneyAccounts;
public String getCompanyId() {
return companyId;
}
public void setCompanyId(String companyId) {
this.companyId = companyId;
}
public Long getTradingCode() {
return tradingCode;
}
public void setTradingCode(Long tradingCode) {
this.tradingCode = tradingCode;
}
public String getClientCode() {
return clientCode;
}
public void setClientCode(String clientCode) {
this.clientCode = clientCode;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public String getTkrCode() {
return tkrCode;
}
public void setTkrCode(String tkrCode) {
this.tkrCode = tkrCode;
}
public String getDepoAccount() {
return depoAccount;
}
public void setDepoAccount(String depoAccount) {
this.depoAccount = depoAccount;
}
public List<MoneyAccountMsg> getMoneyAccounts() {
return moneyAccounts;
}
public void setMoneyAccounts(List<MoneyAccountMsg> moneyAccounts) {
this.moneyAccounts = moneyAccounts;
}
}

View file

@ -0,0 +1,17 @@
package ru.spcex.clearing.platform.messaging.domain.cud.gateway;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TkrAccountsResponse {
@JsonProperty
private List<TkrAccount> accounts;
public List<TkrAccount> getAccounts() {
return accounts;
}
public void setAccounts(List<TkrAccount> accounts) {
this.accounts = accounts;
}
}