打包下载增加一层文件夹

This commit is contained in:
zhal 2022-11-17 19:33:48 +08:00
parent 40f34e1e1a
commit de06841ea4
2 changed files with 51 additions and 19 deletions

View File

@ -509,28 +509,61 @@ public class UpfileWeb extends ActionWeb {
for(String oneuuid:uuidSpilt){ for(String oneuuid:uuidSpilt){
UpfileModel upfileModel = upfileDao.get(oneuuid); UpfileModel upfileModel = upfileDao.get(oneuuid);
DCContext dcContext = getDCContext(upfileModel); DCContext dcContext = getDCContext(upfileModel);
File targetFile = new File(targetDir + dcContext.getFileName());
if (!targetFile.exists()) { String filemodelName=null;
targetFile.createNewFile(); OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
} UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskId, model.getProfileId());
OutputStream out = new FileOutputStream(targetFile); if (file.exists()) {
InputStream in = DCUtil.decryptFile(dcContext); File[] fileList = file.listFiles();
if (in == null) { if (fileList.length > 0) {
String msg = "+ dcContext.getFileName() + "; File docFile1 = null;
if (dcContext.getDCMessage() != null) { for (File file2 : fileList) {
msg = dcContext.getDCMessage().getMessage(); if (file2.isFile() && "doc".equals((file2.getName().substring(file2.getName().lastIndexOf(".") + 1)))) {
docFile1 = file2;
break;
}
}
if (docFile1 == null) {
return ResponseObject.newErrResponse("没有找到文件").toString();
}
filemodelName= docFile1.getName();
} }
return ResponseObject.newErrResponse(msg).toString();
} }
try {
IOUtils.copy(in, out); if(UtilString.isNotEmpty(filemodelName)){
in.close(); filemodelName=filemodelName.substring(0, filemodelName.lastIndexOf("."));
out.close(); //判断文件目录是否存在不存在则创建
} finally { String bdir=targetDir + File.separator+filemodelName+"_file"+File.separator;
IOUtils.closeQuietly(in); File targetFile1 = new File(bdir);
IOUtils.closeQuietly(out); if (!targetFile1.exists()) {
targetFile1.mkdirs();
}
File targetFile = new File(bdir + dcContext.getFileName());
if (!targetFile.exists()) {
targetFile.createNewFile();
}
OutputStream out = new FileOutputStream(targetFile);
InputStream in = DCUtil.decryptFile(dcContext);
if (in == null) {
String msg = "+ dcContext.getFileName() + ";
if (dcContext.getDCMessage() != null) {
msg = dcContext.getDCMessage().getMessage();
}
return ResponseObject.newErrResponse(msg).toString();
}
try {
IOUtils.copy(in, out);
in.close();
out.close();
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
}
}else{
return ResponseObject.newErrResponse("没有找到文件").toString();
} }
} }
} }
@ -538,7 +571,6 @@ public class UpfileWeb extends ActionWeb {
//流程手册打包 //流程手册打包
if (UtilString.isNotEmpty(taskId)) { if (UtilString.isNotEmpty(taskId)) {
OutputTaskModel model = new OutputTask().getTaskReportById(taskId); OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
if (model != null) { if (model != null) {
try { try {