---
 реализовал обработку команд добавления, изменения, удаления Ключевой ставки ЦБ.
This commit is contained in:
aalehin 2022-08-30 18:34:11 +03:00
parent 8fa93e924b
commit 9bdce4dfb6
12 changed files with 461 additions and 155 deletions

View file

@ -1,59 +1,59 @@
package ru.clearing.classes.StaticData.Misc;
import ru.spcex.platform.classes.base.SpcexObjectBase;
import java.math.BigDecimal;
import java.time.Instant;
/**
* Ключевая ставка ЦБ
*
* DB table: KEY_RATE
**/
public class KeyRate extends SpcexObjectBase {
private BigDecimal rate;
private Instant startDate;
private Instant endDate;
private String document;
private String workflowStatus;
public BigDecimal getRate() {
return rate;
}
public void setRate(BigDecimal rate) {
this.rate = rate;
}
public Instant getStartDate() {
return startDate;
}
public void setStartDate(Instant startDate) {
this.startDate = startDate;
}
public Instant getEndDate() {
return endDate;
}
public void setEndDate(Instant endDate) {
this.endDate = endDate;
}
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
public String getWorkflowStatus() {
return workflowStatus;
}
public void setWorkflowStatus(String workflowStatus) {
this.workflowStatus = workflowStatus;
}
}
package ru.clearing.classes.StaticData.Misc;
import ru.spcex.platform.classes.base.SpcexObjectBase;
import java.math.BigDecimal;
import java.time.Instant;
/**
* Ключевая ставка ЦБ
*
* DB table: KEY_RATE
**/
public class KeyRate extends SpcexObjectBase {
private Double rate;
private Instant startDate;
private Instant endDate;
private String document;
private String workflowStatus;
public Double getRate() {
return rate;
}
public void setRate(Double rate) {
this.rate = rate;
}
public Instant getStartDate() {
return startDate;
}
public void setStartDate(Instant startDate) {
this.startDate = startDate;
}
public Instant getEndDate() {
return endDate;
}
public void setEndDate(Instant endDate) {
this.endDate = endDate;
}
public String getDocument() {
return document;
}
public void setDocument(String document) {
this.document = document;
}
public String getWorkflowStatus() {
return workflowStatus;
}
public void setWorkflowStatus(String workflowStatus) {
this.workflowStatus = workflowStatus;
}
}

View file

