Merge branch 'dev' into CLNRWORM
This commit is contained in:
commit
92db7d5f1e
32 changed files with 693 additions and 74 deletions
|
|
@ -42,7 +42,10 @@ public class SDf06Table extends AbstractTable<SDf06> {
|
|||
return (BigDecimal) value;
|
||||
}
|
||||
if (value instanceof String) {
|
||||
return BigDecimal.valueOf(Long.parseLong((String)value));
|
||||
//return BigDecimal.valueOf(Long.parseLong((String)value));
|
||||
String str = ((String)value).trim();
|
||||
if (str.isEmpty()) return null;
|
||||
return new BigDecimal(str);
|
||||
}
|
||||
if (value instanceof Number) {
|
||||
return BigDecimal.valueOf(((Number)value).longValue());
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package ru.spcex.clearing.dbf.importer.logic.data.tables;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class SDf06TableTest {
|
||||
|
||||
@Test
|
||||
void anyNumberToBigDecimal() {
|
||||
SDf06Table table = new SDf06Table();
|
||||
assertNull(table.anyNumberToBigDecimal(null));
|
||||
assertNull(table.anyNumberToBigDecimal(""));
|
||||
assertNull(table.anyNumberToBigDecimal(" "));
|
||||
assertEquals(BigDecimal.valueOf(1234), table.anyNumberToBigDecimal("1234")); // это для INN
|
||||
assertEquals(BigDecimal.valueOf(1234).setScale(0), table.anyNumberToBigDecimal(" 1234"));
|
||||
assertEquals(BigDecimal.valueOf(1234), table.anyNumberToBigDecimal(" 1234 "));
|
||||
assertEquals(new BigDecimal("100000000.0"), table.anyNumberToBigDecimal(" 100000000.0")); // это для SUM
|
||||
assertEquals(BigDecimal.ONE.scaleByPowerOfTen(3).setScale(2), table.anyNumberToBigDecimal(" 1000.00 "));
|
||||
assertNull(table.anyNumberToBigDecimal(null));
|
||||
}
|
||||
}
|
||||
|
|
@ -9,8 +9,10 @@ import com.opencsv.exceptions.CsvFieldAssignmentException;
|
|||
import com.opencsv.exceptions.CsvRequiredFieldEmptyException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.spcex.platform.enumeration.ReportBuilderType;
|
||||
import ru.spcex.platform.enumeration.ReportKeys;
|
||||
import ru.spcex.platform.imdg.api.Imdg;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
|
@ -19,10 +21,11 @@ import java.io.Writer;
|
|||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* Класс для построения отчетов в формате CSV
|
||||
|
|
@ -30,7 +33,7 @@ import java.util.Locale;
|
|||
* @param <P> тип параметров, используемых при построении отчета
|
||||
*/
|
||||
public abstract class CSVReportBuilder<P, R> {
|
||||
protected static final Logger log = LoggerFactory.getLogger(CSVReportBuilder.class);
|
||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||
protected DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy'T'HH:mm:ss");
|
||||
protected DateTimeFormatter dateTimeFormatter_YYMMDDHHmmssSSS = DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
|
||||
protected DateTimeFormatter dateFormatter_yyyyMMdd = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
|
|
@ -139,6 +142,16 @@ public abstract class CSVReportBuilder<P, R> {
|
|||
return filename;
|
||||
}
|
||||
|
||||
protected List<Long> getSessionIdsForCurrentDate(Imdg<Session> sessionImdg) {
|
||||
Collection<Session> sessionForCurrentDay = sessionImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"clearingDate", LocalDate.now()
|
||||
)
|
||||
);
|
||||
Set<Long> sessionIds = sessionForCurrentDay.stream().map(Session::getId).collect(Collectors.toSet());
|
||||
return sessionIds.stream().toList();
|
||||
}
|
||||
|
||||
static class CustomStrategy<T> extends ColumnPositionMappingStrategy<T> {
|
||||
@Override
|
||||
public String[] generateHeader(T bean) throws CsvRequiredFieldEmptyException {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ru.spcex.clearing.reports.reports.bp;
|
|||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.execution.ExecutionFond;
|
||||
import ru.clearing.classes.statics.data.misc.STrades;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.reports.reports.CSVReportBuilder;
|
||||
import ru.spcex.clearing.reports.reports.bean.ExecutedDealReport;
|
||||
|
|
@ -21,6 +22,7 @@ import java.util.Map;
|
|||
public abstract class ExecutedDealReportBuilderCommon<P> extends CSVReportBuilder<P, ExecutedDealReport> {
|
||||
protected final DateTimeFormatter fileNameDateTimeFormatter = DateTimeFormatter.ofPattern("yyMMddHHmmssSSS");
|
||||
protected final Imdg<ExecutionFond> executionFondImdg;
|
||||
protected final Imdg<Session> sessionImdg;
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<STrades> sTradesImdg;
|
||||
|
||||
|
|
@ -32,6 +34,7 @@ public abstract class ExecutedDealReportBuilderCommon<P> extends CSVReportBuilde
|
|||
|
||||
public ExecutedDealReportBuilderCommon(ImdgProvider imdgProvider) {
|
||||
this.executionFondImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class);
|
||||
this.sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
this.sTradesImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_STrades, STrades.class);
|
||||
}
|
||||
|
|
@ -61,6 +64,12 @@ public abstract class ExecutedDealReportBuilderCommon<P> extends CSVReportBuilde
|
|||
for (ExecutionFond executionFond : executionFonds) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(executionFond.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For execution id = {} company with id = {} not found, execution was skipped",
|
||||
executionFond.getId(),
|
||||
executionFond.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
STrades sTrade = null;
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ExecutedDealReportBuilder_INFTYPE_1 extends ExecutedDealReportBuilderCommon<SessionIdParam> {
|
||||
|
|
@ -30,9 +31,11 @@ public class ExecutedDealReportBuilder_INFTYPE_1 extends ExecutedDealReportBuild
|
|||
@Override
|
||||
protected Collection<ExecutionFond> getExecutionFondsForReport(SessionIdParam params) {
|
||||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
return executionFondImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.in("sessionId", sessionIds.toArray(new Long[0])),
|
||||
pb.less("tradingDate", LocalDate.now()),
|
||||
pb.equals("settlementDate", LocalDate.now())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import ru.spcex.platform.imdg.api.predicate.ImdgPredicateBuilder;
|
|||
|
||||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class ExecutedDealReportBuilder_INFTYPE_2 extends ExecutedDealReportBuilderCommon<SessionIdParam> {
|
||||
|
|
@ -30,9 +31,11 @@ public class ExecutedDealReportBuilder_INFTYPE_2 extends ExecutedDealReportBuild
|
|||
@Override
|
||||
protected Collection<ExecutionFond> getExecutionFondsForReport(SessionIdParam params) {
|
||||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
return executionFondImdg.getCollectionObjectsByPredicate(
|
||||
pb.and(
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.in("sessionId",sessionIds.toArray(new Long[0])),
|
||||
pb.equals("tradingDate", LocalDate.now()),
|
||||
pb.equals("settlementDate", LocalDate.now())
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import org.springframework.stereotype.Component;
|
|||
import ru.clearing.classes.statics.data.company.Company;
|
||||
import ru.clearing.classes.statics.data.execution.ExecutionFond;
|
||||
import ru.clearing.classes.statics.data.misc.STrades;
|
||||
import ru.clearing.classes.statics.data.misc.Session;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.reports.reports.CSVReportBuilder;
|
||||
import ru.spcex.clearing.reports.reports.SessionIdParam;
|
||||
|
|
@ -27,11 +28,13 @@ public class UnfulfilledDealReportBuilder extends CSVReportBuilder<SessionIdPara
|
|||
private final Imdg<ExecutionFond> executionFondImdg;
|
||||
private final Imdg<Company> companyImdg;
|
||||
private final Imdg<STrades> sTradesImdg;
|
||||
private final Imdg<Session> sessionImdg;
|
||||
|
||||
public UnfulfilledDealReportBuilder(ImdgProvider imdgProvider) {
|
||||
executionFondImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ExecutionFond, ExecutionFond.class);
|
||||
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||
sTradesImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_STrades, STrades.class);
|
||||
sessionImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Session, Session.class);
|
||||
}
|
||||
|
||||
private List<UnfulfilledDealReport> rows = null;
|
||||
|
|
@ -64,8 +67,10 @@ public class UnfulfilledDealReportBuilder extends CSVReportBuilder<SessionIdPara
|
|||
@Override
|
||||
protected void collect(SessionIdParam params) {
|
||||
ImdgPredicateBuilder pb = executionFondImdg.predicateBuilder();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
ImdgPredicate predicate = pb.and(
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.in("sessionId", sessionIds.toArray(new Long[0])),
|
||||
pb.equals("coverageStatus", Allowed.DENIED.getKey())
|
||||
);
|
||||
Collection<ExecutionFond> executionFonds = executionFondImdg.getCollectionObjectsByPredicate(predicate);
|
||||
|
|
@ -74,6 +79,12 @@ public class UnfulfilledDealReportBuilder extends CSVReportBuilder<SessionIdPara
|
|||
for (ExecutionFond executionFond : executionFonds) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(executionFond.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For execution id = {} company with id = {} not found, execution was skipped",
|
||||
executionFond.getId(),
|
||||
executionFond.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;;
|
||||
|
||||
STrades sTrade = sTradesImdg.getFirstObjectByFieldValues(
|
||||
|
|
|
|||
|
|
@ -85,6 +85,12 @@ public class KSCommissionTradesReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
for (Registry registry : registries) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For registry id = {} company with id = {} not found, registry was skipped",
|
||||
registry.getId(),
|
||||
registry.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
CompanySymbols companySymbols = companySymbolsImdg.getFirstObjectByFieldValues(
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@ public class KSRepCashNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TM_T, RegistryTradingParams.OM_T).build();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.in("sessionId", sessionIds.toArray(new Long[0])),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.sql(sql),
|
||||
pb.or(
|
||||
|
|
|
|||
|
|
@ -81,6 +81,12 @@ public class KSRepCashRegisterSumsReportBuilder extends CSVReportBuilder<EmptyPa
|
|||
for (Statement statement : statements) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(statement.getAddresseeId());
|
||||
if (company == null) {
|
||||
log.warn("For statement id = {} company with id = {} not found, statement was skipped",
|
||||
statement.getId(),
|
||||
statement.getAddresseeId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
||||
|
|
|
|||
|
|
@ -84,6 +84,12 @@ public class KSRepCashRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
for (Registry registry : registries) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For registry id = {} company with id = {} not found, registry was skipped",
|
||||
registry.getId(),
|
||||
registry.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
KSRepCashRegistersReport ksRepCashRegistersReport = new KSRepCashRegistersReport();
|
||||
|
|
|
|||
|
|
@ -62,9 +62,11 @@ public class KSRepDepoNettoReportBuilder extends CSVReportBuilder<SessionIdParam
|
|||
LocalDate nowDate = LocalDate.now();
|
||||
|
||||
ImdgPredicateBuilder pb = registryImdg.predicateBuilder();
|
||||
List<Long> sessionIds = params.getSessionId();
|
||||
if (sessionIds == null || sessionIds.isEmpty()) sessionIds = getSessionIdsForCurrentDate(sessionImdg);
|
||||
String sql = RegistryCodeSqlBuilder.getInstance(RegistryTradingParams.TS_T, RegistryTradingParams.OS_T).build();
|
||||
ImdgPredicate finalPredicate = pb.and(
|
||||
pb.in("sessionId", params.getSessionId().toArray(new Long[0])),
|
||||
pb.in("sessionId", sessionIds.toArray(new Long[0])),
|
||||
pb.equals("clearingDate", nowDate),
|
||||
pb.sql(sql),
|
||||
pb.equals("accountType", AccountType.Depo.getKey()),
|
||||
|
|
|
|||
|
|
@ -91,6 +91,12 @@ public class KSRepDepoRegisterQuantitiesReportBuilder extends CSVReportBuilder<E
|
|||
for (Statement statement : statements) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(statement.getAddresseeId());
|
||||
if (company == null) {
|
||||
log.warn("For statement id = {} company with id = {} not found, statement was skipped",
|
||||
statement.getId(),
|
||||
statement.getAddresseeId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
ImdgPredicateBuilder pbRegistry = registryImdg.predicateBuilder();
|
||||
|
|
|
|||
|
|
@ -82,6 +82,12 @@ public class KSRepDepoRegistersReportBuilder extends CSVReportBuilder<EmptyParam
|
|||
for (Registry registry : registries) {
|
||||
try {
|
||||
Company company = companyImdg.getSingleObjectByID(registry.getCompanyId());
|
||||
if (company == null) {
|
||||
log.warn("For registry id = {} company with id = {} not found, registry was skipped",
|
||||
registry.getId(),
|
||||
registry.getCompanyId());
|
||||
continue;
|
||||
}
|
||||
if (!WorkflowStatus.Active.equalsByKey(company.getWorkflowStatus())) continue;
|
||||
|
||||
KSRepDepoRegistersReport ksRepDepoRegistersReport = new KSRepDepoRegistersReport();
|
||||
|
|
|
|||
|
|
@ -37,7 +37,6 @@ import ru.spcex.platform.utils.enumeration.IEnumKey;
|
|||
import ru.spcex.platform.utils.validation.IValidator;
|
||||
|
||||
import java.io.File;
|
||||
import java.time.LocalDate;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -239,8 +238,6 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<File, ReportInfo> outFiles = createReportsForTask(sessionIds, reportBuildersForGREP.values());
|
||||
|
||||
|
|
@ -261,8 +258,6 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<File, ReportInfo> outFiles = createReportsForTask(sessionIds, reportBuildersForGRET.values());
|
||||
|
||||
|
|
@ -301,8 +296,6 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
List<Long> sessionIds = null;
|
||||
if (userRequest.getRequestPayload().getSessionId() != null) {
|
||||
sessionIds = List.of(userRequest.getRequestPayload().getSessionId());
|
||||
} else {
|
||||
sessionIds = getSessionIdsForDate(LocalDate.now());
|
||||
}
|
||||
Map<File, ReportInfo> outFiles = createReportsForTask(sessionIds, reportBuildersForGREF.values());
|
||||
|
||||
|
|
@ -380,16 +373,6 @@ public class ReportService extends QueueConsumer implements InitializingBean {
|
|||
}
|
||||
}
|
||||
|
||||
private List<Long> getSessionIdsForDate(LocalDate date) {
|
||||
Collection<Session> sessionForCurrentDay = sessionImdg.getCollectionObjectsByFieldValues(
|
||||
Map.of(
|
||||
"clearingDate", date
|
||||
)
|
||||
);
|
||||
Set<Long> sessionIds = sessionForCurrentDay.stream().map(Session::getId).collect(Collectors.toSet());
|
||||
return sessionIds.stream().toList();
|
||||
}
|
||||
|
||||
private void sendFilesToSftp(Collection<File> files) {
|
||||
for (File file : files) {
|
||||
reportsSftpGateway.sendToSftp(file);
|
||||
|
|
|
|||
|
|
@ -8,10 +8,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import ru.spcex.clearing.swt.importer.config.settings.ImportSWTServiceSettings;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.AbstractTable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf08Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf10Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf13Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.*;
|
||||
import ru.spcex.clearing.swt.importer.logic.stages.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
|
@ -60,6 +57,7 @@ public class SWTImporterConfig {
|
|||
map.put(ETable.S_DF_08, new SDf08Table());
|
||||
map.put(ETable.S_DF_10, new SDf10Table());
|
||||
map.put(ETable.S_DF_13, new SDf13Table());
|
||||
map.put(ETable.S_DF_21, new SDf21Table());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,8 @@ package ru.spcex.clearing.swt.importer.logic.data.enums;
|
|||
public enum ETable {
|
||||
S_DF_08("DF-08"),
|
||||
S_DF_10("DF-10"),
|
||||
S_DF_13("DF-13");
|
||||
S_DF_13("DF-13"),
|
||||
S_DF_21("DF-21");
|
||||
//S_DF20("DF-20");
|
||||
|
||||
private final String prefix;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.data.enums;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
|
|
@ -60,6 +60,15 @@ public enum ReadingPatterns {
|
|||
record.setValFor20Tag(getValueWitoutKey(line, ":20:"));
|
||||
}
|
||||
},
|
||||
Tag20C {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":20C:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor20CTag(getValueWitoutKey(line, ":20C:"));
|
||||
}
|
||||
},
|
||||
Tag21 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":21:");
|
||||
|
|
@ -78,13 +87,22 @@ public enum ReadingPatterns {
|
|||
record.setValFor23Tag(getValueWitoutKey(line, ":23:"));
|
||||
}
|
||||
},
|
||||
Tag35A {
|
||||
Tag30 {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":35A:");
|
||||
return line.startsWith(":30:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor35ATag(getValueWitoutKey(line, ":35A:"));
|
||||
record.setValFor30Tag(getValueWitoutKey(line, ":30:"));
|
||||
}
|
||||
},
|
||||
Tag35A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":35A:SHS");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor35ATag(getValueWitoutKey(line, ":35A:SHS").replace(",", ""));
|
||||
}
|
||||
},
|
||||
Tag35B {
|
||||
|
|
@ -93,7 +111,36 @@ public enum ReadingPatterns {
|
|||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor35BTag(getValueWitoutKey(line, ":35B:"));
|
||||
String[] cells = getValueWitoutKey(line, ":35B:ISIN ").split(":");
|
||||
cells = Arrays.copyOf(cells, 3);
|
||||
record.setValFor35BTag(cells);
|
||||
}
|
||||
},
|
||||
Tag60A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":60A:SHS");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor60ATag(getValueWitoutKey(line, ":60A:SHS").replace(",", ""));
|
||||
}
|
||||
},
|
||||
Tag62A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":62A:SHS");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor62ATag(getValueWitoutKey(line, ":62A:SHS").replace(",", ""));
|
||||
}
|
||||
},
|
||||
Tag66A {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":66A:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor66ATag(getValueWitoutKey(line, ":66A:"));
|
||||
}
|
||||
},
|
||||
Tag76 {
|
||||
|
|
@ -123,6 +170,18 @@ public enum ReadingPatterns {
|
|||
record.setValFor82DTag(getValueWitoutKey(line, ":82D:"));
|
||||
}
|
||||
},
|
||||
Tag83D {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":83D:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
String[] cells = getValueWitoutKey(line, ":83D:").split(":");
|
||||
cells = Arrays.copyOf(cells, 3);
|
||||
record.setValFor35BTag(cells);
|
||||
record.setValFor83DTag(cells);
|
||||
}
|
||||
},
|
||||
Tag87C {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":87C:");
|
||||
|
|
@ -132,6 +191,15 @@ public enum ReadingPatterns {
|
|||
record.setValFor87CTag(getValueWitoutKey(line, ":87C:"));
|
||||
}
|
||||
},
|
||||
Tag87D {
|
||||
public boolean canRead(String line) {
|
||||
return line.startsWith(":87D:");
|
||||
}
|
||||
|
||||
public void reed(String line, SWTRecord record) {
|
||||
record.setValFor87DTag(getValueWitoutKey(line, ":87D:"));
|
||||
}
|
||||
},
|
||||
TableRow {
|
||||
public boolean canRead(String line) {
|
||||
String[] sepLine = line.split(":");
|
||||
|
|
@ -145,7 +213,8 @@ public enum ReadingPatterns {
|
|||
cells = Arrays.copyOf(cells, 20);
|
||||
record.setTableRow(cells);
|
||||
}
|
||||
};
|
||||
},
|
||||
EndFile;
|
||||
|
||||
public boolean canRead(String line) {
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.data.tables;
|
||||
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.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;
|
||||
|
|
|
|||
|
|
@ -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.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
|
|||
|
|
@ -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.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
|
|||
|
|
@ -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.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||
|
||||
import java.time.Instant;
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,42 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.data.tables;
|
||||
|
||||
import ru.clearing.classes.statics.data.sdf.SDf21;
|
||||
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 SDf21Table extends AbstractTable<SDf21> {
|
||||
|
||||
private static final String PREFIX = ETable.S_DF_21.name();
|
||||
private static final Class<SDf21> CLAZZ = SDf21.class;
|
||||
private static final String NAME_OF_HZ_MAP = IMDGDistributedNames.Map_SDf21;
|
||||
|
||||
public SDf21Table() {
|
||||
super(PREFIX, CLAZZ, NAME_OF_HZ_MAP);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SDf21 getEntity(SWTRecord record) {
|
||||
SDf21 result = new SDf21();
|
||||
result.setOutDocument(record.getValFor20Tag());
|
||||
result.setInDocument(record.getValFor21Tag());
|
||||
result.setSecurityCode(record.getValFor35BTag()[0]);
|
||||
result.setSecurityName(record.getValFor35BTag()[1]);
|
||||
result.setSecurityType(record.getValFor35BTag()[2]);
|
||||
result.setOpenBalance(record.getValFor60ATag());
|
||||
result.setDepoCodeCl(record.getValFor83DTag()[0]);
|
||||
result.setNameCl(record.getValFor83DTag()[1]);
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -7,8 +7,9 @@ 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.SWTReader;
|
||||
import ru.spcex.clearing.swt.importer.util.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTReader;
|
||||
import ru.spcex.clearing.swt.importer.readers.SWTRecord;
|
||||
import ru.spcex.clearing.swt.importer.readers.ValidationResult;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
import ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
|
|
@ -16,7 +17,11 @@ import java.io.ByteArrayInputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static ru.spcex.clearing.swt.importer.readers.ValidationResult.SUCSESS;
|
||||
|
||||
/**
|
||||
* Заливка проверенных данных в базу
|
||||
|
|
@ -53,14 +58,20 @@ public class ImportToDB extends Stage {
|
|||
hazelcastService.waitAvailable();
|
||||
Long fileId = hazelcastService.getImdgIdGenerator().nextId();
|
||||
table.setFileId(fileId);
|
||||
int counter = 0;
|
||||
AtomicInteger counter = new AtomicInteger();
|
||||
do {
|
||||
SWTRecord record = swtReader.nextRecord();
|
||||
if (record.isNotEmpty()) {
|
||||
table.injectEntity(table.getEntity(record));
|
||||
counter++;
|
||||
log.debug("{} entity stored.", counter);
|
||||
} else continue;
|
||||
ValidationResult result = swtReader.readGroupRecords();
|
||||
if (!SUCSESS.equals(result)) {
|
||||
log.debug("reading error: {}.", result.message());
|
||||
return StageResult.ERROR;
|
||||
}
|
||||
List<SWTRecord> records = swtReader.getGroupRecords();
|
||||
records.forEach(record -> {
|
||||
if (record.isNotEmpty()) {
|
||||
table.injectEntity(table.getEntity(record));
|
||||
log.debug("{} entity stored.", counter.incrementAndGet());
|
||||
}
|
||||
});
|
||||
} while (swtReader.hasNextRecord());
|
||||
kafkaMessenger.notifySystemIfNeeded(currTable, fileId);
|
||||
} catch (IOException exception) {
|
||||
|
|
@ -71,7 +82,6 @@ public class ImportToDB extends Stage {
|
|||
return StageResult.ERROR;
|
||||
}
|
||||
|
||||
|
||||
return StageResult.OK;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,57 @@
|
|||
package ru.spcex.clearing.swt.importer.readers;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ReadingPatterns;
|
||||
import ru.spcex.clearing.swt.importer.readers.template.SDf21Template;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
import static ru.spcex.clearing.swt.importer.readers.ValidationResult.SUCSESS;
|
||||
|
||||
public abstract class AbstractTemplate {
|
||||
protected Logger log = LoggerFactory.getLogger(getClass());
|
||||
protected Scanner scanner;
|
||||
protected boolean readEnded;
|
||||
|
||||
protected abstract List<SWTRecord> getGroupRecords();
|
||||
|
||||
protected abstract ValidationResult readAndValidate();
|
||||
|
||||
public AbstractTemplate(Scanner scanner) {
|
||||
this.scanner = scanner;
|
||||
this.readEnded = false;
|
||||
}
|
||||
|
||||
protected ValidationResult checkNotValue(String line, String errMes) {
|
||||
for (ReadingPatterns pattern : ReadingPatterns.values()) {
|
||||
if (pattern.canRead(line)) {
|
||||
return new ValidationResult(errMes + pattern.name());
|
||||
}
|
||||
}
|
||||
return SUCSESS;
|
||||
}
|
||||
|
||||
protected ValidationResult prepareNextLine(Consumer<String> lineSetter) {
|
||||
while (scanner.hasNextLine()) {
|
||||
lineSetter.accept(scanner.nextLine());
|
||||
return SUCSESS;
|
||||
}
|
||||
return new ValidationResult("Bud file format.");
|
||||
}
|
||||
|
||||
|
||||
public boolean isReadEnded() {
|
||||
return readEnded;
|
||||
}
|
||||
|
||||
public void setReadEnded(boolean readEnded) {
|
||||
this.readEnded = readEnded;
|
||||
}
|
||||
|
||||
public static AbstractTemplate getSDf21Template(Scanner scanner){
|
||||
return new SDf21Template(scanner);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package ru.spcex.clearing.swt.importer.util;
|
||||
package ru.spcex.clearing.swt.importer.readers;
|
||||
|
||||
import ru.spcex.clearing.swt.importer.logic.data.ResultContainer;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
|
|
@ -8,9 +8,10 @@ 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;
|
||||
import java.util.*;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static ru.spcex.clearing.swt.importer.readers.ValidationResult.SUCSESS;
|
||||
|
||||
public class SWTReader implements Closeable {
|
||||
protected InputStream inputStream;
|
||||
|
|
@ -18,20 +19,26 @@ public class SWTReader implements Closeable {
|
|||
protected ResultContainer resultContainer;
|
||||
private SWTRecord record;
|
||||
private static Map<ETable, ReadingPatterns> recordEnds = new HashMap<>();
|
||||
private static Map<ETable, Function<Scanner, AbstractTemplate>> templates = new HashMap<>();
|
||||
private ReadingPatterns recordEnd;
|
||||
private AbstractTemplate template;
|
||||
private List<SWTRecord> groupRecords = new ArrayList<>();
|
||||
|
||||
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);
|
||||
templates.put(ETable.S_DF_21, AbstractTemplate::getSDf21Template);
|
||||
}
|
||||
|
||||
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.recordEnd = recordEnds.get(resultContainer.getSwtTable());
|
||||
this.record = new SWTRecord();
|
||||
if (templates.containsKey(resultContainer.getSwtTable()))
|
||||
this.template = templates.get(resultContainer.getSwtTable()).apply(scanner);
|
||||
}
|
||||
|
||||
public SWTRecord nextRecord() {
|
||||
|
|
@ -51,10 +58,29 @@ public class SWTReader implements Closeable {
|
|||
return record;
|
||||
}
|
||||
|
||||
public ValidationResult readGroupRecords(){
|
||||
groupRecords = new ArrayList<>();
|
||||
if (template != null) {
|
||||
ValidationResult result = template.readAndValidate();
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
groupRecords.addAll(template.getGroupRecords());
|
||||
} else {
|
||||
groupRecords.add(nextRecord());
|
||||
}
|
||||
return SUCSESS;
|
||||
}
|
||||
|
||||
public boolean hasNextRecord() {
|
||||
if (template != null){
|
||||
return !template.isReadEnded();
|
||||
}
|
||||
return scanner.hasNextLine();
|
||||
}
|
||||
|
||||
public List<SWTRecord> getGroupRecords() {
|
||||
return groupRecords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
inputStream.close();
|
||||
|
|
@ -1,24 +1,32 @@
|
|||
package ru.spcex.clearing.swt.importer.util;
|
||||
package ru.spcex.clearing.swt.importer.readers;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class SWTRecord {
|
||||
public class SWTRecord implements Cloneable {
|
||||
private static final DateTimeFormatter dtInFileHeaderFormatter = DateTimeFormatter.ofPattern("yyyyMMdd'/'HHmm");
|
||||
private static final DateTimeFormatter dt30Formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
|
||||
private String to;
|
||||
private String from;
|
||||
private String type;
|
||||
private LocalDateTime dateTime;
|
||||
private String valFor20Tag;
|
||||
private String valFor18ATag;
|
||||
private String valFor20Tag;
|
||||
private String valFor20CTag;
|
||||
private String valFor21Tag;
|
||||
private String valFor23Tag;
|
||||
private String valFor30Tag;
|
||||
private String valFor35ATag;
|
||||
private String valFor35BTag;
|
||||
private String[] valFor35BTag;//Код ценной бумаги:наименование:тип
|
||||
private String valFor60ATag;
|
||||
private String valFor62ATag;
|
||||
private String valFor66ATag;
|
||||
private String valFor76Tag;
|
||||
private String valFor77ATag;
|
||||
private String valFor82DTag;
|
||||
private String[] valFor83DTag;
|
||||
private String valFor87CTag;
|
||||
private String valFor87DTag;
|
||||
private boolean notEmpty;
|
||||
private String[] tableRow;
|
||||
|
||||
|
|
@ -74,6 +82,14 @@ public class SWTRecord {
|
|||
this.dateTime = LocalDateTime.from(dtInFileHeaderFormatter.parse(dateTime));
|
||||
}
|
||||
|
||||
public String getValFor18ATag() {
|
||||
return valFor18ATag;
|
||||
}
|
||||
|
||||
public void setValFor18ATag(String valFor18ATag) {
|
||||
this.valFor18ATag = valFor18ATag;
|
||||
}
|
||||
|
||||
public String getValFor20Tag() {
|
||||
return valFor20Tag;
|
||||
}
|
||||
|
|
@ -82,12 +98,12 @@ public class SWTRecord {
|
|||
this.valFor20Tag = valFor20Tag;
|
||||
}
|
||||
|
||||
public String getValFor18ATag() {
|
||||
return valFor18ATag;
|
||||
public String getValFor20CTag() {
|
||||
return valFor20CTag;
|
||||
}
|
||||
|
||||
public void setValFor18ATag(String valFor18ATag) {
|
||||
this.valFor18ATag = valFor18ATag;
|
||||
public void setValFor20CTag(String valFor20CTag) {
|
||||
this.valFor20CTag = valFor20CTag;
|
||||
}
|
||||
|
||||
public String getValFor21Tag() {
|
||||
|
|
@ -106,6 +122,14 @@ public class SWTRecord {
|
|||
this.valFor23Tag = valFor23Tag;
|
||||
}
|
||||
|
||||
public String getValFor30Tag() {
|
||||
return valFor30Tag;
|
||||
}
|
||||
|
||||
public void setValFor30Tag(String valFor30Tag) {
|
||||
this.valFor30Tag = valFor30Tag;
|
||||
}
|
||||
|
||||
public String getValFor35ATag() {
|
||||
return valFor35ATag;
|
||||
}
|
||||
|
|
@ -114,14 +138,38 @@ public class SWTRecord {
|
|||
this.valFor35ATag = valFor35ATag;
|
||||
}
|
||||
|
||||
public String getValFor35BTag() {
|
||||
public String[] getValFor35BTag() {
|
||||
return valFor35BTag;
|
||||
}
|
||||
|
||||
public void setValFor35BTag(String valFor35BTag) {
|
||||
public void setValFor35BTag(String[] valFor35BTag) {
|
||||
this.valFor35BTag = valFor35BTag;
|
||||
}
|
||||
|
||||
public String getValFor60ATag() {
|
||||
return valFor60ATag;
|
||||
}
|
||||
|
||||
public void setValFor60ATag(String valFor60ATag) {
|
||||
this.valFor60ATag = valFor60ATag;
|
||||
}
|
||||
|
||||
public String getValFor62ATag() {
|
||||
return valFor62ATag;
|
||||
}
|
||||
|
||||
public void setValFor62ATag(String valFor62ATag) {
|
||||
this.valFor62ATag = valFor62ATag;
|
||||
}
|
||||
|
||||
public String getValFor66ATag() {
|
||||
return valFor66ATag;
|
||||
}
|
||||
|
||||
public void setValFor66ATag(String valFor66ATag) {
|
||||
this.valFor66ATag = valFor66ATag;
|
||||
}
|
||||
|
||||
public String getValFor82DTag() {
|
||||
return valFor82DTag;
|
||||
}
|
||||
|
|
@ -130,6 +178,14 @@ public class SWTRecord {
|
|||
this.valFor82DTag = valFor82DTag;
|
||||
}
|
||||
|
||||
public String[] getValFor83DTag() {
|
||||
return valFor83DTag;
|
||||
}
|
||||
|
||||
public void setValFor83DTag(String[] valFor83DTag) {
|
||||
this.valFor83DTag = valFor83DTag;
|
||||
}
|
||||
|
||||
public String getValFor87CTag() {
|
||||
return valFor87CTag;
|
||||
}
|
||||
|
|
@ -138,6 +194,14 @@ public class SWTRecord {
|
|||
this.valFor87CTag = valFor87CTag;
|
||||
}
|
||||
|
||||
public String getValFor87DTag() {
|
||||
return valFor87DTag;
|
||||
}
|
||||
|
||||
public void setValFor87DTag(String valFor87DTag) {
|
||||
this.valFor87DTag = valFor87DTag;
|
||||
}
|
||||
|
||||
public String[] getTableRow() {
|
||||
return tableRow;
|
||||
}
|
||||
|
|
@ -191,4 +255,9 @@ public class SWTRecord {
|
|||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SWTRecord clone() throws CloneNotSupportedException {
|
||||
return (SWTRecord) super.clone();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
package ru.spcex.clearing.swt.importer.readers;
|
||||
|
||||
public record ValidationResult(String message) {
|
||||
public static ValidationResult SUCSESS = new ValidationResult("");
|
||||
}
|
||||
|
|
@ -0,0 +1,141 @@
|
|||
package ru.spcex.clearing.swt.importer.readers.template;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
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 ru.spcex.platform.utils.log.ExceptionUtils;
|
||||
|
||||
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 SDf21Template extends AbstractTemplate {
|
||||
private List<ReadingPatterns> hederPatterns = List.of(
|
||||
To,
|
||||
From,
|
||||
Type,
|
||||
DateTime,
|
||||
Tag20,
|
||||
Tag21,
|
||||
Tag18A);
|
||||
private List<ReadingPatterns> oneDimensionalPatterns = List.of(
|
||||
Tag35B,
|
||||
Tag60A,
|
||||
Tag83D,
|
||||
Tag18A,
|
||||
Tag62A);
|
||||
private List<ReadingPatterns> twoDimensionalPatterns = List.of(
|
||||
Tag20C,
|
||||
Tag35A,
|
||||
Tag23,
|
||||
Tag66A,
|
||||
Tag87D,
|
||||
Tag30);
|
||||
|
||||
private List<SWTRecord> groupRecords = new ArrayList<>();
|
||||
|
||||
private String line = "";
|
||||
|
||||
public SDf21Template(Scanner scanner) {
|
||||
super(scanner);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<SWTRecord> getGroupRecords() {
|
||||
return groupRecords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ValidationResult readAndValidate() {
|
||||
int oneDimensionalCount = 0;
|
||||
SWTRecord currentRecord = new SWTRecord();
|
||||
currentRecord.setNotEmpty(false);
|
||||
ReadingPatterns currentPattern;
|
||||
ValidationResult result = prepareNextLine(this::setLine);
|
||||
List<SWTRecord> currentRecords = new ArrayList<>();
|
||||
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);
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
currentRecord.setNotEmpty(true);
|
||||
if (Tag18A.equals(currentPattern)) {
|
||||
String str18 = currentRecord.getValFor18ATag().trim();
|
||||
if (StringUtils.hasText(str18)) {
|
||||
int count = Integer.parseInt(str18);
|
||||
oneDimensionalCount = oneDimensionalPatterns.size() * count;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = checkNotValue(line, "required teg: " + currentPattern.name() + ", but was: ");
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
i--;
|
||||
}
|
||||
for (int j = 0; j < oneDimensionalCount; j++) {
|
||||
int twoDimensionalCount = 0;
|
||||
currentPattern = oneDimensionalPatterns.get(j % oneDimensionalPatterns.size());
|
||||
if (currentPattern.canRead(line)) {
|
||||
currentPattern.reed(line, currentRecord);
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
currentRecord.setNotEmpty(true);
|
||||
if (Tag18A.equals(currentPattern)) {
|
||||
String str18 = currentRecord.getValFor18ATag().trim();
|
||||
if (StringUtils.hasText(str18)) {
|
||||
int count = Integer.parseInt(str18);
|
||||
twoDimensionalCount = twoDimensionalPatterns.size() * count;
|
||||
}
|
||||
}
|
||||
if (Tag62A.equals(currentPattern)) {
|
||||
currentRecords.forEach(r -> r.setValFor62ATag(currentRecord.getValFor62ATag()));
|
||||
groupRecords.addAll(currentRecords);
|
||||
currentRecords = new ArrayList<>();
|
||||
}
|
||||
} else {
|
||||
result = checkNotValue(line, "required teg: " + currentPattern.name() + ", but was: ");
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
j--;
|
||||
}
|
||||
for (int k = 0; k < twoDimensionalCount; k++) {
|
||||
currentPattern = twoDimensionalPatterns.get(k % twoDimensionalPatterns.size());
|
||||
if (currentPattern.canRead(line)) {
|
||||
currentPattern.reed(line, currentRecord);
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
currentRecord.setNotEmpty(true);
|
||||
if (Tag30.equals(currentPattern)) {
|
||||
try {
|
||||
currentRecords.add(currentRecord.clone());
|
||||
} catch (CloneNotSupportedException e) {
|
||||
log.error(ExceptionUtils.getStackTrace(e));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result = checkNotValue(line, "required teg: " + currentPattern.name() + ", but was: ");
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
result = prepareNextLine(this::setLine);
|
||||
if (!SUCSESS.equals(result)) return result;
|
||||
k--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setReadEnded(true);
|
||||
return SUCSESS;
|
||||
}
|
||||
|
||||
public void setLine(String line) {
|
||||
this.line = line;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,10 +5,7 @@ import org.springframework.context.annotation.Configuration;
|
|||
import ru.spcex.clearing.swt.importer.config.settings.Common;
|
||||
import ru.spcex.clearing.swt.importer.config.settings.ImportSWTServiceSettings;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.enums.ETable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.AbstractTable;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf08Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf10Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.SDf13Table;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.tables.*;
|
||||
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||
import ru.spcex.platform.imdg.iml.hazelcast.service.HazelcastService;
|
||||
|
||||
|
|
@ -33,6 +30,7 @@ public class ImportSWTServiceTest {
|
|||
map.put(ETable.S_DF_08, new SDf08Table());
|
||||
map.put(ETable.S_DF_10, new SDf10Table());
|
||||
map.put(ETable.S_DF_13, new SDf13Table());
|
||||
map.put(ETable.S_DF_21, new SDf21Table());
|
||||
return map;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,111 @@
|
|||
|
||||
To:SPCE
|
||||
|
||||
From:CSO
|
||||
Type:572
|
||||
Date/Time:20230717/1640
|
||||
:20:SDC230717164022
|
||||
:21:NONREF
|
||||
|
||||
empty string
|
||||
|
||||
:18A:4
|
||||
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||
:60A:SHS1,
|
||||
:83D:747200000AT0:ÏÀÎ "Ïðîìñâÿçüáàíê":ðàçäåë îñíîâíîé äëÿ ðàñ÷åòîâ (ñîáñòâåííûå ÖÁ)
|
||||
|
||||
:18A:1
|
||||
34
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS9900000,
|
||||
:23:8711
|
||||
:66A:RECFREE
|
||||
:87D:747288887ZT0
|
||||
:30:20230406
|
||||
1
|
||||
1
|
||||
:62A:SHS1111111,
|
||||
1
|
||||
4
|
||||
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||
:60A:SHS2,
|
||||
:83D:747288887ZT0:ÏÀÎ "Ïðîìñâÿçüáàíê":òåõíè÷åñêèé ñ÷åò
|
||||
:18A:4
|
||||
:20C:Ïîðó÷. SPCEX_NONREF
|
||||
:35A:SHS222222,
|
||||
:23:8712
|
||||
:66A:RECFREE
|
||||
:87D:
|
||||
:30:20230406
|
||||
1
|
||||
4
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS9900000,
|
||||
:23:8713
|
||||
:66A:DELFREE
|
||||
:87D:747200000AT0
|
||||
:30:20230406
|
||||
2
|
||||
4
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS10000,
|
||||
:23:8714
|
||||
:66A:DELFREE
|
||||
:87D:750000000AT0
|
||||
:30:20230406
|
||||
3
|
||||
4
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS90000,
|
||||
:23:8715
|
||||
:66A:DELFREE
|
||||
:87D:750099999BT0
|
||||
:30:20230406
|
||||
4
|
||||
|
||||
4
|
||||
:62A:SHS22222,
|
||||
2
|
||||
4
|
||||
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||
:60A:SHS3,
|
||||
:83D:750000000AT0:ÎÎÎ ÏÒÖ:ðàçäåë îñíîâíîé äëÿ ðàñ÷åòîâ (ñîáñòâåííûå ÖÁ)
|
||||
:18A:1
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS10000,
|
||||
:23:8716
|
||||
:66A:RECFREE
|
||||
:87D:747288887ZT0
|
||||
:30:20230406
|
||||
1
|
||||
1
|
||||
|
||||
:62A:SHS33333,
|
||||
|
||||
3
|
||||
4
|
||||
:35B:ISIN MFBEL-BV-08:Ðåñïóáëèêà Áåëàðóñü:îáëèãàöèè
|
||||
:60A:SHS4,
|
||||
:83D:750099999BT0:ÎÎÎ ÏÒÖ:ðàçäåë îñíîâíîé äëÿ ðàñ÷åòîâ (êëèåíòñêèå ÖÁ)
|
||||
:18A:2
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS90000,
|
||||
:23:8717
|
||||
:66A:RECFREE
|
||||
:87D:747288887ZT0
|
||||
:30:20230406
|
||||
1
|
||||
2
|
||||
:20C:Ïîðó÷åíèå XXX202304061703 îò 2023-04-06
|
||||
:35A:SHS90000,
|
||||
:23:8718
|
||||
:66A:RECFREE
|
||||
:87D:747288887ZT0
|
||||
:30:20230406
|
||||
2
|
||||
2
|
||||
:62A:SHS444444,
|
||||
4
|
||||
4
|
||||
|
||||
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
package ru.spcex.clearing.swt.importer.logic.stages;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
|
|
@ -8,6 +7,7 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf10;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf13;
|
||||
import ru.clearing.classes.statics.data.sdf.SDf21;
|
||||
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||
import ru.spcex.clearing.swt.importer.config.ImportSWTServiceTest;
|
||||
import ru.spcex.clearing.swt.importer.logic.data.ResultContainer;
|
||||
|
|
@ -47,13 +47,22 @@ class ImportToDBTest {
|
|||
waitAvailableImdgProviderAndAddAdminWithDefaultId();
|
||||
|
||||
}
|
||||
@Test
|
||||
// @Test
|
||||
void process() throws IOException {
|
||||
ETable eTable = ETable.S_DF_13;
|
||||
File swtFile = new File("D:\\repo\\mfd\\clearing\\clearing-parent\\swt-importer\\src\\test\\java\\ru\\spcex\\clearing\\swt\\importer\\files\\RDC_KS_DF-13_bond_221111131459718.txt");
|
||||
ETable eTable = ETable.S_DF_21;
|
||||
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");
|
||||
ResultContainer resultContainer = createNewTask(eTable, swtFile);
|
||||
resultContainer.setSwtSource(Files.readAllBytes(Paths.get(swtFile.getAbsolutePath())));
|
||||
|
||||
importToDB.process(resultContainer);
|
||||
Imdg<SDf21> df21Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf21, SDf21.class);
|
||||
df21Imdg.getAllValues();
|
||||
|
||||
eTable = ETable.S_DF_13;
|
||||
swtFile = new File("D:\\repo\\mfd\\clearing\\clearing-parent\\swt-importer\\src\\test\\java\\ru\\spcex\\clearing\\swt\\importer\\files\\RDC_KS_DF-13_bond_221111131459718.txt");
|
||||
resultContainer = createNewTask(eTable, swtFile);
|
||||
resultContainer.setSwtSource(Files.readAllBytes(Paths.get(swtFile.getAbsolutePath())));
|
||||
|
||||
importToDB.process(resultContainer);
|
||||
Imdg<SDf13> df13Imdg = imdgProvider.getImdg(IMDGDistributedNames.Map_SDf13, SDf13.class);
|
||||
df13Imdg.getAllValues();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue