实现下载案件压缩包

This commit is contained in:
qitz
2023-12-11 18:00:37 +08:00
parent b2d42ccfba
commit 0c968937af
4 changed files with 148 additions and 19 deletions
@@ -133,4 +133,6 @@ public interface ICaseApplicationService {
AjaxResult creatTrialRecordnew(ArbitrateRecord arbitrateRecord);
AjaxResult editCaseApplicationDefineval(CaseApplication caseApplication);
CaseAttach downloadCaseZipFile(CaseApplication caseApplication);
}
@@ -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<CaseAttach> 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<Integer> 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<CaseAttach> caseAttachList = caseAttachMapper.queryCaseAttachList( caseApplicationsel);
if(caseAttachList!=null&&caseAttachList.size()>0){
List<String> 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();