parent
2c65f7ab92
commit
d4142e3b03
11 changed files with 180 additions and 3 deletions
|
|
@ -57,6 +57,7 @@ public class SWTImporterConfig {
|
||||||
map.put(ETable.S_DF_08, new SDf08Table());
|
map.put(ETable.S_DF_08, new SDf08Table());
|
||||||
map.put(ETable.S_DF_10, new SDf10Table());
|
map.put(ETable.S_DF_10, new SDf10Table());
|
||||||
map.put(ETable.S_DF_13, new SDf13Table());
|
map.put(ETable.S_DF_13, new SDf13Table());
|
||||||
|
map.put(ETable.S_DF_20, new SDf20Table());
|
||||||
map.put(ETable.S_DF_21, new SDf21Table());
|
map.put(ETable.S_DF_21, new SDf21Table());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ public enum ETable {
|
||||||
S_DF_08("DF-08"),
|
S_DF_08("DF-08"),
|
||||||
S_DF_10("DF-10"),
|
S_DF_10("DF-10"),
|
||||||
S_DF_13("DF-13"),
|
S_DF_13("DF-13"),
|
||||||
|
S_DF_20("DF-20"),
|
||||||
S_DF_21("DF-21");
|
S_DF_21("DF-21");
|
||||||
//S_DF20("DF-20");
|
|
||||||
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
package ru.spcex.clearing.swt.importer.logic.data.tables;
|
||||||
|
|
||||||
|
import ru.clearing.classes.statics.data.sdf.SDf20;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||||
|
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
public class SDf20Table extends AbstractTable<SDf20> {
|
||||||
|
|
||||||
|
private static final String PREFIX = ETable.S_DF_20.name();
|
||||||
|
private static final Class<SDf20> CLAZZ = SDf20.class;
|
||||||
|
private static final String NAME_OF_HZ_MAP = IMDGDistributedNames.Map_SDf20;
|
||||||
|
|
||||||
|
public SDf20Table() {
|
||||||
|
super(PREFIX, CLAZZ, NAME_OF_HZ_MAP);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SDf20 getEntity(SWTRecord record) {
|
||||||
|
SDf20 result = new SDf20();
|
||||||
|
result.setOutDocument(record.getValFor20Tag());
|
||||||
|
result.setInDocument(record.getValFor21Tag());
|
||||||
|
result.setSecurity(record.getValFor35BTag()[0]);
|
||||||
|
result.setOpenBalance(record.getValFor60ATag());
|
||||||
|
result.setDepoCodeCl(record.getValFor83DTag()[0]);
|
||||||
|
result.setQuantity(record.getValFor35ATag());
|
||||||
|
result.setOperationCode(record.getValFor66ATag());
|
||||||
|
result.setDepoCodeCorr(record.getValFor87DTag());
|
||||||
|
result.setOperationDate(record.getValFor30Tag());
|
||||||
|
result.setCloseBalance(record.getValFor62ATag());
|
||||||
|
result.setFileName(filename);
|
||||||
|
result.setGenerationTime(Instant.now());
|
||||||
|
result.setGenerationId(fileId);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -31,6 +31,7 @@ public class SWTImportKafkaMessenger implements InitializingBean {
|
||||||
messengers.put(ETable.S_DF_08, groupId -> messageBalance(groupId, SdfTable.SDF_08));
|
messengers.put(ETable.S_DF_08, groupId -> messageBalance(groupId, SdfTable.SDF_08));
|
||||||
messengers.put(ETable.S_DF_10, groupId -> messageBalance(groupId, SdfTable.SDF_10));
|
messengers.put(ETable.S_DF_10, groupId -> messageBalance(groupId, SdfTable.SDF_10));
|
||||||
messengers.put(ETable.S_DF_13, groupId -> messageBalance(groupId, SdfTable.SDF_13));
|
messengers.put(ETable.S_DF_13, groupId -> messageBalance(groupId, SdfTable.SDF_13));
|
||||||
|
messengers.put(ETable.S_DF_20, groupId -> messageBalance(groupId, SdfTable.SDF_20));
|
||||||
messengers.put(ETable.S_DF_21, groupId -> messageBalance(groupId, SdfTable.SDF_21));
|
messengers.put(ETable.S_DF_21, groupId -> messageBalance(groupId, SdfTable.SDF_21));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.swt.importer.readers;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns;
|
import ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns;
|
||||||
|
import ru.spcex.clearing.swt.importer.readers.template.SDf20Template;
|
||||||
import ru.spcex.clearing.swt.importer.readers.template.SDf21Template;
|
import ru.spcex.clearing.swt.importer.readers.template.SDf21Template;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -54,4 +55,8 @@ public abstract class AbstractTemplate {
|
||||||
public static AbstractTemplate getSDf21Template(Scanner scanner){
|
public static AbstractTemplate getSDf21Template(Scanner scanner){
|
||||||
return new SDf21Template(scanner);
|
return new SDf21Template(scanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static AbstractTemplate getSDf20Template(Scanner scanner){
|
||||||
|
return new SDf20Template(scanner);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ public class SWTReader implements Closeable {
|
||||||
recordEnds.put(ETable.S_DF_08, ReadingPatterns.TableRow);
|
recordEnds.put(ETable.S_DF_08, ReadingPatterns.TableRow);
|
||||||
recordEnds.put(ETable.S_DF_10, ReadingPatterns.TableRow);
|
recordEnds.put(ETable.S_DF_10, ReadingPatterns.TableRow);
|
||||||
recordEnds.put(ETable.S_DF_13, ReadingPatterns.Tag77A);
|
recordEnds.put(ETable.S_DF_13, ReadingPatterns.Tag77A);
|
||||||
|
templates.put(ETable.S_DF_20, AbstractTemplate::getSDf20Template);
|
||||||
templates.put(ETable.S_DF_21, AbstractTemplate::getSDf21Template);
|
templates.put(ETable.S_DF_21, AbstractTemplate::getSDf21Template);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
package ru.spcex.clearing.swt.importer.readers.template;
|
||||||
|
|
||||||
|
import ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns;
|
||||||
|
import ru.spcex.clearing.swt.importer.readers.AbstractTemplate;
|
||||||
|
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||||
|
import ru.spcex.clearing.swt.importer.readers.ValidationResult;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns.*;
|
||||||
|
import static ru.spcex.clearing.swt.importer.readers.ValidationResult.SUCSESS;
|
||||||
|
|
||||||
|
public class SDf20Template extends AbstractTemplate {
|
||||||
|
private List<ReadingPatterns> hederPatterns = List.of(
|
||||||
|
To,
|
||||||
|
From,
|
||||||
|
Type,
|
||||||
|
DateTime,
|
||||||
|
Tag20,
|
||||||
|
Tag21,
|
||||||
|
Tag35B,
|
||||||
|
Tag60A,
|
||||||
|
Tag83D,
|
||||||
|
Tag20C,
|
||||||
|
Tag35A,
|
||||||
|
Tag23,
|
||||||
|
Tag66A,
|
||||||
|
Tag87D,
|
||||||
|
Tag30,
|
||||||
|
Tag62A);
|
||||||
|
|
||||||
|
private List<SWTRecord> groupRecords = new ArrayList<>();
|
||||||
|
|
||||||
|
private String line = "";
|
||||||
|
|
||||||
|
public SDf20Template(Scanner scanner) {
|
||||||
|
super(scanner);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected List<SWTRecord> getGroupRecords() {
|
||||||
|
return groupRecords;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ValidationResult readAndValidate() {
|
||||||
|
SWTRecord currentRecord = new SWTRecord();
|
||||||
|
currentRecord.setNotEmpty(false);
|
||||||
|
ReadingPatterns currentPattern;
|
||||||
|
boolean hederEnded = false;
|
||||||
|
boolean recordEmpty = true;
|
||||||
|
ValidationResult result = prepareNextLine(this::setLine);
|
||||||
|
if (!SUCSESS.equals(result)) return result;
|
||||||
|
for (int i = 0; i < hederPatterns.size() && !isReadEnded(); i++) {
|
||||||
|
currentPattern = hederPatterns.get(i);
|
||||||
|
if (currentPattern.canRead(line)) {
|
||||||
|
currentPattern.reed(line, currentRecord);
|
||||||
|
currentRecord.setNotEmpty(true);
|
||||||
|
if (Tag21.equals(currentPattern)) {
|
||||||
|
hederEnded = true;
|
||||||
|
} else if (Tag35B.equals(currentPattern)) {
|
||||||
|
recordEmpty = false;
|
||||||
|
} else if (Tag62A.equals(currentPattern)) {
|
||||||
|
groupRecords.add(currentRecord);
|
||||||
|
setReadEnded(true);
|
||||||
|
return SUCSESS;
|
||||||
|
}
|
||||||
|
result = prepareNextLine(this::setLine);
|
||||||
|
if (!SUCSESS.equals(result)) {
|
||||||
|
if (hederEnded && recordEmpty) {
|
||||||
|
setReadEnded(true);
|
||||||
|
return SUCSESS;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
result = checkNotValue(line, "required teg: " + currentPattern.name() + ", but was: ");
|
||||||
|
if (!SUCSESS.equals(result)) return result;
|
||||||
|
result = prepareNextLine(this::setLine);
|
||||||
|
if (!SUCSESS.equals(result)) {
|
||||||
|
if (hederEnded && recordEmpty) {
|
||||||
|
setReadEnded(true);
|
||||||
|
return SUCSESS;
|
||||||
|
} else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!recordEmpty) groupRecords.add(currentRecord);
|
||||||
|
setReadEnded(true);
|
||||||
|
return SUCSESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLine(String line) {
|
||||||
|
this.line = line;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -30,6 +30,7 @@ public class ImportSWTServiceTest {
|
||||||
map.put(ETable.S_DF_08, new SDf08Table());
|
map.put(ETable.S_DF_08, new SDf08Table());
|
||||||
map.put(ETable.S_DF_10, new SDf10Table());
|
map.put(ETable.S_DF_10, new SDf10Table());
|
||||||
map.put(ETable.S_DF_13, new SDf13Table());
|
map.put(ETable.S_DF_13, new SDf13Table());
|
||||||
|
map.put(ETable.S_DF_20, new SDf20Table());
|
||||||
map.put(ETable.S_DF_21, new SDf21Table());
|
map.put(ETable.S_DF_21, new SDf21Table());
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
To:SPCE
|
||||||
|
From:CSO
|
||||||
|
Type:512
|
||||||
|
Date/Time:20230717/1639
|
||||||
|
:20:SPCEX_20230717Q8712-512
|
||||||
|
:21:NONREF
|
||||||
|
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||||
|
:60A:SHS0,
|
||||||
|
:83D:747200000AT0:ÏÀÎ "Ïðîìñâÿçüáàíê"
|
||||||
|
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||||
|
:35A:SHS100000,
|
||||||
|
:23:8712
|
||||||
|
:66A:RECFREE
|
||||||
|
:87D:747288887ZT0
|
||||||
|
:30:20230406
|
||||||
|
:62A:SHS9900000,
|
||||||
|
|
@ -7,6 +7,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf10;
|
import ru.clearing.classes.statics.data.sdf.SDf10;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf13;
|
import ru.clearing.classes.statics.data.sdf.SDf13;
|
||||||
|
import ru.clearing.classes.statics.data.sdf.SDf20;
|
||||||
import ru.clearing.classes.statics.data.sdf.SDf21;
|
import ru.clearing.classes.statics.data.sdf.SDf21;
|
||||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
import ru.spcex.clearing.swt.importer.config.ImportSWTServiceTest;
|
import ru.spcex.clearing.swt.importer.config.ImportSWTServiceTest;
|
||||||
|
|
@ -49,11 +50,20 @@ class ImportToDBTest {
|
||||||
}
|
}
|
||||||
// @Test
|
// @Test
|
||||||
void process() throws IOException {
|
void process() throws IOException {
|
||||||
ETable eTable = ETable.S_DF_21;
|
ETable eTable = ETable.S_DF_20;
|
||||||
File swtFile = new File("D:\\repo\\mfd\\clearing\\clearing-parent\\swt-importer\\src\\test\\java\\ru\\spcex\\clearing\\swt\\importer\\files\\RDC_KS_DF-21_230717164021676.txt");
|
File swtFile = new File("D:\\repo\\mfd\\clearing\\clearing-parent\\swt-importer\\src\\test\\java\\ru\\spcex\\clearing\\swt\\importer\\files\\RDC_KS_DF-20_230717163911161.txt");
|
||||||
ResultContainer resultContainer = createNewTask(eTable, swtFile);
|
ResultContainer resultContainer = createNewTask(eTable, swtFile);
|
||||||
resultContainer.setSwtSource(Files.readAllBytes(Paths.get(swtFile.getAbsolutePath())));
|
resultContainer.setSwtSource(Files.readAllBytes(Paths.get(swtFile.getAbsolutePath())));
|
||||||
|
|
||||||
|
importToDB.process(resultContainer);
|
||||||
|
Imdg<SDf20> df20Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf20, SDf20.class);
|
||||||
|
df20Imdg.getAllValues();
|
||||||
|
|
||||||
|
eTable = ETable.S_DF_21;
|
||||||
|
swtFile = new File("D:\\repo\\mfd\\clearing\\clearing-parent\\swt-importer\\src\\test\\java\\ru\\spcex\\clearing\\swt\\importer\\files\\RDC_KS_DF-21_230717164021676.txt");
|
||||||
|
resultContainer = createNewTask(eTable, swtFile);
|
||||||
|
resultContainer.setSwtSource(Files.readAllBytes(Paths.get(swtFile.getAbsolutePath())));
|
||||||
|
|
||||||
importToDB.process(resultContainer);
|
importToDB.process(resultContainer);
|
||||||
Imdg<SDf21> df21Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf21, SDf21.class);
|
Imdg<SDf21> df21Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf21, SDf21.class);
|
||||||
df21Imdg.getAllValues();
|
df21Imdg.getAllValues();
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ public enum SdfTable implements IEnumKey {
|
||||||
SDF_12("SDF_12"),
|
SDF_12("SDF_12"),
|
||||||
SDF_13("SDF_13"),
|
SDF_13("SDF_13"),
|
||||||
SDF_16("SDF_16"),
|
SDF_16("SDF_16"),
|
||||||
|
SDF_20("SDF_20"),
|
||||||
SDF_21("SDF_21"),
|
SDF_21("SDF_21"),
|
||||||
SDF_57("SDF_57");
|
SDF_57("SDF_57");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue