--- реализовал обработку команд добавления, изменения, удаления Ключевой ставки ЦБ.
This commit is contained in:
parent
8fa93e924b
commit
9bdce4dfb6
12 changed files with 461 additions and 155 deletions
|
|
@ -11,17 +11,17 @@ import java.time.Instant;
|
||||||
* DB table: KEY_RATE
|
* DB table: KEY_RATE
|
||||||
**/
|
**/
|
||||||
public class KeyRate extends SpcexObjectBase {
|
public class KeyRate extends SpcexObjectBase {
|
||||||
private BigDecimal rate;
|
private Double rate;
|
||||||
private Instant startDate;
|
private Instant startDate;
|
||||||
private Instant endDate;
|
private Instant endDate;
|
||||||
private String document;
|
private String document;
|
||||||
private String workflowStatus;
|
private String workflowStatus;
|
||||||
|
|
||||||
public BigDecimal getRate() {
|
public Double getRate() {
|
||||||
return rate;
|
return rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRate(BigDecimal rate) {
|
public void setRate(Double rate) {
|
||||||
this.rate = rate;
|
this.rate = rate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ public class KeyRateMapStore extends TemplateMapStore<KeyRate> {
|
||||||
protected KeyRate objectReader(ResultSet resultSet) throws SQLException {
|
protected KeyRate objectReader(ResultSet resultSet) throws SQLException {
|
||||||
KeyRate keyRate = new KeyRate();
|
KeyRate keyRate = new KeyRate();
|
||||||
keyRate.setId(resultSet.getObject("ID", Long.class));
|
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.setStartDate(getInstantFromTimestamp(resultSet,"START_DATE"));
|
||||||
keyRate.setEndDate(getInstantFromTimestamp(resultSet, "END_DATE"));
|
keyRate.setEndDate(getInstantFromTimestamp(resultSet, "END_DATE"));
|
||||||
keyRate.setDocument(resultSet.getObject("DOCUMENT", String.class));
|
keyRate.setDocument(resultSet.getObject("DOCUMENT", String.class));
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<module>dbf-importer</module>
|
<module>dbf-importer</module>
|
||||||
<module>dbf-exporter</module>
|
<module>dbf-exporter</module>
|
||||||
<module>securities-service</module>
|
<module>securities-service</module>
|
||||||
|
<module>utility-service</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
|
|
|
||||||
70
clearing-parent/utility-service/pom.xml
Normal file
70
clearing-parent/utility-service/pom.xml
Normal 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>
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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>
|
||||||
Loading…
Add table
Reference in a new issue