Ver código fonte

实现下载案件压缩包

qitz 2 anos atrás
pai
commit
0c968937af

+ 10
- 0
ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java Ver arquivo

@@ -337,6 +337,16 @@ public class CaseApplicationController extends BaseController {
337 337
         return success(caseApplicationselect);
338 338
     }
339 339
 
340
+    /**
341
+     * 下载案件压缩包
342
+     */
343
+    @PostMapping("/downloadCaseZipFile")
344
+    public AjaxResult downloadCaseZipFile(@Validated @RequestBody CaseApplication caseApplication) {
345
+
346
+        CaseAttach caseAttach = caseApplicationService.downloadCaseZipFile(caseApplication);
347
+        return success(caseAttach);
348
+    }
349
+
340 350
 
341 351
     /**
342 352
      * 发送房间号短信

+ 2
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java Ver arquivo

@@ -133,4 +133,6 @@ public interface ICaseApplicationService {
133 133
     AjaxResult creatTrialRecordnew(ArbitrateRecord arbitrateRecord);
134 134
 
135 135
     AjaxResult editCaseApplicationDefineval(CaseApplication caseApplication);
136
+
137
+    CaseAttach downloadCaseZipFile(CaseApplication caseApplication);
136 138
 }

+ 123
- 0
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java Ver arquivo

@@ -44,6 +44,7 @@ import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService;
44 44
 import com.ruoyi.wisdomarbitrate.utils.OCRUtils;
45 45
 import com.ruoyi.wisdomarbitrate.utils.SignAward;
46 46
 import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils;
47
+import com.ruoyi.wisdomarbitrate.utils.ZipFileUtils;
47 48
 import com.tencentyun.TLSSigAPIv2;
48 49
 
49 50
 import org.apache.pdfbox.pdmodel.PDDocument;
@@ -78,6 +79,7 @@ import java.util.function.Function;
78 79
 import java.util.regex.Matcher;
79 80
 import java.util.regex.Pattern;
80 81
 import java.util.stream.Collectors;
82
+import java.util.zip.ZipOutputStream;
81 83
 
82 84
 import static com.ruoyi.common.core.domain.AjaxResult.error;
83 85
 import static com.ruoyi.common.core.domain.AjaxResult.success;
@@ -2620,6 +2622,127 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService {
2620 2622
         return success();
2621 2623
     }
2622 2624
 
2625
+    @Override
2626
+    @Transactional
2627
+    public CaseAttach downloadCaseZipFile(CaseApplication caseApplication) {
2628
+        caseApplication.setAnnexType(12);
2629
+        CaseAttach caseAttach = new CaseAttach();
2630
+        List<CaseAttach> caseAttachs =  caseAttachMapper.queryCaseAttachList( caseApplication);
2631
+        if(caseAttachs!=null&&caseAttachs.size()>0){
2632
+             caseAttach = caseAttachs.get(0);
2633
+
2634
+            String annexName = caseAttach.getAnnexName();
2635
+            String prefix = "/profile";
2636
+            int startIndex = annexName.indexOf(prefix);
2637
+            if(startIndex!=-1) {
2638
+                startIndex += prefix.length();
2639
+
2640
+                String annexPath = "/uploadPath" + annexName.substring(startIndex);
2641
+                caseAttach.setAnnexPath(annexPath);
2642
+            }
2643
+            int startIndexnew = annexName.lastIndexOf("/");
2644
+            if (startIndexnew != -1) {
2645
+                String annexNamenew = annexName.substring(startIndexnew + 1);
2646
+                caseAttach.setAnnexName(annexNamenew);
2647
+            }
2648
+
2649
+        }else {
2650
+            CaseApplication caseApplicationsel = new CaseApplication();
2651
+            caseApplicationsel.setId(caseApplication.getId());
2652
+            List<Integer> annexTypeList = new ArrayList<>();
2653
+            annexTypeList.add(1);
2654
+            annexTypeList.add(2);
2655
+            annexTypeList.add(3);
2656
+            annexTypeList.add(6);
2657
+            annexTypeList.add(7);
2658
+            annexTypeList.add(9);
2659
+            annexTypeList.add(11);
2660
+            caseApplicationsel.setAnnexTypeList(annexTypeList);
2661
+            List<CaseAttach> caseAttachList =  caseAttachMapper.queryCaseAttachList( caseApplicationsel);
2662
+            if(caseAttachList!=null&&caseAttachList.size()>0){
2663
+                List<String> pathList = new ArrayList<>();
2664
+                for (CaseAttach caseAttach1 : caseAttachList) {
2665
+                    String annexName = caseAttach1.getAnnexName();
2666
+                    String annexPathsel = caseAttach1.getAnnexPath();
2667
+                    String prefix = "/profile";
2668
+                    int startIndex = annexName.indexOf(prefix);
2669
+                    if(startIndex!=-1) {
2670
+                        startIndex += prefix.length();
2671
+
2672
+                        String annexPath = "/uploadPath" + annexName.substring(startIndex);
2673
+                        String path = "/home/ruoyi" + annexPath;
2674
+                        pathList.add(path);
2675
+                    }else if(annexPathsel.contains(annexName)){
2676
+                        pathList.add(annexPathsel);
2677
+                    }
2678
+                }
2679
+                //将案件相关附件压缩zip文件
2680
+                if(pathList!=null&&pathList.size()>0){
2681
+                    LocalDate now = LocalDate.now();
2682
+                    String year = Integer.toString(now.getYear());
2683
+                    String month = String.format("%02d", now.getMonthValue());
2684
+                    String day = String.format("%02d", now.getDayOfMonth());
2685
+                    String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
2686
+//                    String saveFolderPath = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day;
2687
+                    String fileName = UUID.randomUUID().toString().replace("-", "") + ".zip";
2688
+                    File saveFolder = new File(saveFolderPath);
2689
+                    if (!saveFolder.exists()) {
2690
+                        saveFolder.mkdirs();
2691
+                    }
2692
+                    String zipFileOutPath = saveFolderPath + "/" + fileName;
2693
+                        try {
2694
+
2695
+                            FileOutputStream zfous = new FileOutputStream(zipFileOutPath);
2696
+                            ZipOutputStream zipFileOutstream = new ZipOutputStream(zfous);
2697
+
2698
+                            for (String pathstr : pathList) {
2699
+                                FileInputStream fis1 = new FileInputStream(pathstr);
2700
+                                ZipFileUtils.zipFile(pathstr, fis1, zipFileOutstream);
2701
+                            }
2702
+                            zipFileOutstream.close();
2703
+                            zfous.close();
2704
+                        } catch (IOException e) {
2705
+                            e.printStackTrace();
2706
+                        }
2707
+
2708
+                        //保存压缩文件附件
2709
+                        String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName;
2710
+//                      String saveName = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day + "/" + fileName;
2711
+                        String savePath = "/home/ruoyi/uploadPath/upload";
2712
+                        caseAttach = CaseAttach.builder()
2713
+                            .caseAppliId(caseApplication.getId())
2714
+                            .annexName(saveName)
2715
+                            .annexPath(savePath)
2716
+                            .annexType(12)
2717
+                            .build();
2718
+                        int i = caseAttachMapper.save(caseAttach);
2719
+
2720
+                    String annexName = caseAttach.getAnnexName();
2721
+                    String prefix = "/profile";
2722
+                    int startIndex = annexName.indexOf(prefix);
2723
+                    if(startIndex!=-1) {
2724
+                        startIndex += prefix.length();
2725
+
2726
+                        String annexPath = "/uploadPath" + annexName.substring(startIndex);
2727
+                        caseAttach.setAnnexPath(annexPath);
2728
+                    }
2729
+                    int startIndexnew = annexName.lastIndexOf("/");
2730
+                    if (startIndexnew != -1) {
2731
+                        String annexNamenew = annexName.substring(startIndexnew + 1);
2732
+                        caseAttach.setAnnexName(annexNamenew);
2733
+                    }
2734
+
2735
+                        return caseAttach;
2736
+
2737
+                    }
2738
+                }
2739
+            }
2740
+            return  caseAttach;
2741
+        }
2742
+
2743
+
2744
+
2745
+
2623 2746
     @Override
2624 2747
     public CaseApplication selectSignSealUrl(CaseApplication caseApplication) throws EsignDemoException {
2625 2748
         Gson gson = new Gson();

+ 14
- 20
ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/ZipFileUtils.java Ver arquivo

@@ -4,40 +4,34 @@ import java.io.File;
4 4
 import java.io.FileInputStream;
5 5
 import java.io.FileOutputStream;
6 6
 import java.io.IOException;
7
+import java.nio.charset.Charset;
7 8
 import java.util.zip.ZipEntry;
8 9
 import java.util.zip.ZipOutputStream;
9 10
 
10 11
 public class ZipFileUtils {
11 12
 
12 13
     public static void main(String[] args) {
13
-        String filePath1 = "/path/to/file1.txt";
14
-        String filePath2 = "/path/to/file2.txt";
15
-
16
-        // ZIP文件的输出路径
17
-        String zipOutPath = "/path/to/output.zip";
14
+        String file1 = "F:\\testZip\\123.pdf";
15
+        String file2 = "F:\\testZip\\456.png";
16
+        String zipFileOutPath = "F:\\testZip\\outputfile123.zip";
18 17
 
19 18
         try {
20
-            FileOutputStream fous = new FileOutputStream(zipOutPath);
21
-            ZipOutputStream zipOutstream = new ZipOutputStream(fous);
22
-            FileInputStream fis1 = new FileInputStream(filePath1);
23
-            FileInputStream fis2 = new FileInputStream(filePath2);
24
-
25
-            zipFile(filePath1, fis1, zipOutstream);
26
-
27
-            zipFile(filePath2, fis2, zipOutstream);
28
-
19
+            FileOutputStream zfous = new FileOutputStream(zipFileOutPath);
20
+            ZipOutputStream zipFileOutstream = new ZipOutputStream(zfous);
21
+            FileInputStream fis1 = new FileInputStream(file1);
22
+            FileInputStream fis2 = new FileInputStream(file2);
23
+            zipFile(file1, fis1, zipFileOutstream);
24
+            zipFile(file2, fis2, zipFileOutstream);
25
+
26
+            zipFileOutstream.close();
27
+            zfous.close();
29 28
             System.out.println("文件成功打包成ZIP文件!");
30 29
         } catch (IOException e) {
31 30
             e.printStackTrace();
32 31
         }
33 32
     }
34 33
 
35
-
36
-
37
-
38
-
39
-
40
-    private static void zipFile(String zipfilePath, FileInputStream zipFileinsteam, ZipOutputStream zipfileOut)
34
+    public static void zipFile(String zipfilePath, FileInputStream zipFileinsteam, ZipOutputStream zipfileOut)
41 35
             throws IOException {
42 36
         ZipEntry zipfileEntry = new ZipEntry(new File(zipfilePath).getName());
43 37
         zipfileOut.putNextEntry(zipfileEntry);