@ -1,95 +1,95 @@
package ru.clearing.classes.StaticData.Misc;
import ru.spcex.platform.classes.base.SpcexObjectBase;
import java.math.BigDecimal;
import java.time.Instant;
/**
* Инструменты Денежного рынка
* <p>
* DB table: MONEY_MARKET_SECURITY
**/
public class MoneyMarketSecurity extends SpcexObjectBase {
private Long securityId;// (linked to security)
private String description;
private Instant startDate;
private Instant endDate;
private BigDecimal nominalValue;
private Long nominalCurrency; // (linked to currencyCode)
private String instrumentType; // (linked to instrumentType)
private String fullName;
private String securitySymbol;
public Long getSecurityId() {
return securityId;
}
public void setSecurityId(Long securityId) {
this.securityId = securityId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Instant getStartDate() {
return startDate;
}
public void setStartDate(Instant startDate) {
this.startDate = startDate;
}
public Instant getEndDate() {
return endDate;
}
public void setEndDate(Instant endDate) {
this.endDate = endDate;
}
public BigDecimal getNominalValue() {
return nominalValue;
}
public void setNominalValue(BigDecimal nominalValue) {
this.nominalValue = nominalValue;
}
public Long getNominalCurrency() {
return nominalCurrency;
}
public void setNominalCurrency(Long nominalCurrency) {
this.nominalCurrency = nominalCurrency;
}
public String getInstrumentType() {
return instrumentType;
}
public void setInstrumentType(String instrumentType) {
this.instrumentType = instrumentType;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getSecuritySymbol() {
return securitySymbol;
}
public void setSecuritySymbol(String securitySymbol) {
this.securitySymbol = securitySymbol;
}
}
package ru.clearing.classes.StaticData.Misc;
import ru.spcex.platform.classes.base.SpcexObjectBase;
import java.math.BigDecimal;
import java.time.Instant;
/**
* Инструменты Денежного рынка
* <p>
* DB table: MONEY_MARKET_SECURITY
**/
public class MoneyMarketSecurity extends SpcexObjectBase {
private Long securityId;// (linked to security)
private String description;
private Instant startDate;
private Instant endDate;
private BigDecimal nominalValue;
private Long nominalCurrency; // (linked to currencyCode)
private String instrumentType; // (linked to instrumentType)
private String fullName;
private String securitySymbol;
public Long getSecurityId() {
return securityId;
}
public void setSecurityId(Long securityId) {
this.securityId = securityId;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Instant getStartDate() {
return startDate;
}
public void setStartDate(Instant startDate) {
this.startDate = startDate;
}
public Instant getEndDate() {
return endDate;
}
public void setEndDate(Instant endDate) {
this.endDate = endDate;
}
public BigDecimal getNominalValue() {
return nominalValue;
}
public void setNominalValue(BigDecimal nominalValue) {
this.nominalValue = nominalValue;
}
public Long getNominalCurrency() {
return nominalCurrency;
}
public void setNominalCurrency(Long nominalCurrency) {
this.nominalCurrency = nominalCurrency;
}
public String getInstrumentType() {
return instrumentType;
}
public void setInstrumentType(String instrumentType) {
this.instrumentType = instrumentType;
}
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
public String getSecuritySymbol() {
return securitySymbol;
}
public void setSecuritySymbol(String securitySymbol) {
this.securitySymbol = securitySymbol;
}
}

View file

@ -42,7 +42,7 @@ public class KeyRateMapStore extends TemplateMapStore<KeyRate> {
protected KeyRate objectReader(ResultSet resultSet) throws SQLException {
KeyRate keyRate = new KeyRate();
keyRate.setId(resultSet.getObject("ID", Long.class));
keyRate.setRate(resultSet.getObject("RATE", BigDecimal.class));
keyRate.setRate(resultSet.getObject("RATE", Double.class));
keyRate.setStartDate(getInstantFromTimestamp(resultSet,"START_DATE"));
keyRate.setEndDate(getInstantFromTimestamp(resultSet, "END_DATE"));
keyRate.setDocument(resultSet.getObject("DOCUMENT", String.class));

View file

@ -24,6 +24,7 @@
<module>dbf-importer</module>
<module>dbf-exporter</module>
<module>securities-service</module>
<module>utility-service</module>
</modules>
<properties>

View file

@ -0,0 +1,70 @@
<?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"
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>utility-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.utility;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class UtilityServiceApplication {
public static void main(String[] args) {
SpringApplication springApplication = new SpringApplication(UtilityServiceApplication.class);
springApplication.run(args);
}
}

View file

@ -0,0 +1,17 @@
package ru.spcex.clearing.utility.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.platform.messaging.config.KafkaConsumerFactory;
import ru.spcex.clearing.utility.config.settings.UtilityServiceSettings;
@Configuration
public class KafkaConfig {
@Autowired
@Bean
public Consumer<String, Object> createProducer(UtilityServiceSettings settings) {
return KafkaConsumerFactory.consumer(settings.getKafka());
}
}

View file

@ -0,0 +1,49 @@
package ru.spcex.clearing.utility.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.utility.config.settings.UtilityServiceSettings;
import ru.spcex.platform.imdg.api.ImdgProvider;
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
@Configuration
public class UtilityServiceImdgConfig {
@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,
UtilityServiceSettings settings
) {
return new HazelcastService(taskExecutorHazelcastClientInitializer,
taskExecutorIdGeneratorAwaiter,
settings.getHazelcast());
}
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;
}
}

View file

@ -0,0 +1,31 @@
package ru.spcex.clearing.utility.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 UtilityServiceSettings {
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,75 @@
package ru.spcex.clearing.utility.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.Misc.KeyRate;
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.common.CommonDeleteRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.utilities.KeyRateNewRequest;
import ru.spcex.clearing.platform.messaging.domain.cud.utilities.KeyRateUpdateRequest;
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 KeyRateService extends QueueConsumer implements InitializingBean {
private final Logger log = LoggerFactory.getLogger(getClass());
private final Imdg<KeyRate> keyRateMap;
@Autowired
public KeyRateService(Consumer<String, Object> kafkaQueue, ImdgProvider imdgProvider) {
super(kafkaQueue);
this.keyRateMap = imdgProvider.getImdg(IMDGDistributedNames.Map_KeyRate, KeyRate.class);
}
@Override
public void afterPropertiesSet() {
callback(KeyRateNewRequest.class)
.setConsumer(this::newKeyRate)
.forDestination(Consts.DESTINATION_KEY_RATE_NEW, callbacks::put);
callback(KeyRateUpdateRequest.class)
.setConsumer(this::updateKeyRate)
.forDestination(Consts.DESTINATION_KEY_RATE_UPDATE, callbacks::put);
callback(CommonDeleteRequest.class)
.setConsumer(this::deleteKeyRate)
.forDestination(Consts.DESTINATION_KEY_RATE_DELETE, callbacks::put);
init();
}
private void newKeyRate(BaseRequest<KeyRateNewRequest> userRequest) {
KeyRateNewRequest req = userRequest.getRequestPayload();
log.debug("MoneyMarketSecurityNewRequest received");
KeyRate keyRate = new KeyRate();
keyRate.setEndDate(req.getEndDate());
keyRate.setDocument(req.getDocument());
keyRate.setRate(req.getKeyRate());
keyRate.setStartDate(req.getStartDate());
keyRateMap.insert(keyRate);
log.debug("successfully processed, new id {}", keyRate.getId());
}
private void updateKeyRate(BaseRequest<KeyRateUpdateRequest> userRequest) {
KeyRateUpdateRequest req = userRequest.getRequestPayload();
log.debug("MoneyMarketSecurityUpdateRequest received id = {}", req.getId());
KeyRate keyRate = keyRateMap.getSingleObjectByID(req.getId());
keyRate.setEndDate(req.getEndDate());
keyRate.setDocument(req.getDocument());
keyRate.setRate(req.getKeyRate());
keyRate.setStartDate(req.getStartDate());
keyRateMap.update(keyRate);
}
private void deleteKeyRate(BaseRequest<CommonDeleteRequest> userRequest) {
CommonDeleteRequest req = userRequest.getRequestPayload();
log.debug("CommonDeleteRequest received id = {}", req.getId());
KeyRate keyRate = keyRateMap.getSingleObjectByID(req.getId());
keyRateMap.delete(keyRate);
}
}

View file

@ -0,0 +1,13 @@
spring.main.web-application-type=none
utility-service.hazelcast.cluster-members=127.0.0.1
utility-service.hazelcast.login=dev
utility-service.hazelcast.password=dev-pass
utility-service.kafka.bootstrap-servers=localhost:9092
utility-service.kafka.group-id=dev-group
utility-service.kafka.enable-auto-commit=false
utility-service.kafka.session-timeout-ms=30000
utility-service.kafka.auto-offset-reset=latest
utility-service.kafka.linger-ms=1
utility-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/securities-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/securities-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>