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 UUID uuid;
|
||||||
private Table tableForExport;
|
private Table tableForExport;
|
||||||
private File fileForExport;
|
private File fileForExport;
|
||||||
|
private Long groupId;
|
||||||
|
|
||||||
protected ResultContainer() {}
|
protected ResultContainer() {}
|
||||||
|
|
||||||
|
|
@ -45,4 +46,12 @@ public class ResultContainer {
|
||||||
public void setUuid(UUID uuid) {
|
public void setUuid(UUID uuid) {
|
||||||
this.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;
|
boolean emptyMap = true;
|
||||||
try (DBFWriter dbfWriter = new DBFWriter(dbfFile, dbfCharset)) {
|
try (DBFWriter dbfWriter = new DBFWriter(dbfFile, dbfCharset)) {
|
||||||
dbfWriter.setFields(dbfFieldsForTable.get(table));
|
dbfWriter.setFields(dbfFieldsForTable.get(table));
|
||||||
Collection<? extends SpcexObjectBase> allValues = map.getAllValues();
|
Collection<? extends SpcexObjectBase> tableRows;
|
||||||
if (allValues.isEmpty()) {
|
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());
|
log.info("uuid {}. Map {} is empty.", resultContainer.getUuid(), resultContainer.getTableForExport().getHazelcastMapName());
|
||||||
return StageResult.COMPLETE;
|
return StageResult.COMPLETE;
|
||||||
}
|
}
|
||||||
for (SpcexObjectBase value : allValues) {
|
for (SpcexObjectBase value : tableRows) {
|
||||||
Object[] values;
|
Object[] values;
|
||||||
if (value instanceof SDf02 sDf02Value) values = s_df02_converter.toObjectArray(sDf02Value);
|
if (value instanceof SDf02 sDf02Value) values = s_df02_converter.toObjectArray(sDf02Value);
|
||||||
else if (value instanceof SDf08 sDf08Value) values = s_df08_converter.toObjectArray(sDf08Value);
|
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);
|
dbfWriter.addRecord(values);
|
||||||
}
|
}
|
||||||
writeOk = true;
|
writeOk = true;
|
||||||
emptyMap = allValues.isEmpty();
|
emptyMap = tableRows.isEmpty();
|
||||||
} catch (Exception e) {
|
} 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);
|
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;
|
return StageResult.ERROR;
|
||||||
|
|
|
||||||
|
|
@ -3,20 +3,30 @@ package ru.spcex.clearing.dbf.exporter.services;
|
||||||
import org.apache.kafka.clients.consumer.Consumer;
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.stereotype.Service;
|
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.BaseRequest;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
import ru.spcex.clearing.platform.messaging.domain.cud.balance.ExportToFileRequest;
|
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.QueueConsumer;
|
||||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class CommandService extends QueueConsumer implements InitializingBean {
|
public class CommandService extends QueueConsumer implements InitializingBean {
|
||||||
|
|
||||||
private final ImdgProvider imdgProvider;
|
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);
|
super(kafkaQueue);
|
||||||
this.imdgProvider = imdgProvider;
|
this.imdgProvider = imdgProvider;
|
||||||
|
this.processor = processor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -28,6 +38,14 @@ public class CommandService extends QueueConsumer implements InitializingBean {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void process(BaseRequest<ExportToFileRequest> systemRequest) {
|
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