add create info account, fix from TT, deprecate some methods
This commit is contained in:
parent
202feebf0c
commit
2dc844ba3f
15 changed files with 547 additions and 97 deletions
|
|
@ -0,0 +1,60 @@
|
||||||
|
package ru.spcex.clearing.account.config.validation;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.spcex.clearing.account.errors.AccountError;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||||
|
import ru.spcex.clearing.validation.common.rules.IdPresentRule;
|
||||||
|
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||||
|
import ru.spcex.platform.enumeration.WorkflowStatus;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.validation.ImdgValidationContext;
|
||||||
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
import ru.spcex.platform.utils.validation.ValidatorImpl;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Configuration
|
||||||
|
public class InformationAccountValidationConfig {
|
||||||
|
|
||||||
|
@Bean("informationAccountNewRequestValidator")
|
||||||
|
public Function<InformationAccountNewRequest, IValidator> informationAccountNewRequestValidator(
|
||||||
|
Map<String, Imdg<? extends SpcexObjectBase>> imdgForValidation
|
||||||
|
) {
|
||||||
|
return informationAccountNewRequest -> {
|
||||||
|
ImdgValidationContext<InformationAccountNewRequest> context = new ImdgValidationContext<>();
|
||||||
|
context.setValidatedObject(informationAccountNewRequest);
|
||||||
|
Consumer<String> addImdg = (s) -> context.addImdg(s, imdgForValidation.get(s));
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_Company);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_InformationAccount);
|
||||||
|
return new ValidatorImpl<>(context,
|
||||||
|
IdPresentRule.instance("companyId",
|
||||||
|
InformationAccountNewRequest::getCompanyId,
|
||||||
|
IMDGDistributedNames.Map_Company,
|
||||||
|
Company.class,
|
||||||
|
AccountError.RequiredFieldEmpty,
|
||||||
|
AccountError.CompanyNotFound,
|
||||||
|
company -> {
|
||||||
|
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus()))
|
||||||
|
return AccountError.CompanyNotActive;
|
||||||
|
Long companyId = company.getId();
|
||||||
|
Imdg<InformationAccount> informationAccountImdg = context.obtainMap(
|
||||||
|
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||||
|
);
|
||||||
|
Collection<InformationAccount> infoAccounts = informationAccountImdg.getCollectionObjectsByFieldValues(
|
||||||
|
Map.of("companyId", companyId)
|
||||||
|
);
|
||||||
|
if (infoAccounts.isEmpty()) return null;
|
||||||
|
return AccountError.InfoAccountAlreadyExist;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -6,6 +6,7 @@ import org.springframework.context.annotation.Configuration;
|
||||||
import ru.clearing.classes.statics.data.account.Account;
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||||
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
import ru.clearing.classes.statics.data.account.ClearingAccount;
|
||||||
|
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||||
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
||||||
|
|
@ -31,6 +32,7 @@ public class ValidationConfig {
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
addImdg.accept(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
addImdg.accept(IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
addImdg.accept(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
|
addImdg.accept(IMDGDistributedNames.Map_InformationAccount, InformationAccount.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary, Account.class);
|
addImdg.accept(IMDGDistributedNames.Map_AccountTypeDictionary, Account.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
addImdg.accept(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||||
addImdg.accept(IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class);
|
addImdg.accept(IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class);
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public enum AccountError implements IErrorEnumId {
|
||||||
AccountNotActive(5012L),
|
AccountNotActive(5012L),
|
||||||
CompanyNotFound(5013L),
|
CompanyNotFound(5013L),
|
||||||
CompanyNotActive(5014L),
|
CompanyNotActive(5014L),
|
||||||
|
InfoAccountAlreadyExist(5015L),
|
||||||
ClearingCategoryNotFound(5019L)
|
ClearingCategoryNotFound(5019L)
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||||
import ru.spcex.clearing.util.security.UserRoleVerification;
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
import ru.spcex.platform.enumeration.AccountStatus;
|
import ru.spcex.platform.enumeration.AccountStatus;
|
||||||
import ru.spcex.platform.enumeration.Allowed;
|
|
||||||
import ru.spcex.platform.enumeration.ClearingCategory;
|
import ru.spcex.platform.enumeration.ClearingCategory;
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
@ -44,7 +43,6 @@ import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
|
|
@ -98,7 +96,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
public void afterPropertiesSet() {
|
public void afterPropertiesSet() {
|
||||||
callback(AccountSdf01Request.class)
|
callback(AccountSdf01Request.class)
|
||||||
.setConsumer(this::accountNewSdf01)
|
.setConsumer(this::accountNewSdf01)
|
||||||
.forDestination(Consts.CLEARING_ACCOUNT_NEW_SDF01, callbacks::put);
|
.forDestination(Consts.ACCOUNT_NEW_SDF01, callbacks::put);
|
||||||
callback(CorrespondentAccountNewRequest.class)
|
callback(CorrespondentAccountNewRequest.class)
|
||||||
.setConsumer(this::accountCorrespondentNew)
|
.setConsumer(this::accountCorrespondentNew)
|
||||||
.forDestination(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_NEW, callbacks::put);
|
.forDestination(Consts.DESTINATION_CORRESPONDENT_ACCOUNT_NEW, callbacks::put);
|
||||||
|
|
@ -111,6 +109,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public RequestInfoUpdate accountCorrespondentNew(BaseRequest<CorrespondentAccountNewRequest> userRequest) {
|
public RequestInfoUpdate accountCorrespondentNew(BaseRequest<CorrespondentAccountNewRequest> userRequest) {
|
||||||
log.debug("CorrespondentAccountNewRequest received");
|
log.debug("CorrespondentAccountNewRequest received");
|
||||||
|
|
||||||
|
|
@ -122,51 +121,20 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
|
|
||||||
CorrespondentAccountNewRequest req = userRequest.getRequestPayload();
|
CorrespondentAccountNewRequest req = userRequest.getRequestPayload();
|
||||||
|
|
||||||
Long companyId = req.getCompanyId();
|
|
||||||
ImdgPredicateBuilder clearingMemberCategoryPredicateBuilder = clearingMemberCategoryMap.predicateBuilder();
|
|
||||||
ImdgPredicate companyIdEquals = clearingMemberCategoryPredicateBuilder.equals("companyId", companyId);
|
|
||||||
Collection<ClearingMemberCategory> clearingMemberCategories = clearingMemberCategoryMap.getCollectionObjectsByPredicate(companyIdEquals);
|
|
||||||
|
|
||||||
if (clearingMemberCategories.isEmpty())
|
|
||||||
return makeError(AccountError.ClearingCategoryNotFound, "clearingMemberCategory[companyId]", userRequest.getId());
|
|
||||||
if (clearingMemberCategories.size() > 1)
|
|
||||||
log.warn("ClearingMemberCategory for companyId {} contains multiply elements, use first", companyId);
|
|
||||||
ClearingMemberCategory clearingMemberCategory = clearingMemberCategories.iterator().next();
|
|
||||||
|
|
||||||
ImdgPredicateBuilder relationPredicateBuilder = relationMap.predicateBuilder();
|
|
||||||
ImdgPredicate consumerIdPredicate = relationPredicateBuilder.equals("consumerId", companyId);
|
|
||||||
ImdgPredicate servicePredicate = null;
|
|
||||||
String clearingCategoryValue = clearingMemberCategory.getClearingMemberCategory();
|
|
||||||
if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.B, ClearingCategory.I, ClearingCategory.V)) {
|
|
||||||
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.MKR.getKey());
|
|
||||||
} else if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.F, ClearingCategory.C)) {
|
|
||||||
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.FOND.getKey());
|
|
||||||
} else {
|
|
||||||
return makeError(AccountError.ClearingCategoryNotFound, "relation[consumerId = companyId].service", userRequest.getId());
|
|
||||||
}
|
|
||||||
ImdgPredicate finalRelationPredicate = relationPredicateBuilder.and(consumerIdPredicate, servicePredicate);
|
|
||||||
Collection<Relation> relations = relationMap.getCollectionObjectsByPredicate(finalRelationPredicate);
|
|
||||||
|
|
||||||
if (relations.isEmpty()) return makeError(AccountError.WrongFieldValue, "companyId", userRequest.getId());
|
|
||||||
if (relations.size() > 1)
|
|
||||||
log.warn("Relation for consumerId {} contains multiply elements, use first", companyId);
|
|
||||||
Relation relation = relations.iterator().next();
|
|
||||||
|
|
||||||
Collection<Account> companies = accountMap.getCollectionObjectsByFieldValues(Map.of("companyId", companyId));
|
|
||||||
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
|
account.setCompanyId(req.getCompanyId());
|
||||||
account.setAccount(req.getAccount());
|
account.setAccount(req.getAccount());
|
||||||
account.setAccountType(req.getAccountType());
|
account.setAccountType(req.getAccountType());
|
||||||
account.setRelationId(relation.getId());
|
|
||||||
account.setStatus(req.getStatus());
|
account.setStatus(req.getStatus());
|
||||||
account.setProcessingSign(companies.isEmpty() ? Allowed.ALLOWED.getKey() : Allowed.DENIED.getKey());
|
|
||||||
account.setCompanyId(relation.getConsumerId());
|
|
||||||
account.setCreated(now);
|
account.setCreated(now);
|
||||||
account.setUpdated(now);
|
account.setUpdated(now);
|
||||||
Long id = accountMap.insert(account);
|
|
||||||
|
|
||||||
log.debug("successfully processed, new account id {}", id);
|
requestInfoUpdate = fillAccountFromRelation(account, userRequest.getId());
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
Long newId = accountMap.insert(account);
|
||||||
|
log.debug("successfully processed, new account id {}", newId);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -214,6 +182,7 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public RequestInfoUpdate accountNewSdf01(BaseRequest<AccountSdf01Request> userRequest) {
|
public RequestInfoUpdate accountNewSdf01(BaseRequest<AccountSdf01Request> userRequest) {
|
||||||
log.debug("AccountSdf01Request received");
|
log.debug("AccountSdf01Request received");
|
||||||
|
|
||||||
|
|
@ -255,6 +224,46 @@ public class AccountService extends QueueConsumer implements InitializingBean {
|
||||||
kafkaSender.sendRequestToQueue(Consts.STATEMENT_PROCESS, request);
|
kafkaSender.sendRequestToQueue(Consts.STATEMENT_PROCESS, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Заполняет поля relationId и companyId из соответствующей записи Relation
|
||||||
|
*
|
||||||
|
* @param requestId Идентификатор запроса для вывода лога
|
||||||
|
*/
|
||||||
|
public RequestInfoUpdate fillAccountFromRelation(Account account, Long requestId) {
|
||||||
|
Long companyId = account.getCompanyId();
|
||||||
|
ImdgPredicateBuilder clearingMemberCategoryPredicateBuilder = clearingMemberCategoryMap.predicateBuilder();
|
||||||
|
ImdgPredicate companyIdEquals = clearingMemberCategoryPredicateBuilder.equals("companyId", companyId);
|
||||||
|
Collection<ClearingMemberCategory> clearingMemberCategories = clearingMemberCategoryMap.getCollectionObjectsByPredicate(companyIdEquals);
|
||||||
|
|
||||||
|
if (clearingMemberCategories.isEmpty())
|
||||||
|
return makeError(AccountError.ClearingCategoryNotFound, "clearingMemberCategory[companyId]", requestId);
|
||||||
|
if (clearingMemberCategories.size() > 1)
|
||||||
|
log.warn("ClearingMemberCategory for companyId {} contains multiply elements, use first", companyId);
|
||||||
|
ClearingMemberCategory clearingMemberCategory = clearingMemberCategories.iterator().next();
|
||||||
|
|
||||||
|
ImdgPredicateBuilder relationPredicateBuilder = relationMap.predicateBuilder();
|
||||||
|
ImdgPredicate consumerIdPredicate = relationPredicateBuilder.equals("consumerId", companyId);
|
||||||
|
ImdgPredicate servicePredicate;
|
||||||
|
String clearingCategoryValue = clearingMemberCategory.getClearingMemberCategory();
|
||||||
|
if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.B, ClearingCategory.I, ClearingCategory.V)) {
|
||||||
|
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.MKR.getKey());
|
||||||
|
} else if (IEnumKey.contains(clearingCategoryValue, ClearingCategory.F, ClearingCategory.C)) {
|
||||||
|
servicePredicate = relationPredicateBuilder.equals("service", ru.spcex.platform.enumeration.Service.FOND.getKey());
|
||||||
|
} else {
|
||||||
|
return makeError(AccountError.ClearingCategoryNotFound, "relation[consumerId = companyId].service", requestId);
|
||||||
|
}
|
||||||
|
ImdgPredicate finalRelationPredicate = relationPredicateBuilder.and(consumerIdPredicate, servicePredicate);
|
||||||
|
Collection<Relation> relations = relationMap.getCollectionObjectsByPredicate(finalRelationPredicate);
|
||||||
|
|
||||||
|
if (relations.isEmpty()) return makeError(AccountError.WrongFieldValue, "companyId", requestId);
|
||||||
|
if (relations.size() > 1)
|
||||||
|
log.warn("Relation for consumerId {} contains multiply elements, use first", companyId);
|
||||||
|
Relation relation = relations.iterator().next();
|
||||||
|
account.setRelationId(relation.getId());
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private RequestInfoUpdate makeError(AccountError accountError, String fieldName, Long reqId) {
|
private RequestInfoUpdate makeError(AccountError accountError, String fieldName, Long reqId) {
|
||||||
String errMsg = messageResolver.resolve(new EnumMessage(accountError, fieldName));
|
String errMsg = messageResolver.resolve(new EnumMessage(accountError, fieldName));
|
||||||
return new RequestInfoUpdate()
|
return new RequestInfoUpdate()
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,6 @@ import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import ru.clearing.classes.statics.data.account.Account;
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||||
import ru.clearing.classes.statics.data.company.relation.Relation;
|
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
|
@ -23,9 +22,9 @@ import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
import ru.spcex.clearing.validation.common.ValidationHelper;
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
import ru.spcex.platform.enumeration.AccountStatus;
|
import ru.spcex.platform.enumeration.AccountStatus;
|
||||||
import ru.spcex.platform.enumeration.AccountType;
|
import ru.spcex.platform.enumeration.AccountType;
|
||||||
import ru.spcex.platform.enumeration.Allowed;
|
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||||
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
import ru.spcex.platform.utils.validation.IValidator;
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
|
|
@ -37,13 +36,13 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
||||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
private final Imdg<BankAccount> bankAccountMap;
|
private final Imdg<BankAccount> bankAccountMap;
|
||||||
private final Imdg<Account> accountMap;
|
private final Imdg<Account> accountMap;
|
||||||
private final Imdg<Relation> relationMap;
|
private final ImdgProvider imdgProvider;
|
||||||
private final IMessageResolver messageResolver;
|
|
||||||
|
private final UserRoleVerification userRoleVerification;
|
||||||
|
private final ValidationHelper validationHelper;
|
||||||
|
|
||||||
|
private final AccountService accountService;
|
||||||
|
|
||||||
private UserRoleVerification userRoleVerification;
|
|
||||||
private ValidationHelper validationHelper;
|
|
||||||
// private final Imdg<User> userImdg;
|
|
||||||
// private final Imdg<UserRoleSession> userRoleSessionImdg;
|
|
||||||
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
private final Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator;
|
||||||
private final Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator;
|
private final Function<BankAccountUpdateRequest, IValidator> bankAccountUpdateRequestValidator;
|
||||||
private final Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator;
|
private final Function<CommonDeleteRequest, IValidator> bankAccountDeleteRequestValidator;
|
||||||
|
|
@ -55,6 +54,7 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
||||||
IMessageResolver messageResolver,
|
IMessageResolver messageResolver,
|
||||||
UserRoleVerification userRoleVerification,
|
UserRoleVerification userRoleVerification,
|
||||||
ValidationHelper validationHelper,
|
ValidationHelper validationHelper,
|
||||||
|
AccountService accountService,
|
||||||
@Qualifier("bankAccountNewRequestValidator")
|
@Qualifier("bankAccountNewRequestValidator")
|
||||||
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator,
|
Function<BankAccountNewRequest, IValidator> bankAccountNewRequestValidator,
|
||||||
@Qualifier("bankAccountUpdateRequestValidator")
|
@Qualifier("bankAccountUpdateRequestValidator")
|
||||||
|
|
@ -64,10 +64,10 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
||||||
super(kafkaQueue, kafkaProducer);
|
super(kafkaQueue, kafkaProducer);
|
||||||
this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class);
|
||||||
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
this.accountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
this.relationMap = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class);
|
this.imdgProvider = imdgProvider;
|
||||||
this.messageResolver = messageResolver;
|
|
||||||
this.userRoleVerification = userRoleVerification;
|
this.userRoleVerification = userRoleVerification;
|
||||||
this.validationHelper = validationHelper;
|
this.validationHelper = validationHelper;
|
||||||
|
this.accountService = accountService;
|
||||||
this.bankAccountNewRequestValidator = bankAccountNewRequestValidator;
|
this.bankAccountNewRequestValidator = bankAccountNewRequestValidator;
|
||||||
this.bankAccountUpdateRequestValidator = bankAccountUpdateRequestValidator;
|
this.bankAccountUpdateRequestValidator = bankAccountUpdateRequestValidator;
|
||||||
this.bankAccountDeleteRequestValidator = bankAccountDeleteRequestValidator;
|
this.bankAccountDeleteRequestValidator = bankAccountDeleteRequestValidator;
|
||||||
|
|
@ -99,44 +99,52 @@ public class BankAccountService extends QueueConsumer implements InitializingBea
|
||||||
|
|
||||||
BankAccountNewRequest req = userRequest.getRequestPayload();
|
BankAccountNewRequest req = userRequest.getRequestPayload();
|
||||||
|
|
||||||
Long relationId = null;
|
|
||||||
Long consumerId = null;
|
|
||||||
String relationSqlCondition = String.format("consumerId = %s and service = %s", req.companyId,
|
|
||||||
ru.spcex.platform.enumeration.Service.MKR.getKey());
|
|
||||||
Relation relationByCompany = relationMap.getSingleObjectBySQL(relationSqlCondition);
|
|
||||||
if (relationByCompany != null) {
|
|
||||||
relationId = relationByCompany.getId();
|
|
||||||
consumerId = relationByCompany.getConsumerId();
|
|
||||||
} else {
|
|
||||||
log.warn("Not found relation by condition: {}", relationSqlCondition);
|
|
||||||
}
|
|
||||||
|
|
||||||
Instant now = Instant.now();
|
Instant now = Instant.now();
|
||||||
Account account = new Account();
|
Account account = new Account();
|
||||||
account.setAccount(req.getAccount());
|
account.setAccount(req.getAccount());
|
||||||
account.setAccountType(AccountType.Bank.getKey());
|
account.setAccountType(AccountType.Bank.getKey());
|
||||||
account.setStatus(AccountStatus.ACTIVE.getKey());
|
account.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
account.setRelationId(relationId);
|
account.setCompanyId(req.getCompanyId());
|
||||||
account.setCompanyId(consumerId);
|
|
||||||
account.setProcessingSign(Allowed.ALLOWED.getKey());
|
|
||||||
account.setCreated(now);
|
account.setCreated(now);
|
||||||
account.setUpdated(now);
|
account.setUpdated(now);
|
||||||
accountMap.insert(account);
|
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId());
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
BankAccount bankAccount = new BankAccount();
|
Long bankAccountId = -1L;
|
||||||
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
Long accountId = -1L;
|
||||||
bankAccount.setBankName(req.getBankName());
|
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||||
bankAccount.setCorrespondentAccount(req.getCorrespondentAccount());
|
boolean txOk = false;
|
||||||
bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName());
|
imdgTransaction.beginTransaction();
|
||||||
bankAccount.setCurrency(req.getCurrency());
|
try {
|
||||||
bankAccount.setDestination(req.getDestination());
|
accountId = accountMap.insert(account);
|
||||||
bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber());
|
|
||||||
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
|
BankAccount bankAccount = new BankAccount();
|
||||||
bankAccount.setAccount(req.getAccount());
|
bankAccount.setBankIdentificationCode(req.getBankIdentificationCode());
|
||||||
bankAccount.setCompanyId(req.getCompanyId());
|
bankAccount.setBankName(req.getBankName());
|
||||||
bankAccount.setAccountId(account.getId());
|
bankAccount.setCorrespondentAccount(req.getCorrespondentAccount());
|
||||||
Long bankAccountId = bankAccountMap.insert(bankAccount);
|
bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName());
|
||||||
log.debug("successfully processed, new id {}", bankAccountId);
|
bankAccount.setCurrency(req.getCurrency());
|
||||||
|
bankAccount.setDestination(req.getDestination());
|
||||||
|
bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber());
|
||||||
|
bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode());
|
||||||
|
bankAccount.setAccount(req.getAccount());
|
||||||
|
bankAccount.setCompanyId(req.getCompanyId());
|
||||||
|
bankAccount.setAccountId(account.getId());
|
||||||
|
bankAccountId = bankAccountMap.insert(bankAccount);
|
||||||
|
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk) {
|
||||||
|
imdgTransaction.commitTransaction();
|
||||||
|
log.debug("successfully processed, new bank account id {}, account id {}", bankAccountId, accountId);
|
||||||
|
} else {
|
||||||
|
// todo выяснить, что возвращать из метода в этой ситуации
|
||||||
|
log.debug("failed insert, new bank account id {}, new account id {} (if id = -1, insert is failed)",
|
||||||
|
bankAccountId,
|
||||||
|
accountId);
|
||||||
|
imdgTransaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,160 @@
|
||||||
|
package ru.spcex.clearing.account.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
|
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||||
|
import ru.spcex.clearing.account.errors.AccountError;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.Status;
|
||||||
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
|
import ru.spcex.clearing.validation.common.ValidationHelper;
|
||||||
|
import ru.spcex.platform.enumeration.AccountStatus;
|
||||||
|
import ru.spcex.platform.enumeration.AccountType;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgTransaction;
|
||||||
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicate;
|
||||||
|
import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
||||||
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
|
import ru.spcex.platform.utils.enumeration.IMessageResolver;
|
||||||
|
import ru.spcex.platform.utils.validation.IValidator;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class InformationAccountService extends QueueConsumer implements InitializingBean {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final IMessageResolver messageResolver;
|
||||||
|
private final ImdgProvider imdgProvider;
|
||||||
|
private final UserRoleVerification userRoleVerification;
|
||||||
|
private final ValidationHelper validationHelper;
|
||||||
|
private final AccountService accountService;
|
||||||
|
private final Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator;
|
||||||
|
private final Imdg<InformationAccount> informationAccountImdg;
|
||||||
|
private final Imdg<Account> accountImdg;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public InformationAccountService(Consumer<String, Object> kafkaQueue,
|
||||||
|
Producer<String, Object> kafkaResponseQueue,
|
||||||
|
IMessageResolver messageResolver,
|
||||||
|
ImdgProvider imdgProvider,
|
||||||
|
UserRoleVerification userRoleVerification,
|
||||||
|
ValidationHelper validationHelper,
|
||||||
|
AccountService accountService,
|
||||||
|
@Qualifier("informationAccountNewRequestValidator")
|
||||||
|
Function<InformationAccountNewRequest, IValidator> infoAccountNewRequestValidator) {
|
||||||
|
super(kafkaQueue, kafkaResponseQueue);
|
||||||
|
this.messageResolver = messageResolver;
|
||||||
|
this.imdgProvider = imdgProvider;
|
||||||
|
this.userRoleVerification = userRoleVerification;
|
||||||
|
this.validationHelper = validationHelper;
|
||||||
|
this.accountService = accountService;
|
||||||
|
this.infoAccountNewRequestValidator = infoAccountNewRequestValidator;
|
||||||
|
this.informationAccountImdg = imdgProvider.getImdg(
|
||||||
|
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||||
|
);
|
||||||
|
this.accountImdg = imdgProvider.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Account, Account.class
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
callback(InformationAccountNewRequest.class)
|
||||||
|
.setConsumer(this::informationAccountNew)
|
||||||
|
.forDestination(Consts.DESTINATION_INFORMATION_ACCOUNT_NEW, callbacks::put);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestInfoUpdate informationAccountNew(BaseRequest<InformationAccountNewRequest> userRequest) {
|
||||||
|
log.debug("InformationAccountNewRequest received");
|
||||||
|
|
||||||
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
requestInfoUpdate = validationHelper.validateTillFirstError(userRequest, infoAccountNewRequestValidator);
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
Long newId = informationAccountImdg.nextIDSequenceFor();
|
||||||
|
String accountValue = generateInfoAccount(newId);
|
||||||
|
|
||||||
|
// todo уточнить у репортера
|
||||||
|
ImdgPredicateBuilder accountPredicateBuilder = accountImdg.predicateBuilder();
|
||||||
|
ImdgPredicate companyIdPredicate = accountPredicateBuilder.equals("companyId", 1);
|
||||||
|
ImdgPredicate accountTypePredicate = accountPredicateBuilder.equals("accountType", AccountType.Anlt.getKey());
|
||||||
|
ImdgPredicate andPredicate = accountPredicateBuilder.and(companyIdPredicate, accountTypePredicate);
|
||||||
|
Collection<Account> accountsAnlt = accountImdg.getCollectionObjectsByPredicate(andPredicate);
|
||||||
|
if (accountsAnlt.isEmpty()) {
|
||||||
|
String errMsg = messageResolver.resolve(new EnumMessage(AccountError.WrongFieldValue, "clearingAccountId"));
|
||||||
|
return new RequestInfoUpdate()
|
||||||
|
.setId(userRequest.getId())
|
||||||
|
.setStatus(Status.Error)
|
||||||
|
.setMessage(errMsg);
|
||||||
|
} else if (accountsAnlt.size() > 1) {
|
||||||
|
log.warn("Account for companyId 1 and accountType=ANLT contains multiply elements, use first");
|
||||||
|
}
|
||||||
|
Account anltAccount = accountsAnlt.iterator().next();
|
||||||
|
|
||||||
|
Instant now = Instant.now();
|
||||||
|
Account account = new Account();
|
||||||
|
account.setAccount(accountValue);
|
||||||
|
account.setAccountType(AccountType.Info.getKey());
|
||||||
|
account.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
|
account.setCompanyId(userRequest.getRequestPayload().getCompanyId());
|
||||||
|
account.setCreated(now);
|
||||||
|
account.setUpdated(now);
|
||||||
|
requestInfoUpdate = accountService.fillAccountFromRelation(account, userRequest.getId());
|
||||||
|
if (requestInfoUpdate != null) return requestInfoUpdate;
|
||||||
|
|
||||||
|
ImdgTransaction imdgTransaction = imdgProvider.newTransaction();
|
||||||
|
imdgTransaction.beginTransaction();
|
||||||
|
boolean txOk = false;
|
||||||
|
Long informationAccountId = -1L;
|
||||||
|
Long accountId = -1L;
|
||||||
|
try {
|
||||||
|
accountId = accountImdg.insert(account);
|
||||||
|
|
||||||
|
InformationAccount informationAccount = new InformationAccount();
|
||||||
|
informationAccount.setId(newId);
|
||||||
|
informationAccount.setAccountId(accountId);
|
||||||
|
informationAccount.setClearingAccountId(anltAccount.getId());
|
||||||
|
informationAccount.setCompanyId(userRequest.getRequestPayload().getCompanyId());
|
||||||
|
informationAccountId = informationAccountImdg.insert(informationAccount);
|
||||||
|
txOk = true;
|
||||||
|
} finally {
|
||||||
|
if (txOk) {
|
||||||
|
imdgTransaction.commitTransaction();
|
||||||
|
log.debug("successfully processed, new information account id {}, new account id {}",
|
||||||
|
informationAccountId,
|
||||||
|
accountId);
|
||||||
|
} else {
|
||||||
|
// todo выяснить, что возвращать из метода в этой ситуации
|
||||||
|
log.debug("failed insert, new information account id {}, new account id {} (if id = -1, insert is failed)",
|
||||||
|
informationAccountId,
|
||||||
|
accountId);
|
||||||
|
imdgTransaction.rollbackTransaction();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String generateInfoAccount(Long id) {
|
||||||
|
return "%d%d%08d%d".formatted(39911, 810, id, 7000);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -67,7 +67,7 @@ class AccountServiceTest {
|
||||||
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
public static final MatcherFactory.Matcher<RequestInfo> REQUEST_INFO_MATCHER_MATCHER = usingIgnoringFieldsComparator("created");
|
public static final MatcherFactory.Matcher<RequestInfo> REQUEST_INFO_MATCHER_MATCHER = usingIgnoringFieldsComparator("created");
|
||||||
private static final int PARTITION = 0;
|
private static final int PARTITION = 0;
|
||||||
private static final String TOPIC_ACCOUNT_NEW = Consts.CLEARING_ACCOUNT_NEW_SDF01;
|
private static final String TOPIC_ACCOUNT_NEW = Consts.ACCOUNT_NEW_SDF01;
|
||||||
private static final String account = "123456789123";
|
private static final String account = "123456789123";
|
||||||
private static final Long companyId = 0L;
|
private static final Long companyId = 0L;
|
||||||
private static final Long relationId = 0L;
|
private static final Long relationId = 0L;
|
||||||
|
|
@ -143,7 +143,6 @@ class AccountServiceTest {
|
||||||
predictableAccount.setAccount(uniqueAccount);
|
predictableAccount.setAccount(uniqueAccount);
|
||||||
predictableAccount.setAccountType(AccountType.Corr.getKey());
|
predictableAccount.setAccountType(AccountType.Corr.getKey());
|
||||||
predictableAccount.setCompanyId(companyId);
|
predictableAccount.setCompanyId(companyId);
|
||||||
predictableAccount.setProcessingSign(Allowed.ALLOWED.getKey());
|
|
||||||
predictableAccount.setStatus(AccountStatus.ACTIVE.getKey());
|
predictableAccount.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
predictableAccount.setRelationId(relationId);
|
predictableAccount.setRelationId(relationId);
|
||||||
|
|
||||||
|
|
@ -167,17 +166,15 @@ class AccountServiceTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void accountCorrespondentUpdate() {
|
void accountCorrespondentUpdate() {
|
||||||
String updatedAccount = account + "_updated";
|
|
||||||
|
|
||||||
Account existAccount = new Account();
|
Account existAccount = new Account();
|
||||||
existAccount.setAccount(account);
|
existAccount.setAccount(account);
|
||||||
existAccount.setAccountType(AccountType.Corr.getKey());
|
existAccount.setAccountType(AccountType.Corr.getKey());
|
||||||
existAccount.setStatus(AccountStatus.ACTIVE.getKey());
|
existAccount.setStatus(AccountStatus.CLOSE.getKey());
|
||||||
existAccount.setCompanyId(companyId);
|
existAccount.setCompanyId(companyId);
|
||||||
Long accountId = accountImdg.insert(existAccount);
|
Long accountId = accountImdg.insert(existAccount);
|
||||||
|
|
||||||
CorrespondentAccountUpdateRequest correspondentAccountUpdateRequest = new CorrespondentAccountUpdateRequest();
|
CorrespondentAccountUpdateRequest correspondentAccountUpdateRequest = new CorrespondentAccountUpdateRequest();
|
||||||
correspondentAccountUpdateRequest.setAccount(updatedAccount);
|
correspondentAccountUpdateRequest.setAccount(account);
|
||||||
correspondentAccountUpdateRequest.setAccountType(AccountType.Corr.getKey());
|
correspondentAccountUpdateRequest.setAccountType(AccountType.Corr.getKey());
|
||||||
correspondentAccountUpdateRequest.setStatus(AccountStatus.ACTIVE.getKey());
|
correspondentAccountUpdateRequest.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
correspondentAccountUpdateRequest.setCompanyId(companyId);
|
correspondentAccountUpdateRequest.setCompanyId(companyId);
|
||||||
|
|
@ -196,8 +193,6 @@ class AccountServiceTest {
|
||||||
//ASSERT
|
//ASSERT
|
||||||
waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord);
|
waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord);
|
||||||
|
|
||||||
existAccount.setAccount(updatedAccount);
|
|
||||||
|
|
||||||
Account resultUpdating = accountImdg.getSingleObjectByID(accountId);
|
Account resultUpdating = accountImdg.getSingleObjectByID(accountId);
|
||||||
existAccount.setUpdated(resultUpdating.getUpdated());
|
existAccount.setUpdated(resultUpdating.getUpdated());
|
||||||
ACCOUNT_MATCHER.assertMatch(resultUpdating, existAccount);
|
ACCOUNT_MATCHER.assertMatch(resultUpdating, existAccount);
|
||||||
|
|
|
||||||
|
|
@ -15,11 +15,14 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.account.Account;
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
import ru.clearing.classes.statics.data.account.BankAccount;
|
import ru.clearing.classes.statics.data.account.BankAccount;
|
||||||
|
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||||
import ru.clearing.classes.statics.data.company.Company;
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||||
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
import ru.clearing.platform.dictionary.CurrencyCodeDictionary;
|
||||||
import ru.spcex.clearing.account.config.BeanConfiguration;
|
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||||
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
||||||
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
||||||
|
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||||
import ru.spcex.clearing.account.config.validation.BankAccountValidationConfig;
|
import ru.spcex.clearing.account.config.validation.BankAccountValidationConfig;
|
||||||
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||||
import ru.spcex.clearing.account.errors.AccountError;
|
import ru.spcex.clearing.account.errors.AccountError;
|
||||||
|
|
@ -32,10 +35,7 @@ import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountNewReq
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.BankAccountUpdateRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
import ru.spcex.clearing.platform.messaging.domain.cud.common.CommonDeleteRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
import ru.spcex.platform.enumeration.AccountType;
|
import ru.spcex.platform.enumeration.*;
|
||||||
import ru.spcex.platform.enumeration.Allowed;
|
|
||||||
import ru.spcex.platform.enumeration.Status;
|
|
||||||
import ru.spcex.platform.enumeration.WorkflowStatus;
|
|
||||||
import ru.spcex.platform.imdg.api.Imdg;
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
import ru.spcex.platform.utils.enumeration.EnumMessage;
|
||||||
|
|
@ -53,9 +53,11 @@ import static ru.spcex.clearing.platform.messaging.service.Status.Error;
|
||||||
|
|
||||||
@ExtendWith(SpringExtension.class)
|
@ExtendWith(SpringExtension.class)
|
||||||
@ContextConfiguration(classes = {
|
@ContextConfiguration(classes = {
|
||||||
|
AccountService.class,
|
||||||
BankAccountService.class,
|
BankAccountService.class,
|
||||||
ValidationConfig.class,
|
ValidationConfig.class,
|
||||||
BankAccountValidationConfig.class,
|
BankAccountValidationConfig.class,
|
||||||
|
AccountValidationConfig.class,
|
||||||
BeanConfiguration.class,
|
BeanConfiguration.class,
|
||||||
HazelcastServiceTestConfiguration.class,
|
HazelcastServiceTestConfiguration.class,
|
||||||
KafkaConfigTest.class})
|
KafkaConfigTest.class})
|
||||||
|
|
@ -85,6 +87,8 @@ public class BankAccountServiceTest {
|
||||||
private Imdg<BankAccount> bankAccountImdg;
|
private Imdg<BankAccount> bankAccountImdg;
|
||||||
private Imdg<Account> accountImdg;
|
private Imdg<Account> accountImdg;
|
||||||
private Imdg<CurrencyCodeDictionary> currencyCodeDictionaryImdg;
|
private Imdg<CurrencyCodeDictionary> currencyCodeDictionaryImdg;
|
||||||
|
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||||
|
private Imdg<Relation> relationImdg;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private IMessageResolver messageResolver;
|
private IMessageResolver messageResolver;
|
||||||
|
|
@ -110,6 +114,12 @@ public class BankAccountServiceTest {
|
||||||
currencyCodeDictionaryImdg = hazelcastServiceTest.getImdg(
|
currencyCodeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||||
IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class
|
IMDGDistributedNames.Map_CurrencyCodeDictionary, CurrencyCodeDictionary.class
|
||||||
);
|
);
|
||||||
|
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||||
|
);
|
||||||
|
relationImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Relation, Relation.class
|
||||||
|
);
|
||||||
CurrencyCodeDictionary currencyCodeDictionary = new CurrencyCodeDictionary();
|
CurrencyCodeDictionary currencyCodeDictionary = new CurrencyCodeDictionary();
|
||||||
currencyCodeDictionary.setCode("RUB");
|
currencyCodeDictionary.setCode("RUB");
|
||||||
currencyCodeDictionary.setName("RUB");
|
currencyCodeDictionary.setName("RUB");
|
||||||
|
|
@ -136,9 +146,25 @@ public class BankAccountServiceTest {
|
||||||
BankAccount predictableBankAccount = getBankAccount();
|
BankAccount predictableBankAccount = getBankAccount();
|
||||||
|
|
||||||
Company company = getTestCompany();
|
Company company = getTestCompany();
|
||||||
companyImdg.insert(company);
|
Long companyId = companyImdg.insert(company);
|
||||||
|
Long relationId = 777L;
|
||||||
Account predictableAccount = getTestAccount(accountId, acc);
|
Account predictableAccount = getTestAccount(accountId, acc);
|
||||||
|
predictableAccount.setProcessingSign(null);
|
||||||
|
predictableAccount.setCompanyId(companyId);
|
||||||
|
predictableAccount.setRelationId(relationId);
|
||||||
clearImdg(accountImdg);
|
clearImdg(accountImdg);
|
||||||
|
|
||||||
|
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||||
|
clearingMemberCategory.setCompanyId(companyId);
|
||||||
|
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||||
|
|
||||||
|
Relation relation = new Relation();
|
||||||
|
relation.setId(relationId);
|
||||||
|
relation.setConsumerId(companyId);
|
||||||
|
relation.setService(Service.MKR.getKey());
|
||||||
|
relationImdg.insert(relation);
|
||||||
|
|
||||||
BankAccountNewRequest bankAccountNewRequest = getBankAccountNewRequest(predictableBankAccount);
|
BankAccountNewRequest bankAccountNewRequest = getBankAccountNewRequest(predictableBankAccount);
|
||||||
String jsonString = getJsonStringForNew(bankAccountNewRequest, ID);
|
String jsonString = getJsonStringForNew(bankAccountNewRequest, ID);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,170 @@
|
||||||
|
package ru.spcex.clearing.account.service;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.MockConsumer;
|
||||||
|
import org.apache.kafka.clients.producer.MockProducer;
|
||||||
|
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
import org.mockito.Captor;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
|
import ru.clearing.classes.statics.data.account.InformationAccount;
|
||||||
|
import ru.clearing.classes.statics.data.company.ClearingMemberCategory;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.company.relation.Relation;
|
||||||
|
import ru.clearing.platform.dictionary.AccountTypeDictionary;
|
||||||
|
import ru.spcex.clearing.account.config.BeanConfiguration;
|
||||||
|
import ru.spcex.clearing.account.config.HazelcastServiceTestConfiguration;
|
||||||
|
import ru.spcex.clearing.account.config.KafkaConfigTest;
|
||||||
|
import ru.spcex.clearing.account.config.validation.AccountValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.config.validation.InformationAccountValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.config.validation.ValidationConfig;
|
||||||
|
import ru.spcex.clearing.account.utils.MatcherFactory;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.account.InformationAccountNewRequest;
|
||||||
|
import ru.spcex.platform.enumeration.*;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.account.utils.MatcherFactory.usingIgnoringFieldsComparator;
|
||||||
|
import static ru.spcex.clearing.account.utils.TestUtils.*;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
BeanConfiguration.class,
|
||||||
|
ValidationConfig.class,
|
||||||
|
InformationAccountValidationConfig.class,
|
||||||
|
AccountValidationConfig.class,
|
||||||
|
AccountService.class,
|
||||||
|
InformationAccountService.class,
|
||||||
|
HazelcastServiceTestConfiguration.class,
|
||||||
|
KafkaConfigTest.class})
|
||||||
|
class InformationAccountServiceTest {
|
||||||
|
public static final MatcherFactory.Matcher<InformationAccount> INFORMATION_ACCOUNT_MATCHER = usingIgnoringFieldsComparator();
|
||||||
|
public static final MatcherFactory.Matcher<Account> ACCOUNT_MATCHER = usingIgnoringFieldsComparator("created", "updated");
|
||||||
|
private static final int PARTITION = 0;
|
||||||
|
private static final String account = "123456789123";
|
||||||
|
private static final Long companyId = 0L;
|
||||||
|
private static final Long relationId = 0L;
|
||||||
|
private Long anltAccountId;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
InformationAccountService informationAccountService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
private HazelcastService hazelcastServiceTest;
|
||||||
|
|
||||||
|
@Captor
|
||||||
|
private ArgumentCaptor<ProducerRecord> producerRecord;
|
||||||
|
@SpyBean
|
||||||
|
private MockProducer<String, Object> producer;
|
||||||
|
|
||||||
|
private Imdg<InformationAccount> informationAccountImdg;
|
||||||
|
private Imdg<Account> accountImdg;
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<AccountTypeDictionary> accountTypeDictionaryImdg;
|
||||||
|
private Imdg<ClearingMemberCategory> clearingMemberCategoryImdg;
|
||||||
|
private Imdg<Relation> relationImdg;
|
||||||
|
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
private void init() {
|
||||||
|
hazelcastServiceTest.waitAvailable();
|
||||||
|
informationAccountImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_InformationAccount, InformationAccount.class
|
||||||
|
);
|
||||||
|
accountImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Account, Account.class
|
||||||
|
);
|
||||||
|
|
||||||
|
companyImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Company, Company.class
|
||||||
|
);
|
||||||
|
accountTypeDictionaryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_AccountTypeDictionary, AccountTypeDictionary.class
|
||||||
|
);
|
||||||
|
clearingMemberCategoryImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_ClearingMemberCategory, ClearingMemberCategory.class
|
||||||
|
);
|
||||||
|
relationImdg = hazelcastServiceTest.getImdg(
|
||||||
|
IMDGDistributedNames.Map_Relation, Relation.class
|
||||||
|
);
|
||||||
|
|
||||||
|
Company company = new Company();
|
||||||
|
company.setId(companyId);
|
||||||
|
company.setWorkflowStatus(WorkflowStatus.Active.getKey());
|
||||||
|
companyImdg.insert(company);
|
||||||
|
|
||||||
|
AccountTypeDictionary accountTypeDictionary = new AccountTypeDictionary();
|
||||||
|
accountTypeDictionary.setCode(AccountType.Corr.getKey());
|
||||||
|
accountTypeDictionary.setName(AccountType.Corr.getKey());
|
||||||
|
accountTypeDictionaryImdg.insert(accountTypeDictionary);
|
||||||
|
|
||||||
|
ClearingMemberCategory clearingMemberCategory = new ClearingMemberCategory();
|
||||||
|
clearingMemberCategory.setClearingMemberCategory(ClearingCategory.B.getKey());
|
||||||
|
clearingMemberCategory.setCompanyId(companyId);
|
||||||
|
clearingMemberCategoryImdg.insert(clearingMemberCategory);
|
||||||
|
|
||||||
|
Relation relation = new Relation();
|
||||||
|
relation.setId(relationId);
|
||||||
|
relation.setConsumerId(companyId);
|
||||||
|
relation.setService(Service.MKR.getKey());
|
||||||
|
relationImdg.insert(relation);
|
||||||
|
|
||||||
|
Account accountAnlt = new Account();
|
||||||
|
accountAnlt.setAccountType(AccountType.Anlt.getKey());
|
||||||
|
accountAnlt.setCompanyId(1L);
|
||||||
|
anltAccountId = accountImdg.insert(accountAnlt);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void accountInformationNew() {
|
||||||
|
InformationAccountNewRequest InformationAccountNewRequest = new InformationAccountNewRequest();
|
||||||
|
InformationAccountNewRequest.setCompanyId(companyId);
|
||||||
|
|
||||||
|
String jsonString = getJsonStringForNew(InformationAccountNewRequest, 0L);
|
||||||
|
|
||||||
|
addRecordToKafka((MockConsumer) informationAccountService.getConsumer(),
|
||||||
|
Consts.DESTINATION_INFORMATION_ACCOUNT_NEW,
|
||||||
|
PARTITION,
|
||||||
|
0,
|
||||||
|
jsonString);
|
||||||
|
|
||||||
|
waitingWhenAddedRecordAndCheckIt(0L, producer, producerRecord);
|
||||||
|
|
||||||
|
Account predictableAccount = new Account();
|
||||||
|
predictableAccount.setAccountType(AccountType.Info.getKey());
|
||||||
|
predictableAccount.setStatus(AccountStatus.ACTIVE.getKey());
|
||||||
|
predictableAccount.setRelationId(relationId);
|
||||||
|
predictableAccount.setCompanyId(companyId);
|
||||||
|
|
||||||
|
InformationAccount predictableInfoAccount = new InformationAccount();
|
||||||
|
predictableInfoAccount.setCompanyId(companyId);
|
||||||
|
predictableInfoAccount.setClearingAccountId(anltAccountId);
|
||||||
|
|
||||||
|
Account resultAccountNew = accountImdg.getSingleObjectByFieldValues(Map.of("accountType", AccountType.Info.getKey()));
|
||||||
|
InformationAccount resultInfoAccountNew = informationAccountImdg.getSingleObjectByFieldValues(Map.of("accountId", resultAccountNew.getId()));
|
||||||
|
|
||||||
|
predictableAccount.setId(resultAccountNew.getId());
|
||||||
|
predictableAccount.setAccount(informationAccountService.generateInfoAccount(resultInfoAccountNew.getId()));
|
||||||
|
predictableInfoAccount.setAccountId(resultAccountNew.getId());
|
||||||
|
predictableInfoAccount.setId(resultInfoAccountNew.getId());
|
||||||
|
|
||||||
|
ACCOUNT_MATCHER.assertMatch(resultAccountNew, predictableAccount);
|
||||||
|
INFORMATION_ACCOUNT_MATCHER.assertMatch(resultInfoAccountNew, predictableInfoAccount);
|
||||||
|
|
||||||
|
informationAccountImdg.delete(resultInfoAccountNew);
|
||||||
|
accountImdg.delete(resultAccountNew);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -106,7 +106,7 @@ public class StatementService extends QueueConsumer implements InitializingBean
|
||||||
exportRequest.setNameOfTable(service.exportTableName());
|
exportRequest.setNameOfTable(service.exportTableName());
|
||||||
kafkaReqProducer.sendRequestToQueue(Consts.EXPORT_PROCESS, exportRequest);
|
kafkaReqProducer.sendRequestToQueue(Consts.EXPORT_PROCESS, exportRequest);
|
||||||
} else {
|
} else {
|
||||||
kafkaReqProducer.sendRequestToQueue(Consts.CLEARING_ACCOUNT_NEW_SDF01, createAccountsRequest(statementRequest.getGroupId(), res.getAccountRequests()));
|
kafkaReqProducer.sendRequestToQueue(Consts.ACCOUNT_NEW_SDF01, createAccountsRequest(statementRequest.getGroupId(), res.getAccountRequests()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -130,7 +130,7 @@ class StatementServiceServiceTest extends AbstractServiceTest {
|
||||||
BaseRequest<Object> baseRequest = (BaseRequest<Object>) producerRecord.getValue().value();
|
BaseRequest<Object> baseRequest = (BaseRequest<Object>) producerRecord.getValue().value();
|
||||||
RequestInfo resultRequestInfo = requestInfoImdg.getSingleObjectByID(baseRequest.getId());
|
RequestInfo resultRequestInfo = requestInfoImdg.getSingleObjectByID(baseRequest.getId());
|
||||||
|
|
||||||
assertEquals(Consts.CLEARING_ACCOUNT_NEW_SDF01, producerRecord.getValue().topic());
|
assertEquals(Consts.ACCOUNT_NEW_SDF01, producerRecord.getValue().topic());
|
||||||
assertNotNull(baseRequest);
|
assertNotNull(baseRequest);
|
||||||
assertNotNull(resultRequestInfo);
|
assertNotNull(resultRequestInfo);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -54,6 +54,7 @@ public interface Consts {
|
||||||
String DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE = "clearing-member-category-update";
|
String DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE = "clearing-member-category-update";
|
||||||
String DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE = "clearing-member-category-delete";
|
String DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE = "clearing-member-category-delete";
|
||||||
|
|
||||||
|
String DESTINATION_INFORMATION_ACCOUNT_NEW = "information-account-new";
|
||||||
|
|
||||||
String DESTINATION_CORRESPONDENT_ACCOUNT_NEW = "correspondent-account-new";
|
String DESTINATION_CORRESPONDENT_ACCOUNT_NEW = "correspondent-account-new";
|
||||||
String DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE = "correspondent-account-update";
|
String DESTINATION_CORRESPONDENT_ACCOUNT_UPDATE = "correspondent-account-update";
|
||||||
|
|
@ -63,8 +64,8 @@ public interface Consts {
|
||||||
String DESTINATION_BANK_ACCOUNT_UPDATE = "bank-account-update";
|
String DESTINATION_BANK_ACCOUNT_UPDATE = "bank-account-update";
|
||||||
String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new";
|
String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new";
|
||||||
|
|
||||||
String CLEARING_ACCOUNT_NEW_SDF01 = "clearing-account-new-sdf01";
|
@Deprecated
|
||||||
String CLEARING_ACCOUNT_UPDATE_SDF52 = "clearing-account-update-sdf52";
|
String ACCOUNT_NEW_SDF01 = "account-new-sdf01";
|
||||||
|
|
||||||
String DESTINATION_RELATION_UPDATE = "relation-update";
|
String DESTINATION_RELATION_UPDATE = "relation-update";
|
||||||
String DESTINATION_PROFILE_DOCUMENT_NEW = "profile-document-new";
|
String DESTINATION_PROFILE_DOCUMENT_NEW = "profile-document-new";
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
package ru.spcex.clearing.platform.messaging.domain.cud.account;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
public class InformationAccountNewRequest {
|
||||||
|
@JsonProperty
|
||||||
|
public Long companyId;
|
||||||
|
|
||||||
|
public Long getCompanyId() {
|
||||||
|
return companyId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCompanyId(Long companyId) {
|
||||||
|
this.companyId = companyId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class AccountSdf01Request {
|
public class AccountSdf01Request {
|
||||||
|
|
||||||
private Long groupingSdf01Id;
|
private Long groupingSdf01Id;
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package ru.spcex.clearing.platform.messaging.domain.cud.account.sdf01;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public class AccountSdfRequestPart {
|
public class AccountSdfRequestPart {
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
private Long sdfId;
|
private Long sdfId;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue