From 4497f5b1e322eba5ec519ebc1955317ed656aa8e Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期四, 26 十二月 2024 14:31:15 +0800
Subject: [PATCH] Merge branch 'master' into cnas
---
cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java | 74 +++++++++---------------------------
1 files changed, 19 insertions(+), 55 deletions(-)
diff --git a/cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java b/cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java
index dd370a3..c7c05cc 100644
--- a/cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java
+++ b/cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java
@@ -21,6 +21,7 @@
import com.yuanchu.mom.service.ManageRecordCheckService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanchu.mom.utils.QueryWrappers;
+import com.yuanchu.mom.utils.XWPFDocumentUtils;
import org.apache.commons.io.IOUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.springframework.beans.factory.annotation.Value;
@@ -31,6 +32,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
+import java.net.URLEncoder;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.time.LocalDate;
@@ -91,21 +93,10 @@
}
@Override
- public String exportOutManageRecordCheck(ManageRecordCheck manageRecordCheck, HttpServletResponse response) {
+ public void exportOutManageRecordCheck(ManageRecordCheck manageRecordCheck, HttpServletResponse response) {
List<ManageRecordCheck> manageRecordCheckList = manageRecordCheckMapper.pageManageRecordCheck(new Page(-1, -1), QueryWrappers.queryWrappers(manageRecordCheck)).getRecords();
//鐢熸垚妫�楠屾姤鍛婂彂鏀剧櫥璁拌〃
- String url;
- try {
- InputStream inputStream = this.getClass().getResourceAsStream("/static/check-deal.docx");
- File file = File.createTempFile("temp", ".tmp");
- OutputStream outputStream = new FileOutputStream(file);
- IOUtils.copy(inputStream, outputStream);
- url = file.getAbsolutePath();
- } catch (FileNotFoundException e) {
- throw new ErrorException("鎵句笉鍒版ā鏉挎枃浠�");
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
+ InputStream inputStream = this.getClass().getResourceAsStream("/static/check-deal.docx");
ConfigureBuilder builder = Configure.builder();
builder.useSpringEL(true);
@@ -349,57 +340,30 @@
tableRenderData.setTableStyle(tableStyle);
Map<String, Object> table = new HashMap<>();
table.put("check", tableRenderData);
- table.put("index1", index1);
checkList.add(table);
index1++;
}
}
- Integer finalIndex = index1;
- XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render(
+ XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
new HashMap<String, Object>() {{
- put("size", finalIndex);
put("checkList", checkList);
}});
- String name = UUID.randomUUID() + "_鏂囦欢瀹℃壒璁板綍" + ".docx";
+ // 澶勭悊鎹㈣闂
+ XWPFDocumentUtils.updateMergeByDocument(template.getXWPFDocument());
try {
- template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name)));
- } catch (IOException e) {
- throw new RuntimeException(e);
+ response.setContentType("application/msword");
+ String fileName = URLEncoder.encode(
+ "鏂囦欢瀹℃壒璁板綍", "UTF-8");
+ response.setHeader("Content-disposition",
+ "attachment;filename=" + fileName + ".docx");
+ OutputStream os = response.getOutputStream();
+ template.write(os);
+ os.flush();
+ os.close();
+ } catch (Exception e) {
+ e.printStackTrace();
+ throw new RuntimeException("瀵煎嚭澶辫触");
}
- //澶勭悊涓嫳鏂囨崲琛岀殑闂
- String path = wordUrl + "/" + name;
- try {
- FileInputStream stream1 = new FileInputStream(path);
- XWPFDocument document1 = new XWPFDocument(stream1);
- List<XWPFTable> xwpfTables1 = document1.getTables();
- for (int i = 0; i < xwpfTables1.size(); i++) {
- for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) {
- for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) {
- if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) {
- String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
- String[] split = text.split("@");
- xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
- XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
- XWPFRun run = xwpfParagraph.createRun();
- run.setText(split[0]);
- if (ObjectUtils.isNotNull(split[1])) {
- run.addBreak();
- run.setText(split[1]);
- }
- xwpfParagraph.setAlignment(ParagraphAlignment.CENTER);
- }
- }
- }
- }
- FileOutputStream fileOutputStream1 = new FileOutputStream(path);
- document1.write(fileOutputStream1);
- fileOutputStream1.close();
- } catch (FileNotFoundException e) {
- throw new RuntimeException(e);
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- return name;
}
@Override
--
Gitblit v1.9.3