|
|
@@ -8,6 +8,9 @@ import cn.hutool.core.util.ZipUtil;
|
|
8
|
8
|
import com.alibaba.fastjson.JSON;
|
|
9
|
9
|
import com.alibaba.fastjson.JSONArray;
|
|
10
|
10
|
import com.alibaba.fastjson.JSONObject;
|
|
|
11
|
+import com.documents4j.api.DocumentType;
|
|
|
12
|
+import com.documents4j.api.IConverter;
|
|
|
13
|
+import com.documents4j.job.LocalConverter;
|
|
11
|
14
|
import com.google.gson.Gson;
|
|
12
|
15
|
import com.google.gson.JsonArray;
|
|
13
|
16
|
import com.google.gson.JsonObject;
|
|
|
@@ -47,6 +50,8 @@ import org.apache.http.entity.StringEntity;
|
|
47
|
50
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
48
|
51
|
import org.apache.http.impl.client.HttpClients;
|
|
49
|
52
|
import org.apache.http.util.EntityUtils;
|
|
|
53
|
+import org.apache.poi.xwpf.usermodel.Document;
|
|
|
54
|
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
|
50
|
55
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
51
|
56
|
import org.springframework.beans.factory.annotation.Value;
|
|
52
|
57
|
import org.springframework.stereotype.Service;
|
|
|
@@ -2791,12 +2796,15 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
2791
|
2796
|
return AjaxResult.error("请选择要上传的文件");
|
|
2792
|
2797
|
}
|
|
2793
|
2798
|
//String targetPath = "/home/ruoyi/uploadPath/upload/unzipFile";
|
|
2794
|
|
- String targetPath = "D:\\home\\unzip\\";
|
|
|
2799
|
+ UUID uuid = UUID.randomUUID();
|
|
|
2800
|
+ String targetPath = "D:\\home\\unzip\\"+uuid+"\\";
|
|
2795
|
2801
|
File zipFile = null;
|
|
2796
|
2802
|
InputStream ins = null;
|
|
2797
|
2803
|
try {
|
|
2798
|
2804
|
ins = file.getInputStream();
|
|
2799
|
|
- zipFile = new File(file.getOriginalFilename());
|
|
|
2805
|
+ String savePath = "D:\\develop\\java\\";
|
|
|
2806
|
+ String saveName = uuid+file.getOriginalFilename();
|
|
|
2807
|
+ zipFile = new File(savePath+saveName);
|
|
2800
|
2808
|
inputChangeToFile(ins, zipFile);
|
|
2801
|
2809
|
} catch (IOException e) {
|
|
2802
|
2810
|
e.printStackTrace();
|
|
|
@@ -2804,12 +2812,14 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
2804
|
2812
|
//解压缩上传的压缩包
|
|
2805
|
2813
|
boolean unzipSuccess = UnZipFileUtils.unZipFile(zipFile, targetPath);
|
|
2806
|
2814
|
if (unzipSuccess ) {
|
|
2807
|
|
- String unzipPath = targetPath + file.getOriginalFilename() + "\\";
|
|
|
2815
|
+ //去掉后缀名,拿到解压后的文件夹路径
|
|
|
2816
|
+ String fileName = file.getOriginalFilename();
|
|
|
2817
|
+ String nameWithoutExtension = fileName.substring(0, fileName.lastIndexOf("."));
|
|
2808
|
2818
|
File directory = new File(targetPath);
|
|
2809
|
|
- String pdfFilePath = findAndConvertPDF(directory);
|
|
2810
|
|
- if (pdfFilePath != null){
|
|
|
2819
|
+ List<String> andConvertPDF = findAndConvertPDF(directory);
|
|
|
2820
|
+ if (andConvertPDF != null && andConvertPDF.size() > 0){
|
|
2811
|
2821
|
// 返回找到的PDF文件路径
|
|
2812
|
|
- return AjaxResult.success(pdfFilePath);
|
|
|
2822
|
+ return AjaxResult.success(andConvertPDF);
|
|
2813
|
2823
|
}else {
|
|
2814
|
2824
|
// 没有找到符合条件的文件
|
|
2815
|
2825
|
return AjaxResult.error("未找到符合条件的文件");
|
|
|
@@ -2820,33 +2830,100 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
|
|
2820
|
2830
|
}
|
|
2821
|
2831
|
|
|
2822
|
2832
|
}
|
|
2823
|
|
- public static String findAndConvertPDF(File directory) {
|
|
2824
|
|
-
|
|
2825
|
|
- File[] matches = directory.listFiles(new FilenameFilter() {
|
|
2826
|
|
- public boolean accept(File dir, String name) {
|
|
2827
|
|
- return name.contains("仲裁申请书");
|
|
2828
|
|
- }
|
|
2829
|
|
- });
|
|
2830
|
|
-
|
|
2831
|
|
- if (matches != null && matches.length > 0) {
|
|
2832
|
|
- for (File file : matches) {
|
|
2833
|
|
- if (file.isFile() && file.getName().toLowerCase().endsWith(".pdf")) {
|
|
2834
|
|
- // 如果是PDF格式直接返回路径
|
|
2835
|
|
- return file.getAbsolutePath();
|
|
|
2833
|
+ public static List<String> findAndConvertPDF(File directory) {
|
|
|
2834
|
+ List<String> pdfPaths = new ArrayList<>();
|
|
|
2835
|
+ if (directory.isFile()) {
|
|
|
2836
|
+ String path = "";
|
|
|
2837
|
+ // 如果传入的参数是一个文件
|
|
|
2838
|
+ if (directory.getName().contains("仲裁申请书")) {
|
|
|
2839
|
+ if (isPDF(directory)) {
|
|
|
2840
|
+ // 如果文件名包含"仲裁申请书"且是PDF格式,直接返回路径
|
|
|
2841
|
+ path = directory.getAbsolutePath();
|
|
2836
|
2842
|
} else {
|
|
2837
|
2843
|
// 如果不是PDF格式,进行转换成PDF并返回路径
|
|
2838
|
|
- String pdfPath = convertToPDF(file);
|
|
2839
|
|
- return pdfPath;
|
|
|
2844
|
+ String pdfPath = convertToPDF(directory);
|
|
|
2845
|
+ if (pdfPath != null) {
|
|
|
2846
|
+ path = pdfPath;
|
|
|
2847
|
+ }
|
|
|
2848
|
+ }
|
|
|
2849
|
+ if (path!= null) {
|
|
|
2850
|
+ pdfPaths.add(path);
|
|
2840
|
2851
|
}
|
|
2841
|
2852
|
}
|
|
|
2853
|
+ } else if (directory.isDirectory()) {
|
|
|
2854
|
+ searchAndConvertPDF(directory, pdfPaths);
|
|
|
2855
|
+ }else {
|
|
|
2856
|
+ return null;
|
|
2842
|
2857
|
}
|
|
2843
|
|
- return null;
|
|
|
2858
|
+ return pdfPaths;
|
|
|
2859
|
+ }
|
|
|
2860
|
+
|
|
|
2861
|
+ public static boolean isPDF(File file) {
|
|
|
2862
|
+ String extension = getFileExtension(file);
|
|
|
2863
|
+ return extension.equalsIgnoreCase("pdf");
|
|
2844
|
2864
|
}
|
|
2845
|
2865
|
|
|
|
2866
|
+ public static String getFileExtension(File file) {
|
|
|
2867
|
+ String name = file.getName();
|
|
|
2868
|
+ int lastIndexOfDot = name.lastIndexOf(".");
|
|
|
2869
|
+ if (lastIndexOfDot != -1 && lastIndexOfDot < name.length() - 1) {
|
|
|
2870
|
+ return name.substring(lastIndexOfDot + 1);
|
|
|
2871
|
+ } else {
|
|
|
2872
|
+ return "";
|
|
|
2873
|
+ }
|
|
|
2874
|
+ }
|
|
|
2875
|
+ public static void searchAndConvertPDF(File directory, List<String> pdfPaths) {
|
|
|
2876
|
+ File[] files = directory.listFiles();
|
|
|
2877
|
+ if (files != null) {
|
|
|
2878
|
+ for (File file : files) {
|
|
|
2879
|
+ if (file.isFile()) {
|
|
|
2880
|
+ // 如果是文件且文件名包含"仲裁申请书"
|
|
|
2881
|
+ if (file.getName().contains("仲裁申请书")) {
|
|
|
2882
|
+ if (isPDF(file)) {
|
|
|
2883
|
+ // 如果是PDF格式,直接添加到列表中
|
|
|
2884
|
+ pdfPaths.add(file.getAbsolutePath());
|
|
|
2885
|
+ } else {
|
|
|
2886
|
+ // 如果不是PDF格式,进行转换成PDF并添加转换后的路径到列表中
|
|
|
2887
|
+ String pdfPath = convertToPDF(file);
|
|
|
2888
|
+ if (pdfPath != null) {
|
|
|
2889
|
+ pdfPaths.add(pdfPath);
|
|
|
2890
|
+ }
|
|
|
2891
|
+ }
|
|
|
2892
|
+ }
|
|
|
2893
|
+ } else if (file.isDirectory()) {
|
|
|
2894
|
+ // 如果是目录,递归查找
|
|
|
2895
|
+ searchAndConvertPDF(file, pdfPaths);
|
|
|
2896
|
+ }
|
|
|
2897
|
+ }
|
|
|
2898
|
+ }
|
|
|
2899
|
+ }
|
|
2846
|
2900
|
private static String convertToPDF(File file) {
|
|
2847
|
|
- // 实现文件格式转换逻辑,这里假设已经实现了转换逻辑,返回转换后的PDF文件路径
|
|
2848
|
|
- String pdfPath = "convertedFilePath.pdf"; // 这里替换为实际转换后的PDF文件路径
|
|
2849
|
|
- return pdfPath;
|
|
|
2901
|
+ String wordFilePath = file.getAbsolutePath();
|
|
|
2902
|
+ String pdfSaveDirectory ="D:\\home\\unzip\\wordToPDF\\";
|
|
|
2903
|
+ File directory = new File(pdfSaveDirectory);
|
|
|
2904
|
+ if (!directory.exists()) {
|
|
|
2905
|
+ directory.mkdirs();
|
|
|
2906
|
+ }
|
|
|
2907
|
+ String name = file.getName();
|
|
|
2908
|
+ String nameWithoutExtension = name.substring(0, name.lastIndexOf("."));
|
|
|
2909
|
+ String pdfFilePath =pdfSaveDirectory+nameWithoutExtension+".pdf";
|
|
|
2910
|
+ File inputWord = new File(wordFilePath);
|
|
|
2911
|
+ File outputFile = new File(pdfFilePath);
|
|
|
2912
|
+ try {
|
|
|
2913
|
+ InputStream docxInputStream = new FileInputStream(inputWord);
|
|
|
2914
|
+ OutputStream outputStream = new FileOutputStream(outputFile);
|
|
|
2915
|
+ IConverter converter = LocalConverter.builder().build();
|
|
|
2916
|
+ converter.convert(docxInputStream).as(DocumentType.DOCX).to(outputStream).as(DocumentType.PDF).execute();
|
|
|
2917
|
+ docxInputStream.close();
|
|
|
2918
|
+ outputStream.close();
|
|
|
2919
|
+ System.out.println("success");
|
|
|
2920
|
+ File file1= new File(pdfFilePath);
|
|
|
2921
|
+ System.out.println("这是转化后的PDF文件路径"+file1);
|
|
|
2922
|
+
|
|
|
2923
|
+ } catch (Exception e) {
|
|
|
2924
|
+ e.printStackTrace();
|
|
|
2925
|
+ }
|
|
|
2926
|
+ return pdfFilePath;
|
|
2850
|
2927
|
}
|
|
2851
|
2928
|
}
|
|
2852
|
2929
|
|