-
Notifications
You must be signed in to change notification settings - Fork 109
Поддержка брокера Альфа-Инвестиции #542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
src/main/java/ru/investbook/parser/alfa/AlfaBrokerReportFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| /* | ||
| * InvestBook | ||
| * Copyright (C) 2020 Vitalii Ananev <spacious-team@ya.ru> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package ru.investbook.parser.alfa; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.spacious_team.broker.report_parser.api.AbstractBrokerReportFactory; | ||
| import org.spacious_team.broker.report_parser.api.BrokerReport; | ||
| import org.springframework.core.Ordered; | ||
| import org.springframework.core.annotation.Order; | ||
| import org.springframework.stereotype.Component; | ||
| import ru.investbook.parser.SecurityRegistrar; | ||
|
|
||
| import java.io.InputStream; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| @Component | ||
| @Order(Ordered.HIGHEST_PRECEDENCE) | ||
| @Slf4j | ||
| @RequiredArgsConstructor | ||
| public class AlfaBrokerReportFactory extends AbstractBrokerReportFactory { | ||
| private final SecurityRegistrar securityRegistrar; | ||
|
|
||
| @Getter | ||
| private final String brokerName = "Альфа-Инвестиции"; | ||
| private final Pattern expectedFileNamePattern = Pattern.compile("^[0-9]+\\([^()]+\\)[0-9\\-]+\\.xls(x)?$"); // FIXME - уточнить про регэксп | ||
|
vananiev marked this conversation as resolved.
|
||
|
|
||
| @Override | ||
| public boolean canCreate(String excelFileName, InputStream is) { | ||
| return super.canCreate(expectedFileNamePattern, excelFileName, is); | ||
| } | ||
|
|
||
| @Override | ||
| public BrokerReport create(String excelFileName, InputStream is) { | ||
| BrokerReport brokerReport = create(excelFileName, is, | ||
| (fileName, stream) -> new AlfaCashflowBrokerReport(fileName, stream, securityRegistrar)); | ||
| if (brokerReport != null) { | ||
| log.info("Обнаружен отчет '{}' Альфа брокера", excelFileName); | ||
| } | ||
| return brokerReport; | ||
|
vananiev marked this conversation as resolved.
|
||
| } | ||
| } | ||
40 changes: 40 additions & 0 deletions
40
src/main/java/ru/investbook/parser/alfa/AlfaBrokerReportWrapper.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * InvestBook | ||
| * Copyright (C) 2023 Vitalii Ananev <spacious-team@ya.ru> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package ru.investbook.parser.alfa; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.spacious_team.broker.report_parser.api.BrokerReport; | ||
| import org.spacious_team.table_wrapper.api.ReportPage; | ||
|
|
||
| @Getter | ||
| @RequiredArgsConstructor | ||
| public class AlfaBrokerReportWrapper implements BrokerReport { | ||
|
|
||
| private final AlfaCashflowBrokerReport alfaCashflowBrokerReport; | ||
|
|
||
| @Override | ||
| public ReportPage getReportPage() { | ||
| throw new UnsupportedOperationException(); | ||
|
vananiev marked this conversation as resolved.
|
||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| } | ||
| } | ||
105 changes: 105 additions & 0 deletions
105
src/main/java/ru/investbook/parser/alfa/AlfaCashflowBrokerReport.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| /* | ||
| * InvestBook | ||
| * Copyright (C) 2020 Vitalii Ananev <spacious-team@ya.ru> | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package ru.investbook.parser.alfa; | ||
|
|
||
| import lombok.EqualsAndHashCode; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.apache.poi.ss.usermodel.Workbook; | ||
| import org.spacious_team.table_wrapper.api.ReportPage; | ||
| import org.spacious_team.table_wrapper.api.TableCellAddress; | ||
| import org.spacious_team.table_wrapper.excel.ExcelSheet; | ||
| import ru.investbook.parser.AbstractExcelBrokerReport; | ||
| import ru.investbook.parser.SecurityRegistrar; | ||
|
|
||
| import java.io.IOException; | ||
| import java.io.InputStream; | ||
| import java.nio.file.Files; | ||
| import java.nio.file.Path; | ||
| import java.nio.file.Paths; | ||
| import java.time.Instant; | ||
| import java.time.temporal.ChronoUnit; | ||
|
|
||
| @EqualsAndHashCode(callSuper = true) | ||
| public class AlfaCashflowBrokerReport extends AbstractExcelBrokerReport { | ||
| public static final String UNIQ_TEXT = "Движение денежных средств за период"; | ||
| private static final String PORTFOLIO_MARKER = "Ген. соглашение"; | ||
| private static final String REPORT_DATE_MARKER = "Отчетный период"; | ||
|
|
||
| private final Workbook book; | ||
|
|
||
| public AlfaCashflowBrokerReport(String excelFileName, SecurityRegistrar securityRegistrar) throws IOException { | ||
| this(Paths.get(excelFileName), securityRegistrar); | ||
| } | ||
|
|
||
| public AlfaCashflowBrokerReport(Path report, SecurityRegistrar securityRegistrar) throws IOException { | ||
| this(report.getFileName().toString(), Files.newInputStream(report), securityRegistrar); | ||
| } | ||
|
|
||
| public AlfaCashflowBrokerReport(String excelFileName, InputStream is, SecurityRegistrar securityRegistrar) { | ||
| super(securityRegistrar); | ||
| this.book = getWorkBook(excelFileName, is); | ||
| ReportPage reportPage = new ExcelSheet(book.getSheetAt(3)); | ||
| checkReportFormat(excelFileName, reportPage); | ||
| setPath(Paths.get(excelFileName)); | ||
| setReportPage(reportPage); | ||
| setPortfolio(getPortfolio(reportPage)); | ||
| setReportEndDateTime(getReportEndDateTime(reportPage)); | ||
| } | ||
|
|
||
| public static void checkReportFormat(String excelFileName, ReportPage reportPage) { | ||
| if (reportPage instanceof ExcelSheet excelSheet) { | ||
|
|
||
| if (!excelSheet.getSheet().getSheetName().trim().equals("Движение ДС")) { | ||
| throw new RuntimeException("В файле " + excelFileName + " не содержится отчет брокера Альфа-Инвестиции"); | ||
| } | ||
|
|
||
| if (reportPage.findByPrefix(UNIQ_TEXT, 11, 13) == TableCellAddress.NOT_FOUND) { | ||
|
vananiev marked this conversation as resolved.
|
||
| throw new RuntimeException("В файле " + excelFileName + " не содержится отчет брокера Альфа-Инвестиции"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private static String getPortfolio(ReportPage reportPage) { | ||
| try { | ||
| String value = String.valueOf(reportPage.getNextColumnValue(PORTFOLIO_MARKER)); | ||
|
|
||
| return StringUtils.substringBetween(value, "№ ", " от"); | ||
|
|
||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException( | ||
| "В отчете не найден номер договора по заданному шаблону '" + PORTFOLIO_MARKER + " XXX'"); | ||
| } | ||
| } | ||
|
|
||
| private Instant getReportEndDateTime(ReportPage reportPage) { | ||
| try { | ||
| String value = String.valueOf(reportPage.getNextColumnValue(REPORT_DATE_MARKER)); | ||
| return convertToInstant(value.split(" - ")[1].trim()) | ||
| .plus(LAST_TRADE_HOUR, ChronoUnit.HOURS); | ||
| } catch (Exception e) { | ||
| throw new IllegalArgumentException( | ||
| "Не найдена дата отчета по заданному шаблону '" + REPORT_DATE_MARKER + " XXX'"); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void close() throws IOException { | ||
| this.book.close(); | ||
|
vananiev marked this conversation as resolved.
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.