Merge branch 'zcwy-0724' into dev0525

This commit is contained in:
nisen
2024-08-05 14:04:09 +08:00

View File

@@ -19,9 +19,7 @@ import com.xboe.core.orm.FieldFilters;
import com.xboe.module.course.entity.*; import com.xboe.module.course.entity.*;
import com.xboe.module.course.vo.TeacherVo; import com.xboe.module.course.vo.TeacherVo;
import com.xboe.school.study.dao.StudyCourseDao; import com.xboe.school.study.dao.StudyCourseDao;
import com.xboe.school.study.dao.StudySignupDao;
import com.xboe.school.study.entity.StudyHomeWork; import com.xboe.school.study.entity.StudyHomeWork;
import com.xboe.school.study.entity.StudySignup;
import com.xboe.school.study.service.IStudyHomeWorkService; import com.xboe.school.study.service.IStudyHomeWorkService;
import com.xboe.school.study.service.IStudyService; import com.xboe.school.study.service.IStudyService;
import com.xboe.system.user.entity.User; import com.xboe.system.user.entity.User;
@@ -394,6 +392,14 @@ public class CoursePortalApi extends ApiBaseController{
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException("导出异常"+e.getMessage()); throw new RuntimeException("导出异常"+e.getMessage());
} }
long totalFileSize = map.values().stream()
.mapToLong(path -> new File(path).length())
.sum();
// 检查文件总大小是否超过 2GB
if (totalFileSize > 2L * 1024 * 1024 * 1024) {
return success("您要下载的作业过大,请分批下载或联系管理员!");
}
String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip") String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip")
.replace("+", "%20") // 空格替换为"%20" .replace("+", "%20") // 空格替换为"%20"
.replace("%2F", "/"); // 解决斜杠问题 .replace("%2F", "/"); // 解决斜杠问题
@@ -407,15 +413,9 @@ public class CoursePortalApi extends ApiBaseController{
// 设置响应类型和Content-Disposition头 // 设置响应类型和Content-Disposition头
response.setContentType("application/zip"); response.setContentType("application/zip");
response.setHeader("Content-Disposition", contentDispositionValue.toString()); response.setHeader("Content-Disposition", contentDispositionValue.toString());
long totalCompressedSize = 0;
try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) {
for (Map.Entry<String, String> e : map.entrySet()) { for (Map.Entry<String, String> e : map.entrySet()) {
File fileToZip = new File(e.getValue()); File fileToZip = new File(e.getValue());
// 检查加上当前文件大小后是否会超过2GB
long fileSizeInBytes = fileToZip.length();
if (totalCompressedSize + fileSizeInBytes > 2L * 1024 * 1024 * 1024) {
return success("您要下载的作业过大,联系管理员!");
}
// 添加 ZIP 条目 // 添加 ZIP 条目
ZipEntry entry = new ZipEntry(e.getKey()); ZipEntry entry = new ZipEntry(e.getKey());
entry.setSize(fileToZip.length()); entry.setSize(fileToZip.length());
@@ -427,7 +427,6 @@ public class CoursePortalApi extends ApiBaseController{
int len; int len;
while ((len = fis.read(buffer)) > 0) { while ((len = fis.read(buffer)) > 0) {
zos.write(buffer, 0, len); zos.write(buffer, 0, len);
totalCompressedSize += len;
} }
} }