在线监测功能
1.动态生成预告警单、下载预告警单
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
package com.njcn.harmonic.utils;
|
||||
|
||||
import ch.qos.logback.core.rolling.helper.FileStoreUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.apache.poi.xwpf.usermodel.*;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -51,6 +54,42 @@ public class WordUtil2 {
|
||||
}
|
||||
}
|
||||
|
||||
public InputStream getReportFile(String path, Map<String, Object> params, List<List<String[]>> tableList)
|
||||
throws Exception {
|
||||
path = ClearPathUtil.cleanString(path);
|
||||
InputStream inStream = null,in = null;
|
||||
CustomXWPFDocument doc = null;
|
||||
//读取报告模板
|
||||
try {
|
||||
inStream = new ClassPathResource(path).getInputStream();;
|
||||
doc = new CustomXWPFDocument(inStream);
|
||||
this.replaceInTable(doc,params,tableList);
|
||||
this.replaceInPara(doc, params);
|
||||
} catch (IOException e) {
|
||||
logger.error("获取报告模板异常,原因为:" + e);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
inStream.close();
|
||||
}
|
||||
}
|
||||
try {
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.write(out);
|
||||
byte[] docByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(docByteAry);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("输出稳态报告异常,原因为:" + e);
|
||||
} finally {
|
||||
if (doc != null) {
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 替换段落里面的变量
|
||||
*
|
||||
@@ -212,14 +251,16 @@ public class WordUtil2 {
|
||||
private static void insertTable(XWPFTable table, List<String[]> tableList) {
|
||||
//删除占位符行数
|
||||
table.removeRow(1);
|
||||
// 创建行,根据需要插入的数据添加新行,不处理表头
|
||||
for (int i = 0; i < tableList.size(); i++) {
|
||||
XWPFTableRow row = table.createRow();
|
||||
List<XWPFTableCell> cells = row.getTableCells();
|
||||
for (int j = 0; j < cells.size(); j++) {
|
||||
XWPFTableCell cell = cells.get(j);
|
||||
String s = tableList.get(i)[j];
|
||||
cell.setText(s);
|
||||
if (CollUtil.isNotEmpty(tableList)) {
|
||||
// 创建行,根据需要插入的数据添加新行,不处理表头
|
||||
for (int i = 0; i < tableList.size(); i++) {
|
||||
XWPFTableRow row = table.createRow();
|
||||
List<XWPFTableCell> cells = row.getTableCells();
|
||||
for (int j = 0; j < cells.size(); j++) {
|
||||
XWPFTableCell cell = cells.get(j);
|
||||
String s = tableList.get(i)[j];
|
||||
cell.setText(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,10 +288,8 @@ public class WordUtil2 {
|
||||
for (XWPFTableRow row : rows) {
|
||||
cells = row.getTableCells();
|
||||
for (XWPFTableCell cell : cells) {
|
||||
paras = cell.getParagraphs();
|
||||
for (XWPFParagraph para : paras) {
|
||||
this.replaceInPara(para, params, doc);
|
||||
}
|
||||
List<XWPFParagraph> paragraphListTable = cell.getParagraphs();
|
||||
processParagraphs(paragraphListTable, params, doc);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user