|
@@ -26,12 +26,16 @@ import cn.com.qmth.examcloud.web.support.ControllerSupport;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiParam;
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Optional;
|
|
|
|
|
@@ -40,6 +44,8 @@ import java.util.Optional;
|
|
|
@RequestMapping("${$rmp.ctr.oe}/client/exam/process")
|
|
|
public class ExamProcessController extends ControllerSupport {
|
|
|
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(ExamProcessController.class);
|
|
|
+
|
|
|
@Autowired
|
|
|
private ExamStudentService examStudentService;
|
|
|
|
|
@@ -170,8 +176,8 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
|
|
|
@ApiOperation(value = "离线考试:交卷")
|
|
|
@PostMapping("/submitPaper")
|
|
|
- public void submitPaper(@RequestPart(value = "file") MultipartFile file,
|
|
|
- @RequestParam Long examRecordDataId) throws Exception {
|
|
|
+ public void submitPaper(@RequestParam Long examRecordDataId,
|
|
|
+ @RequestPart(value = "file") MultipartFile file) throws Exception {
|
|
|
Check.isNull(file, "上传文件不能为空");
|
|
|
|
|
|
String fileSuffix = FileUtil.getFileSuffix(file.getOriginalFilename());
|
|
@@ -204,12 +210,13 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
if (ArrayUtils.isEmpty(settingFileTypes)) {
|
|
|
throw new StatusException("400403", "当前考试设置不允许上传附件");
|
|
|
}
|
|
|
+
|
|
|
if (!matchFileTypes(settingFileTypes, fileSuffix)) {
|
|
|
throw new StatusException("400403", "当前考试允许上传文件格式为:" + examProperty.getValue());
|
|
|
}
|
|
|
|
|
|
// todo
|
|
|
- // offlineExamService.submitPaper(examRecordDataId, file.getInputStream(), fileSuffix);
|
|
|
+ // offlineExamService.submitPaper(examRecordDataId, file.getBytes(), fileSuffix);
|
|
|
|
|
|
User user = getAccessUser();
|
|
|
ReportsUtil.report(new AdminOperateReport(user.getRootOrgId(), user.getUserId(), "考试进度详情-上传作答",
|
|
@@ -218,14 +225,14 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
|
|
|
@ApiOperation(value = "离线考试:多文件交卷")
|
|
|
@PostMapping("/batchSubmitPaper")
|
|
|
- public void batchSubmitPaper(@ApiParam(value = "文件数组") @RequestPart MultipartFile[] fileArray,
|
|
|
- @ApiParam(value = "考试记录id") @RequestParam Long examRecordDataId,
|
|
|
- @ApiParam(value = "文件类型:ZIP/PDF/IMAGE") @RequestParam String fileType,
|
|
|
- @ApiParam(value = "md5加密的文件摘要") @RequestParam String[] fileMd5Array) throws Exception {
|
|
|
+ public void batchSubmitPaper(@ApiParam(value = "考试记录id") @RequestParam Long examRecordDataId,
|
|
|
+ @ApiParam(value = "文件类型:ZIP、PDF、IMAGE") @RequestParam String fileType,
|
|
|
+ @ApiParam(value = "文件MD5信息") @RequestParam String[] fileMd5Array,
|
|
|
+ @ApiParam(value = "文件数组") @RequestPart MultipartFile[] fileArray) throws Exception {
|
|
|
Check.isNull(fileArray, "上传文件不能为空");
|
|
|
|
|
|
if (fileArray.length != fileMd5Array.length) {
|
|
|
- throw new StatusException("400401", "文件数量和文件摘要信息不匹配");
|
|
|
+ throw new StatusException("400401", "文件数量和文件MD5数量不匹配");
|
|
|
}
|
|
|
|
|
|
Optional<ExamRecordDataEntity> optional = examRecordDataRepo.findById(examRecordDataId);
|
|
@@ -250,6 +257,37 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
throw new StatusException("400403", "当前考试设置不允许上传附件");
|
|
|
}
|
|
|
|
|
|
+ String uploadFileType = fileType.toUpperCase();
|
|
|
+ if (!ArrayUtils.contains(settingFileTypes, uploadFileType)) {
|
|
|
+ throw new StatusException("400403", "当前考试允许上传文件格式为:" + examProperty.getValue());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (("ZIP".equals(uploadFileType) || "PDF".equals(uploadFileType)) && fileArray.length > 1) {
|
|
|
+ throw new StatusException("400403", "上传" + uploadFileType + "类型文件时只能传一个文件");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<byte[]> resultFiles = new ArrayList<>();
|
|
|
+ for (int i = 0; i < fileArray.length; i++) {
|
|
|
+ MultipartFile file = fileArray[i];
|
|
|
+ log.info("OfflineExam file {} - {}", i + 1, file.getOriginalFilename());
|
|
|
+
|
|
|
+ String fileSuffix = FileUtil.getFileSuffix(file.getOriginalFilename());
|
|
|
+ if (!matchFileTypes(new String[]{uploadFileType}, fileSuffix)) {
|
|
|
+ throw new StatusException("400401", "文件格式不正确");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (file.getSize() > Constants.ANSWER_FILE_MAX_SIZE * Constants.M_SIZE) {
|
|
|
+ throw new StatusException("400402", "文件大小不能超过" + Constants.ANSWER_FILE_MAX_SIZE + "M");
|
|
|
+ }
|
|
|
+
|
|
|
+ String realMD5 = DigestUtils.md5Hex(file.getInputStream());
|
|
|
+ String tempMD5 = fileMd5Array[i];
|
|
|
+ if (!realMD5.equals(tempMD5)) {
|
|
|
+ throw new StatusException("400403", "文件数据不完整,请重新上传");
|
|
|
+ }
|
|
|
+
|
|
|
+ resultFiles.add(file.getBytes());
|
|
|
+ }
|
|
|
|
|
|
// todo
|
|
|
// offlineExamService.batchSubmitPaper(examRecordDataId, resultFiles, fileType);
|