add new fields

This commit is contained in:
etreschenkov 2024-05-31 11:45:02 +03:00
parent 69e815f984
commit 224179a9e1
7 changed files with 75 additions and 5 deletions

View file

@ -4,6 +4,8 @@ import java.util.List;
import com.fasterxml.jackson.annotation.JsonProperty;
public class InfoAccount {
@JsonProperty("type_operation_client")
private String typeOperationClient;
@JsonProperty("company_id")
private String companyId;
@JsonProperty("trading_code")
@ -19,6 +21,14 @@ public class InfoAccount {
@JsonProperty("money_account")
private List<MoneyAccount> moneyAccounts;
public String getTypeOperationClient() {
return typeOperationClient;
}
public void setTypeOperationClient(String typeOperationClient) {
this.typeOperationClient = typeOperationClient;
}
public String getCompanyId() {
return companyId;
}

View file

@ -7,6 +7,8 @@ public class MoneyAccount {
private String currCode;
@JsonProperty("account")
private String account;
@JsonProperty("status")
private String status;
public String getCurrCode() {
return currCode;
@ -23,4 +25,12 @@ public class MoneyAccount {
public void setAccount(String account) {
this.account = account;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
}

View file

@ -0,0 +1,25 @@
package ru.spcex.clearing.gatewayapi.enums;
import ru.spcex.platform.utils.enumeration.IEnumKey;
public enum TypeOperations implements IEnumKey{
CHECK("CHECK"),
ADD("ADD"),
UPDATE("UPD");
private final String key;
TypeOperations(String key) {
this.key = key;
}
@Override
public String getKey() {
return this.key;
}
@Override
public boolean equalsByKey(String key) {
return IEnumKey.super.equalsByKey(key);
}
}

View file

@ -1,9 +1,10 @@
package ru.spcex.clearing.gatewayapi.service;
import java.util.List;
import java.util.Objects;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import ru.spcex.clearing.gatewayapi.controller.inbound.request.tkr.request.TkrRequest;
import ru.spcex.clearing.gatewayapi.enums.TypeOperations;
import ru.spcex.clearing.gatewayapi.service.adapter.TkrAdapter;
import ru.spcex.clearing.platform.messaging.domain.Consts;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
@ -23,12 +24,16 @@ public class TkrService {
public void processedTkrRequest(TkrRequest tkrRequest) {
List<TkrAccount> tkrAccountsForCheck = tkrRequest.getInfoAccount()
.stream().filter(infoAccount -> !StringUtils.hasText(infoAccount.getClientCode()))
.map(tkrAdapter::toTkrResponse).toList();
.stream().filter(infoAccount -> TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()))
.map(tkrAdapter::toTkrResponse)
.filter(Objects::nonNull)
.toList();
List<TkrAccount> tkrAccountsForNew = tkrRequest.getInfoAccount()
.stream().filter(infoAccount -> !StringUtils.hasText(infoAccount.getTkrCode()))
.map(tkrAdapter::toTkrResponse).toList();
.stream().filter(infoAccount -> TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()))
.map(tkrAdapter::toTkrResponse)
.filter(Objects::nonNull)
.toList();
if (!tkrAccountsForCheck.isEmpty()) {
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();

View file

@ -1,22 +1,38 @@
package ru.spcex.clearing.gatewayapi.service.adapter;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
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.gatewayapi.enums.TypeOperations;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsg;
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
@Service
public class TkrAdapter {
private final Logger log = LoggerFactory.getLogger(getClass());
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());
if (TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()) &&
!StringUtils.hasText(infoAccount.getTkrCode())){
log.warn("For check action trk_code is required, skip this account.client_code: {}", infoAccount.getClientCode());
return null;
}
if (TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()) &&
!StringUtils.hasText(infoAccount.getClientCode())){
log.warn("For check action client_code is required, skip this account.tkr_code: {}", infoAccount.getTkrCode());
return null;
}
tkrResponse.setTkrCode(infoAccount.getTkrCode());
tkrResponse.setDepoAccount(infoAccount.getDepoAccount());
if (infoAccount.getMoneyAccounts() != null) {
List<MoneyAccountMsg> moneyAccountMsgs = infoAccount.getMoneyAccounts().stream()
.map(this::toMoneyAccountMsg).toList();

View file

@ -5,6 +5,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
import ru.spcex.clearing.platform.messaging.domain.cud.gateway.MoneyAccountMsg;
public class TkrAccount {
@JsonProperty
private String typeOperationClient;
@JsonProperty
private String companyId;
@JsonProperty

View file

@ -7,6 +7,8 @@ public class MoneyAccountMsg {
private String currCode;
@JsonProperty("account")
private String account;
@JsonProperty("status")
private String status;
public String getCurrCode() {
return currCode;