From 9a77ad254e7ee64dc6590fae0cc8b25b73bd8678 Mon Sep 17 00:00:00 2001 From: aalehin Date: Mon, 5 Sep 2022 15:05:07 +0300 Subject: [PATCH] =?UTF-8?q?http://jira.mfd.msk:8088/browse/CLS-32=20---=20?= =?UTF-8?q?account=5Fservices:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5,=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5,=20=D1=83=D0=B4=D0=B0=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=BD=D0=BA=D0=BE=D0=B2=D1=81?= =?UTF-8?q?=D0=BA=D0=B8=D1=85=20=D1=80=D0=B5=D0=BA=D0=B2=D0=B8=D0=B7=D0=B8?= =?UTF-8?q?=D1=82=D0=BE=D0=B2=20bankAccount?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- clearing-parent/account-service/pom.xml | 69 ++++++++++++ .../account/AccountServiceApplication.java | 12 ++ .../config/AccountServiceImdgConfig.java | 47 ++++++++ .../clearing/account/config/KafkaConfig.java | 18 +++ .../settings/AccountServiceSettings.java | 31 +++++ .../account/service/BankAccountService.java | 84 ++++++++++++++ .../src/main/resources/application.properties | 11 ++ .../src/main/resources/logback.xml | 38 +++++++ clearing-parent/pom.xml | 3 +- .../platform/messaging/domain/Consts.java | 5 +- .../cud/account/BankAccountNewRequest.java | 96 ++++++++++++++++ .../cud/account/BankAccountUpdateRequest.java | 106 ++++++++++++++++++ 12 files changed, 518 insertions(+), 2 deletions(-) create mode 100644 clearing-parent/account-service/pom.xml create mode 100644 clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/AccountServiceApplication.java create mode 100644 clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/AccountServiceImdgConfig.java create mode 100644 clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/KafkaConfig.java create mode 100644 clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/settings/AccountServiceSettings.java create mode 100644 clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java create mode 100644 clearing-parent/account-service/src/main/resources/application.properties create mode 100644 clearing-parent/account-service/src/main/resources/logback.xml create mode 100644 platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountNewRequest.java create mode 100644 platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountUpdateRequest.java diff --git a/clearing-parent/account-service/pom.xml b/clearing-parent/account-service/pom.xml new file mode 100644 index 000000000..7585732cf --- /dev/null +++ b/clearing-parent/account-service/pom.xml @@ -0,0 +1,69 @@ + + + + clearing-parent + ru.spcex.clearing + SPCEX-1.0.0.0 + + 4.0.0 + + account-service + + + 17 + 17 + + + + ru.spcex.platform + platform-messaging + + + ru.spcex.platform + platform-imdg-api-hazelcast-impl + + + ru.spcex.clearing + classes + + + org.springframework.boot + spring-boot-starter + + + com.fasterxml.jackson.core + jackson-databind + + + + + + + src/main/resources + + application.properties + + false + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + repackage + + + + + ${project.artifactId} + + + + + + \ No newline at end of file diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/AccountServiceApplication.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/AccountServiceApplication.java new file mode 100644 index 000000000..1b8ba13c8 --- /dev/null +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/AccountServiceApplication.java @@ -0,0 +1,12 @@ +package ru.spcex.clearing.account; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class AccountServiceApplication { + public static void main(String[] args) { + SpringApplication springApplication = new SpringApplication(AccountServiceApplication.class); + springApplication.run(args); + } +} diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/AccountServiceImdgConfig.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/AccountServiceImdgConfig.java new file mode 100644 index 000000000..a129869d5 --- /dev/null +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/AccountServiceImdgConfig.java @@ -0,0 +1,47 @@ +package ru.spcex.clearing.account.config; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; +import ru.spcex.clearing.account.config.settings.AccountServiceSettings; +import ru.spcex.platform.imdg.api.ImdgProvider; +import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService; + +@Configuration +public class AccountServiceImdgConfig { + private static ThreadPoolTaskExecutor createThreadPoolTaskExecutor(int maxPoolSz, boolean waitForCompletion) { + ThreadPoolTaskExecutor pool = new ThreadPoolTaskExecutor(); + if (maxPoolSz > 2) { + pool.setKeepAliveSeconds(60); + pool.setAllowCoreThreadTimeOut(true); + } + pool.setCorePoolSize(maxPoolSz); + pool.setWaitForTasksToCompleteOnShutdown(waitForCompletion); + return pool; + } + + @Bean(name = "taskExecutorHazelcastClientInitializer") + public ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer() { + return createThreadPoolTaskExecutor(1, true); + } + + @Bean(name = "taskExecutorIdGeneratorAwaiter") + public ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter() { + return createThreadPoolTaskExecutor(1, false); + } + + @Autowired + @Bean + public ImdgProvider imdgProvider( + @Qualifier("taskExecutorHazelcastClientInitializer") ThreadPoolTaskExecutor taskExecutorHazelcastClientInitializer, + @Qualifier("taskExecutorIdGeneratorAwaiter") ThreadPoolTaskExecutor taskExecutorIdGeneratorAwaiter, + AccountServiceSettings settings + ) { + return new HazelcastService(taskExecutorHazelcastClientInitializer, + taskExecutorIdGeneratorAwaiter, + settings.getHazelcast()); + } + +} diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/KafkaConfig.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/KafkaConfig.java new file mode 100644 index 000000000..34973fffa --- /dev/null +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/KafkaConfig.java @@ -0,0 +1,18 @@ +package ru.spcex.clearing.account.config; + +import org.apache.kafka.clients.consumer.Consumer; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import ru.spcex.clearing.account.config.settings.AccountServiceSettings; +import ru.spcex.clearing.platform.messaging.config.KafkaConsumerFactory; + + +@Configuration +public class KafkaConfig { + @Autowired + @Bean + public Consumer createProducer(AccountServiceSettings settings) { + return KafkaConsumerFactory.consumer(settings.getKafka()); + } +} diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/settings/AccountServiceSettings.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/settings/AccountServiceSettings.java new file mode 100644 index 000000000..6f6a12280 --- /dev/null +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/config/settings/AccountServiceSettings.java @@ -0,0 +1,31 @@ +package ru.spcex.clearing.account.config.settings; + +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.PropertySource; +import org.springframework.stereotype.Component; +import ru.spcex.clearing.platform.messaging.config.element.KafkaConsumerSettings; +import ru.spcex.platform.imdg.iml.hazelcast.config.HazelcastClientParams; + +@Component +@PropertySource("file:${spring.config.location}/application.properties") +@ConfigurationProperties("utility-service") +public class AccountServiceSettings { + private HazelcastClientParams hazelcast; + private KafkaConsumerSettings kafka; + + public HazelcastClientParams getHazelcast() { + return hazelcast; + } + + public void setHazelcast(HazelcastClientParams hazelcast) { + this.hazelcast = hazelcast; + } + + public KafkaConsumerSettings getKafka() { + return kafka; + } + + public void setKafka(KafkaConsumerSettings kafka) { + this.kafka = kafka; + } +} diff --git a/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java new file mode 100644 index 000000000..57db13a20 --- /dev/null +++ b/clearing-parent/account-service/src/main/java/ru/spcex/clearing/account/service/BankAccountService.java @@ -0,0 +1,84 @@ +package ru.spcex.clearing.account.service; + +import org.apache.kafka.clients.consumer.Consumer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import ru.clearing.classes.StaticData.Account.BankAccount; +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.BankAccountNewRequest; +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.service.QueueConsumer; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +@Service +public class BankAccountService extends QueueConsumer implements InitializingBean { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg bankAccountMap; + + @Autowired + public BankAccountService(Consumer kafkaQueue, ImdgProvider imdgProvider) { + super(kafkaQueue); + this.bankAccountMap = imdgProvider.getImdg(IMDGDistributedNames.Map_BankAccount, BankAccount.class); + } + + @Override + public void afterPropertiesSet() { + callback(BankAccountNewRequest.class) + .setConsumer(this::bankAccountNew) + .forDestination(Consts.DESTINATION_BANK_ACCOUNT_NEW, callbacks::put); + callback(BankAccountUpdateRequest.class) + .setConsumer(this::bankAccountUpdate) + .forDestination(Consts.DESTINATION_BANK_ACCOUNT_UPDATE, callbacks::put); + callback(CommonDeleteRequest.class) + .setConsumer(this::bankAccountDelete) + .forDestination(Consts.DESTINATION_BANK_ACCOUNT_DELETE, callbacks::put); + init(); + } + + private void bankAccountNew(BaseRequest userRequest) { + BankAccountNewRequest req = userRequest.getRequestPayload(); + log.debug("MoneyMarketSecurityNewRequest received"); + BankAccount bankAccount = new BankAccount(); + bankAccount.setBankIdentificationCode(req.getBankIdentificationCode()); + bankAccount.setBankName(req.getBankName()); + bankAccount.setCorrespondentAccount(req.getCorrespondentAccount()); + bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName()); + bankAccount.setCurrency(req.getCurrency()); + bankAccount.setDestination(req.getDestination()); + bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber()); + bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode()); + + bankAccountMap.insert(bankAccount); + log.debug("successfully processed, new id {}", bankAccount.getId()); + } + + private void bankAccountUpdate(BaseRequest userRequest) { + BankAccountUpdateRequest req = userRequest.getRequestPayload(); + log.debug("MoneyMarketSecurityUpdateRequest received id = {}", req.getId()); + BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId()); + bankAccount.setBankIdentificationCode(req.getBankIdentificationCode()); + bankAccount.setBankName(req.getBankName()); + bankAccount.setCorrespondentAccount(req.getCorrespondentAccount()); + bankAccount.setCorrespondentAccountName(req.getCorrespondentAccountName()); + bankAccount.setCurrency(req.getCurrency()); + bankAccount.setDestination(req.getDestination()); + bankAccount.setTaxpayerIdentificationNumber(req.getTaxpayerIdentificationNumber()); + bankAccount.setTaxRegistrationReasonCode(req.getTaxRegistrationReasonCode()); + bankAccountMap.update(bankAccount); + } + + private void bankAccountDelete(BaseRequest userRequest) { + CommonDeleteRequest req = userRequest.getRequestPayload(); + log.debug("CommonDeleteRequest received id = {}", req.getId()); + BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId()); + bankAccountMap.delete(bankAccount); + } + +} diff --git a/clearing-parent/account-service/src/main/resources/application.properties b/clearing-parent/account-service/src/main/resources/application.properties new file mode 100644 index 000000000..f2d6fe4d8 --- /dev/null +++ b/clearing-parent/account-service/src/main/resources/application.properties @@ -0,0 +1,11 @@ +spring.main.web-application-type=none +account-service.hazelcast.cluster-members=127.0.0.1 +account-service.hazelcast.login=dev +account-service.hazelcast.password=dev-pass +account-service.kafka.bootstrap-servers=localhost:9092 +account-service.kafka.group-id=dev-group +account-service.kafka.enable-auto-commit=false +account-service.kafka.session-timeout-ms=30000 +account-service.kafka.auto-offset-reset=latest +account-service.kafka.linger-ms=1 +account-service.kafka.buffer-memory=33554432 \ No newline at end of file diff --git a/clearing-parent/account-service/src/main/resources/logback.xml b/clearing-parent/account-service/src/main/resources/logback.xml new file mode 100644 index 000000000..28e170416 --- /dev/null +++ b/clearing-parent/account-service/src/main/resources/logback.xml @@ -0,0 +1,38 @@ + + + + + + %date{HH:mm:ss.SSS} [%thread] %-5level %class{0}:%line - %message%n + utf-8 + + + + ./logs/account-service.log + + + %d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n + utf8 + + + + ./logs/account-service.%i.log + + 1 + 10 + + + 500MB + + + + + + + + + + + + + diff --git a/clearing-parent/pom.xml b/clearing-parent/pom.xml index 717490f8d..859773303 100644 --- a/clearing-parent/pom.xml +++ b/clearing-parent/pom.xml @@ -1,5 +1,5 @@ - 4.0.0 @@ -27,6 +27,7 @@ utility-service company-service reports-service + account-service diff --git a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/Consts.java b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/Consts.java index fdbb8c116..cbaeefcd7 100644 --- a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/Consts.java +++ b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/Consts.java @@ -14,5 +14,8 @@ public interface Consts { String DESTINATION_COMPANY_SYMBOL_UPDATE = "company-symbol-update"; String DESTINATION_CONTACT_UPDATE = "contact-update"; String DESTINATION_CLEARING_MEMBER_CATEGORY_UPDATE = "clearing-member-category-update"; - String DESTINATION_CLEARING_MEMBER_CATEGORY_DELETE = "clearing-member-category-delete"; + String DESTINATION_BANK_ACCOUNT_DELETE = "bank-account-delete"; + String DESTINATION_BANK_ACCOUNT_UPDATE = "bank-account-update"; + String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new"; + } diff --git a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountNewRequest.java b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountNewRequest.java new file mode 100644 index 000000000..527ed2ce4 --- /dev/null +++ b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountNewRequest.java @@ -0,0 +1,96 @@ +package ru.spcex.clearing.platform.messaging.domain.cud.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class BankAccountNewRequest { + @JsonProperty + public String bankIdentificationCode;//Банковский идентификационный код (БИК) + @JsonProperty + public String bankName;//Наименование банка + @JsonProperty + public String correspondentAccount;//Корреспондентский счет + @JsonProperty + public String correspondentAccountName;//Наименование корреспондентского счета + @JsonProperty + public String currency;//Идентификатор валюты + @JsonProperty + public String destination;//Назначение + @JsonProperty + public String taxpayerIdentificationNumber;//Идентификационный номер налогоплательщика (ИНН) + @JsonProperty + public String taxRegistrationReasonCode;//Код причины постановки (КПП) + @JsonProperty + public String account;//Номер счета + + public String getBankIdentificationCode() { + return bankIdentificationCode; + } + + public void setBankIdentificationCode(String bankIdentificationCode) { + this.bankIdentificationCode = bankIdentificationCode; + } + + public String getBankName() { + return bankName; + } + + public void setBankName(String bankName) { + this.bankName = bankName; + } + + public String getCorrespondentAccount() { + return correspondentAccount; + } + + public void setCorrespondentAccount(String correspondentAccount) { + this.correspondentAccount = correspondentAccount; + } + + public String getCorrespondentAccountName() { + return correspondentAccountName; + } + + public void setCorrespondentAccountName(String correspondentAccountName) { + this.correspondentAccountName = correspondentAccountName; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public String getDestination() { + return destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + + public String getTaxpayerIdentificationNumber() { + return taxpayerIdentificationNumber; + } + + public void setTaxpayerIdentificationNumber(String taxpayerIdentificationNumber) { + this.taxpayerIdentificationNumber = taxpayerIdentificationNumber; + } + + public String getTaxRegistrationReasonCode() { + return taxRegistrationReasonCode; + } + + public void setTaxRegistrationReasonCode(String taxRegistrationReasonCode) { + this.taxRegistrationReasonCode = taxRegistrationReasonCode; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } +} diff --git a/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountUpdateRequest.java b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountUpdateRequest.java new file mode 100644 index 000000000..5ee6fc958 --- /dev/null +++ b/platform-parent/platform-messaging/src/main/java/ru/spcex/clearing/platform/messaging/domain/cud/account/BankAccountUpdateRequest.java @@ -0,0 +1,106 @@ +package ru.spcex.clearing.platform.messaging.domain.cud.account; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class BankAccountUpdateRequest { + @JsonProperty + public Long id; //Идентификатор записи + @JsonProperty + public String bankIdentificationCode;//Банковский идентификационный код (БИК) + @JsonProperty + public String bankName;//Наименование банка + @JsonProperty + public String correspondentAccount;//Корреспондентский счет + @JsonProperty + public String correspondentAccountName;//Наименование корреспондентского счета + @JsonProperty + public String currency;//Идентификатор валюты + @JsonProperty + public String destination;//Назначение + @JsonProperty + public String taxpayerIdentificationNumber;//Идентификационный номер налогоплательщика (ИНН) + @JsonProperty + public String taxRegistrationReasonCode;//Код причины постановки (КПП) + @JsonProperty + public String account;//Номер счета + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getBankIdentificationCode() { + return bankIdentificationCode; + } + + public void setBankIdentificationCode(String bankIdentificationCode) { + this.bankIdentificationCode = bankIdentificationCode; + } + + public String getBankName() { + return bankName; + } + + public void setBankName(String bankName) { + this.bankName = bankName; + } + + public String getCorrespondentAccount() { + return correspondentAccount; + } + + public void setCorrespondentAccount(String correspondentAccount) { + this.correspondentAccount = correspondentAccount; + } + + public String getCorrespondentAccountName() { + return correspondentAccountName; + } + + public void setCorrespondentAccountName(String correspondentAccountName) { + this.correspondentAccountName = correspondentAccountName; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public String getDestination() { + return destination; + } + + public void setDestination(String destination) { + this.destination = destination; + } + + public String getTaxpayerIdentificationNumber() { + return taxpayerIdentificationNumber; + } + + public void setTaxpayerIdentificationNumber(String taxpayerIdentificationNumber) { + this.taxpayerIdentificationNumber = taxpayerIdentificationNumber; + } + + public String getTaxRegistrationReasonCode() { + return taxRegistrationReasonCode; + } + + public void setTaxRegistrationReasonCode(String taxRegistrationReasonCode) { + this.taxRegistrationReasonCode = taxRegistrationReasonCode; + } + + public String getAccount() { + return account; + } + + public void setAccount(String account) { + this.account = account; + } +}