etreschenkov 2024-06-25 12:44:15 +03:00
parent 9bb50750c0
commit 3bd46a0bca
11 changed files with 150 additions and 74 deletions

View file

@ -186,7 +186,7 @@ public class GatewayController {
log.debug("Received message: {}", request);
executor.submit(() -> {
operationService.checkAssetsAndSendMessage(request);
notificationService.updateGatewayResultInMap(request);
notificationService.sendToJournal(request);
});
return createCommonResponse(request.getId());
}
@ -206,6 +206,7 @@ public class GatewayController {
log.debug("Received message: {}", request);
executor.submit(() -> {
tkrService.processedTkrRequest(request);
notificationService.sendToJournal(request);
});
return createCommonResponse(request.getId());
}

View file

@ -0,0 +1,7 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request;
import java.util.UUID;
public interface WithId {
UUID getId();
}

View file

@ -0,0 +1,5 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request;
public interface WithResult {
Boolean getResult();
}

View file

@ -1,10 +1,11 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.limit;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonProperty;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithId;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithResult;
public class LimitRequest {
public class LimitRequest implements WithId, WithResult {
@JsonProperty("result")
private Boolean result;
@JsonProperty("description")
@ -16,6 +17,7 @@ public class LimitRequest {
@JsonProperty("error_file")
private String errorFile;
@Override
public Boolean getResult() {
return result;
}
@ -32,6 +34,7 @@ public class LimitRequest {
this.description = description;
}
@Override
public UUID getId() {
return id;
}

View file

@ -1,10 +1,11 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.operations;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonProperty;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithId;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithResult;
public class OperationsRequest {
public class OperationsRequest implements WithId, WithResult {
@JsonProperty("id")
private UUID id;
@JsonProperty("result")
@ -12,6 +13,7 @@ public class OperationsRequest {
@JsonProperty("description")
private String description;
@Override
public UUID getId() {
return id;
}
@ -20,6 +22,7 @@ public class OperationsRequest {
this.id = id;
}
@Override
public Boolean getResult() {
return result;
}

View file

@ -0,0 +1,46 @@
package ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request;
import com.fasterxml.jackson.annotation.JsonProperty;
public class TkrError {
@JsonProperty("trading_code")
private Integer tradingCode;
@JsonProperty("client_code")
private String clientCode;
@JsonProperty("tkr_code")
private String tkrCode;
@JsonProperty("error_message")
private String errorMessage;
public Integer getTradingCode() {
return tradingCode;
}
public void setTradingCode(Integer tradingCode) {
this.tradingCode = tradingCode;
}
public String getClientCode() {
return clientCode;
}
public void setClientCode(String clientCode) {
this.clientCode = clientCode;
}
public String getTkrCode() {
return tkrCode;
}
public void setTkrCode(String tkrCode) {
this.tkrCode = tkrCode;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
}

View file

@ -6,8 +6,10 @@ 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;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithId;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithResult;
public class TkrRequest {
public class TkrRequest implements WithId, WithResult {
@JsonProperty("id")
private UUID id;
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
@ -17,7 +19,12 @@ public class TkrRequest {
private String type;
@JsonProperty("sent_info_accounts")
private List<InfoAccount> infoAccount;
@JsonProperty("errors")
private List<TkrError> errors;
@JsonProperty("result")
private Boolean result;
@Override
public UUID getId() {
return id;
}
@ -49,4 +56,22 @@ public class TkrRequest {
public void setInfoAccount(List<InfoAccount> infoAccount) {
this.infoAccount = infoAccount;
}
public List<TkrError> getErrors() {
return errors;
}
public void setErrors(List<TkrError> errors) {
this.errors = errors;
}
@Override
public Boolean getResult() {
return result;
}
public void setResult(Boolean result) {
this.result = result;
}
}

View file

@ -1,14 +1,14 @@
package ru.spcex.clearing.gatewayapi.controller.outbound.response;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithId;
public class ErrorResponse {
public class ErrorResponse implements WithId {
@JsonProperty("id")
private UUID id;
@JsonProperty("message")
@ -22,6 +22,7 @@ public class ErrorResponse {
unknownProperties.put(key, value);
}
@Override
public UUID getId() {
return id;
}

View file

@ -1,11 +1,16 @@
package ru.spcex.clearing.gatewayapi.service;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import ru.clearing.classes.statics.data.register.GatewayResult;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithId;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.WithResult;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.limit.LimitRequest;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.operations.OperationsRequest;
import ru.spcex.clearing.gatewayapi.controller.outbound.request.OutboundRequest;
import ru.spcex.clearing.gatewayapi.controller.outbound.response.ErrorResponse;
import ru.spcex.clearing.gatewayapi.enums.OutboundRequestType;
@ -20,11 +25,6 @@ import ru.spcex.platform.enumeration.ResultStatuses;
import ru.spcex.platform.imdg.api.Imdg;
import ru.spcex.platform.imdg.api.ImdgProvider;
import java.time.Instant;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Service
public class NotificationService {
private final Logger log = LoggerFactory.getLogger(getClass());
@ -50,9 +50,9 @@ public class NotificationService {
return;
}
log.info("Receive request: uuid = {}, file = {} with result = {} and sending section = {}.",
request.getId(), request.getLogFile(), request.getResult(), outboundReq.getSection());
request.getId(), request.getLogFile(), request.getResult(), outboundReq.getSection());
updateGatewayResultInMap(request);
sendToJournal(request);
newRequest.setObjectType(ObjectType.rgst.getKey());
newRequest.setComment(request.getDescription());
@ -67,63 +67,12 @@ public class NotificationService {
kafkaSender.sendRequestToQueue(Consts.NOTIFICATION_NEW, newRequest);
}
public void updateGatewayResultInMap(LimitRequest request) {
if (request.getId() == null || request.getResult() == null) {
log.warn("GatewayResult not found because LimitRequest not valid: {}", LogFormatter.toString(request));
return;
}
GatewayResult gatewayResult = gatewayResultImdg.getFirstObjectByFieldValues(Map.of("requestId", request.getId().toString()));
if (gatewayResult == null) {
log.warn("GatewayResult by requestId = {} not found in map", request.getId().toString());
return;
}
gatewayResult.setUpdated(Instant.now());
gatewayResult.setGatewayResultStatus(request.getResult() ? ResultStatuses.success.getKey() : ResultStatuses.notSuccess.getKey());
gatewayResult.setResult(LogFormatter.toString(request));
gatewayResultImdg.update(gatewayResult);
log.info("Updated gatewayResult: {} in map", LogFormatter.toString(gatewayResult));
}
public void updateGatewayResultInMap(OperationsRequest request) {
if (request.getId() == null || request.getResult() == null) {
log.warn("GatewayResult not found because OperationsRequest not valid: {}", LogFormatter.toString(request));
return;
}
GatewayResult gatewayResult = gatewayResultImdg.getFirstObjectByFieldValues(Map.of("requestId", request.getId().toString()));
if (gatewayResult == null) {
log.warn("GatewayResult by requestId = {} not found in map", request.getId().toString());
return;
}
gatewayResult.setUpdated(Instant.now());
gatewayResult.setGatewayResultStatus(request.getResult() ? ResultStatuses.success.getKey() : ResultStatuses.notSuccess.getKey());
gatewayResult.setResult(LogFormatter.toString(request));
gatewayResultImdg.update(gatewayResult);
log.info("Updated gatewayResult: {} in map", LogFormatter.toString(gatewayResult));
}
public void updateGatewayResultInMap(ErrorResponse response) {
if (response.getId() == null) {
log.warn("GatewayResult not found because OperationsRequest not valid: {}", LogFormatter.toString(response));
return;
}
GatewayResult gatewayResult = gatewayResultImdg.getFirstObjectByFieldValues(Map.of("requestId", response.getId().toString()));
if (gatewayResult == null) {
log.warn("GatewayResult by requestId = {} not found in map", response.getId().toString());
return;
}
gatewayResult.setUpdated(Instant.now());
gatewayResult.setGatewayResultStatus(ResultStatuses.notSuccess.getKey());
gatewayResult.setResult(LogFormatter.toString(response));
gatewayResultImdg.update(gatewayResult);
log.info("Updated gatewayResult: {} in map", LogFormatter.toString(gatewayResult));
}
public void sendErrorNotification(ErrorResponse response, OutboundRequest request) {
NotificationNewRequest newRequest = new NotificationNewRequest();
updateGatewayResultInMap(response);
sendErrorToJournal(response);
if (OutboundRequestType.FILL_LIMITS.equalsByKey(request.getType()) && request.getContent() != null && request.getContent().size() > 0)
log.info("Receive ErrorResponse: uuid = {}, file = {}, sending type = {} and section = {}.",
response.getId(), request.getContent().get("file"), request.getType(), request.getSection());
response.getId(), request.getContent().get("file"), request.getType(), request.getSection());
else
log.info("Receive ErrorResponse: uuid = {}, sending type = {} and section = {}.", response.getId(), request.getType(), request.getSection());
newRequest.setObjectType(ObjectType.rgst.getKey());
@ -133,6 +82,35 @@ public class NotificationService {
kafkaSender.sendRequestToQueue(Consts.NOTIFICATION_NEW, newRequest);
}
public <T extends WithId & WithResult> void sendToJournal(T request) {
if (request.getResult() == null) {
log.warn("GatewayResult not found because LimitRequest not valid: {}", LogFormatter.toString(request));
return;
}
updateResult(request, ResultStatuses.successOrNot(request.getResult()));
}
public void sendErrorToJournal(ErrorResponse response) {
updateResult(response, ResultStatuses.notSuccess);
}
private <T extends WithId> void updateResult(T request, ResultStatuses resultStatus) {
if (request.getId() == null) {
log.warn("Request without id: {}; skipping...", LogFormatter.toString(request));
return;
}
GatewayResult gatewayResult = gatewayResultImdg.getFirstObjectByFieldValues(Map.of("requestId", request.getId().toString()));
if (gatewayResult == null) {
log.warn("GatewayResult by requestId = {} not found in map", request.getId().toString());
return;
}
gatewayResult.setUpdated(Instant.now());
gatewayResult.setGatewayResultStatus(resultStatus.getKey());
gatewayResult.setResult(LogFormatter.toString(request).substring(0, 1000));
gatewayResultImdg.update(gatewayResult);
log.info("Updated gatewayResult: {} in map", LogFormatter.toString(gatewayResult));
}
public boolean canProcess(String type) {
return supportedTypes.contains(type);
}

View file

@ -23,6 +23,9 @@ public class TkrService {
}
public void processedTkrRequest(TkrRequest tkrRequest) {
if (!tkrRequest.getErrors().isEmpty()) {
return;
}
List<TkrAccount> tkrAccountsForCheck = tkrRequest.getInfoAccount()
.stream().filter(infoAccount -> TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()))
.map(tkrAdapter::toTkrResponse)

View file

@ -19,4 +19,8 @@ public enum ResultStatuses implements IEnumKey {
public String getKey() {
return key;
}
public static ResultStatuses successOrNot(final Boolean val){
return val ? ResultStatuses.success : ResultStatuses.notSuccess;
}
}