diff --git a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java index eb72f82b..3e93694e 100644 --- a/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java +++ b/servers/boe-server-all/src/main/java/com/xboe/module/course/api/CoursePortalApi.java @@ -19,9 +19,7 @@ import com.xboe.core.orm.FieldFilters; import com.xboe.module.course.entity.*; import com.xboe.module.course.vo.TeacherVo; 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.StudySignup; import com.xboe.school.study.service.IStudyHomeWorkService; import com.xboe.school.study.service.IStudyService; import com.xboe.system.user.entity.User; @@ -394,6 +392,14 @@ public class CoursePortalApi extends ApiBaseController{ e.printStackTrace(); 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") .replace("+", "%20") // 空格替换为"%20" .replace("%2F", "/"); // 解决斜杠问题 @@ -407,15 +413,9 @@ public class CoursePortalApi extends ApiBaseController{ // 设置响应类型和Content-Disposition头 response.setContentType("application/zip"); response.setHeader("Content-Disposition", contentDispositionValue.toString()); - long totalCompressedSize = 0; try (ZipOutputStream zos = new ZipOutputStream(response.getOutputStream())) { for (Map.Entry e : map.entrySet()) { File fileToZip = new File(e.getValue()); - // 检查加上当前文件大小后,是否会超过2GB - long fileSizeInBytes = fileToZip.length(); - if (totalCompressedSize + fileSizeInBytes > 2L * 1024 * 1024 * 1024) { - return success("您要下载的作业过大,联系管理员!"); - } // 添加 ZIP 条目 ZipEntry entry = new ZipEntry(e.getKey()); entry.setSize(fileToZip.length()); @@ -427,7 +427,6 @@ public class CoursePortalApi extends ApiBaseController{ int len; while ((len = fis.read(buffer)) > 0) { zos.write(buffer, 0, len); - totalCompressedSize += len; } }