打包下载增加一层文件夹

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){
UpfileModel upfileModel = upfileDao.get(oneuuid);
DCContext dcContext = getDCContext(upfileModel);
File targetFile = new File(targetDir + 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();
String filemodelName=null;
OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
UtilFile file = OutputAPIManager.getInstance().getFilePath(model.getWsId(), taskId, model.getProfileId());
if (file.exists()) {
File[] fileList = file.listFiles();
if (fileList.length > 0) {
File docFile1 = null;
for (File file2 : fileList) {
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);
in.close();
out.close();
} finally {
IOUtils.closeQuietly(in);
IOUtils.closeQuietly(out);
if(UtilString.isNotEmpty(filemodelName)){
filemodelName=filemodelName.substring(0, filemodelName.lastIndexOf("."));
//判断文件目录是否存在不存在则创建
String bdir=targetDir + File.separator+filemodelName+"_file"+File.separator;
File targetFile1 = new File(bdir);
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)) {
OutputTaskModel model = new OutputTask().getTaskReportById(taskId);
if (model != null) {
try {