From 5070be06201417badc9855272940a910ea95596d Mon Sep 17 00:00:00 2001 From: lu Date: Mon, 2 Sep 2024 11:39:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A=E5=AF=BC=E5=87=BA=E7=A1=AE?= =?UTF-8?q?=E4=BF=9D=E7=9B=AE=E5=BD=95=E5=AD=98=E5=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/course/api/CoursePortalApi.java | 21 +++++-------------- 1 file changed, 5 insertions(+), 16 deletions(-) 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 990e1fa7..07d15909 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 @@ -365,7 +365,7 @@ public class CoursePortalApi extends ApiBaseController{ } //作业导出 @GetMapping("/export") - public JsonResponse export(String courseName,String courseId,String contentId,String name,Integer status) throws IOException { + public JsonResponse export(String courseId,String contentId,String name,Integer status) throws IOException { Mapmap=new HashMap<>(); List userIds = studyCourseDao.findList(FieldFilters.eq("courseId", courseId)).stream().filter(Objects::nonNull).map(StudyCourse::getAid).collect(Collectors.toList()); if (userIds.isEmpty()){ @@ -404,21 +404,7 @@ public class CoursePortalApi extends ApiBaseController{ if (totalFileSize > 2L * 1024 * 1024 * 1024) { return success("您要下载的作业过大,请分批下载或联系管理员!"); } - -// String encodedFilename = URLEncoder.encode(courseName+"【作业】.zip") -// .replace("+", "%20") // 空格替换为"%20" -// .replace("%2F", "/"); // 解决斜杠问题 -// StringBuilder contentDispositionValue = new StringBuilder(); -// contentDispositionValue.append("attachment; filename=\"") -// .append(encodedFilename) -// .append("\"") -// .append("; filename*=utf-8''") -// .append(encodedFilename); -// -// // 设置响应类型和Content-Disposition头 -// response.setContentType("application/zip"); - - // 创建一个临时文件用于存储ZIP文件 + // 创建一个临时文件用于存储ZIP文件 File tempZipFile = new File("/home/www/elearning/upload/temp.zip"); try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(tempZipFile))) { @@ -447,6 +433,9 @@ public class CoursePortalApi extends ApiBaseController{ String uuid = UUID.randomUUID().toString(); Path destination = Paths.get("/home/www/elearning/upload/saveZip/" + uuid + ".zip"); + // 确保目标目录存在 + Files.createDirectories(destination.getParent()); + // 删除目标文件如果已存在 if (Files.exists(destination)) { Files.delete(destination);