diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_ACTV_NotificationBuilder.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_ACTV_NotificationBuilder.java new file mode 100644 index 000000000..5dbf69886 --- /dev/null +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_ACTV_NotificationBuilder.java @@ -0,0 +1,111 @@ +package ru.spcex.clearing.reports.notifications; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import ru.clearing.classes.objects.BusinessObject; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanySymbols; +import ru.clearing.classes.statics.data.company.relation.Relation; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +import java.io.File; +import java.time.Instant; +import java.time.LocalDate; +import java.util.*; + +@Component +public class ROOT_ACTV_NotificationBuilder extends NotificationBuilder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg companyImdg; + private final Imdg relationImdg; + private final Imdg companySymbolsImdg; + + public ROOT_ACTV_NotificationBuilder(ImdgProvider imdgProvider) { + super(null); + companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + relationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class); + companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class); + } + + @Override + public File buildNotification(Long consumerId) { + Company company = companyImdg.getSingleObjectByID(consumerId); + if (company == null) { + log.error("Company for companyId={} is null", consumerId); + return null; + } + String companyClearingCode = company.getClearingCode(); + if (StringUtils.isBlank(companyClearingCode)) { + log.error("Company.clearing_code for companyId={} is null", consumerId); + return null; + } + + String relationsSql = "consumerId = %d".formatted(consumerId); + Relation relation = null; + Collection relations = relationImdg.getCollectionObjectsBySQL(relationsSql); + if (relations.size() >= 1) { + Optional relationOptional = relations.stream().max(Comparator.comparing(BusinessObject::getUpdated)); + relation = relationOptional.get(); + } else { + log.warn("Relation with sql {} not found", relationsSql); + return null; + } + Long notificationId = relation.getId(); + Instant updatedAt = relation.getUpdated(); + if (updatedAt == null) { + log.error("updated_at is null for relation {}", relation); + return null; + } + + String companySymbolsSql = "companyId = %d AND companySymbol = INN"; + CompanySymbols companySymbols = null; + Collection companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql); + if (companySymbolsCollection.size() >= 1) { + companySymbols = companySymbolsCollection.iterator().next(); + } else { + log.warn("CompanySymbols with sql {} not found", companySymbolsSql); + return null; + } + + LocalDate notificationDate = LocalDate.now(); + int day = notificationDate.getDayOfMonth(); + int month = notificationDate.getMonthValue(); + int year = notificationDate.getYear(); + String dateStr = "%02d%02d%04d".formatted(day, month, year); + + Map valuesForTemplate = new HashMap<>(); + valuesForTemplate.put("${dateStr}", dateStr); + valuesForTemplate.put("${count}", String.valueOf(notificationId)); + valuesForTemplate.put("${currDay}", "%02d".formatted(day)); + valuesForTemplate.put("${currMonth}", "%02d".formatted(month)); + valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100)); + + valuesForTemplate.put("${companyFullName}", company.getFullName()); + valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue()); + valuesForTemplate.put("${companyClearingCode}", companyClearingCode); + valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt)); + + String outputFilename = "ROOT.ACTV.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate)); + outputFilename = normalizeFilenameForOS(outputFilename); + + File outputFile = new File(outputFilename); + try { + docxService.insertValues(outputFile, valuesForTemplate, true); + } catch (Exception e) { + log.error("Can't insert values into template.", e); + return null; + } + + return outputFile; + } + + @Override + protected String getTemplateResourceName() { + return "templates/ROOT.ACTV_TEMPLATE.docx"; + } + +} diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_BLKD_NotificationBuilder.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_BLKD_NotificationBuilder.java new file mode 100644 index 000000000..7b619e177 --- /dev/null +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_BLKD_NotificationBuilder.java @@ -0,0 +1,111 @@ +package ru.spcex.clearing.reports.notifications; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import ru.clearing.classes.objects.BusinessObject; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanySymbols; +import ru.clearing.classes.statics.data.company.relation.Relation; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +import java.io.File; +import java.time.Instant; +import java.time.LocalDate; +import java.util.*; + +@Component +public class ROOT_BLKD_NotificationBuilder extends NotificationBuilder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg companyImdg; + private final Imdg relationImdg; + private final Imdg companySymbolsImdg; + + public ROOT_BLKD_NotificationBuilder(ImdgProvider imdgProvider) { + super(null); + companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + relationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class); + companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class); + } + + @Override + public File buildNotification(Long consumerId) { + Company company = companyImdg.getSingleObjectByID(consumerId); + if (company == null) { + log.error("Company for companyId={} is null", consumerId); + return null; + } + String companyClearingCode = company.getClearingCode(); + if (StringUtils.isBlank(companyClearingCode)) { + log.error("Company.clearing_code for companyId={} is null", consumerId); + return null; + } + + String relationsSql = "consumerId = %d".formatted(consumerId); + Relation relation = null; + Collection relations = relationImdg.getCollectionObjectsBySQL(relationsSql); + if (relations.size() >= 1) { + Optional relationOptional = relations.stream().max(Comparator.comparing(BusinessObject::getUpdated)); + relation = relationOptional.get(); + } else { + log.warn("Relation with sql {} not found", relationsSql); + return null; + } + Long notificationId = relation.getId(); + Instant updatedAt = relation.getUpdated(); + if (updatedAt == null) { + log.error("updated_at is null for relation {}", relation); + return null; + } + + String companySymbolsSql = "companyId = %d AND companySymbol = INN"; + CompanySymbols companySymbols = null; + Collection companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql); + if (companySymbolsCollection.size() >= 1) { + companySymbols = companySymbolsCollection.iterator().next(); + } else { + log.warn("CompanySymbols with sql {} not found", companySymbolsSql); + return null; + } + + LocalDate notificationDate = LocalDate.now(); + int day = notificationDate.getDayOfMonth(); + int month = notificationDate.getMonthValue(); + int year = notificationDate.getYear(); + String dateStr = "%02d%02d%04d".formatted(day, month, year); + + Map valuesForTemplate = new HashMap<>(); + valuesForTemplate.put("${dateStr}", dateStr); + valuesForTemplate.put("${count}", String.valueOf(notificationId)); + valuesForTemplate.put("${currDay}", "%02d".formatted(day)); + valuesForTemplate.put("${currMonth}", "%02d".formatted(month)); + valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100)); + + valuesForTemplate.put("${companyFullName}", company.getFullName()); + valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue()); + valuesForTemplate.put("${companyClearingCode}", companyClearingCode); + valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt)); + + String outputFilename = "ROOT.BLKD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate)); + outputFilename = normalizeFilenameForOS(outputFilename); + + File outputFile = new File(outputFilename); + try { + docxService.insertValues(outputFile, valuesForTemplate, true); + } catch (Exception e) { + log.error("Can't insert values into template.", e); + return null; + } + + return outputFile; + } + + @Override + protected String getTemplateResourceName() { + return "templates/ROOT.BLKD_TEMPLATE.docx"; + } + +} diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_CLOS_NotificationBuilder.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_CLOS_NotificationBuilder.java new file mode 100644 index 000000000..e84ee9b06 --- /dev/null +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_CLOS_NotificationBuilder.java @@ -0,0 +1,123 @@ +package ru.spcex.clearing.reports.notifications; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanySymbols; +import ru.clearing.classes.statics.data.profile.ProfileDocument; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +import java.io.File; +import java.time.LocalDate; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@Component +public class ROOT_CLOS_NotificationBuilder extends NotificationBuilder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg profileDocumentImdg; + private final Imdg companyImdg; + private final Imdg companySymbolsImdg; + + public ROOT_CLOS_NotificationBuilder(ImdgProvider imdgProvider) { + super(null); + profileDocumentImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class); + companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class); + } + + @Override + public File buildNotification(Long consumerId) { + String sql = "companyId = %d AND documentType = 'CNTR'".formatted(consumerId); + Collection profileDocuments = profileDocumentImdg.getCollectionObjectsBySQL(sql); + ProfileDocument currentProfileDocument = null; + if (profileDocuments.size() >= 1) { + Optional profileDocumentOptional = profileDocuments.stream().max((o1, o2) -> { + LocalDate o1ValidFromDate = o1.getValidFromDate(); + LocalDate o2ValidFromDate = o2.getValidFromDate(); + o1ValidFromDate = o1ValidFromDate == null ? LocalDate.MIN : o1ValidFromDate; + o2ValidFromDate = o2ValidFromDate == null ? LocalDate.MIN : o2ValidFromDate; + return o1ValidFromDate.compareTo(o2ValidFromDate); + }); + currentProfileDocument = profileDocumentOptional.get(); + } else { + log.warn("Profile_document with sql {} not found", sql); + return null; + } + + Long notificationId = currentProfileDocument.getId(); + LocalDate validFromDate = currentProfileDocument.getValidFromDate(); + if (validFromDate == null) { + log.error("validFromDate is null for profile_document {}", currentProfileDocument); + return null; + } + Long companyId = currentProfileDocument.getCompanyId(); + if (companyId == null) { + log.error("companyId is null for profile_document {}", currentProfileDocument); + return null; + } + Company company = companyImdg.getSingleObjectByID(companyId); + if (company == null) { + log.error("Company for companyId={} is null", companyId); + return null; + } + String companyClearingCode = company.getClearingCode(); + if (StringUtils.isBlank(companyClearingCode)) { + log.error("Company.clearing_code for companyId={} is null", companyId); + return null; + } + + String companySymbolsSql = "companyId = %d AND companySymbol = INN"; + CompanySymbols companySymbols = null; + Collection companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql); + if (companySymbolsCollection.size() >= 1) { + companySymbols = companySymbolsCollection.iterator().next(); + } else { + log.warn("CompanySymbols with sql {} not found", companySymbolsSql); + return null; + } + + LocalDate notificationDate = LocalDate.now(); + int day = notificationDate.getDayOfMonth(); + int month = notificationDate.getMonthValue(); + int year = notificationDate.getYear(); + String dateStr = "%02d%02d%04d".formatted(day, month, year); + + Map valuesForTemplate = new HashMap<>(); + valuesForTemplate.put("${dateStr}", dateStr); + valuesForTemplate.put("${count}", String.valueOf(notificationId)); + valuesForTemplate.put("${currDay}", "%02d".formatted(day)); + valuesForTemplate.put("${currMonth}", "%02d".formatted(month)); + valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100)); + 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)); + outputFilename = normalizeFilenameForOS(outputFilename); + + File outputFile = new File(outputFilename); + try { + docxService.insertValues(outputFile, valuesForTemplate, true); + } catch (Exception e) { + log.error("Can't insert values into template.", e); + return null; + } + + return outputFile; + } + + @Override + protected String getTemplateResourceName() { + return "templates/ROOT.CLOS_TEMPLATE.docx"; + } + +} diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_NEW_NotificationBuilder.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_NEW_NotificationBuilder.java new file mode 100644 index 000000000..a698ce90c --- /dev/null +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_NEW_NotificationBuilder.java @@ -0,0 +1,123 @@ +package ru.spcex.clearing.reports.notifications; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanySymbols; +import ru.clearing.classes.statics.data.profile.ProfileDocument; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +import java.io.File; +import java.time.LocalDate; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +@Component +public class ROOT_NEW_NotificationBuilder extends NotificationBuilder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg profileDocumentImdg; + private final Imdg companyImdg; + private final Imdg companySymbolsImdg; + + public ROOT_NEW_NotificationBuilder(ImdgProvider imdgProvider) { + super(null); + profileDocumentImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class); + companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class); + } + + @Override + public File buildNotification(Long consumerId) { + String sql = "companyId = %d AND documentType = 'CNTR'".formatted(consumerId); + Collection profileDocuments = profileDocumentImdg.getCollectionObjectsBySQL(sql); + ProfileDocument currentProfileDocument = null; + if (profileDocuments.size() >= 1) { + Optional profileDocumentOptional = profileDocuments.stream().max((o1, o2) -> { + LocalDate o1ValidFromDate = o1.getValidFromDate(); + LocalDate o2ValidFromDate = o2.getValidFromDate(); + o1ValidFromDate = o1ValidFromDate == null ? LocalDate.MIN : o1ValidFromDate; + o2ValidFromDate = o2ValidFromDate == null ? LocalDate.MIN : o2ValidFromDate; + return o1ValidFromDate.compareTo(o2ValidFromDate); + }); + currentProfileDocument = profileDocumentOptional.get(); + } else { + log.warn("Profile_document with sql {} not found", sql); + return null; + } + + Long notificationId = currentProfileDocument.getId(); + LocalDate validFromDate = currentProfileDocument.getValidFromDate(); + if (validFromDate == null) { + log.error("validFromDate is null for profile_document {}", currentProfileDocument); + return null; + } + Long companyId = currentProfileDocument.getCompanyId(); + if (companyId == null) { + log.error("companyId is null for profile_document {}", currentProfileDocument); + return null; + } + Company company = companyImdg.getSingleObjectByID(companyId); + if (company == null) { + log.error("Company for companyId={} is null", companyId); + return null; + } + String companyClearingCode = company.getClearingCode(); + if (StringUtils.isBlank(companyClearingCode)) { + log.error("Company.clearing_code for companyId={} is null", companyId); + return null; + } + + String companySymbolsSql = "companyId = %d AND companySymbol = INN"; + CompanySymbols companySymbols = null; + Collection companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql); + if (companySymbolsCollection.size() >= 1) { + companySymbols = companySymbolsCollection.iterator().next(); + } else { + log.warn("CompanySymbols with sql {} not found", companySymbolsSql); + return null; + } + + LocalDate notificationDate = LocalDate.now(); + int day = notificationDate.getDayOfMonth(); + int month = notificationDate.getMonthValue(); + int year = notificationDate.getYear(); + String dateStr = "%02d%02d%04d".formatted(day, month, year); + + Map valuesForTemplate = new HashMap<>(); + valuesForTemplate.put("${dateStr}", dateStr); + valuesForTemplate.put("${count}", String.valueOf(notificationId)); + valuesForTemplate.put("${currDay}", "%02d".formatted(day)); + valuesForTemplate.put("${currMonth}", "%02d".formatted(month)); + valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100)); + 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)); + outputFilename = normalizeFilenameForOS(outputFilename); + + File outputFile = new File(outputFilename); + try { + docxService.insertValues(outputFile, valuesForTemplate, true); + } catch (Exception e) { + log.error("Can't insert values into template.", e); + return null; + } + + return outputFile; + } + + @Override + protected String getTemplateResourceName() { + return "templates/ROOT.NEW_TEMPLATE.docx"; + } + +} diff --git a/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_SSPD_NotificationBuilder.java b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_SSPD_NotificationBuilder.java new file mode 100644 index 000000000..9497e3631 --- /dev/null +++ b/clearing-parent/reports-service/src/main/java/ru/spcex/clearing/reports/notifications/ROOT_SSPD_NotificationBuilder.java @@ -0,0 +1,111 @@ +package ru.spcex.clearing.reports.notifications; + +import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Component; +import ru.clearing.classes.objects.BusinessObject; +import ru.clearing.classes.statics.data.company.Company; +import ru.clearing.classes.statics.data.company.CompanySymbols; +import ru.clearing.classes.statics.data.company.relation.Relation; +import ru.spcex.clearing.imdg.IMDGDistributedNames; +import ru.spcex.platform.imdg.api.Imdg; +import ru.spcex.platform.imdg.api.ImdgProvider; + +import java.io.File; +import java.time.Instant; +import java.time.LocalDate; +import java.util.*; + +@Component +public class ROOT_SSPD_NotificationBuilder extends NotificationBuilder { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final Imdg companyImdg; + private final Imdg relationImdg; + private final Imdg companySymbolsImdg; + + public ROOT_SSPD_NotificationBuilder(ImdgProvider imdgProvider) { + super(null); + companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class); + relationImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Relation, Relation.class); + companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class); + } + + @Override + public File buildNotification(Long consumerId) { + Company company = companyImdg.getSingleObjectByID(consumerId); + if (company == null) { + log.error("Company for companyId={} is null", consumerId); + return null; + } + String companyClearingCode = company.getClearingCode(); + if (StringUtils.isBlank(companyClearingCode)) { + log.error("Company.clearing_code for companyId={} is null", consumerId); + return null; + } + + String relationsSql = "consumerId = %d".formatted(consumerId); + Relation relation = null; + Collection relations = relationImdg.getCollectionObjectsBySQL(relationsSql); + if (relations.size() >= 1) { + Optional relationOptional = relations.stream().max(Comparator.comparing(BusinessObject::getUpdated)); + relation = relationOptional.get(); + } else { + log.warn("Relation with sql {} not found", relationsSql); + return null; + } + Long notificationId = relation.getId(); + Instant updatedAt = relation.getUpdated(); + if (updatedAt == null) { + log.error("updated_at is null for relation {}", relation); + return null; + } + + String companySymbolsSql = "companyId = %d AND companySymbol = INN"; + CompanySymbols companySymbols = null; + Collection companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql); + if (companySymbolsCollection.size() >= 1) { + companySymbols = companySymbolsCollection.iterator().next(); + } else { + log.warn("CompanySymbols with sql {} not found", companySymbolsSql); + return null; + } + + LocalDate notificationDate = LocalDate.now(); + int day = notificationDate.getDayOfMonth(); + int month = notificationDate.getMonthValue(); + int year = notificationDate.getYear(); + String dateStr = "%02d%02d%04d".formatted(day, month, year); + + Map valuesForTemplate = new HashMap<>(); + valuesForTemplate.put("${dateStr}", dateStr); + valuesForTemplate.put("${count}", String.valueOf(notificationId)); + valuesForTemplate.put("${currDay}", "%02d".formatted(day)); + valuesForTemplate.put("${currMonth}", "%02d".formatted(month)); + valuesForTemplate.put("${currYear}", "%04d".formatted(year % 100)); + + valuesForTemplate.put("${companyFullName}", company.getFullName()); + valuesForTemplate.put("${companySymbolsINN}", companySymbols.getCompanySymbolValue()); + valuesForTemplate.put("${companyClearingCode}", companyClearingCode); + valuesForTemplate.put("${relationUpdatedAt}", dateFormatter.format(updatedAt)); + + String outputFilename = "ROOT.SSPD.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(notificationDate)); + outputFilename = normalizeFilenameForOS(outputFilename); + + File outputFile = new File(outputFilename); + try { + docxService.insertValues(outputFile, valuesForTemplate, true); + } catch (Exception e) { + log.error("Can't insert values into template.", e); + return null; + } + + return outputFile; + } + + @Override + protected String getTemplateResourceName() { + return "templates/ROOT.SSPD_TEMPLATE.docx"; + } + +} diff --git a/clearing-parent/reports-service/src/main/resources/templates/ROOT.ACTV_TEMPLATE.docx b/clearing-parent/reports-service/src/main/resources/templates/ROOT.ACTV_TEMPLATE.docx new file mode 100644 index 000000000..135d87f99 Binary files /dev/null and b/clearing-parent/reports-service/src/main/resources/templates/ROOT.ACTV_TEMPLATE.docx differ diff --git a/clearing-parent/reports-service/src/main/resources/templates/ROOT.BLKD_TEMPLATE.docx b/clearing-parent/reports-service/src/main/resources/templates/ROOT.BLKD_TEMPLATE.docx new file mode 100644 index 000000000..b5463419d Binary files /dev/null and b/clearing-parent/reports-service/src/main/resources/templates/ROOT.BLKD_TEMPLATE.docx differ diff --git a/clearing-parent/reports-service/src/main/resources/templates/ROOT.CLOS_TEMPLATE.docx b/clearing-parent/reports-service/src/main/resources/templates/ROOT.CLOS_TEMPLATE.docx new file mode 100644 index 000000000..e9941a6ee Binary files /dev/null and b/clearing-parent/reports-service/src/main/resources/templates/ROOT.CLOS_TEMPLATE.docx differ diff --git a/clearing-parent/reports-service/src/main/resources/templates/ROOT.NEW_TEMPLATE.docx b/clearing-parent/reports-service/src/main/resources/templates/ROOT.NEW_TEMPLATE.docx new file mode 100644 index 000000000..1cd7ae7bd Binary files /dev/null and b/clearing-parent/reports-service/src/main/resources/templates/ROOT.NEW_TEMPLATE.docx differ diff --git a/clearing-parent/reports-service/src/main/resources/templates/ROOT.SSPD_TEMPLATE.docx b/clearing-parent/reports-service/src/main/resources/templates/ROOT.SSPD_TEMPLATE.docx new file mode 100644 index 000000000..65f964c52 Binary files /dev/null and b/clearing-parent/reports-service/src/main/resources/templates/ROOT.SSPD_TEMPLATE.docx differ