Commit 59ec6e0a authored by luzhuang's avatar luzhuang

Merge remote-tracking branch 'origin/meiteng' into meiteng

parents 04e3834e 88671c48
...@@ -675,7 +675,6 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -675,7 +675,6 @@ public class BChapterServiceImpl implements BChapterService {
public String getBatchDownload(String bFileJson) { public String getBatchDownload(String bFileJson) {
//批量打包下载 //批量打包下载
List<BFile> fileList = JSONObject.parseArray(bFileJson, BFile.class); List<BFile> fileList = JSONObject.parseArray(bFileJson, BFile.class);
List<File> bFiles = new ArrayList<>();
if (fileList == null || fileList.size() < 1){ if (fileList == null || fileList.size() < 1){
throw new ServiceException(ResultServiceEnums.NOT_DOWNLOAD_FILE); throw new ServiceException(ResultServiceEnums.NOT_DOWNLOAD_FILE);
} }
...@@ -686,17 +685,16 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -686,17 +685,16 @@ public class BChapterServiceImpl implements BChapterService {
} }
String name = bFile.getVideoUrl().substring(bFile.getVideoUrl().lastIndexOf("/") + 1); String name = bFile.getVideoUrl().substring(bFile.getVideoUrl().lastIndexOf("/") + 1);
String filePath = global.getBASE_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + bFile.getLessonId(); String filePath = global.getBASE_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + bFile.getLessonId();
String returnBasePath = global.getRETURN_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + bFile.getLessonId();
File file = new File(filePath); File file = new File(filePath);
File fileOld = new File(filePath + File.separator + name); File fileOld = new File(filePath + File.separator + name);
if (fileOld.exists()) { if (fileOld.exists()) {
bFiles.add(new File(returnBasePath + File.separator + name)); bFile.setFileUrl(filePath + File.separator + name);
} else { } else {
String downLoadName = downLoadFile(bFile, file, filePath); String downLoadName = downLoadFile(bFile, file, filePath);
bFiles.add(new File(returnBasePath + File.separator + downLoadName)); bFile.setFileUrl(filePath + File.separator + downLoadName);
} }
}); });
if (bFiles.size() < 1){ if (fileList.size() < 1){
throw new ServiceException(ResultServiceEnums.NOT_DOWNLOAD_FILE); throw new ServiceException(ResultServiceEnums.NOT_DOWNLOAD_FILE);
} }
String uuid = IdGen.uuid(); String uuid = IdGen.uuid();
...@@ -705,7 +703,7 @@ public class BChapterServiceImpl implements BChapterService { ...@@ -705,7 +703,7 @@ public class BChapterServiceImpl implements BChapterService {
//返回地址 //返回地址
String returnAddress = global.getRETURN_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + global.getZIP_LOCATION() + File.separator + uuid +".zip"; String returnAddress = global.getRETURN_UPLOAD_SERVER_LOCATION() + global.getCOURSE_LOCATION() + File.separator + global.getZIP_LOCATION() + File.separator + uuid +".zip";
//打包 //打包
ZipMultiFile.zipFiles(bFiles, zipFile); ZipMultiFile.zipFiles(fileList, zipFile);
return returnAddress; return returnAddress;
} }
......
package org.rcisoft.core.util; package org.rcisoft.core.util;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.rcisoft.business.bfile.entity.BFile;
import java.io.*; import java.io.*;
import java.util.Arrays; import java.util.Arrays;
...@@ -21,10 +22,10 @@ public class ZipMultiFile { ...@@ -21,10 +22,10 @@ public class ZipMultiFile {
File zipFile = new File("C:\\Users\\三\\Desktop\\暂时\\deleteFile\\1234\\ZipFile.zip"); File zipFile = new File("C:\\Users\\三\\Desktop\\暂时\\deleteFile\\1234\\ZipFile.zip");
// 调用压缩方法 // 调用压缩方法
zipFiles(Arrays.asList(srcFiles), zipFile); // zipFiles(Arrays.asList(srcFiles), zipFile);
} }
public static String zipFiles(List<File> srcFiles, File zipFile) { public static String zipFiles(List<BFile> srcFiles, File zipFile) {
// 判断压缩后的文件存在不,不存在则创建 // 判断压缩后的文件存在不,不存在则创建
if (!zipFile.getParentFile().exists()){ if (!zipFile.getParentFile().exists()){
zipFile.getParentFile().mkdirs(); zipFile.getParentFile().mkdirs();
...@@ -54,9 +55,9 @@ public class ZipMultiFile { ...@@ -54,9 +55,9 @@ public class ZipMultiFile {
// 遍历源文件数组 // 遍历源文件数组
for (int i = 0; i < srcFiles.size(); i++) { for (int i = 0; i < srcFiles.size(); i++) {
// 将源文件数组中的当前文件读入 FileInputStream 流中 // 将源文件数组中的当前文件读入 FileInputStream 流中
fileInputStream = new FileInputStream(srcFiles.get(i)); fileInputStream = new FileInputStream(new File(srcFiles.get(i).getFileUrl()));
// 实例化 ZipEntry 对象,源文件数组中的当前文件 // 实例化 ZipEntry 对象,源文件数组中的当前文件
zipEntry = new ZipEntry(srcFiles.get(i).getName()); zipEntry = new ZipEntry(srcFiles.get(i).getFileName()+srcFiles.get(i).getFileUrl().substring(srcFiles.get(i).getFileUrl().lastIndexOf(".")));
zipOutputStream.putNextEntry(zipEntry); zipOutputStream.putNextEntry(zipEntry);
// 该变量记录每次真正读的字节个数 // 该变量记录每次真正读的字节个数
int len; int len;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment