1.技术监督试运行评估-试运行结束后生成试运行报告
2.技术监督计划管理,权限调整为负责地市进行信息修改 3.调整常态化干扰源用户信息更新逻辑 4.调整谐波报告数据请求格式
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
package com.njcn.harmonic.utils;
|
||||
|
||||
import ch.qos.logback.core.rolling.helper.FileStoreUtil;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import com.njcn.oss.constant.OssPath;
|
||||
import com.njcn.oss.utils.FileStorageUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
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 org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.ServletOutputStream;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
@@ -16,10 +17,14 @@ import java.util.Map.Entry;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@RequiredArgsConstructor
|
||||
public class WordUtil2 {
|
||||
// 日志记录
|
||||
private static final Logger logger = LoggerFactory.getLogger(WordUtil2.class);
|
||||
|
||||
|
||||
private final FileStorageUtil fileStorageUtil;
|
||||
|
||||
|
||||
public void getWord(String path, Map<String, Object> params, String fileName, HttpServletResponse response)
|
||||
throws Exception {
|
||||
@@ -33,7 +38,7 @@ public class WordUtil2 {
|
||||
this.replaceInTable(doc, params); // 替换表格里面的变量
|
||||
this.replaceInPara(doc, params); // 替换文本里面的变量
|
||||
} catch (IOException e) {
|
||||
logger.error("获取报告模板异常,原因为:" + e);
|
||||
getError("获取报告模板异常,原因为:" + e);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
inStream.close();
|
||||
@@ -46,7 +51,7 @@ public class WordUtil2 {
|
||||
doc.write(outputStream);
|
||||
outputStream.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("输出稳态报告异常,原因为:" + e);
|
||||
getError("输出稳态报告异常,原因为:" + e);
|
||||
} finally {
|
||||
if (doc != null) {
|
||||
doc.close();
|
||||
@@ -66,7 +71,7 @@ public class WordUtil2 {
|
||||
this.replaceInTable(doc,params,tableList);
|
||||
this.replaceInPara(doc, params);
|
||||
} catch (IOException e) {
|
||||
logger.error("获取报告模板异常,原因为:" + e);
|
||||
getError("获取报告模板异常,原因为:" + e);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
inStream.close();
|
||||
@@ -80,7 +85,7 @@ public class WordUtil2 {
|
||||
in = new ByteArrayInputStream(docByteAry);
|
||||
out.close();
|
||||
} catch (Exception e) {
|
||||
logger.error("输出稳态报告异常,原因为:" + e);
|
||||
getError("输出稳态报告异常,原因为:" + e);
|
||||
} finally {
|
||||
if (doc != null) {
|
||||
doc.close();
|
||||
@@ -90,6 +95,43 @@ public class WordUtil2 {
|
||||
}
|
||||
|
||||
|
||||
|
||||
public String getReportFileUrl(String path,String fileName, Map<String, Object> params)
|
||||
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); // 替换表格里面的变量
|
||||
this.replaceInPara(doc, params); // 替换文本里面的变量
|
||||
|
||||
//临时缓冲区
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
doc.write(out);
|
||||
byte[] docByteAry = out.toByteArray();
|
||||
in = new ByteArrayInputStream(docByteAry);
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
getError("获取报告模板异常,原因为:" + e);
|
||||
} finally {
|
||||
if (null != inStream) {
|
||||
inStream.close();
|
||||
}
|
||||
if (doc != null) {
|
||||
doc.close();
|
||||
}
|
||||
}
|
||||
//上传文件服务器
|
||||
return fileStorageUtil.uploadStreamSpecifyName(in, OssPath.ONLINE_REPORT, fileName);
|
||||
}
|
||||
|
||||
|
||||
private static void getError(String e) {
|
||||
log.error(e);
|
||||
}
|
||||
/**
|
||||
* 替换段落里面的变量
|
||||
*
|
||||
@@ -155,7 +197,7 @@ public class WordUtil2 {
|
||||
s,paragraph);
|
||||
bflag = "break";
|
||||
} catch (Exception e) {
|
||||
logger.error("文本替换发生异常,异常是" + e.getMessage());
|
||||
getError("文本替换发生异常,异常是" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -234,7 +276,7 @@ public class WordUtil2 {
|
||||
para.createRun().setText(str, 0);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
logger.error("文件替换发生异常,异常是" + e.getMessage());
|
||||
getError("文件替换发生异常,异常是" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -336,33 +378,4 @@ public class WordUtil2 {
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭输入流
|
||||
*
|
||||
* @param is
|
||||
*/
|
||||
private void close(InputStream is) {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("关闭输入流发生异常,异常是" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭输出流
|
||||
*
|
||||
* @param os
|
||||
*/
|
||||
private void close(OutputStream os) {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (IOException e) {
|
||||
logger.error("关闭输出流发生异常,异常是" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user