ROOT_(NEW/CLOS/ACTV/BLKD/SSPD) notification, prepared for test

This commit is contained in:
akulikov 2022-12-29 14:51:41 +03:00
parent f069bab18a
commit f66c334100
10 changed files with 579 additions and 0 deletions

View file

@ -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<Company> companyImdg;
private final Imdg<Relation> relationImdg;
private final Imdg<CompanySymbols> 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<Relation> relations = relationImdg.getCollectionObjectsBySQL(relationsSql);
if (relations.size() >= 1) {
Optional<Relation> 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<CompanySymbols> 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<String, String> 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";
}
}

View file

@ -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<Company> companyImdg;
private final Imdg<Relation> relationImdg;
private final Imdg<CompanySymbols> 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<Relation> relations = relationImdg.getCollectionObjectsBySQL(relationsSql);
if (relations.size() >= 1) {
Optional<Relation> 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<CompanySymbols> 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<String, String> 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";
}
}

View file

@ -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<ProfileDocument> profileDocumentImdg;
private final Imdg<Company> companyImdg;
private final Imdg<CompanySymbols> 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<ProfileDocument> profileDocuments = profileDocumentImdg.getCollectionObjectsBySQL(sql);
ProfileDocument currentProfileDocument = null;
if (profileDocuments.size() >= 1) {
Optional<ProfileDocument> 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<CompanySymbols> 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<String, String> 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";
}
}

View file

@ -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<ProfileDocument> profileDocumentImdg;
private final Imdg<Company> companyImdg;
private final Imdg<CompanySymbols> 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<ProfileDocument> profileDocuments = profileDocumentImdg.getCollectionObjectsBySQL(sql);
ProfileDocument currentProfileDocument = null;
if (profileDocuments.size() >= 1) {
Optional<ProfileDocument> 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<CompanySymbols> 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<String, String> 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";
}
}

View file

@ -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<Company> companyImdg;
private final Imdg<Relation> relationImdg;
private final Imdg<CompanySymbols> 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<Relation> relations = relationImdg.getCollectionObjectsBySQL(relationsSql);
if (relations.size() >= 1) {
Optional<Relation> 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<CompanySymbols> 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<String, String> 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";
}
}