From 51ec98113c6d49d0f7eec4e3c030e55e337e97db Mon Sep 17 00:00:00 2001
From: zss <zss@example.com>
Date: 星期一, 26 五月 2025 15:47:16 +0800
Subject: [PATCH] 芯导软件(江苏)有限公司  delete

---
 cnas-manage/src/main/java/com/yuanchu/mom/service/impl/ManageRecordCheckServiceImpl.java |   76 ++++++++++----------------------------
 1 files changed, 20 insertions(+), 56 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..6144117 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;
@@ -45,7 +47,7 @@
  * 鏂囦欢瀹℃壒璁板綍(鍚慨璁㈠悗鍐嶆瀹℃壒璁板綍) 鏈嶅姟瀹炵幇绫�
  * </p>
  *
- * @author 鑺杞欢锛堟睙鑻忥級鏈夐檺鍏徃
+ * @author
  * @since 2024-11-12 02:31:36
  */
 @Service
@@ -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