diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java index 568c0ac..61b603e 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/wisdomarbitrate/CaseApplicationController.java @@ -337,6 +337,16 @@ public class CaseApplicationController extends BaseController { return success(caseApplicationselect); } + /** + * 下载案件压缩包 + */ + @PostMapping("/downloadCaseZipFile") + public AjaxResult downloadCaseZipFile(@Validated @RequestBody CaseApplication caseApplication) { + + CaseAttach caseAttach = caseApplicationService.downloadCaseZipFile(caseApplication); + return success(caseAttach); + } + /** * 发送房间号短信 diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java index dfb8ae7..47044a5 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/ICaseApplicationService.java @@ -133,4 +133,6 @@ public interface ICaseApplicationService { AjaxResult creatTrialRecordnew(ArbitrateRecord arbitrateRecord); AjaxResult editCaseApplicationDefineval(CaseApplication caseApplication); + + CaseAttach downloadCaseZipFile(CaseApplication caseApplication); } diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java index 73cf370..1a214ff 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/service/impl/CaseApplicationServiceImpl.java @@ -44,6 +44,7 @@ import com.ruoyi.wisdomarbitrate.service.ICaseApplicationService; import com.ruoyi.wisdomarbitrate.utils.OCRUtils; import com.ruoyi.wisdomarbitrate.utils.SignAward; import com.ruoyi.wisdomarbitrate.utils.UnZipFileUtils; +import com.ruoyi.wisdomarbitrate.utils.ZipFileUtils; import com.tencentyun.TLSSigAPIv2; import org.apache.pdfbox.pdmodel.PDDocument; @@ -78,6 +79,7 @@ import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; +import java.util.zip.ZipOutputStream; import static com.ruoyi.common.core.domain.AjaxResult.error; import static com.ruoyi.common.core.domain.AjaxResult.success; @@ -2620,6 +2622,127 @@ public class CaseApplicationServiceImpl implements ICaseApplicationService { return success(); } + @Override + @Transactional + public CaseAttach downloadCaseZipFile(CaseApplication caseApplication) { + caseApplication.setAnnexType(12); + CaseAttach caseAttach = new CaseAttach(); + List caseAttachs = caseAttachMapper.queryCaseAttachList( caseApplication); + if(caseAttachs!=null&&caseAttachs.size()>0){ + caseAttach = caseAttachs.get(0); + + String annexName = caseAttach.getAnnexName(); + String prefix = "/profile"; + int startIndex = annexName.indexOf(prefix); + if(startIndex!=-1) { + startIndex += prefix.length(); + + String annexPath = "/uploadPath" + annexName.substring(startIndex); + caseAttach.setAnnexPath(annexPath); + } + int startIndexnew = annexName.lastIndexOf("/"); + if (startIndexnew != -1) { + String annexNamenew = annexName.substring(startIndexnew + 1); + caseAttach.setAnnexName(annexNamenew); + } + + }else { + CaseApplication caseApplicationsel = new CaseApplication(); + caseApplicationsel.setId(caseApplication.getId()); + List annexTypeList = new ArrayList<>(); + annexTypeList.add(1); + annexTypeList.add(2); + annexTypeList.add(3); + annexTypeList.add(6); + annexTypeList.add(7); + annexTypeList.add(9); + annexTypeList.add(11); + caseApplicationsel.setAnnexTypeList(annexTypeList); + List caseAttachList = caseAttachMapper.queryCaseAttachList( caseApplicationsel); + if(caseAttachList!=null&&caseAttachList.size()>0){ + List pathList = new ArrayList<>(); + for (CaseAttach caseAttach1 : caseAttachList) { + String annexName = caseAttach1.getAnnexName(); + String annexPathsel = caseAttach1.getAnnexPath(); + String prefix = "/profile"; + int startIndex = annexName.indexOf(prefix); + if(startIndex!=-1) { + startIndex += prefix.length(); + + String annexPath = "/uploadPath" + annexName.substring(startIndex); + String path = "/home/ruoyi" + annexPath; + pathList.add(path); + }else if(annexPathsel.contains(annexName)){ + pathList.add(annexPathsel); + } + } + //将案件相关附件压缩zip文件 + if(pathList!=null&&pathList.size()>0){ + LocalDate now = LocalDate.now(); + String year = Integer.toString(now.getYear()); + String month = String.format("%02d", now.getMonthValue()); + String day = String.format("%02d", now.getDayOfMonth()); + String saveFolderPath = "/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day; +// String saveFolderPath = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day; + String fileName = UUID.randomUUID().toString().replace("-", "") + ".zip"; + File saveFolder = new File(saveFolderPath); + if (!saveFolder.exists()) { + saveFolder.mkdirs(); + } + String zipFileOutPath = saveFolderPath + "/" + fileName; + try { + + FileOutputStream zfous = new FileOutputStream(zipFileOutPath); + ZipOutputStream zipFileOutstream = new ZipOutputStream(zfous); + + for (String pathstr : pathList) { + FileInputStream fis1 = new FileInputStream(pathstr); + ZipFileUtils.zipFile(pathstr, fis1, zipFileOutstream); + } + zipFileOutstream.close(); + zfous.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + //保存压缩文件附件 + String saveName = "/profile/upload/" + year + "/" + month + "/" + day + "/" + fileName; +// String saveName = "D:/home/ruoyi/uploadPath/upload/" + year + "/" + month + "/" + day + "/" + fileName; + String savePath = "/home/ruoyi/uploadPath/upload"; + caseAttach = CaseAttach.builder() + .caseAppliId(caseApplication.getId()) + .annexName(saveName) + .annexPath(savePath) + .annexType(12) + .build(); + int i = caseAttachMapper.save(caseAttach); + + String annexName = caseAttach.getAnnexName(); + String prefix = "/profile"; + int startIndex = annexName.indexOf(prefix); + if(startIndex!=-1) { + startIndex += prefix.length(); + + String annexPath = "/uploadPath" + annexName.substring(startIndex); + caseAttach.setAnnexPath(annexPath); + } + int startIndexnew = annexName.lastIndexOf("/"); + if (startIndexnew != -1) { + String annexNamenew = annexName.substring(startIndexnew + 1); + caseAttach.setAnnexName(annexNamenew); + } + + return caseAttach; + + } + } + } + return caseAttach; + } + + + + @Override public CaseApplication selectSignSealUrl(CaseApplication caseApplication) throws EsignDemoException { Gson gson = new Gson(); diff --git a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/ZipFileUtils.java b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/ZipFileUtils.java index 2c03de5..18e8d69 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/ZipFileUtils.java +++ b/ruoyi-system/src/main/java/com/ruoyi/wisdomarbitrate/utils/ZipFileUtils.java @@ -4,40 +4,34 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class ZipFileUtils { public static void main(String[] args) { - String filePath1 = "/path/to/file1.txt"; - String filePath2 = "/path/to/file2.txt"; - - // ZIP文件的输出路径 - String zipOutPath = "/path/to/output.zip"; + String file1 = "F:\\testZip\\123.pdf"; + String file2 = "F:\\testZip\\456.png"; + String zipFileOutPath = "F:\\testZip\\outputfile123.zip"; try { - FileOutputStream fous = new FileOutputStream(zipOutPath); - ZipOutputStream zipOutstream = new ZipOutputStream(fous); - FileInputStream fis1 = new FileInputStream(filePath1); - FileInputStream fis2 = new FileInputStream(filePath2); - - zipFile(filePath1, fis1, zipOutstream); - - zipFile(filePath2, fis2, zipOutstream); + FileOutputStream zfous = new FileOutputStream(zipFileOutPath); + ZipOutputStream zipFileOutstream = new ZipOutputStream(zfous); + FileInputStream fis1 = new FileInputStream(file1); + FileInputStream fis2 = new FileInputStream(file2); + zipFile(file1, fis1, zipFileOutstream); + zipFile(file2, fis2, zipFileOutstream); + zipFileOutstream.close(); + zfous.close(); System.out.println("文件成功打包成ZIP文件!"); } catch (IOException e) { e.printStackTrace(); } } - - - - - - private static void zipFile(String zipfilePath, FileInputStream zipFileinsteam, ZipOutputStream zipfileOut) + public static void zipFile(String zipfilePath, FileInputStream zipFileinsteam, ZipOutputStream zipfileOut) throws IOException { ZipEntry zipfileEntry = new ZipEntry(new File(zipfilePath).getName()); zipfileOut.putNextEntry(zipfileEntry);