insert values in docx (raw)
This commit is contained in:
parent
a396d54c7b
commit
eed33ce35b
5 changed files with 74 additions and 0 deletions
|
|
@ -15,6 +15,11 @@ import java.util.stream.Collectors;
|
|||
/**
|
||||
* Сервис для работы с DOCX файлами
|
||||
* Читает шаблон .docx и во всех текстовых элементах меняет переданные ключи на соответствующие им значения
|
||||
* Пример ключа по умолчанию: ${ключ}
|
||||
*
|
||||
* При использовании нового шаблона, необходимо отредактировать docx документ так, чтобы ключ содержался в одном
|
||||
* элементе. Для этого нужно вырезать ключ и в это же место вставить его как текст, без форматирования. Если нужно,
|
||||
* идентификатору потом можно установить стиль, который будет применён к вставляемой строке.
|
||||
*/
|
||||
public class DOCXService {
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,12 @@
|
|||
package ru.spcex.clearing.reports.services.builders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import ru.spcex.clearing.reports.reports.AbstractReport;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class DOCXReportBuilder<R extends AbstractReport> extends FileReportBuilder<R> {
|
||||
protected DOCXReportBuilder(Class<R> reportClass, Logger log, String filename) throws IOException {
|
||||
super(reportClass, log, filename);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package ru.spcex.clearing.reports.services.builders;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import ru.spcex.clearing.reports.reports.AbstractReport;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class FileReportBuilder<R extends AbstractReport> {
|
||||
protected final Class<R> reportClass;
|
||||
protected final Logger log;
|
||||
protected final String filename;
|
||||
protected final File file;
|
||||
|
||||
protected FileReportBuilder(Class<R> reportClass, Logger log, String filename) throws IOException {
|
||||
this.reportClass = reportClass;
|
||||
this.log = log;
|
||||
this.filename = filename;
|
||||
this.file = new File(filename);
|
||||
if (file.exists()) {
|
||||
if (file.isFile()) {
|
||||
log.warn("Файл {} существует и будет перезаписан", filename);
|
||||
boolean deleteOk = file.delete();
|
||||
if (!deleteOk) throw new IOException("Не удалось удалить файл " + filename);
|
||||
} else throw new IOException(filename + " существует, но не является файлом");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
package ru.spcex.clearing.reports.services.builders;
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.io.naming.NoNameCoder;
|
||||
import com.thoughtworks.xstream.io.xml.XppDriver;
|
||||
import org.slf4j.Logger;
|
||||
import ru.spcex.clearing.reports.reports.AbstractReport;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public abstract class XMLReportBuilder<R extends AbstractReport> extends FileReportBuilder<R> {
|
||||
protected final XStream xStream;
|
||||
|
||||
protected XMLReportBuilder(Class<R> reportClass, Logger log, String filename) throws IOException {
|
||||
super(reportClass, log, filename);
|
||||
this.xStream = new XStream(new XppDriver(new NoNameCoder()));
|
||||
xStream.processAnnotations(reportClass);
|
||||
}
|
||||
}
|
||||
|
|
@ -135,6 +135,15 @@ public class ImdgHazelcast<T extends SpcexObjectBase> implements Imdg<T> {
|
|||
return searchResult;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> getCollectionObjectsBySQL(String paramString) {
|
||||
SqlPredicate sqlPredicate = new SqlPredicate(paramString);
|
||||
Set<Map.Entry<Long, T>> found = map.entrySet(sqlPredicate);
|
||||
List<T> result = new ArrayList<>(found.size());
|
||||
for (Map.Entry<Long, T> entry : found) result.add(entry.getValue());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long nextIDSequenceFor() {
|
||||
return idGenerator.newId();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue