Merge remote-tracking branch 'origin/dev' into dev
This commit is contained in:
commit
91433d2710
9 changed files with 105 additions and 98 deletions
|
|
@ -16,6 +16,11 @@ public class MoneyMarketSecurityUpdateAction implements IAction<MoneyMarketSecur
|
|||
@ApiModelProperty(hidden = true)
|
||||
@JsonProperty
|
||||
public Long id;
|
||||
@ApiModelProperty(value = "Дата начала действия", example = "2022-02-21")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Europe/Moscow")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonProperty
|
||||
public LocalDate startDate;
|
||||
@ApiModelProperty(value = "Дата окончания действия", example = "2022-02-21")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Europe/Moscow")
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
|
|
@ -41,6 +46,7 @@ public class MoneyMarketSecurityUpdateAction implements IAction<MoneyMarketSecur
|
|||
public MoneyMarketSecurityUpdateRequest toRequest() {
|
||||
var req = new MoneyMarketSecurityUpdateRequest();
|
||||
req.setId(this.getId());
|
||||
req.setStartDate(this.getStartDate());
|
||||
req.setEndDate(this.getEndDate());
|
||||
req.setNominalValue(this.getNominalValue());
|
||||
req.setNominalCurrency(this.getNominalCurrency());
|
||||
|
|
@ -112,4 +118,12 @@ public class MoneyMarketSecurityUpdateAction implements IAction<MoneyMarketSecur
|
|||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,39 +9,53 @@ import ru.clearing.classes.statics.data.sdf.SDf08;
|
|||
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.balance.SDf08NewRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.enumeration.Task;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.api.ImdgId;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
|
||||
@Service
|
||||
public class Sdf08Service extends QueueConsumer implements InitializingBean {
|
||||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final Imdg<SDf08> sdf8Map;
|
||||
private final ImdgId idGenerator;
|
||||
private final KafkaSender kafkaReqProducer;
|
||||
|
||||
|
||||
public Sdf08Service(Consumer<String, Object> kafkaQueue, ImdgProvider imdgProvider) {
|
||||
public Sdf08Service(Consumer<String, Object> kafkaQueue, ImdgProvider imdgProvider, KafkaSender kafkaReqProducer) {
|
||||
super(kafkaQueue);
|
||||
this.sdf8Map = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf08, SDf08.class);
|
||||
this.idGenerator = imdgProvider.getImdgIdGenerator();
|
||||
this.kafkaReqProducer = kafkaReqProducer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterPropertiesSet() {
|
||||
callback(SDf08NewRequest.class)
|
||||
callback(Object.class)
|
||||
.setConsumer(this::newSDf08)
|
||||
.forDestination(Consts.DESTINATION_SDF08_NEW, callbacks::put);
|
||||
.forDestination(Task.getAllBalance.topic(), callbacks::put);
|
||||
init();
|
||||
}
|
||||
|
||||
private void newSDf08(BaseRequest<SDf08NewRequest> userRequest) {
|
||||
SDf08NewRequest req = userRequest.getRequestPayload();
|
||||
log.debug("SDf08NewRequest received");
|
||||
private void newSDf08(BaseRequest<Object> userRequest) {
|
||||
log.debug("getAllBalance request received");
|
||||
SDf08 sDf08 = new SDf08();
|
||||
sDf08.setNumber(req.getNumber());
|
||||
sDf08.setDatetime(req.getDatetime());
|
||||
sDf08.setGenerationTime(req.getGenerationTime());
|
||||
sDf08.setGenerationId(req.getGenerationId());
|
||||
sDf08.setNumber(BigDecimal.valueOf(Math.random()));
|
||||
Instant now = Instant.now();
|
||||
sDf08.setDatetime(now);
|
||||
sDf08.setGenerationTime(now);
|
||||
sDf08.setGenerationId(idGenerator.nextId());
|
||||
sdf8Map.insert(sDf08);
|
||||
ExportToFileRequest exportRequest = new ExportToFileRequest();
|
||||
exportRequest.setSdfGroupId(sDf08.getGenerationId());
|
||||
exportRequest.setNameOfTable("DF-08");
|
||||
kafkaReqProducer.sendRequestToQueue(Consts.EXPORT_PROCESS, exportRequest);
|
||||
log.debug("successfully processed, new id {}", sDf08.getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import ru.spcex.clearing.platform.messaging.domain.Consts;
|
|||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.StatementRequest;
|
||||
import ru.spcex.clearing.platform.messaging.domain.cud.clearing.Sdf04Request;
|
||||
import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
||||
import ru.spcex.platform.enumeration.SdfTable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
|
@ -43,6 +44,7 @@ public class DbfImportKafkaMessenger implements InitializingBean {
|
|||
private void messageDf01(Long groupId) {
|
||||
StatementRequest statementRequest = new StatementRequest();
|
||||
statementRequest.setGroupId(groupId);
|
||||
statementRequest.setTable(SdfTable.SDF_01);
|
||||
kafka.get().sendRequestToQueue(Consts.STATEMENT_PROCESS, statementRequest);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@ import ru.spcex.clearing.dbf.importer.logic.data.ResultContainer;
|
|||
import ru.spcex.clearing.dbf.importer.logic.data.enums.ETable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
|
@ -26,6 +25,7 @@ public class DBFImporterService {
|
|||
private final FileChecker fileChecker;
|
||||
private final ThreadPoolTaskExecutor executorService;
|
||||
private final Processor processor;
|
||||
private final Set<Path> filesCurrentlyInProcess;
|
||||
|
||||
public DBFImporterService(@Qualifier("fileChecker") FileChecker messageListener,
|
||||
@Qualifier("executor") ThreadPoolTaskExecutor executorService,
|
||||
|
|
@ -33,6 +33,7 @@ public class DBFImporterService {
|
|||
this.fileChecker = messageListener;
|
||||
this.executorService = executorService;
|
||||
this.processor = processor;
|
||||
this.filesCurrentlyInProcess = new HashSet<>();
|
||||
}
|
||||
|
||||
@Scheduled(cron = "${import-dbf-service.scheduler.check-src-dir-cron}")
|
||||
|
|
@ -43,23 +44,52 @@ public class DBFImporterService {
|
|||
public void run(ETable specificTable) {
|
||||
log.info("adding import task {}", specificTable != null ? specificTable.name() : "");
|
||||
executorService.execute(() -> {
|
||||
log.info("checking new files... {}", specificTable != null ? specificTable.name() : "");
|
||||
Map<ETable, List<File>> newFiles = fileChecker.checkNewFiles(specificTable);
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("following files will be processed {}", forLogging(newFiles));
|
||||
} else {
|
||||
log.info("following files will be processed {}", forLoggingSizeOnly(newFiles));
|
||||
}
|
||||
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
||||
ETable currTable = newFilesEntry.getKey();
|
||||
List<File> fileList = newFilesEntry.getValue();
|
||||
for (File dbfFile : fileList) {
|
||||
processor.process(ResultContainer.createNewTask(currTable, dbfFile));
|
||||
Map<ETable, List<File>> newFiles = null;
|
||||
try {
|
||||
log.info("checking new files... {}", specificTable != null ? specificTable.name() : "");
|
||||
newFiles = getFiles(specificTable);
|
||||
if (newFiles.size() > 0 && log.isDebugEnabled()) {
|
||||
log.debug("following files will be processed {}", forLogging(newFiles));
|
||||
} else if (newFiles.size() > 0) {
|
||||
log.info("following files will be processed {}", forLoggingSizeOnly(newFiles));
|
||||
} else {
|
||||
log.info("no files were found");
|
||||
}
|
||||
for (Map.Entry<ETable, List<File>> newFilesEntry : newFiles.entrySet()) {
|
||||
ETable currTable = newFilesEntry.getKey();
|
||||
List<File> fileList = newFilesEntry.getValue();
|
||||
for (File dbfFile : fileList) {
|
||||
processor.process(ResultContainer.createNewTask(currTable, dbfFile));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (newFiles != null && newFiles.size() > 0) {
|
||||
cleanFiles(newFiles);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private synchronized Map<ETable, List<File>> getFiles(ETable specificTable) {
|
||||
Map<ETable, List<File>> newFiles = fileChecker.checkNewFiles(specificTable);
|
||||
Map<ETable, List<File>> newFilesFiltered = newFiles.entrySet()
|
||||
.stream()
|
||||
.map(entry ->
|
||||
new AbstractMap.SimpleEntry<>(entry.getKey(), entry.getValue()
|
||||
.stream()
|
||||
.filter(file -> !filesCurrentlyInProcess.contains(file.toPath()))
|
||||
.collect(Collectors.toList())))
|
||||
.collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue));
|
||||
newFilesFiltered.forEach((table, files)
|
||||
-> files.forEach(file -> filesCurrentlyInProcess.add(file.toPath())));
|
||||
return newFilesFiltered;
|
||||
}
|
||||
|
||||
private synchronized void cleanFiles(Map<ETable, List<File>> filesFromTask) {
|
||||
filesFromTask.forEach((table, files)
|
||||
-> files.forEach(file -> filesCurrentlyInProcess.remove(file.toPath())));
|
||||
}
|
||||
|
||||
private static String forLogging(Map<ETable, List<File>> files) {
|
||||
return files
|
||||
.entrySet()
|
||||
|
|
|
|||
|
|
@ -112,6 +112,7 @@ public class MoneyMarketSecurityService extends QueueConsumer implements Initial
|
|||
log.debug("MoneyMarketSecurityUpdateRequest received id = {}", req.getId());
|
||||
MoneyMarketSecurity mms = moneyMarketSecurityMap.getSingleObjectByID(req.getId());
|
||||
mms.setUpdated(Instant.now());
|
||||
mms.setStartDate(req.getStartDate());
|
||||
mms.setEndDate(req.getEndDate());
|
||||
mms.setNominalValue(req.getNominalValue() != null ? BigDecimal.valueOf(req.getNominalValue()) : null);
|
||||
mms.setNominalCurrency(req.getNominalCurrency());
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ru.spcex.platform.enumeration;
|
|||
import ru.spcex.platform.utils.enumeration.IEnumKey;
|
||||
|
||||
public enum Task implements IEnumKey {
|
||||
createOrder("CORD"), createOrderConfirm("CORC");
|
||||
createOrder("CORD"), createOrderConfirm("CORC"), getAllBalance("GALB");
|
||||
|
||||
private final String key;
|
||||
|
||||
|
|
|
|||
|
|
@ -90,8 +90,8 @@ public class ImdgHazelcast<T extends SpcexObjectBase> implements Imdg<T> {
|
|||
predicates[i[0]] = Predicates.equal(key, value);
|
||||
i[0]++;
|
||||
});
|
||||
Predicate<Long, T> or = Predicates.or(predicates);
|
||||
Set<Map.Entry<Long, T>> found = map.entrySet(or);
|
||||
Predicate<Long, T> and = Predicates.and(predicates);
|
||||
Set<Map.Entry<Long, T>> found = map.entrySet(and);
|
||||
Iterator<Map.Entry<Long, T>> allFoundByCondition = found.iterator();
|
||||
if (allFoundByCondition.hasNext()) {
|
||||
return allFoundByCondition.next().getValue();
|
||||
|
|
@ -122,8 +122,8 @@ public class ImdgHazelcast<T extends SpcexObjectBase> implements Imdg<T> {
|
|||
predicates[i[0]] = Predicates.equal(key, value);
|
||||
i[0]++;
|
||||
});
|
||||
Predicate<Long, T> or = Predicates.or(predicates);
|
||||
Set<Long> ids = map.keySet(or);
|
||||
Predicate<Long, T> and = Predicates.and(predicates);
|
||||
Set<Long> ids = map.keySet(and);
|
||||
Iterator<Long> idIterator = ids.iterator();
|
||||
Collection<T> searchResult = new ArrayList<>();
|
||||
while (idIterator.hasNext()) {
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
package ru.spcex.clearing.platform.messaging.domain.cud.balance;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import ru.spcex.clearing.platform.messaging.domain.json.deserialize.InstantDeserializer;
|
||||
import ru.spcex.clearing.platform.messaging.domain.json.serialize.InstantSerializer;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.Instant;
|
||||
|
||||
public class SDf08NewRequest {
|
||||
@JsonProperty
|
||||
private BigDecimal number;
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
private Instant datetime;
|
||||
@JsonProperty
|
||||
private String fileName;
|
||||
@JsonSerialize(using = InstantSerializer.class)
|
||||
@JsonDeserialize(using = InstantDeserializer.class)
|
||||
@JsonProperty
|
||||
private Instant generationTime;
|
||||
@JsonProperty
|
||||
private Long generationId;
|
||||
|
||||
public BigDecimal getNumber() {
|
||||
return number;
|
||||
}
|
||||
|
||||
public void setNumber(BigDecimal number) {
|
||||
this.number = number;
|
||||
}
|
||||
|
||||
public Instant getDatetime() {
|
||||
return datetime;
|
||||
}
|
||||
|
||||
public void setDatetime(Instant datetime) {
|
||||
this.datetime = datetime;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public Instant getGenerationTime() {
|
||||
return generationTime;
|
||||
}
|
||||
|
||||
public void setGenerationTime(Instant generationTime) {
|
||||
this.generationTime = generationTime;
|
||||
}
|
||||
|
||||
public Long getGenerationId() {
|
||||
return generationId;
|
||||
}
|
||||
|
||||
public void setGenerationId(Long generationId) {
|
||||
this.generationId = generationId;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,11 @@ public class MoneyMarketSecurityUpdateRequest {
|
|||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonProperty
|
||||
public LocalDate startDate;
|
||||
@JsonFormat(pattern = "yyyy-MM-dd", timezone = "Europe/Moscow")
|
||||
@JsonSerialize(using = LocalDateSerializer.class)
|
||||
@JsonDeserialize(using = LocalDateDeserializer.class)
|
||||
@JsonProperty
|
||||
public LocalDate endDate;
|
||||
@JsonProperty
|
||||
public Double nominalValue;
|
||||
|
|
@ -83,4 +88,12 @@ public class MoneyMarketSecurityUpdateRequest {
|
|||
public void setLotSize(Double lotSize) {
|
||||
this.lotSize = lotSize;
|
||||
}
|
||||
|
||||
public LocalDate getStartDate() {
|
||||
return startDate;
|
||||
}
|
||||
|
||||
public void setStartDate(LocalDate startDate) {
|
||||
this.startDate = startDate;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue