Реализовал формирование уведомлений newInfoAccount и newTradingClearingRegistry.
This commit is contained in:
parent
c8f7f5212e
commit
e049752508
12 changed files with 633 additions and 6 deletions
|
|
@ -204,7 +204,13 @@ public class DOCXService {
|
||||||
* Сбор ключей из параграфа
|
* Сбор ключей из параграфа
|
||||||
*/
|
*/
|
||||||
private void collectKeysFromParagraph(XWPFParagraph paragraph) {
|
private void collectKeysFromParagraph(XWPFParagraph paragraph) {
|
||||||
for (XWPFRun run : paragraph.getRuns()) {
|
XWPFRun runForConcat = null;
|
||||||
|
int first = 0;
|
||||||
|
String concatText = "";
|
||||||
|
boolean needConcat = false;
|
||||||
|
List<XWPFRun> runs = paragraph.getRuns();
|
||||||
|
for (XWPFRun run : runs) {
|
||||||
|
boolean finded = false;
|
||||||
try {
|
try {
|
||||||
int MAX_POSITION = 128;
|
int MAX_POSITION = 128;
|
||||||
for (int currPos = 0; currPos < MAX_POSITION; currPos++) {
|
for (int currPos = 0; currPos < MAX_POSITION; currPos++) {
|
||||||
|
|
@ -212,9 +218,53 @@ public class DOCXService {
|
||||||
if (currText == null) break;
|
if (currText == null) break;
|
||||||
Matcher matcher = keyPattern.matcher(currText);
|
Matcher matcher = keyPattern.matcher(currText);
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
|
finded = true;
|
||||||
String key = matcher.group();
|
String key = matcher.group();
|
||||||
keyPositions.add(new KeyPositionInDoc(key, run, currPos));
|
keyPositions.add(new KeyPositionInDoc(key, run, currPos));
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* если ключ не нашли регуляркой но есть начало ключа "${" соберем ключ из фрагментов и отделим от текста
|
||||||
|
* например из фрагментов XWPFRun(учитывается только текст):
|
||||||
|
* [test , someText${, some, Key}/${ano, ther, Key}someText, test]
|
||||||
|
* получим [test , someText, ${someKey}, /, ${anotherKey}, someText, test]
|
||||||
|
*/
|
||||||
|
if (needConcat) {
|
||||||
|
concatText = concatText + currText;
|
||||||
|
if (currText.contains("}")) {
|
||||||
|
String[] strAr = new String[3];
|
||||||
|
int start = concatText.indexOf("${");
|
||||||
|
int end = concatText.indexOf("}") + 1;
|
||||||
|
strAr[0] = concatText.substring(0, start);
|
||||||
|
strAr[1] = concatText.substring(start, end);
|
||||||
|
strAr[2] = concatText.substring(end, concatText.length());
|
||||||
|
|
||||||
|
int last = runs.indexOf(run);
|
||||||
|
for (int i = first; i <= last; i++) {
|
||||||
|
if (i - first < 3) {
|
||||||
|
runs.get(i).setText(strAr[i - first], 0);
|
||||||
|
if (i - first == 1) {
|
||||||
|
keyPositions.add(new KeyPositionInDoc(runs.get(i).getText(0), runs.get(i), 0));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
runs.get(i).setText("", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currText = strAr[2];
|
||||||
|
if (currText.contains("${")) {
|
||||||
|
needConcat = true;
|
||||||
|
concatText = currText;
|
||||||
|
first = runs.indexOf(run);
|
||||||
|
} else {
|
||||||
|
needConcat = false;
|
||||||
|
concatText = "";
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (currText.contains("${") && !finded) {
|
||||||
|
needConcat = true;
|
||||||
|
concatText = currText;
|
||||||
|
first = runs.indexOf(run);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (IndexOutOfBoundsException ignored) {
|
} catch (IndexOutOfBoundsException ignored) {
|
||||||
// can't get all max text position for XWPFRun
|
// can't get all max text position for XWPFRun
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,105 @@
|
||||||
|
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.account.Account;
|
||||||
|
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.time.LocalDateTime;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class NCMPNotificationBuilder extends NotificationBuilder {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final Imdg<Company> companyImdg;
|
||||||
|
private final Imdg<ProfileDocument> profileDocumentImdg;
|
||||||
|
private final Imdg<Account> accountImdg;
|
||||||
|
private final Imdg<CompanySymbols> companySymbolsImdg;
|
||||||
|
|
||||||
|
public NCMPNotificationBuilder(ImdgProvider imdgProvider) {
|
||||||
|
super(null);
|
||||||
|
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
this.profileDocumentImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
|
||||||
|
this.accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
|
this.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 profileDocumentSql = "companyId = %d AND documentType = CLRN".formatted(consumerId);
|
||||||
|
ProfileDocument profileDocument = null;
|
||||||
|
Collection<ProfileDocument> profileDocuments = profileDocumentImdg.getCollectionObjectsBySQL(profileDocumentSql);
|
||||||
|
if (profileDocuments.size() >= 1) {
|
||||||
|
profileDocument = profileDocuments.iterator().next();
|
||||||
|
} else {
|
||||||
|
log.warn("ProfileDocument with sql {} not found", profileDocumentSql);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
String companySymbolsValueINN = getCompanySymbolValue("companyId = %d AND companySymbol = INN".formatted(consumerId), companySymbolsImdg);
|
||||||
|
String companySymbolValueCLRC = getCompanySymbolValue("companyId = %d AND companySymbol = CLRC".formatted(consumerId), companySymbolsImdg);
|
||||||
|
String companySymbolValueRGRC = getCompanySymbolValue("companyId = %d AND companySymbol = RGRC".formatted(consumerId), companySymbolsImdg);
|
||||||
|
|
||||||
|
String accountSql = "companyId = %d AND accountType = INFO".formatted(consumerId);
|
||||||
|
Account account = null;
|
||||||
|
Collection<Account> accounts = accountImdg.getCollectionObjectsBySQL(accountSql);
|
||||||
|
if (profileDocuments.size() >= 1) {
|
||||||
|
account = accounts.iterator().next();
|
||||||
|
} else {
|
||||||
|
log.warn("Account with sql {} not found", accountSql);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||||
|
|
||||||
|
valuesForTemplate.put("${issDate}", profileDocument.getIssueDate().format(dateFormatter));
|
||||||
|
valuesForTemplate.put("${date}", LocalDate.now().format(dateFormatterYYMMDD));
|
||||||
|
valuesForTemplate.put("${profileDocumentNumber}", getNotNull(profileDocument.getNumber()));
|
||||||
|
valuesForTemplate.put("${companyFullName}", getNotNull(company.getFullName()));
|
||||||
|
valuesForTemplate.put("${companyShortName}", getNotNull(company.getShortName()));
|
||||||
|
valuesForTemplate.put("${companySymbolsValueINN}", companySymbolsValueINN);
|
||||||
|
valuesForTemplate.put("${companySymbolValueCLRC}", companySymbolValueCLRC);
|
||||||
|
valuesForTemplate.put("${companySymbolValueRGRC}", companySymbolValueRGRC);
|
||||||
|
valuesForTemplate.put("${accountINFO}", getNotNull(account.getAccount()));
|
||||||
|
|
||||||
|
String outputFilename = "NCMP.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||||
|
|
||||||
|
File outputFile = createOutFile(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/NCMP_TEMPLATE.docx";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,96 @@
|
||||||
|
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.registry.TradingClearingRegistry;
|
||||||
|
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.time.LocalDateTime;
|
||||||
|
import java.time.ZoneId;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class NTCRNotificationBuilder extends NotificationBuilder {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final Imdg<Company> companyImdg;
|
||||||
|
private final Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||||
|
private final Imdg<CompanySymbols> companySymbolsImdg;
|
||||||
|
|
||||||
|
public NTCRNotificationBuilder(ImdgProvider imdgProvider) {
|
||||||
|
super(null);
|
||||||
|
imdgProvider.waitAvailable();
|
||||||
|
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||||
|
this.companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public File buildNotification(Long consumerId) {
|
||||||
|
TradingClearingRegistry tradingClearingRegistry = tradingClearingRegistryImdg.getSingleObjectByID(consumerId);
|
||||||
|
if (tradingClearingRegistry == null) {
|
||||||
|
log.error("TradingClearingRegistry for Id={} is null", consumerId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Instant createdAt = tradingClearingRegistry.getCreated();
|
||||||
|
if (createdAt == null) {
|
||||||
|
log.error("TradingClearingRegistry.created for id={} is null", consumerId);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Company company = companyImdg.getSingleObjectByID(tradingClearingRegistry.getCompanyId());
|
||||||
|
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 companySymbolValueCLRC = getCompanySymbolValue("companyId = %d AND companySymbol = CLRC".formatted(consumerId), companySymbolsImdg);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, String> valuesForTemplate = new HashMap<>();
|
||||||
|
|
||||||
|
valuesForTemplate.put("${createdAt}", dateFormatter.format(createdAt.atZone(ZoneId.systemDefault()).toLocalDate()));
|
||||||
|
valuesForTemplate.put("${date}", LocalDate.now().format(dateFormatterYYMMDD));
|
||||||
|
valuesForTemplate.put("${TCRCode}", getNotNull(tradingClearingRegistry.getCode()));
|
||||||
|
valuesForTemplate.put("${companyFullName}", getNotNull(company.getFullName()));
|
||||||
|
valuesForTemplate.put("${companyShortName}", getNotNull(company.getShortName()));
|
||||||
|
valuesForTemplate.put("${companySymbolValueCLRC}", companySymbolValueCLRC);
|
||||||
|
valuesForTemplate.put("${TCRPurpose}", getNotNull(tradingClearingRegistry.getTradingClearingRegistryPurpose()));
|
||||||
|
valuesForTemplate.put("${TCRMoneyAccountId}", getNotNull(tradingClearingRegistry.getMoneyAccountId()));
|
||||||
|
valuesForTemplate.put("${TCRDepoAccountId}", getNotNull(tradingClearingRegistry.getDepoAccountId()));
|
||||||
|
|
||||||
|
String outputFilename = "NTCR.%s.%s.docx".formatted(companyClearingCode, filenameDateTimeFormatter.format(LocalDateTime.now()));
|
||||||
|
outputFilename = normalizeFilenameForOS(outputFilename);
|
||||||
|
|
||||||
|
File outputFile = createOutFile(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/NTCR_TEMPLATE.docx";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -2,21 +2,26 @@ package ru.spcex.clearing.reports.notifications;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
import ru.spcex.clearing.reports.exceptions.ConfigException;
|
import ru.spcex.clearing.reports.exceptions.ConfigException;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.time.format.TextStyle;
|
import java.time.format.TextStyle;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public abstract class NotificationBuilder {
|
public abstract class NotificationBuilder {
|
||||||
protected final Logger log = LoggerFactory.getLogger(getClass());
|
protected final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
protected final DateTimeFormatter filenameDateTimeFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy'T'HH:mm:ss");
|
protected final DateTimeFormatter filenameDateTimeFormatter = DateTimeFormatter.ofPattern("YYMMDDHHmmssSSS");
|
||||||
protected final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
protected final DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("dd.MM.yyyy");
|
||||||
|
protected final DateTimeFormatter dateFormatterYYMMDD = DateTimeFormatter.ofPattern("YYMMDD");
|
||||||
protected final DOCXService docxService;
|
protected final DOCXService docxService;
|
||||||
|
protected File outFolder;
|
||||||
|
|
||||||
protected NotificationBuilder(String keyPattern) {
|
protected NotificationBuilder(String keyPattern) {
|
||||||
this.docxService = new DOCXService();
|
this.docxService = new DOCXService();
|
||||||
|
|
@ -26,6 +31,12 @@ public abstract class NotificationBuilder {
|
||||||
|
|
||||||
abstract public File buildNotification(Long consumerId);
|
abstract public File buildNotification(Long consumerId);
|
||||||
|
|
||||||
|
public File buildNotification(Long consumerId, File outFolder) {
|
||||||
|
assert outFolder != null && outFolder.isDirectory();
|
||||||
|
setOutFolder(outFolder);
|
||||||
|
return buildNotification(consumerId);
|
||||||
|
}
|
||||||
|
|
||||||
protected void fillHeaderValues(Map<String, String> valuesMap, Long notificationId) {
|
protected void fillHeaderValues(Map<String, String> valuesMap, Long notificationId) {
|
||||||
LocalDate notificationDate = LocalDate.now();
|
LocalDate notificationDate = LocalDate.now();
|
||||||
int day = notificationDate.getDayOfMonth();
|
int day = notificationDate.getDayOfMonth();
|
||||||
|
|
@ -48,7 +59,7 @@ public abstract class NotificationBuilder {
|
||||||
resource = getClass().getClassLoader().getResource(templateResourceName);
|
resource = getClass().getClassLoader().getResource(templateResourceName);
|
||||||
if (resource == null) throw new Exception();
|
if (resource == null) throw new Exception();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new ConfigException("Can't read template resource " + templateResourceName +" (URL \""+resource+"\")", e);
|
throw new ConfigException("Can't read template resource " + templateResourceName + " (URL \"" + resource + "\")", e);
|
||||||
}
|
}
|
||||||
log.info("Use resource: {}", resource);
|
log.info("Use resource: {}", resource);
|
||||||
return resource;
|
return resource;
|
||||||
|
|
@ -60,5 +71,31 @@ public abstract class NotificationBuilder {
|
||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected String getCompanySymbolValue(String companySymbolsSql, Imdg<CompanySymbols> companySymbolsImdg) {
|
||||||
|
CompanySymbols companySymbols;
|
||||||
|
Collection<CompanySymbols> companySymbolsCollection = companySymbolsImdg.getCollectionObjectsBySQL(companySymbolsSql);
|
||||||
|
if (companySymbolsCollection.size() >= 1) {
|
||||||
|
companySymbols = companySymbolsCollection.iterator().next();
|
||||||
|
} else {
|
||||||
|
// log.warn("CompanySymbols with sql {} not found", companySymbolsSql);
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return companySymbols.getCompanySymbolValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected String getNotNull(Object value) {
|
||||||
|
if (value == null) return "";
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
abstract protected String getTemplateResourceName();
|
abstract protected String getTemplateResourceName();
|
||||||
|
|
||||||
|
public File createOutFile(String outputFilename) {
|
||||||
|
if (outFolder != null && outFolder.isDirectory()) return new File(outFolder, outputFilename);
|
||||||
|
return new File(outputFilename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutFolder(File outFolder) {
|
||||||
|
this.outFolder = outFolder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,94 @@
|
||||||
|
package ru.spcex.clearing.reports.services;
|
||||||
|
|
||||||
|
import org.apache.kafka.clients.consumer.Consumer;
|
||||||
|
import org.apache.kafka.clients.producer.Producer;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.BaseRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.Consts;
|
||||||
|
import ru.spcex.clearing.platform.messaging.domain.cud.reports.NotificationRequest;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.QueueConsumer;
|
||||||
|
import ru.spcex.clearing.platform.messaging.service.RequestInfoUpdate;
|
||||||
|
import ru.spcex.clearing.reports.config.element.ReportsServiceSettings;
|
||||||
|
import ru.spcex.clearing.reports.notifications.NCMPNotificationBuilder;
|
||||||
|
import ru.spcex.clearing.util.security.UserRoleVerification;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class NotificationService extends QueueConsumer implements InitializingBean {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(getClass());
|
||||||
|
private final UserRoleVerification userRoleVerification;
|
||||||
|
private final NCMPNotificationBuilder ncmpNotificationBuilder;
|
||||||
|
|
||||||
|
private final File outFolder;
|
||||||
|
|
||||||
|
public NotificationService(Consumer<String, Object> kafkaQueue,
|
||||||
|
Producer<String, Object> kafkaResponseQueue,
|
||||||
|
UserRoleVerification userRoleVerification,
|
||||||
|
NCMPNotificationBuilder ncmpNotificationBuilder,
|
||||||
|
ReportsServiceSettings reportsServiceSettings) {
|
||||||
|
super(kafkaQueue, kafkaResponseQueue);
|
||||||
|
this.userRoleVerification = userRoleVerification;
|
||||||
|
this.ncmpNotificationBuilder = ncmpNotificationBuilder;
|
||||||
|
this.outFolder = new File(reportsServiceSettings.getReportModuleOut());
|
||||||
|
assert outFolder.isDirectory();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterPropertiesSet() throws Exception {
|
||||||
|
callback(NotificationRequest.class)
|
||||||
|
.setFunction(this::createNotificationNCMP)
|
||||||
|
.forDestination(Consts.CREATE_NOTIFICATION_NCMP, callbacks::put);
|
||||||
|
callback(NotificationRequest.class)
|
||||||
|
.setFunction(this::createNotificationNTCR)
|
||||||
|
.forDestination(Consts.CREATE_NOTIFICATION_NTCR, callbacks::put);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestInfoUpdate createNotificationNCMP(BaseRequest<NotificationRequest> userRequest) {
|
||||||
|
log.debug("NotificationRequest NCMP received");
|
||||||
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||||
|
if (requestInfoUpdate != null) return null;
|
||||||
|
|
||||||
|
NotificationRequest req = userRequest.getRequestPayload();
|
||||||
|
|
||||||
|
logUnknownProperties(userRequest);
|
||||||
|
|
||||||
|
File outFile = ncmpNotificationBuilder.buildNotification(req.getConsumerId(), outFolder);
|
||||||
|
if (outFile == null) {
|
||||||
|
log.error("Create notification NCMP for id={} failed, see log", req.getConsumerId());
|
||||||
|
} else {
|
||||||
|
log.debug("Notification NCMP for id={} successfully created. Output files: {}", req.getConsumerId(), outFile);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RequestInfoUpdate createNotificationNTCR(BaseRequest<NotificationRequest> userRequest) {
|
||||||
|
log.debug("NotificationRequest NTCR received");
|
||||||
|
RequestInfoUpdate requestInfoUpdate = userRoleVerification.validateRoleAndGetResult(userRequest);
|
||||||
|
if (requestInfoUpdate != null) return null;
|
||||||
|
|
||||||
|
NotificationRequest req = userRequest.getRequestPayload();
|
||||||
|
|
||||||
|
logUnknownProperties(userRequest);
|
||||||
|
|
||||||
|
File outFile = ncmpNotificationBuilder.buildNotification(req.getConsumerId(), outFolder);
|
||||||
|
if (outFile == null) {
|
||||||
|
log.error("Create notification NTCR for id={} failed, see log", req.getConsumerId());
|
||||||
|
} else {
|
||||||
|
log.debug("Notification NTCR for id={} successfully created. Output files: {}", req.getConsumerId(), outFile);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logUnknownProperties(BaseRequest<?> request) {
|
||||||
|
Map<String, Object> unknownProperties = request.getUnknownProperties();
|
||||||
|
for (Map.Entry<String, Object> unknownProperty : unknownProperties.entrySet()) {
|
||||||
|
log.warn("Unknown property in request {} = {}", unknownProperty.getKey(), unknownProperty.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Binary file not shown.
Binary file not shown.
|
|
@ -0,0 +1,100 @@
|
||||||
|
package ru.spcex.clearing.reports.notifications;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
import ru.clearing.classes.statics.data.account.Account;
|
||||||
|
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.clearing.test.config.ImdgTestConfig;
|
||||||
|
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.test.config.ImdgTestConfig.currentID;
|
||||||
|
import static ru.spcex.clearing.test.config.ImdgTestConfig.waitAvailableImdgProviderAndAddAdminWithDefaultId;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
ImdgTestConfig.class,
|
||||||
|
KafkaTestConfig.class})
|
||||||
|
class NCMPNotificationBuilderTest {
|
||||||
|
|
||||||
|
private Long consumerId = 888L;
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<ProfileDocument> profileDocumentImdg;
|
||||||
|
private Imdg<Account> accountImdg;
|
||||||
|
private Imdg<CompanySymbols> companySymbolsImdg;
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
protected ImdgProvider imdgProvider;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init() {
|
||||||
|
waitAvailableImdgProviderAndAddAdminWithDefaultId();
|
||||||
|
companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
profileDocumentImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_ProfileDocument, ProfileDocument.class);
|
||||||
|
accountImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Account, Account.class);
|
||||||
|
companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||||
|
|
||||||
|
Company company = new Company();
|
||||||
|
company.setId(consumerId);
|
||||||
|
company.setClearingCode("326546");
|
||||||
|
company.setShortName("ShortName");
|
||||||
|
company.setFullName("FullName");
|
||||||
|
companyImdg.insert(company);
|
||||||
|
|
||||||
|
ProfileDocument profileDocument = new ProfileDocument();
|
||||||
|
profileDocument.setCompanyId(consumerId);
|
||||||
|
profileDocument.setIssueDate(LocalDate.now());
|
||||||
|
profileDocument.setNumber("65446565");
|
||||||
|
profileDocument.setDocumentType("CLRN");
|
||||||
|
profileDocumentImdg.insert(profileDocument);
|
||||||
|
|
||||||
|
CompanySymbols companySymbols = new CompanySymbols();
|
||||||
|
companySymbols.setId(currentID.getAndIncrement());
|
||||||
|
companySymbols.setCompanyId(consumerId);
|
||||||
|
companySymbols.setCompanySymbol("INN");
|
||||||
|
companySymbols.setCompanySymbolValue("INN 65324654646446");
|
||||||
|
companySymbolsImdg.insert(companySymbols);
|
||||||
|
|
||||||
|
companySymbols.setId(currentID.getAndIncrement());
|
||||||
|
companySymbols.setCompanySymbol("CLRC");
|
||||||
|
companySymbols.setCompanySymbolValue("CLRC test");
|
||||||
|
companySymbolsImdg.insert(companySymbols);
|
||||||
|
|
||||||
|
companySymbols.setId(currentID.getAndIncrement());
|
||||||
|
companySymbols.setCompanySymbol("RGRC");
|
||||||
|
companySymbols.setCompanySymbolValue("RGRC test");
|
||||||
|
companySymbolsImdg.insert(companySymbols);
|
||||||
|
|
||||||
|
// clearAllInImdg(accountImdg);
|
||||||
|
Account account = new Account();
|
||||||
|
account.setId(consumerId);
|
||||||
|
account.setCompanyId(consumerId);
|
||||||
|
account.setAccountType("INFO");
|
||||||
|
account.setAccount("3548903459684");
|
||||||
|
accountImdg.insert(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test//тест заполнения шаблона
|
||||||
|
void buildNotification() {
|
||||||
|
NCMPNotificationBuilder builder = new NCMPNotificationBuilder(imdgProvider);
|
||||||
|
File outputFile = builder.buildNotification(consumerId);
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(outputFile.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package ru.spcex.clearing.reports.notifications;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
import ru.clearing.classes.statics.data.company.Company;
|
||||||
|
import ru.clearing.classes.statics.data.company.CompanySymbols;
|
||||||
|
import ru.clearing.classes.statics.data.registry.TradingClearingRegistry;
|
||||||
|
import ru.spcex.clearing.imdg.IMDGDistributedNames;
|
||||||
|
import ru.spcex.clearing.test.config.ImdgTestConfig;
|
||||||
|
import ru.spcex.clearing.test.config.KafkaTestConfig;
|
||||||
|
import ru.spcex.platform.imdg.api.Imdg;
|
||||||
|
import ru.spcex.platform.imdg.api.ImdgProvider;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import static ru.spcex.clearing.test.config.ImdgTestConfig.currentID;
|
||||||
|
import static ru.spcex.clearing.test.config.ImdgTestConfig.waitAvailableImdgProviderAndAddAdminWithDefaultId;
|
||||||
|
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
@ContextConfiguration(classes = {
|
||||||
|
ImdgTestConfig.class,
|
||||||
|
KafkaTestConfig.class})
|
||||||
|
class NTCRNotificationBuilderTest {
|
||||||
|
|
||||||
|
private Long consumerId = 222L;
|
||||||
|
private Imdg<Company> companyImdg;
|
||||||
|
private Imdg<TradingClearingRegistry> tradingClearingRegistryImdg;
|
||||||
|
private Imdg<CompanySymbols> companySymbolsImdg;
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("hazelcastServiceTest")
|
||||||
|
protected ImdgProvider imdgProvider;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init() {
|
||||||
|
waitAvailableImdgProviderAndAddAdminWithDefaultId();
|
||||||
|
this.companyImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_Company, Company.class);
|
||||||
|
this.tradingClearingRegistryImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_TradingClearingRegistry, TradingClearingRegistry.class);
|
||||||
|
this.companySymbolsImdg = imdgProvider.getImdg(IMDGDistributedNames.Map_CompanySymbols, CompanySymbols.class);
|
||||||
|
|
||||||
|
Company company = new Company();
|
||||||
|
company.setId(consumerId);
|
||||||
|
company.setClearingCode("326546");
|
||||||
|
company.setShortName("ShortName test");
|
||||||
|
company.setFullName("FullName test");
|
||||||
|
companyImdg.insert(company);
|
||||||
|
|
||||||
|
|
||||||
|
CompanySymbols companySymbols = new CompanySymbols();
|
||||||
|
companySymbols.setId(currentID.getAndIncrement());
|
||||||
|
companySymbols.setCompanyId(consumerId);
|
||||||
|
companySymbols.setCompanySymbol("CLRC");
|
||||||
|
companySymbols.setCompanySymbolValue("Symbol test");
|
||||||
|
companySymbolsImdg.insert(companySymbols);
|
||||||
|
|
||||||
|
|
||||||
|
TradingClearingRegistry tradingClearingRegistry = new TradingClearingRegistry();
|
||||||
|
tradingClearingRegistry.setId(consumerId);
|
||||||
|
tradingClearingRegistry.setCreated(Instant.now());
|
||||||
|
tradingClearingRegistry.setCompanyId(consumerId);
|
||||||
|
tradingClearingRegistry.setCode("test code");
|
||||||
|
tradingClearingRegistry.setTradingClearingRegistryPurpose("test Purpose");
|
||||||
|
tradingClearingRegistry.setMoneyAccountId(consumerId);
|
||||||
|
tradingClearingRegistry.setDepoAccountId(consumerId);
|
||||||
|
tradingClearingRegistryImdg.insert(tradingClearingRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
// @Test//тест заполнения шаблона
|
||||||
|
void buildNotification() {
|
||||||
|
NTCRNotificationBuilder builder = new NTCRNotificationBuilder(imdgProvider);
|
||||||
|
File outputFile = builder.buildNotification(consumerId);
|
||||||
|
try {
|
||||||
|
Files.deleteIfExists(outputFile.toPath());
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -4,7 +4,9 @@ import org.junit.jupiter.api.Test;
|
||||||
import ru.spcex.clearing.reports.notifications.DOCXService;
|
import ru.spcex.clearing.reports.notifications.DOCXService;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
class DOCXServiceTest {
|
class DOCXServiceTest {
|
||||||
|
|
@ -30,4 +32,61 @@ class DOCXServiceTest {
|
||||||
file.delete();
|
file.delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Test//для отладки алгоритма объединения ключей
|
||||||
|
void normalize() {
|
||||||
|
List<String> data = Arrays.asList(new String[]{"test ", "someText${", "some", "Key}/${ano", "ther", "Key}someText", "test"});
|
||||||
|
|
||||||
|
String concatText = "";
|
||||||
|
boolean needConcat = false;
|
||||||
|
int first = 0;
|
||||||
|
for (String run : data) {
|
||||||
|
boolean finded = false;
|
||||||
|
try {
|
||||||
|
|
||||||
|
String currText = run;
|
||||||
|
if (currText == null) break;
|
||||||
|
if (needConcat) {
|
||||||
|
concatText = concatText + currText;
|
||||||
|
if (currText.contains("}")) {
|
||||||
|
String[] strAr = new String[3];
|
||||||
|
int start = concatText.indexOf("${");
|
||||||
|
int end = concatText.indexOf("}") + 1;
|
||||||
|
strAr[0] = concatText.substring(0, start);
|
||||||
|
strAr[1] = concatText.substring(start, end);
|
||||||
|
strAr[2] = concatText.substring(end, concatText.length());
|
||||||
|
System.out.println(strAr);
|
||||||
|
|
||||||
|
int last = data.indexOf(currText);
|
||||||
|
for (int i = first; i <= last; i++){
|
||||||
|
if (i - first < 3){
|
||||||
|
data.set(i, strAr[i - first]);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
data.set(i, "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
currText = strAr[2];
|
||||||
|
if (currText.contains("${")){
|
||||||
|
needConcat = true;
|
||||||
|
concatText = currText;
|
||||||
|
first = data.indexOf(currText);
|
||||||
|
} else {
|
||||||
|
needConcat = false;
|
||||||
|
concatText = "";
|
||||||
|
first = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (currText.contains("${") && !finded) {
|
||||||
|
needConcat = true;
|
||||||
|
concatText = currText;
|
||||||
|
first = data.indexOf(currText);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IndexOutOfBoundsException ignored) {
|
||||||
|
// can't get all max text position for XWPFRun
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(data.toString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -77,6 +77,8 @@ public interface Consts {
|
||||||
String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new";
|
String DESTINATION_BANK_ACCOUNT_NEW = "bank-account-new";
|
||||||
|
|
||||||
String CREATE_REPORT = "create-report";
|
String CREATE_REPORT = "create-report";
|
||||||
|
String CREATE_NOTIFICATION_NTCR = "create-notification-ntcr";
|
||||||
|
String CREATE_NOTIFICATION_NCMP = "create-notification-ncmp";
|
||||||
String CREATE_REPORT_FOR_SESSION_ID = "create-report-for-session-id";
|
String CREATE_REPORT_FOR_SESSION_ID = "create-report-for-session-id";
|
||||||
String CREATE_REPORT_FOR_SESSION_ID_LIST = "create-report-for-session-id-list";
|
String CREATE_REPORT_FOR_SESSION_ID_LIST = "create-report-for-session-id-list";
|
||||||
String CREATE_REPORT_FOR_PERIOD = "create-report-for-period";
|
String CREATE_REPORT_FOR_PERIOD = "create-report-for-period";
|
||||||
|
|
|
||||||
|
|
@ -10,14 +10,14 @@ public class NotificationRequest {
|
||||||
* Идентификатор участника клиринга
|
* Идентификатор участника клиринга
|
||||||
*/
|
*/
|
||||||
@JsonProperty
|
@JsonProperty
|
||||||
protected String consumerId;
|
protected Long consumerId;
|
||||||
|
|
||||||
|
|
||||||
public String getConsumerId() {
|
public Long getConsumerId() {
|
||||||
return consumerId;
|
return consumerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setConsumerId(String consumerId) {
|
public void setConsumerId(Long consumerId) {
|
||||||
this.consumerId = consumerId;
|
this.consumerId = consumerId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue