---
account_services: добавление, изменение, удаление банковских реквизитов bankAccount
This commit is contained in:
aalehin 2022-09-05 15:05:07 +03:00
parent 36540fe503
commit 9a77ad254e
12 changed files with 518 additions and 2 deletions

View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>clearing-parent</artifactId>
<groupId>ru.spcex.clearing</groupId>
<version>SPCEX-1.0.0.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>account-service</artifactId>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>ru.spcex.platform</groupId>
<artifactId>platform-messaging</artifactId>
</dependency>
<dependency>
<groupId>ru.spcex.platform</groupId>
<artifactId>platform-imdg-api-hazelcast-impl</artifactId>
</dependency>
<dependency>
<groupId>ru.spcex.clearing</groupId>
<artifactId>classes</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<excludes>
<exclude>application.properties</exclude>
</excludes>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.artifactId}</finalName>
</configuration>
</plugin>
</plugins>
</build>
</project>

View file

@ -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);
}
}

View file

@ -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());
}
}

View file

@ -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<String, Object> createProducer(AccountServiceSettings settings) {
return KafkaConsumerFactory.consumer(settings.getKafka());
}
}

View file

@ -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;
}
}

View file

@ -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<BankAccount> bankAccountMap;
@Autowired
public BankAccountService(Consumer<String, Object> 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<BankAccountNewRequest> 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<BankAccountUpdateRequest> 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<CommonDeleteRequest> userRequest) {
CommonDeleteRequest req = userRequest.getRequestPayload();
log.debug("CommonDeleteRequest received id = {}", req.getId());
BankAccount bankAccount = bankAccountMap.getSingleObjectByID(req.getId());
bankAccountMap.delete(bankAccount);
}
}

View file

@ -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

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
<Pattern>%date{HH:mm:ss.SSS} [%thread] %-5level %class{0}:%line - %message%n</Pattern>
<charset>utf-8</charset>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>./logs/account-service.log</file>
<encoder>
<!-- |%X{ru.nbch.scoring.web.logging.mdc_key}-->
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %class{0}:%msg%n</Pattern>
<charset>utf8</charset>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>
./logs/account-service.%i.log
</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>10</maxIndex>
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>500MB</maxFileSize>
</triggeringPolicy>
</appender>
<root level="warn">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE"/>
</root>
<logger name="ru.spcex" level="debug" additivity="false">
<appender-ref ref="FILE"/>
<appender-ref ref="CONSOLE"/>
</logger>
</configuration>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
@ -27,6 +27,7 @@
<module>utility-service</module>
<module>company-service</module>
<module>reports-service</module>
<module>account-service</module>
</modules>
<properties>

View file

@ -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";
}

View file

@ -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;
}
}

View file

@ -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;
}
}