refactoring
This commit is contained in:
parent
10e9ef9079
commit
702cfacad1
4 changed files with 44 additions and 64 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package ru.spcex.clearing.xml.importer.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import com.ctc.wstx.stax.WstxInputFactory;
|
||||
import com.ctc.wstx.stax.WstxOutputFactory;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
|
|
@ -7,8 +9,6 @@ import com.fasterxml.jackson.dataformat.xml.XmlFactory;
|
|||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import javax.xml.stream.XMLInputFactory;
|
||||
import javax.xml.stream.XMLOutputFactory;
|
||||
import org.slf4j.Logger;
|
||||
|
|
@ -19,16 +19,12 @@ import org.springframework.context.annotation.Bean;
|
|||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf01;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.xml.importer.config.settings.ImportXMLServiceSettings;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF01ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF04ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF06ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF52ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF55ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.DF57ObjectTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.ObjectTag;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
@Configuration
|
||||
@EnableConfigurationProperties
|
||||
|
|
@ -37,10 +33,14 @@ public class XMLImporterConfig {
|
|||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final ImportXMLServiceSettings settings;
|
||||
private final ApplicationContext context;
|
||||
private final HazelcastService hazelcastService;
|
||||
|
||||
public XMLImporterConfig(ImportXMLServiceSettings settings, ApplicationContext context) {
|
||||
public XMLImporterConfig(ImportXMLServiceSettings settings,
|
||||
ApplicationContext context,
|
||||
HazelcastService hazelcastService) {
|
||||
this.settings = settings;
|
||||
this.context = context;
|
||||
this.hazelcastService = hazelcastService;
|
||||
}
|
||||
|
||||
@Bean("executor")
|
||||
|
|
@ -58,14 +58,14 @@ public class XMLImporterConfig {
|
|||
}
|
||||
|
||||
@Bean("mapOfTable")
|
||||
public Map<ETable, ObjectTag<? extends SpcexObjectBase>> getMapOfTables() {
|
||||
Map<ETable, ObjectTag<? extends SpcexObjectBase>> map = new HashMap<>();
|
||||
map.put(ETable.DF_01, new DF01ObjectTag());
|
||||
map.put(ETable.DF_04, new DF04ObjectTag());
|
||||
map.put(ETable.DF_06, new DF06ObjectTag());
|
||||
map.put(ETable.DF_52, new DF52ObjectTag());
|
||||
map.put(ETable.DF_55, new DF55ObjectTag());
|
||||
map.put(ETable.DF_57, new DF57ObjectTag());
|
||||
public Map<String, Imdg<?>> getMapOfTables() {
|
||||
Map<String, Imdg<?>> map = new HashMap<>();
|
||||
map.put(ETable.DF_01.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
map.put(ETable.DF_04.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
map.put(ETable.DF_06.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
map.put(ETable.DF_52.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
map.put(ETable.DF_55.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
map.put(ETable.DF_57.name(), hazelcastService.getImdg(IMDGDistributedNames.Map_SDf01, SDf01.class));
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,8 +3,7 @@ package ru.spcex.clearing.xml.importer.logic.data.tags.objects;
|
|||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.adapter.ImdgHazelcast;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
|
||||
@JsonSubTypes({
|
||||
|
|
@ -19,8 +18,8 @@ public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
|||
private final String prefix;
|
||||
private final Class<T1> clazz;
|
||||
private final String nameOfMap;
|
||||
protected HazelcastService hazelcastService;
|
||||
protected ImdgHazelcast<T1> map;
|
||||
// protected HazelcastService hazelcastService;
|
||||
|
||||
protected String filename;
|
||||
protected Long fileId;
|
||||
|
||||
|
|
@ -32,12 +31,14 @@ public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
|||
|
||||
public abstract T1 getSDfEntity();
|
||||
|
||||
public void insertEntity(T1 obj) {
|
||||
if (map == null) {
|
||||
bootMap();
|
||||
}
|
||||
public String getPrefix() {
|
||||
return prefix;
|
||||
}
|
||||
|
||||
public void insertEntity(Imdg<?> map) {
|
||||
T1 obj = getSDfEntity();
|
||||
if (checkOnExisting(obj)) {
|
||||
map.insert(obj);
|
||||
// map.insert(obj);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,14 +46,6 @@ public abstract class ObjectTag<T1 extends SpcexObjectBase> {
|
|||
return true;
|
||||
}
|
||||
|
||||
protected void bootMap() {
|
||||
map = (ImdgHazelcast<T1>) hazelcastService.getImdg(nameOfMap, clazz);
|
||||
}
|
||||
|
||||
public void setHazelcastService(HazelcastService hazelcastService) {
|
||||
this.hazelcastService = hazelcastService;
|
||||
}
|
||||
|
||||
public String getFilename() {
|
||||
return filename;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
package ru.spcex.clearing.xml.importer.logic.steps;
|
||||
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
|
@ -13,7 +13,7 @@ import ru.spcex.clearing.xml.importer.logic.data.enums.ETable;
|
|||
import ru.spcex.clearing.xml.importer.logic.data.enums.StageResult;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.DocumentTag;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.ObjectTag;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
|
|
@ -22,17 +22,17 @@ public class ImportToDB {
|
|||
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||
private final XmlMapper xmlMapper;
|
||||
private final HazelcastService hazelcastService;
|
||||
private final Map<ETable, ObjectTag<? extends SpcexObjectBase>> objectTagMap;
|
||||
private final XmlImportKafkaMessenger kafkaMessenger;
|
||||
private final Map<String, Imdg<?>> mapOfTable;
|
||||
|
||||
public ImportToDB(@Qualifier("xmlMapper") XmlMapper xmlMapper,
|
||||
HazelcastService hazelcastService,
|
||||
@Qualifier("mapOfTable") Map<ETable, ObjectTag<? extends SpcexObjectBase>> objectTagMap,
|
||||
XmlImportKafkaMessenger kafkaMessenger) {
|
||||
XmlImportKafkaMessenger kafkaMessenger,
|
||||
@Qualifier("mapOfTable") Map<String, Imdg<?>> mapOfTable) {
|
||||
this.xmlMapper = xmlMapper;
|
||||
this.hazelcastService = hazelcastService;
|
||||
this.objectTagMap = objectTagMap;
|
||||
this.kafkaMessenger = kafkaMessenger;
|
||||
this.mapOfTable = mapOfTable;
|
||||
}
|
||||
|
||||
public StageResult process(ResultContainer resultContainer) {
|
||||
|
|
@ -50,25 +50,15 @@ public class ImportToDB {
|
|||
return StageResult.ERROR;
|
||||
}
|
||||
|
||||
ObjectTag objectTag = objectTagMap.get(currTable);
|
||||
objectTag.setHazelcastService(hazelcastService);
|
||||
objectTag.setFilename(resultContainer.getXmlFile().getName());
|
||||
String fileName = resultContainer.getXmlFile().getName();
|
||||
Long fileId = hazelcastService.getImdgIdGenerator().nextId();
|
||||
objectTag.setFileId(fileId);
|
||||
|
||||
int i = 0;
|
||||
for (ObjectTag o : documentTag.getObjects()) {
|
||||
if (o == null) {
|
||||
log.warn("record index {} null", i);
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
objectTag.insertEntity(o.getSDfEntity());
|
||||
i++;
|
||||
for (ObjectTag<?> o : documentTag.getObjects()) {
|
||||
Imdg<?> imdgMap = mapOfTable.get(o.getPrefix());
|
||||
o.insertEntity(imdgMap);
|
||||
}
|
||||
|
||||
if (ETable.DF_01.equals(currTable)) {
|
||||
kafkaMessenger.sendPairSdfRequest(objectTag, currTable.getPrefix());
|
||||
kafkaMessenger.sendPairSdfRequest(fileName, fileId, currTable.getPrefix());
|
||||
}
|
||||
kafkaMessenger.notifySystemIfNeeded(currTable, fileId);
|
||||
kafkaMessenger.notifyUserAboutSuccessLoad(resultContainer);
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
package ru.spcex.clearing.xml.importer.logic.steps;
|
||||
|
||||
import static ru.spcex.clearing.platform.messaging.domain.Consts.PAIR_SDF;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
|
|
@ -11,6 +9,7 @@ import org.slf4j.LoggerFactory;
|
|||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||
import static ru.spcex.clearing.platform.messaging.domain.Consts.PAIR_SDF;
|
||||
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.domain.cud.utilities.NotificationNewRequest;
|
||||
|
|
@ -20,8 +19,6 @@ import ru.spcex.clearing.platform.messaging.service.sender.KafkaSender;
|
|||
import ru.spcex.clearing.xml.importer.logic.data.ResultContainer;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.enums.StageResult;
|
||||
import ru.spcex.clearing.xml.importer.logic.data.tags.objects.ObjectTag;
|
||||
import ru.spcex.platform.classes.base.SpcexObjectBase;
|
||||
import ru.spcex.platform.enumeration.ObjectType;
|
||||
import ru.spcex.platform.enumeration.Priority;
|
||||
import ru.spcex.platform.enumeration.SdfTable;
|
||||
|
|
@ -103,10 +100,10 @@ public class XmlImportKafkaMessenger implements InitializingBean {
|
|||
groupId, table, msgId, destination);
|
||||
}
|
||||
|
||||
public void sendPairSdfRequest(ObjectTag<? extends SpcexObjectBase> tag, String tableSdf) {
|
||||
public void sendPairSdfRequest(String fileName, Long fileId, String tableSdf) {
|
||||
PairSdfRequest request = new PairSdfRequest();
|
||||
request.setGenerationId(tag.getFileId());
|
||||
request.setFileNameSDf(tag.getFilename());
|
||||
request.setFileNameSDf(fileName);
|
||||
request.setGenerationId(fileId);
|
||||
request.setTableSDf(tableSdf);
|
||||
Long msgId = kafka.get().sendRequestToQueue(PAIR_SDF, request);
|
||||
log.info("Send PairSdfRequest={} message id={} to kafka \"{}\"", LogFormatter.toString(request), msgId, PAIR_SDF);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue