Sfoglia il codice sorgente

Merge branch 'wq' of SH-Arbitrate/Arbitrate-Backend into dev

wangqiong123 2 anni fa
parent
commit
532baf1682

+ 14
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/VideoController.java Vedi File

@@ -118,6 +118,20 @@ public class VideoController extends BaseController {
118 118
 
119 119
         return  videoService.secretaryRoleByUserId(userId);
120 120
     }
121
+    /**
122
+     * 根据html字符串转pdf并和案件关联
123
+     * @param reservedConferenceVO
124
+     * @return
125
+     */
126
+    @Anonymous
127
+    @PostMapping("htmlToPDF")
128
+    public AjaxResult secretaryRoleByUserId( @RequestBody ReservedConferenceVO reservedConferenceVO) {
129
+        if( reservedConferenceVO.getCaseId()==null || StrUtil.isEmpty(reservedConferenceVO.getHtmlContent())){
130
+            return success();
131
+        }
132
+
133
+        return  videoService.htmlToPDF(reservedConferenceVO);
134
+    }
121 135
 
122 136
 
123 137
 }

+ 11
- 0
ruoyi-common/pom.xml Vedi File

@@ -181,6 +181,17 @@
181 181
         </dependency>
182 182
 
183 183
 
184
+        <dependency>
185
+            <groupId>com.itextpdf</groupId>
186
+            <artifactId>itextpdf</artifactId>
187
+            <version>5.5.13</version>
188
+        </dependency>
189
+        <dependency>
190
+            <groupId>com.itextpdf.tool</groupId>
191
+            <artifactId>xmlworker</artifactId>
192
+            <version>5.5.13</version>
193
+        </dependency>
194
+
184 195
 
185 196
         <!--  发送邮件-->
186 197
         <dependency>

+ 4
- 0
ruoyi-common/src/main/java/com/ruoyi/common/config/RuoYiConfig.java Vedi File

@@ -140,5 +140,9 @@ public class RuoYiConfig
140 140
     {
141 141
         return getProfile() + "/video";
142 142
     }
143
+    public static String getHtml2PDFPath()
144
+    {
145
+        return getProfile() + "/upload/html2PDF/";
146
+    }
143 147
     // https://1304001529.vod-qcloud.com/b78823bbvodcq1304001529/3ce565bf3270835011486046286/f0.mp4
144 148
 }

+ 148
- 0
ruoyi-common/src/main/java/com/ruoyi/common/utils/PdfUtils.java Vedi File

@@ -0,0 +1,148 @@
1
+package com.ruoyi.common.utils;
2
+
3
+import com.documents4j.api.DocumentType;
4
+import com.documents4j.api.IConverter;
5
+import com.documents4j.job.LocalConverter;
6
+import com.itextpdf.text.Document;
7
+import com.itextpdf.text.PageSize;
8
+import com.itextpdf.text.pdf.PdfWriter;
9
+import com.itextpdf.tool.xml.XMLWorkerHelper;
10
+
11
+import java.io.*;
12
+import java.nio.charset.Charset;
13
+import java.nio.file.Files;
14
+
15
+/**
16
+ * @author wangqiong
17
+ * @description pdf转换工具类
18
+ * @date 2023-11-28 15:20
19
+ */
20
+public class PdfUtils {
21
+    /**
22
+     * 将html字符串转为pdf
23
+     * @param pdfFilePath 保存的路径
24
+     * @param htmlcontent:必须是完整的html格式,比如<html><body>123</body></html>
25
+     */
26
+    public static boolean htmlStringConvertToPDF(String pdfFilePath, String htmlcontent) {
27
+        Document document = new Document();
28
+        PdfWriter writer = null;
29
+        try {
30
+            if(!new File(pdfFilePath).exists()){
31
+                new File(pdfFilePath).createNewFile();
32
+            }
33
+            writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
34
+            // 设置底部距离60,解决重叠问题
35
+            document.setPageSize(PageSize.A4);
36
+            document.setMargins(50, 45, 50, 60);
37
+            document.setMarginMirroring(false);
38
+            document.open();
39
+            XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("UTF-8")), null, Charset.forName("UTF-8"));
40
+        } catch (Exception e) {
41
+           return false;
42
+        } finally {
43
+            if (null != document) {
44
+                document.close();
45
+            }
46
+            if (null != writer) {
47
+                writer.close();
48
+            }
49
+        }
50
+        return true;
51
+    }
52
+    /**
53
+     * 根据html文件生成pdf
54
+     * @param pdfFilePath pdf文件生成路径
55
+     * @param htmlFilePath html文件路径
56
+     */
57
+    public static boolean htmlFileConvertToPDF(String pdfFilePath, String htmlFilePath) {
58
+        Document document = new Document();
59
+        PdfWriter writer = null;
60
+        FileOutputStream fileOutputStream = null;
61
+        FileInputStream fileInputStream = null;
62
+        try {
63
+            fileOutputStream = new FileOutputStream(pdfFilePath);
64
+            writer = PdfWriter.getInstance(document, fileOutputStream);
65
+            // 设置底部距离60,解决重叠问题
66
+            document.setPageSize(PageSize.A4);
67
+            document.setMargins(50, 45, 50, 60);
68
+            document.setMarginMirroring(false);
69
+            document.open();
70
+            StringBuffer sb = new StringBuffer();
71
+            fileInputStream = new FileInputStream(htmlFilePath);
72
+            BufferedReader br = new BufferedReader(new InputStreamReader(fileInputStream, "UTF-8"));
73
+            String readStr = "";
74
+            while ((readStr = br.readLine()) != null) {
75
+                sb.append(readStr);
76
+            }
77
+            XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(sb.toString().getBytes("Utf-8")), null, Charset.forName("UTF-8"));
78
+        } catch (Exception e) {
79
+            e.printStackTrace();
80
+        } finally {
81
+            if (null != document) {
82
+                document.close();
83
+            }
84
+            if (null != writer) {
85
+                writer.close();
86
+            }
87
+            if (null != fileInputStream) {
88
+                try {
89
+                    fileInputStream.close();
90
+                } catch (IOException e) {
91
+                    e.printStackTrace();
92
+                }
93
+            }
94
+            if (null != fileOutputStream) {
95
+                try {
96
+                    fileOutputStream.close();
97
+                } catch (IOException e) {
98
+                    e.printStackTrace();
99
+                }
100
+            }
101
+        }
102
+        return true;
103
+    }
104
+
105
+    /**
106
+     * docx转pdf
107
+     * @param pdfSaveDirectory:文件保存目录,例:D:\\pdf\\
108
+     * @param fileName:保存的文件名称,例:test.pdf
109
+     * @param docxFile:需要转换的docx文件
110
+     * @return
111
+     */
112
+    private static boolean docxConvertToPDF(String pdfSaveDirectory,String fileName,File docxFile) {
113
+        // 不存在则新建
114
+        File directory = new File(pdfSaveDirectory);
115
+        if (!directory.exists()) {
116
+            directory.mkdirs();
117
+        }
118
+        String pdfFilePath = pdfSaveDirectory + fileName;
119
+        File outputFile = new File(pdfFilePath);
120
+        try {
121
+            InputStream docxInputStream = Files.newInputStream(docxFile.toPath());
122
+            OutputStream outputStream = Files.newOutputStream(outputFile.toPath());
123
+            IConverter converter = LocalConverter.builder().build();
124
+            converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
125
+            docxInputStream.close();
126
+            outputStream.close();
127
+
128
+        } catch (Exception e) {
129
+            return false;
130
+        }
131
+        return true;
132
+    }
133
+
134
+    public static void main(String[] args) {
135
+        try {
136
+
137
+            String pdfFile = "D:\\test2.pdf";
138
+            String htmlContent1 = "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2>";
139
+            String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋体\">" + "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
140
+            String htmlContent2 = "<html><body >" + "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
141
+
142
+            htmlStringConvertToPDF(pdfFile,htmlContent);
143
+//            parseHtml2PdfByFilePath(pdfFile,htmlFile);
144
+        } catch (Exception e) {
145
+            e.printStackTrace();
146
+        }
147
+    }
148
+}

+ 14
- 1
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/domain/vo/ReservedConferenceVO.java Vedi File

@@ -23,12 +23,25 @@ public class ReservedConferenceVO {
23 23
      * 房间号id
24 24
      */
25 25
     private Long roomId;
26
+    /**
27
+     * 会议开始时间
28
+     */
26 29
     @NotNull(message = "会议开始时间不能为空")
27 30
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
28 31
     private Date scheduleStartTime;
29
-
32
+    /**
33
+     * 会议结束时间
34
+     */
30 35
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
31 36
     private Date scheduleEndTime;
37
+    /**
38
+     * 案件id
39
+     */
32 40
     @NotNull(message = "案件id不能为空")
33 41
     private Long caseId;
42
+    /**
43
+     * html内容
44
+     */
45
+    private String htmlContent;
46
+
34 47
 }

+ 8
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/VideoService.java Vedi File

@@ -2,6 +2,7 @@ package com.ruoyi.wisdomarbitrate.service;
2 2
 
3 3
 import com.ruoyi.common.core.domain.AjaxResult;
4 4
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
5
+import com.ruoyi.wisdomarbitrate.domain.vo.ReservedConferenceVO;
5 6
 import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
6 7
 
7 8
 import javax.servlet.http.HttpServletRequest;
@@ -39,4 +40,11 @@ public interface VideoService {
39 40
      * @return
40 41
      */
41 42
     AjaxResult secretaryRoleByUserId(Long userId);
43
+
44
+    /**
45
+     * 根据html字符串转pdf并和案件关联
46
+     * @param reservedConferenceVO
47
+     * @return
48
+     */
49
+    AjaxResult htmlToPDF(ReservedConferenceVO reservedConferenceVO);
42 50
 }

+ 35
- 3
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/VideoServiceImpl.java Vedi File

@@ -13,9 +13,11 @@ import com.ruoyi.common.core.domain.entity.SysRole;
13 13
 import com.ruoyi.common.core.domain.entity.SysUser;
14 14
 import com.ruoyi.common.core.domain.model.LoginUser;
15 15
 import com.ruoyi.common.core.redis.RedisCache;
16
+import com.ruoyi.common.utils.PdfUtils;
16 17
 import com.ruoyi.common.utils.SecurityUtils;
17 18
 import com.ruoyi.common.utils.SmsUtils;
18 19
 import com.ruoyi.common.utils.StringUtils;
20
+import com.ruoyi.common.utils.file.FileUploadUtils;
19 21
 import com.ruoyi.common.utils.spring.SpringUtils;
20 22
 import com.ruoyi.system.mapper.SysRoleMapper;
21 23
 import com.ruoyi.system.mapper.SysUserMapper;
@@ -23,6 +25,7 @@ import com.ruoyi.system.mapper.SysUserRoleMapper;
23 25
 import com.ruoyi.wisdomarbitrate.domain.CaseApplication;
24 26
 import com.ruoyi.wisdomarbitrate.domain.CaseAttach;
25 27
 import com.ruoyi.wisdomarbitrate.domain.IdentityAuthentication;
28
+import com.ruoyi.wisdomarbitrate.domain.vo.ReservedConferenceVO;
26 29
 import com.ruoyi.wisdomarbitrate.domain.vo.WeChatUserVO;
27 30
 import com.ruoyi.wisdomarbitrate.mapper.CaseApplicationMapper;
28 31
 import com.ruoyi.wisdomarbitrate.mapper.CaseAttachMapper;
@@ -312,6 +315,38 @@ public class VideoServiceImpl implements VideoService {
312 315
         return success(jsonObject);
313 316
     }
314 317
 
318
+    /**
319
+     * 根据html字符串转pdf并和案件关联
320
+     * @param reservedConferenceVO
321
+     * @return
322
+     */
323
+    @Override
324
+    public AjaxResult htmlToPDF(ReservedConferenceVO reservedConferenceVO) {
325
+        String currentFileName = System.currentTimeMillis() + ".pdf";
326
+        String fileName = null;
327
+        try {
328
+            fileName = getPathFileName(RuoYiConfig.getHtml2PDFPath(), currentFileName);
329
+        } catch (IOException e) {
330
+            throw new RuntimeException(e);
331
+        }
332
+
333
+        // html转pdf并上传到服务器
334
+        boolean convertFlag = PdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, reservedConferenceVO.getHtmlContent());
335
+
336
+        // 绑定案件
337
+        if(convertFlag){
338
+            CaseAttach caseAttach = CaseAttach.builder().caseAppliId(reservedConferenceVO.getCaseId())
339
+                    .annexName(fileName)
340
+                    .annexPath(RuoYiConfig.getHtml2PDFPath())
341
+                    .annexType(11)
342
+                    .build();
343
+            caseAttachMapper.save(caseAttach);
344
+            return AjaxResult.success();
345
+        }else {
346
+            return AjaxResult.error("pdf转换失败");
347
+        }
348
+    }
349
+
315 350
 
316 351
     /**
317 352
      *  查询出音视频集合,并下载,在将云点播上面的音视频删除
@@ -388,9 +423,7 @@ public class VideoServiceImpl implements VideoService {
388 423
                 staticAndMksDir = Paths.get(absPath).toFile().toString();
389 424
             long downloadFile = HttpUtil.downloadFile(fileUrl, staticAndMksDir);
390 425
             if(downloadFile>0) {
391
-                log.info("下载成功roomId"+roomId);
392 426
                 Long caseId = caseApplicationMapper.selectCaseIdByRoomId(roomId);
393
-                log.info("下载成功caseId"+caseId);
394 427
                 String annexName = getPathFileName(RuoYiConfig.getVideoUploadPath(), fileName);
395 428
                 // 存入数据库
396 429
                 CaseAttach caseAttach = CaseAttach.builder().caseAppliId(caseId)
@@ -399,7 +432,6 @@ public class VideoServiceImpl implements VideoService {
399 432
                         .annexType(9)
400 433
                         .build();
401 434
                 caseAttachMapper.save(caseAttach);
402
-                log.info("保存附件号成功");
403 435
                 return annexName;
404 436
             }
405 437
         }