|
|
@@ -1,14 +1,18 @@
|
|
|
package com.njuzr.eaibackend.controller;
|
|
|
|
|
|
+import com.njuzr.eaibackend.mapper.UserMapper;
|
|
|
+import com.njuzr.eaibackend.po.User;
|
|
|
import com.njuzr.eaibackend.service.ExportCompositionService;
|
|
|
import com.njuzr.eaibackend.service.ExportBehaviorOverviewService;
|
|
|
import com.njuzr.eaibackend.service.UserService;
|
|
|
import com.njuzr.eaibackend.service.AssignmentService;
|
|
|
+import com.njuzr.eaibackend.service.ClassService;
|
|
|
import com.njuzr.eaibackend.vo.UserVO;
|
|
|
import com.njuzr.eaibackend.vo.AssignmentVO;
|
|
|
import freemarker.template.TemplateException;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.ContentDisposition;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
@@ -17,6 +21,7 @@ import org.springframework.web.bind.annotation.*;
|
|
|
import java.io.IOException;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
|
|
|
@RestController
|
|
|
@@ -29,7 +34,11 @@ public class ExportController {
|
|
|
@Autowired
|
|
|
private UserService userService;
|
|
|
@Autowired
|
|
|
+ private UserMapper userMapper;
|
|
|
+ @Autowired
|
|
|
private AssignmentService assignmentService;
|
|
|
+ @Autowired
|
|
|
+ private ClassService classService;
|
|
|
|
|
|
@GetMapping("/composition/word")
|
|
|
public ResponseEntity<byte[]> exportWord(@RequestParam Long assignmentId, @RequestParam Long studentId) throws TemplateException, IOException {
|
|
|
@@ -66,18 +75,35 @@ public class ExportController {
|
|
|
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
- // 查询学生姓名
|
|
|
+ // 查询学生信息
|
|
|
String name = null;
|
|
|
+ String officialNumber = null;
|
|
|
try {
|
|
|
- name = userService.getNameById(studentId);
|
|
|
+ User user = userMapper.selectById(studentId);
|
|
|
+ if (user != null) {
|
|
|
+ name = user.getName();
|
|
|
+ officialNumber = user.getOfficialNumber();
|
|
|
+ }
|
|
|
+ } catch (Exception ignored) { }
|
|
|
+ // 查询作业名称
|
|
|
+ String assignmentName = null;
|
|
|
+ try {
|
|
|
+ AssignmentVO vo = assignmentService.findAssignmentById(assignmentId);
|
|
|
+ assignmentName = vo != null ? vo.getAssignmentName() : null;
|
|
|
} catch (Exception ignored) { }
|
|
|
|
|
|
- String fileName = name == null || name.isEmpty()
|
|
|
- ? String.format("behavior_overview_%d_%d.xlsx", studentId, assignmentId)
|
|
|
- : String.format("behavior_overview_%d_%d_%s.xlsx", studentId, assignmentId, name);
|
|
|
+ String fileName;
|
|
|
+ if (name == null || name.isEmpty() || officialNumber == null) {
|
|
|
+ fileName = String.format("行为数据记录_%d_%d.xlsx", studentId, assignmentId);
|
|
|
+ } else if (assignmentName == null || assignmentName.isEmpty()) {
|
|
|
+ fileName = String.format("行为数据记录_%s_%s.xlsx", officialNumber, name);
|
|
|
+ } else {
|
|
|
+ fileName = String.format("行为数据记录_%s_%s_%s.xlsx", officialNumber, name, assignmentName);
|
|
|
+ }
|
|
|
|
|
|
- headers.setContentDispositionFormData("attachment",
|
|
|
- URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build());
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
.headers(headers)
|
|
|
@@ -97,11 +123,12 @@ public class ExportController {
|
|
|
} catch (Exception ignored) { }
|
|
|
|
|
|
String fileName = assignmentName == null || assignmentName.isEmpty()
|
|
|
- ? String.format("behavior_overview_assignment_%d.xlsx", assignmentId)
|
|
|
- : String.format("behavior_overview_assignment_%d_%s.xlsx", assignmentId, assignmentName);
|
|
|
+ ? String.format("行为数据记录_%d.xlsx", assignmentId)
|
|
|
+ : String.format("行为数据记录_%d_%s.xlsx", assignmentId, assignmentName);
|
|
|
|
|
|
- headers.setContentDispositionFormData("attachment",
|
|
|
- URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build());
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
.headers(headers)
|
|
|
@@ -126,11 +153,89 @@ public class ExportController {
|
|
|
? String.format("pause_statistics_assignment_%d_threshold_%d.xlsx", assignmentId, threshold)
|
|
|
: String.format("pause_statistics_assignment_%d_%s_threshold_%d.xlsx", assignmentId, assignmentName, threshold);
|
|
|
|
|
|
- headers.setContentDispositionFormData("attachment",
|
|
|
- URLEncoder.encode(fileName, StandardCharsets.UTF_8));
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build());
|
|
|
|
|
|
return ResponseEntity.ok()
|
|
|
.headers(headers)
|
|
|
.body(bytes);
|
|
|
}
|
|
|
+
|
|
|
+ @GetMapping("/behaviorOverview/excel/class")
|
|
|
+ public ResponseEntity<byte[]> exportClassBehaviorOverviewExcel(@RequestParam Long classId) {
|
|
|
+ byte[] bytes = exportBehaviorOverviewService.exportClassBehaviorOverviewExcel(classId);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
+ String className = null;
|
|
|
+ try {
|
|
|
+ com.njuzr.eaibackend.po.Class cls = classService.getClassById(classId);
|
|
|
+ className = cls != null ? cls.getClassName() : null;
|
|
|
+ } catch (Exception ignored) { }
|
|
|
+
|
|
|
+ String fileName = className == null || className.isEmpty()
|
|
|
+ ? String.format("行为数据记录_%d.xlsx", classId)
|
|
|
+ : String.format("行为数据记录_%d_%s.xlsx", classId, className);
|
|
|
+
|
|
|
+ headers.setContentDisposition(ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build());
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .body(bytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/class/download")
|
|
|
+ public ResponseEntity<byte[]> downloadClassAssignments(@RequestParam Long classId) {
|
|
|
+ byte[] zipBytes = exportCompositionService.downloadClassAssignments(classId);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
+ String className = null;
|
|
|
+ try {
|
|
|
+ com.njuzr.eaibackend.po.Class cls = classService.getClassById(classId);
|
|
|
+ className = cls != null ? cls.getClassName() : null;
|
|
|
+ } catch (Exception ignored) { }
|
|
|
+
|
|
|
+ String fileName = className == null || className.isEmpty()
|
|
|
+ ? String.format("class_%d_%s.zip", classId, new java.text.SimpleDateFormat("yyyyMMdd").format(new Date()))
|
|
|
+ : String.format("%s_%s.zip", className, new java.text.SimpleDateFormat("yyyyMMdd").format(new Date()));
|
|
|
+
|
|
|
+ ContentDisposition contentDisposition = ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build();
|
|
|
+ headers.setContentDisposition(contentDisposition);
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .body(zipBytes);
|
|
|
+ }
|
|
|
+
|
|
|
+ @GetMapping("/assignment/download")
|
|
|
+ public ResponseEntity<byte[]> downloadAssignmentSubmissions(@RequestParam Long assignmentId) {
|
|
|
+ byte[] zipBytes = exportCompositionService.downloadAssignmentSubmissions(assignmentId);
|
|
|
+
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
|
+ String assignmentName = null;
|
|
|
+ try {
|
|
|
+ AssignmentVO vo = assignmentService.findAssignmentById(assignmentId);
|
|
|
+ assignmentName = vo != null ? vo.getAssignmentName() : null;
|
|
|
+ } catch (Exception ignored) { }
|
|
|
+
|
|
|
+ String fileName = assignmentName == null || assignmentName.isEmpty()
|
|
|
+ ? String.format("assignment_%d_%s.zip", assignmentId, new java.text.SimpleDateFormat("yyyyMMdd").format(new Date()))
|
|
|
+ : String.format("%s_%s.zip", assignmentName, new java.text.SimpleDateFormat("yyyyMMdd").format(new Date()));
|
|
|
+
|
|
|
+ ContentDisposition contentDisposition = ContentDisposition.builder("attachment")
|
|
|
+ .filename(fileName, StandardCharsets.UTF_8)
|
|
|
+ .build();
|
|
|
+ headers.setContentDisposition(contentDisposition);
|
|
|
+
|
|
|
+ return ResponseEntity.ok()
|
|
|
+ .headers(headers)
|
|
|
+ .body(zipBytes);
|
|
|
+ }
|
|
|
}
|