This commit is contained in:
parent
b8a4b114fa
commit
e51ac0d819
1 changed files with 27 additions and 17 deletions
|
|
@ -1,8 +1,11 @@
|
|||
package ru.spcex.clearing.gatewayapi.service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
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.TkrRequest;
|
||||
import ru.spcex.clearing.gatewayapi.enums.TypeOperations;
|
||||
import ru.spcex.clearing.gatewayapi.service.adapter.TkrAdapter;
|
||||
|
|
@ -10,9 +13,11 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccount;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.TkrAccountsGatewayRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
@Service
|
||||
public class TkrService {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final KafkaSender kafkaSender;
|
||||
private final TkrAdapter tkrAdapter;
|
||||
|
||||
|
|
@ -29,23 +34,28 @@ public class TkrService {
|
|||
if (tkrRequest.getInfoAccount() == null || tkrRequest.getInfoAccount().isEmpty()) {
|
||||
return;
|
||||
}
|
||||
List<TkrAccount> tkrAccountsForCheck = tkrRequest.getInfoAccount()
|
||||
.stream().filter(infoAccount -> TypeOperations.CHECK.equalsByKey(infoAccount.getTypeOperationClient()))
|
||||
.map(tkrAdapter::toTkrResponse)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
List<TkrAccount> tkrAccountsForNew = tkrRequest.getInfoAccount()
|
||||
.stream().filter(infoAccount -> TypeOperations.ADD.equalsByKey(infoAccount.getTypeOperationClient()))
|
||||
.map(tkrAdapter::toTkrResponse)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
|
||||
List<TkrAccount> tkrAccountsForUpdate = tkrRequest.getInfoAccount()
|
||||
.stream().filter(infoAccount -> TypeOperations.UPDATE.equalsByKey(infoAccount.getTypeOperationClient()))
|
||||
.map(tkrAdapter::toTkrResponse)
|
||||
.filter(Objects::nonNull)
|
||||
.toList();
|
||||
List<TkrAccount> tkrAccountsForCheck = new ArrayList<>();
|
||||
List<TkrAccount> tkrAccountsForNew = new ArrayList<>();
|
||||
List<TkrAccount> tkrAccountsForUpdate = new ArrayList<>();
|
||||
for (InfoAccount infoAccount : tkrRequest.getInfoAccount()) {
|
||||
TypeOperations typeOperations = IEnumKey.getEnumByKey(TypeOperations.class, infoAccount.getTypeOperationClient());
|
||||
if (typeOperations == null) {
|
||||
log.warn("operation_client_code is not undefined for company_id: {}...skip", infoAccount.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
TkrAccount tkrAccount = tkrAdapter.toTkrResponse(infoAccount);
|
||||
if (tkrAccount == null) {
|
||||
log.warn("Cannot convert info_account to TkrAccount for company_id: {}...skip", infoAccount.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
switch (typeOperations) {
|
||||
case CHECK -> tkrAccountsForCheck.add(tkrAccount);
|
||||
case ADD -> tkrAccountsForNew.add(tkrAccount);
|
||||
case UPDATE -> tkrAccountsForUpdate.add(tkrAccount);
|
||||
default -> log.warn("unsupported operation_client_code {}...skip", typeOperations);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tkrAccountsForCheck.isEmpty()) {
|
||||
TkrAccountsGatewayRequest tkrAccountsRequest = new TkrAccountsGatewayRequest();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue