Поправил ошибку загрузки нескольких строк.
This commit is contained in:
parent
8f7a64122c
commit
5dd546ae4f
10 changed files with 239 additions and 138 deletions
|
|
@ -0,0 +1,157 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.data.enums;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
|
||||
public enum ReadingPatterns {
|
||||
To {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith("To:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setTo(getValueWitoutKey(line, "To:"));
|
||||
}
|
||||
},
|
||||
From {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith("From:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setFrom(getValueWitoutKey(line, "From:"));
|
||||
}
|
||||
},
|
||||
Type {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith("Type:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setType(getValueWitoutKey(line, "Type:"));
|
||||
}
|
||||
},
|
||||
DateTime {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith("Date/Time:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setDateTime(getValueWitoutKey(line, "Date/Time:"));
|
||||
}
|
||||
},
|
||||
Tag18A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":18A:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor18ATag(getValueWitoutKey(line, ":18A:"));
|
||||
}
|
||||
},
|
||||
Tag20 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":20:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor20Tag(getValueWitoutKey(line, ":20:"));
|
||||
}
|
||||
},
|
||||
Tag21 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":21:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor21Tag(getValueWitoutKey(line, ":21:"));
|
||||
}
|
||||
},
|
||||
Tag23 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":23:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor23Tag(getValueWitoutKey(line, ":23:"));
|
||||
}
|
||||
},
|
||||
Tag35A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":35A:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor35ATag(getValueWitoutKey(line, ":35A:"));
|
||||
}
|
||||
},
|
||||
Tag35B {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":35B:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor35BTag(getValueWitoutKey(line, ":35B:"));
|
||||
}
|
||||
},
|
||||
Tag76 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":76:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor76Tag(getValueWitoutKey(line, ":76:"));
|
||||
}
|
||||
},
|
||||
Tag77A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":77A:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor77ATag(getValueWitoutKey(line, ":77A:"));
|
||||
}
|
||||
},
|
||||
Tag82D {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":82D:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor82DTag(getValueWitoutKey(line, ":82D:"));
|
||||
}
|
||||
},
|
||||
Tag87C {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":87C:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor87CTag(getValueWitoutKey(line, ":87C:"));
|
||||
}
|
||||
},
|
||||
TableRow {
|
||||
public boolean canRead(String line) {
|
||||
String[] sepLine = line.split(":");
|
||||
return sepLine.length > 1 && StringUtils.hasText(sepLine[0])
|
||||
&& !sepLine[0].startsWith("To") && !sepLine[0].startsWith("From")
|
||||
&& !sepLine[0].startsWith("Type") && !sepLine[0].startsWith("Date/Time");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setTableRow(line.split(":"));
|
||||
}
|
||||
};
|
||||
|
||||
public boolean canRead(String line) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
|
||||
}
|
||||
|
||||
protected String getValueWitoutKey(String line, String key) {
|
||||
return line.substring(line.lastIndexOf(key) + key.length());
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.data.tables;
|
||||
|
||||
import ru.spcex.clearing.swt.importer.util.SWTHeaderData;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
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;
|
||||
|
|
@ -32,7 +32,7 @@ public abstract class AbstractTable<T extends SpcexObjectBase> {
|
|||
this.hazelcastService = hazelcastService;
|
||||
}
|
||||
|
||||
public abstract T getEntity(SWTHeaderData header, String[] entity);
|
||||
public abstract T getEntity(SWTRecord record);
|
||||
|
||||
public void injectEntity(T obj) {
|
||||
if (map == null) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ru.spcex.clearing.swt.importer.logic.data.tables;
|
|||
import ru.clearing.classes.statics.data.sdf.SDf08;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTHeaderData;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
@ -18,9 +18,10 @@ public class SDf08Table extends AbstractTable<SDf08> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SDf08 getEntity(SWTHeaderData header, String[] entity) {
|
||||
public SDf08 getEntity(SWTRecord record) {
|
||||
SDf08 result = new SDf08();
|
||||
result.setOutDocument(header.getValFor20Tag());
|
||||
String[] entity = record.getTableRow();
|
||||
result.setOutDocument(record.getValFor20Tag());
|
||||
result.setDepoCode(entity[0]);
|
||||
result.setQuantity(entity[1]);
|
||||
result.setSecurityCode(entity[2]);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ru.spcex.clearing.swt.importer.logic.data.tables;
|
|||
import ru.clearing.classes.statics.data.sdf.SDf10;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTHeaderData;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
@ -18,9 +18,10 @@ public class SDf10Table extends AbstractTable<SDf10> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SDf10 getEntity(SWTHeaderData header, String[] entity) {
|
||||
public SDf10 getEntity(SWTRecord record) {
|
||||
SDf10 result = new SDf10();
|
||||
result.setOutDocument(header.getValFor20Tag());
|
||||
String[] entity = record.getTableRow();
|
||||
result.setOutDocument(record.getValFor20Tag());
|
||||
result.setDepoCode(entity[0]);
|
||||
result.setQuantity(entity[1]);
|
||||
result.setSecurityCode(entity[2]);
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ru.spcex.clearing.swt.importer.logic.data.tables;
|
|||
import ru.clearing.classes.statics.data.sdf.SDf13;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTHeaderData;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
@ -18,13 +18,13 @@ public class SDf13Table extends AbstractTable<SDf13> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public SDf13 getEntity(SWTHeaderData header, String[] entity) {
|
||||
public SDf13 getEntity(SWTRecord record) {
|
||||
SDf13 result = new SDf13();
|
||||
result.setFileName(filename);
|
||||
result.setOutDocument(header.getValFor20Tag());
|
||||
result.setInDocument(header.getValFor21Tag());
|
||||
result.setResult(header.getValFor76Tag());
|
||||
result.setTextError(header.getValFor77ATag());
|
||||
result.setOutDocument(record.getValFor20Tag());
|
||||
result.setInDocument(record.getValFor21Tag());
|
||||
result.setResult(record.getValFor76Tag());
|
||||
result.setTextError(record.getValFor77ATag());
|
||||
result.setGenerationTime(Instant.now());
|
||||
result.setGenerationId(fileId);
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import ru.spcex.clearing.swt.importer.logic.data.ResultContainer;
|
|||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.StageResult;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.AbstractTable;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTHeaderData;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTReader;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
|
|
@ -54,15 +54,12 @@ public class ImportToDB extends Stage {
|
|||
Long fileId = hazelcastService.getImdgIdGenerator().nextId();
|
||||
table.setFileId(fileId);
|
||||
int counter = 0;
|
||||
SWTHeaderData swtHeaderData = swtReader.getSWTHeader();
|
||||
do {
|
||||
counter++;
|
||||
String[] entity = swtReader.nextRecord();
|
||||
if (entity == null) {
|
||||
log.warn("record index {} null", counter);
|
||||
continue;
|
||||
}
|
||||
table.injectEntity(table.getEntity(swtHeaderData, entity));
|
||||
SWTRecord record = swtReader.nextRecord();
|
||||
if (record.isNotEmpty()) {
|
||||
table.injectEntity(table.getEntity(record));
|
||||
} else continue;
|
||||
} while (swtReader.hasNextRecord());
|
||||
kafkaMessenger.notifySystemIfNeeded(currTable, fileId);
|
||||
} catch (IOException exception) {
|
||||
|
|
|
|||
|
|
@ -1,141 +1,58 @@
|
|||
package ru.spcex.clearing.swt.importer.util;
|
||||
|
||||
import ru.spcex.clearing.swt.importer.logic.data.ResultContainer;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class SWTReader implements Closeable {
|
||||
protected InputStream inputStream;
|
||||
protected Scanner scanner;
|
||||
protected ResultContainer resultContainer;
|
||||
private SWTRecord record;
|
||||
private static Map<ETable, ReadingPatterns> recordEnds = new HashMap<>();
|
||||
private ReadingPatterns recordEnd;
|
||||
|
||||
static {
|
||||
recordEnds.put(ETable.S_DF_08, ReadingPatterns.TableRow);
|
||||
recordEnds.put(ETable.S_DF_10, ReadingPatterns.TableRow);
|
||||
recordEnds.put(ETable.S_DF_13, ReadingPatterns.Tag77A);
|
||||
}
|
||||
|
||||
public SWTReader(InputStream inputStream, Charset charset, ResultContainer resultContainer) {
|
||||
this.inputStream = inputStream;
|
||||
this.scanner = new Scanner(inputStream, charset);
|
||||
this.resultContainer = resultContainer;
|
||||
recordEnd = recordEnds.get(resultContainer.getSwtTable());
|
||||
this.record = new SWTRecord();
|
||||
}
|
||||
|
||||
public SWTHeaderData getSWTHeader() {
|
||||
SWTHeaderData swtHeaderData = new SWTHeaderData();
|
||||
String to, from, type, dateTime;
|
||||
/*
|
||||
* To:SPCEX
|
||||
From:RDC
|
||||
Type:596
|
||||
Date/Time:20220908/1534
|
||||
S_DF_08
|
||||
S_DF_10
|
||||
S_DF_13
|
||||
* */
|
||||
String line = scanner.nextLine();
|
||||
to = line.substring(line.lastIndexOf("To:") + "To:".length());
|
||||
line = scanner.nextLine();
|
||||
from = line.substring(line.lastIndexOf("From:") + "From:".length());
|
||||
line = scanner.nextLine();
|
||||
type = line.substring(line.lastIndexOf("Type:") + "Type:".length());
|
||||
line = scanner.nextLine();
|
||||
dateTime = line.substring(line.lastIndexOf("Date/Time:") + "Date/Time:".length());
|
||||
swtHeaderData.setTo(to);
|
||||
swtHeaderData.setFrom(from);
|
||||
swtHeaderData.setType(type);
|
||||
swtHeaderData.setDateTime(dateTime);
|
||||
|
||||
switch (resultContainer.getSwtTable()) {
|
||||
case S_DF_08: {
|
||||
String val20, val21, val18A;
|
||||
/*
|
||||
* :20:SDC230227084839
|
||||
:21:NONREF
|
||||
:18A:46
|
||||
* */
|
||||
line = scanner.nextLine();
|
||||
val20 = line.substring(line.lastIndexOf(":20:") + ":20:".length());
|
||||
line = scanner.nextLine();
|
||||
val21 = line.substring(line.lastIndexOf(":21:") + ":21:".length());
|
||||
line = scanner.nextLine();
|
||||
val18A = line.substring(line.lastIndexOf(":18A:") + ":18A:".length());
|
||||
swtHeaderData.setValFor20Tag(val20);
|
||||
swtHeaderData.setValFor21Tag(val21);
|
||||
swtHeaderData.setValFor18ATag(val18A);
|
||||
}
|
||||
break;
|
||||
case S_DF_10: {
|
||||
/*
|
||||
* :20:RNCB_2210170001-010
|
||||
* */
|
||||
String val20;
|
||||
line = scanner.nextLine();
|
||||
val20 = line.substring(line.lastIndexOf(":20:") + ":20:".length());
|
||||
swtHeaderData.setValFor20Tag(val20);
|
||||
}
|
||||
break;
|
||||
case S_DF_13:
|
||||
/*
|
||||
* :20:220908M58C0001EX
|
||||
:21:XXX202209081526
|
||||
:76:EXECUTED
|
||||
|
||||
:77A:Поручение исполнено
|
||||
*
|
||||
* */
|
||||
String val20, val21, val76, val77A;
|
||||
line = scanner.nextLine();
|
||||
val20 = line.substring(line.lastIndexOf(":20:") + ":20:".length());
|
||||
line = scanner.nextLine();
|
||||
val21 = line.substring(line.lastIndexOf(":21:") + ":21:".length());
|
||||
line = scanner.nextLine();
|
||||
val76 = line.substring(line.lastIndexOf(":76:") + ":76:".length());
|
||||
line = scanner.nextLine();
|
||||
val77A = line.substring(line.lastIndexOf(":77A:") + ":77A:".length());
|
||||
swtHeaderData.setValFor20Tag(val20);
|
||||
swtHeaderData.setValFor21Tag(val21);
|
||||
swtHeaderData.setValFor76Tag(val76);
|
||||
swtHeaderData.setValFor77ATag(val77A);
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Could not map header data for " + resultContainer.getSwtTable().name());
|
||||
}
|
||||
return swtHeaderData;
|
||||
}
|
||||
|
||||
public String[] nextRecord() {
|
||||
switch (resultContainer.getSwtTable()) {
|
||||
case S_DF_08:
|
||||
String line = scanner.nextLine();
|
||||
String[] separetedLine = line.split(":");
|
||||
if (separetedLine.length < 5) {
|
||||
return null;
|
||||
public SWTRecord nextRecord() {
|
||||
record.setNotEmpty(false);
|
||||
while (scanner.hasNextLine()) {
|
||||
String line = scanner.nextLine();
|
||||
for (ReadingPatterns pattern : ReadingPatterns.values()) {
|
||||
if (pattern.canRead(line)) {
|
||||
pattern.reed(line, record);
|
||||
if (pattern.equals(recordEnd)) {
|
||||
record.setNotEmpty(true);
|
||||
return record;
|
||||
}
|
||||
}
|
||||
return separetedLine;
|
||||
case S_DF_10:
|
||||
line = scanner.nextLine();
|
||||
separetedLine = line.split(":");
|
||||
if (separetedLine.length < 4) {
|
||||
return null;
|
||||
}
|
||||
return separetedLine;
|
||||
case S_DF_13:
|
||||
return new String[0];
|
||||
default:
|
||||
throw new IllegalStateException("Could not process this type of table");
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
public boolean hasNextRecord() {
|
||||
switch (resultContainer.getSwtTable()) {
|
||||
case S_DF_08:
|
||||
scanner.hasNextLine();
|
||||
case S_DF_10:
|
||||
return false;
|
||||
case S_DF_13:
|
||||
return false;
|
||||
default:
|
||||
throw new IllegalStateException("Could not process this type of table");
|
||||
}
|
||||
return scanner.hasNextLine();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ package ru.spcex.clearing.swt.importer.util;
|
|||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class SWTHeaderData {
|
||||
public class SWTRecord {
|
||||
private static final DateTimeFormatter dtInFileHeaderFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'/'HHmm");
|
||||
private String to;
|
||||
private String from;
|
||||
|
|
@ -19,6 +19,8 @@ public class SWTHeaderData {
|
|||
private String valFor77ATag;
|
||||
private String valFor82DTag;
|
||||
private String valFor87CTag;
|
||||
private boolean notEmpty;
|
||||
private String[] tableRow;
|
||||
|
||||
public String getTo() {
|
||||
return to;
|
||||
|
|
@ -136,6 +138,22 @@ public class SWTHeaderData {
|
|||
this.valFor87CTag = valFor87CTag;
|
||||
}
|
||||
|
||||
public String[] getTableRow() {
|
||||
return tableRow;
|
||||
}
|
||||
|
||||
public void setTableRow(String[] tableRow) {
|
||||
this.tableRow = tableRow;
|
||||
}
|
||||
|
||||
public boolean isNotEmpty() {
|
||||
return notEmpty;
|
||||
}
|
||||
|
||||
public void setNotEmpty(boolean notEmpty) {
|
||||
this.notEmpty = notEmpty;
|
||||
}
|
||||
|
||||
public String buildString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
if (to != null) {
|
||||
|
|
@ -3,5 +3,7 @@ From:CSO
|
|||
Type:010
|
||||
Date/Time:20221017/1450
|
||||
:20:RNCB_2210170001-010
|
||||
758200000AT0:000000010:RNCB-BE-01:<3A><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>(<28><><EFBFBD>)
|
||||
10
|
||||
758200000AT0:000000010:RNCB-BE-01:РНКБ Банк(ПАО)
|
||||
758399999BT0:000000100:SOVKB-BV-01:NW:0:ЦМРБанк(ООО)
|
||||
704500000AT0:000000002:SOVKB-BV-01:NW:0:АО "АБ "РОССИЯ"
|
||||
112
|
||||
|
|
@ -5,4 +5,12 @@ Date/Time:20221111/1314
|
|||
:20:221111M58C0001EX
|
||||
:21:XXX202211111247
|
||||
:76:EXECUTED
|
||||
:77A:<3A><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
:77A:Поручение исполнено
|
||||
1
|
||||
2
|
||||
:20:220901M58C0001P2
|
||||
:21:XXX202209011502
|
||||
:76:PENDING
|
||||
:77A:Ошибка в KS_RDC_DF-12_bond_220901150230962.txt
|
||||
2
|
||||
2
|
||||
Loading…
Add table
Reference in a new issue