reports-service refactoring
This commit is contained in:
parent
d0267aa78c
commit
af8ff434ec
9 changed files with 5 additions and 70 deletions
|
|
@ -32,18 +32,6 @@ public abstract class ReportDataCollector<T extends AbstractReport> {
|
||||||
// */
|
// */
|
||||||
// abstract public List<T> collectReportWithClearingStatus(LocalDate startDate, LocalDate endDate, String clearingStatus);
|
// abstract public List<T> collectReportWithClearingStatus(LocalDate startDate, LocalDate endDate, String clearingStatus);
|
||||||
|
|
||||||
/**
|
|
||||||
* todo убрать метод, он уже лишний
|
|
||||||
* @param startDate
|
|
||||||
* @param endDate
|
|
||||||
* @param dateTimeNow LocalDateTime.now()
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
@Deprecated
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
throw new IllegalArgumentException("deprecated");
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract public Class<T> getReportClass();
|
abstract public Class<T> getReportClass();
|
||||||
|
|
||||||
protected String toString(Long val) {
|
protected String toString(Long val) {
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,8 @@ public abstract class FileReportBuilder<R extends AbstractReport> {
|
||||||
this.reportClass = reportClass;
|
this.reportClass = reportClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String makeFileName(String reportName, String extension) {
|
||||||
|
if (System.getProperty("os.name").toLowerCase().contains("windows")) reportName = reportName.replace(":", "_");
|
||||||
|
return reportName + extension;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,8 @@ public class XMLReportBuilder<R extends AbstractReport> extends FileReportBuilde
|
||||||
public File createReport(LocalDate startDate, LocalDate endDate) throws IOException {
|
public File createReport(LocalDate startDate, LocalDate endDate) throws IOException {
|
||||||
R report = collector.collectReportWithPeriod(startDate, endDate);
|
R report = collector.collectReportWithPeriod(startDate, endDate);
|
||||||
String reportName = report.getReportName(LocalDateTime.now());
|
String reportName = report.getReportName(LocalDateTime.now());
|
||||||
|
String reportFileName = makeFileName(reportName, ".xml");
|
||||||
|
|
||||||
if (System.getProperty("os.name").toLowerCase().contains("windows")) reportName = reportName.replace(":", "_");
|
|
||||||
|
|
||||||
String reportFileName = reportName + ".xml";
|
|
||||||
File reportFile = new File(reportFileName);
|
File reportFile = new File(reportFileName);
|
||||||
if (reportFile.exists()) {
|
if (reportFile.exists()) {
|
||||||
if (reportFile.isFile()) {
|
if (reportFile.isFile()) {
|
||||||
|
|
|
||||||
|
|
@ -129,13 +129,6 @@ public class Bt17_1_P1_collector extends ReportDataCollector<ReportBR_0420315_P1
|
||||||
return reportBR_0420315_p1;
|
return reportBR_0420315_p1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
return String.format("REPBR.0420315.P1.%s-%s.%s", DATE_FORMATTER.format(startDate), DATE_FORMATTER.format(endDate),
|
|
||||||
DATE_TIME_FORMATTER.format(dateTimeNow));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ReportBR_0420315_P1> getReportClass() {
|
public Class<ReportBR_0420315_P1> getReportClass() {
|
||||||
return ReportBR_0420315_P1.class;
|
return ReportBR_0420315_P1.class;
|
||||||
|
|
|
||||||
|
|
@ -53,12 +53,6 @@ public class Bt17_1_P2_collector extends ReportDataCollector<ReportBR_0420315_P2
|
||||||
return reportBR_0420315_p2;
|
return reportBR_0420315_p2;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
return String.format("REPBR.0420315.P2.%s-%s.%s", DATE_FORMATTER.format(startDate), DATE_FORMATTER.format(endDate),
|
|
||||||
DATE_TIME_FORMATTER.format(dateTimeNow));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ReportBR_0420315_P2> getReportClass() {
|
public Class<ReportBR_0420315_P2> getReportClass() {
|
||||||
return ReportBR_0420315_P2.class;
|
return ReportBR_0420315_P2.class;
|
||||||
|
|
|
||||||
|
|
@ -68,13 +68,6 @@ public class Bt17_2_collector extends ReportDataCollector<ReportBR_0420317> {
|
||||||
return reportBR_0420317;
|
return reportBR_0420317;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
return String.format("REPBR.0420317.%s-%s.%s", DATE_FORMATTER.format(startDate), DATE_FORMATTER.format(endDate),
|
|
||||||
DATE_TIME_FORMATTER.format(dateTimeNow));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ReportBR_0420317> getReportClass() {
|
public Class<ReportBR_0420317> getReportClass() {
|
||||||
return ReportBR_0420317.class;
|
return ReportBR_0420317.class;
|
||||||
|
|
|
||||||
|
|
@ -56,12 +56,6 @@ public class Bt17_5_P1_collector extends ReportDataCollector<ReportBR_0420312_P1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
return String.format("REPBR.0420312_р1-1.%s-%s.%s", DATE_FORMATTER.format(startDate), DATE_FORMATTER.format(endDate),
|
|
||||||
DATE_TIME_FORMATTER.format(dateTimeNow));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<ReportBR_0420312_P1> getReportClass() {
|
public Class<ReportBR_0420312_P1> getReportClass() {
|
||||||
return ReportBR_0420312_P1.class;
|
return ReportBR_0420312_P1.class;
|
||||||
|
|
|
||||||
|
|
@ -33,11 +33,6 @@ class ReportDataCollectorTest extends ReportDataCollector {
|
||||||
throw new IllegalStateException("test");
|
throw new IllegalStateException("test");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFileName(LocalDate startDate, LocalDate endDate, LocalDateTime dateTimeNow) {
|
|
||||||
throw new IllegalStateException("test");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Class<AbstractReport> getReportClass() {
|
public Class<AbstractReport> getReportClass() {
|
||||||
return AbstractReport.class;
|
return AbstractReport.class;
|
||||||
|
|
|
||||||
|
|
@ -1,24 +0,0 @@
|
||||||
package ru.spcex.clearing.reports.services.impl;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import ru.spcex.clearing.reports.services.collector.Bt17_1_P1_collector;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
|
||||||
|
|
||||||
class Bt17_1_collectorTest {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void getFileName() {
|
|
||||||
Bt17_1_P1_collector collector = Mockito.mock(Bt17_1_P1_collector.class);
|
|
||||||
Mockito.when(collector.getFileName(Mockito.any(),Mockito.any(),Mockito.any())).thenCallRealMethod();
|
|
||||||
|
|
||||||
String str = collector.getFileName(LocalDate.of(2020,1,1),
|
|
||||||
LocalDate.of(2020,1,31),
|
|
||||||
LocalDateTime.of(2021,4,20,12,20,44));
|
|
||||||
assertEquals("REPBR.0420315.P1.01.01.2020-31.01.2020.20.04.2021T12:20:44", str);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Reference in a new issue