some refactor
This commit is contained in:
parent
867f30de6a
commit
e794177155
8 changed files with 36 additions and 89 deletions
|
|
@ -5,7 +5,13 @@ import ru.spcex.clearing.reports.services.DOCXService;
|
|||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.time.format.TextStyle;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class NotificationBuilder {
|
||||
protected final DateTimeFormatter filenameDateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy'T'HH:mm:ss");
|
||||
|
|
@ -20,6 +26,21 @@ public abstract class NotificationBuilder {
|
|||
|
||||
abstract public File buildNotification(Long consumerId);
|
||||
|
||||
protected void fillHeaderValues(Map<String, String> valuesMap, Long notificationId) {
|
||||
LocalDate notificationDate = LocalDate.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%04d%02d%02d".formatted(year, month, day);
|
||||
|
||||
valuesMap.put("${dateStr}", dateStr);
|
||||
valuesMap.put("${count}", String.valueOf(notificationId));
|
||||
valuesMap.put("${currDay}", "%02d".formatted(day));
|
||||
valuesMap.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesMap.put("${currYear}", "%02d".formatted(year % 100));
|
||||
|
||||
}
|
||||
|
||||
protected File getTemplateFile() {
|
||||
File templateFile;
|
||||
String templateResourceName = getTemplateResourceName();
|
||||
|
|
|
|||
|
|
@ -69,21 +69,11 @@ public class REXNotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
valuesForTemplate.put("${validFromDate}", "%02d.%02d.%04d".formatted(day, month, year));
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${validFromDate}", dateFormatter.format(validFromDate));
|
||||
|
||||
String outputFilename = "REX.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "REX.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -74,25 +74,14 @@ public class ROOT_ACTV_NotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
|
||||
|
||||
String outputFilename = "ROOT.ACTV.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "ROOT.ACTV.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -74,25 +74,14 @@ public class ROOT_BLKD_NotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
|
||||
|
||||
String outputFilename = "ROOT.BLKD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "ROOT.BLKD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -82,25 +82,15 @@ public class ROOT_CLOS_NotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
valuesForTemplate.put("${profileDocumentNumber}", currentProfileDocument.getNumber());
|
||||
valuesForTemplate.put("${validFromDate}", dateFormatter.format(validFromDate));
|
||||
|
||||
String outputFilename = "ROOT.CLOS.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "ROOT.CLOS.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -82,25 +82,15 @@ public class ROOT_NEW_NotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
valuesForTemplate.put("${profileDocumentNumber}", currentProfileDocument.getNumber());
|
||||
valuesForTemplate.put("${validFromDate}", dateFormatter.format(validFromDate));
|
||||
|
||||
String outputFilename = "ROOT.NEW.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "ROOT.NEW.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ import ru.spcex.platform.imdg.api.ImdgProvider;
|
|||
|
||||
import java.io.File;
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.TextStyle;
|
||||
|
|
@ -74,25 +73,14 @@ public class ROOT_SSPD_NotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
|
||||
|
||||
String outputFilename = "ROOT.SSPD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "ROOT.SSPD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
|
|
@ -73,18 +73,8 @@ public class RRPCNotificationBuilder extends NotificationBuilder {
|
|||
return null;
|
||||
}
|
||||
|
||||
LocalDateTime notificationDate = LocalDateTime.now();
|
||||
int day = notificationDate.getDayOfMonth();
|
||||
int month = notificationDate.getMonthValue();
|
||||
int year = notificationDate.getYear();
|
||||
String dateStr = "%02d%02d%04d".formatted(day, month, year);
|
||||
|
||||
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||
valuesForTemplate.put("${dateStr}", dateStr);
|
||||
valuesForTemplate.put("${count}", String.valueOf(notificationId));
|
||||
valuesForTemplate.put("${currDay}", "%02d".formatted(day));
|
||||
valuesForTemplate.put("${currMonth}", notificationDate.getMonth().getDisplayName(TextStyle.FULL, new Locale("ru")));
|
||||
valuesForTemplate.put("${currYear}", "%02d".formatted(year % 100));
|
||||
fillHeaderValues(valuesForTemplate, notificationId);
|
||||
|
||||
valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt.atZone(ZoneId.systemDefault()).toLocalDate()));
|
||||
valuesForTemplate.put("${companyFullName}", company.getFullName());
|
||||
|
|
@ -92,7 +82,7 @@ public class RRPCNotificationBuilder extends NotificationBuilder {
|
|||
valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue());
|
||||
valuesForTemplate.put("${companyClearingCode}", companyClearingCode);
|
||||
|
||||
String outputFilename = "RRPC.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate));
|
||||
String outputFilename = "RRPC.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||
|
||||
File outputFile = new File(outputFilename);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue