export by request
This commit is contained in:
parent
f4100e394d
commit
0b2e5a13fb
3 changed files with 39 additions and 6 deletions
|
|
@ -12,6 +12,7 @@ public class ResultContainer {
|
|||
private UUID uuid;
|
||||
private Table tableForExport;
|
||||
private File fileForExport;
|
||||
private Long groupId;
|
||||
|
||||
protected ResultContainer() {}
|
||||
|
||||
|
|
@ -45,4 +46,12 @@ public class ResultContainer {
|
|||
public void setUuid(UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public Long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public void setGroupId(Long groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,12 +68,18 @@ public class ExportFromHazelcast extends Stage implements InitializingBean {
|
|||
boolean emptyMap = true;
|
||||
try (DBFWriter dbfWriter = new DBFWriter(dbfFile, dbfCharset)) {
|
||||
dbfWriter.setFields(dbfFieldsForTable.get(table));
|
||||
Collection<? extends SpcexObjectBase> allValues = map.getAllValues();
|
||||
if (allValues.isEmpty()) {
|
||||
Collection<? extends SpcexObjectBase> tableRows;
|
||||
if (resultContainer.getGroupId() != null) {
|
||||
Map<String, Long> queryParams = Map.of("generationId", resultContainer.getGroupId());
|
||||
tableRows = map.getCollectionObjectsByFieldValues(queryParams);
|
||||
} else {
|
||||
tableRows = map.getAllValues();
|
||||
}
|
||||
if (tableRows.isEmpty()) {
|
||||
log.info("uuid {}. Map {} is empty.", resultContainer.getUuid(), resultContainer.getTableForExport().getHazelcastMapName());
|
||||
return StageResult.COMPLETE;
|
||||
}
|
||||
for (SpcexObjectBase value : allValues) {
|
||||
for (SpcexObjectBase value : tableRows) {
|
||||
Object[] values;
|
||||
if (value instanceof SDf02 sDf02Value) values = s_df02_converter.toObjectArray(sDf02Value);
|
||||
else if (value instanceof SDf08 sDf08Value) values = s_df08_converter.toObjectArray(sDf08Value);
|
||||
|
|
@ -84,7 +90,7 @@ public class ExportFromHazelcast extends Stage implements InitializingBean {
|
|||
dbfWriter.addRecord(values);
|
||||
}
|
||||
writeOk = true;
|
||||
emptyMap = allValues.isEmpty();
|
||||
emptyMap = tableRows.isEmpty();
|
||||
} catch (Exception e) {
|
||||
log.error(String.format("uuid %s. Can't export table %s to file %s. Table was skipped.", resultContainer.getUuid(), table, dbfFile), e);
|
||||
return StageResult.ERROR;
|
||||
|
|
|
|||
|
|
@ -3,20 +3,30 @@ package ru.spcex.clearing.dbf.exporter.services;
|
|||
import org.apache.kafka.clients.consumer.Consumer;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.spcex.clearing.dbf.exporter.logic.data.ResultContainer;
|
||||
import ru.spcex.clearing.dbf.exporter.logic.data.enums.Table;
|
||||
import ru.spcex.clearing.dbf.exporter.logic.stages.Processor;
|
||||
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.ExportToFileRequest;
|
||||
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class CommandService extends QueueConsumer implements InitializingBean {
|
||||
|
||||
private final ImdgProvider imdgProvider;
|
||||
private final Processor processor;
|
||||
|
||||
public CommandService(Consumer<String, Object> kafkaQueue, ImdgProvider imdgProvider) {
|
||||
public CommandService(Consumer<String, Object> kafkaQueue,
|
||||
ImdgProvider imdgProvider,
|
||||
Processor processor) {
|
||||
super(kafkaQueue);
|
||||
this.imdgProvider = imdgProvider;
|
||||
this.processor = processor;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -28,6 +38,14 @@ public class CommandService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
|
||||
private void process(BaseRequest<ExportToFileRequest> systemRequest) {
|
||||
|
||||
ExportToFileRequest request = systemRequest.getRequestPayload();
|
||||
Optional<Table> tableForExport = Arrays.stream(Table.values()).
|
||||
filter(table -> table.getFilePrefix().equalsIgnoreCase(request.getNameOfTable())).findFirst();
|
||||
if (tableForExport.isEmpty()) {
|
||||
throw new IllegalStateException("Unsupported table prefix");
|
||||
}
|
||||
ResultContainer resultContainer = ResultContainer.createNewTask(tableForExport.get());
|
||||
resultContainer.setGroupId(request.getSdfGroupId());
|
||||
processor.process(resultContainer);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue