|
|
|
@ -55,7 +55,28 @@ public class BaseUtil {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 文件导出 |
|
|
|
|
* pdf文件导出 |
|
|
|
|
* @param templateFile 模板文件路径 |
|
|
|
|
* @param params 数据参数 |
|
|
|
|
* @param wordPath 文件生成路径 |
|
|
|
|
* @param pdfPath pdf生成路径 |
|
|
|
|
* @param response 响应类 |
|
|
|
|
*/ |
|
|
|
|
public static void exportDocument(String templateFile, Map<String, Object> params, String wordPath, String pdfPath, HttpServletResponse response) { |
|
|
|
|
try { |
|
|
|
|
List<XWPFDocument> res = new ArrayList<>(); |
|
|
|
|
XWPFDocument document = BaseUtil.fillDocument(templateFile, params); |
|
|
|
|
res.add(document); |
|
|
|
|
BaseUtil.exportWord(res, wordPath); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
log.error("文件导出异常: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
AsposeUtil.wordToPdf(wordPath, pdfPath); |
|
|
|
|
BaseUtil.readPdf(response,pdfPath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* word文件导出 |
|
|
|
|
* @param documents doc文件 |
|
|
|
|
* @param savePath 存储路径 |
|
|
|
|
*/ |
|
|
|
@ -67,22 +88,22 @@ public class BaseUtil {
|
|
|
|
|
document.write(out); |
|
|
|
|
} |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("文件导出异常: {}", e.getMessage()); |
|
|
|
|
log.error("word文件导出异常: {}", e.getMessage()); |
|
|
|
|
} finally { |
|
|
|
|
if (out != null) { |
|
|
|
|
try { |
|
|
|
|
out.close(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
log.error("文件导出-输出流关闭异常: {}", e.getMessage()); |
|
|
|
|
log.error("word文件导出-输出流关闭异常: {}", e.getMessage()); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 数据写入模板文件 |
|
|
|
|
* @param templatePath 模板路径 |
|
|
|
|
* @param params 数据 |
|
|
|
|
* 数据写入 |
|
|
|
|
* @param templatePath 模板文件路径 |
|
|
|
|
* @param params 数据参数 |
|
|
|
|
*/ |
|
|
|
|
public static XWPFDocument fillDocument(String templatePath, Map<String, Object> params) { |
|
|
|
|
XWPFDocument xwpfDocument = null; |
|
|
|
@ -113,7 +134,7 @@ public class BaseUtil {
|
|
|
|
|
"inline; filename= " + URLEncoder.encode(file.getName(), "UTF-8")); |
|
|
|
|
outputStream.flush(); |
|
|
|
|
} catch (IOException e) { |
|
|
|
|
e.printStackTrace(); |
|
|
|
|
log.error("本地pdf文件读取异常: {}", e.getMessage()); |
|
|
|
|
} finally { |
|
|
|
|
try { |
|
|
|
|
if (fileInputStream != null) { |
|
|
|
@ -128,6 +149,11 @@ public class BaseUtil {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 对象转map |
|
|
|
|
* @param obj 对象类 |
|
|
|
|
* @return map参数 |
|
|
|
|
*/ |
|
|
|
|
public static Map<String, Object> obj2Map(Object obj) { |
|
|
|
|
if (ObjectUtil.isNotEmpty(obj) && null != obj.getClass()) { |
|
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
@ -191,7 +217,7 @@ public class BaseUtil {
|
|
|
|
|
* @return map对象 |
|
|
|
|
*/ |
|
|
|
|
public static Map<String, Object> LocalDateConvertMap(LocalDateTime dateTime,String prefix,String split) { |
|
|
|
|
HashMap<String, Object> result = new HashMap<String, Object>() {{ |
|
|
|
|
return new HashMap<String, Object>() {{ |
|
|
|
|
put(prefix + split + "year", dateTime.getYear()); |
|
|
|
|
put(prefix + split + "month", dateTime.getMonthValue()); |
|
|
|
|
put(prefix + split + "day", dateTime.getDayOfMonth()); |
|
|
|
@ -199,19 +225,5 @@ public class BaseUtil {
|
|
|
|
|
put(prefix + split + "minuter", dateTime.getMinute()); |
|
|
|
|
put(prefix + split + "second", dateTime.getSecond()); |
|
|
|
|
}}; |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public static void exportDocument(String templateFile, Map<String, Object> params, String wordPath, String pdfPath, HttpServletResponse response) { |
|
|
|
|
try { |
|
|
|
|
List<XWPFDocument> res = new ArrayList<>(); |
|
|
|
|
XWPFDocument document = BaseUtil.fillDocument(templateFile, params); |
|
|
|
|
res.add(document); |
|
|
|
|
BaseUtil.exportWord(res, wordPath); |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
throw new RuntimeException(e); |
|
|
|
|
} |
|
|
|
|
AsposeUtil.wordToPdf(wordPath, pdfPath); |
|
|
|
|
BaseUtil.readPdf(response,pdfPath); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|