|
@@ -4,7 +4,6 @@ import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
|
import cn.com.qmth.examcloud.api.commons.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.commons.util.FileUtil;
|
|
|
-import cn.com.qmth.examcloud.commons.util.JsonMapper;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordDataBeanConvert;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.api.bean.ExamRecordDataDomain;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.Constants;
|
|
@@ -17,19 +16,12 @@ import cn.com.qmth.examcloud.core.oe.admin.service.*;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.*;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.examscore.ObjectiveScoreInfo;
|
|
|
import cn.com.qmth.examcloud.core.oe.admin.service.bean.uploadfile.FileInfo;
|
|
|
-import cn.com.qmth.examcloud.reports.commons.bean.AdminOperateReport;
|
|
|
-import cn.com.qmth.examcloud.reports.commons.util.ReportsUtil;
|
|
|
-import cn.com.qmth.examcloud.support.cache.bean.ExamPropertyCacheBean;
|
|
|
-import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
|
-import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
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;
|
|
@@ -38,7 +30,6 @@ import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
|
|
|
@Api(tags = "(客户端)考试过程相关接口")
|
|
|
@RestController
|
|
@@ -199,52 +190,17 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
@ApiParam(value = "文件MD5信息") @RequestParam String[] fileMd5Array,
|
|
|
@ApiParam(value = "文件数组") @RequestPart MultipartFile[] fileArray) throws Exception {
|
|
|
Check.isNull(fileArray, "上传文件不能为空");
|
|
|
+ User user = getAccessUser();
|
|
|
|
|
|
if (fileArray.length != fileMd5Array.length) {
|
|
|
throw new StatusException("400401", "文件数量和文件MD5数量不匹配");
|
|
|
}
|
|
|
|
|
|
- Optional<ExamRecordDataEntity> optional = examRecordDataRepo.findById(examRecordDataId);
|
|
|
- if (!optional.isPresent()) {
|
|
|
- throw new StatusException("400403", "考试记录不存在");
|
|
|
- }
|
|
|
-
|
|
|
- ExamRecordDataEntity examRecordData = optional.get();
|
|
|
- if (ExamType.OFFLINE != examRecordData.getExamType()) {
|
|
|
- throw new StatusException("400403", "非离线考试");
|
|
|
- }
|
|
|
-
|
|
|
- if (!examStudentService.isEnableExamStudent(examRecordData.getExamStudentId())) {
|
|
|
- throw new StatusException("400403", "当前考生已禁用");
|
|
|
- }
|
|
|
-
|
|
|
- // 当前考试允许的附件类型,示例:["ZIP","PDF","IMAGE"]
|
|
|
- ExamPropertyCacheBean examProperty = ExamCacheTransferHelper.getCachedExamProperty(examRecordData.getExamId(),
|
|
|
- examRecordData.getStudentId(), ExamProperties.OFFLINE_UPLOAD_FILE_TYPE.name());
|
|
|
- String[] settingFileTypes = new JsonMapper().toArray(examProperty.getValue(), String.class);
|
|
|
- if (ArrayUtils.isEmpty(settingFileTypes)) {
|
|
|
- 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<>();
|
|
|
+ List<FileInfo> fileInfoList = 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");
|
|
|
}
|
|
@@ -252,38 +208,20 @@ public class ExamProcessController extends ControllerSupport {
|
|
|
String realMD5 = DigestUtils.md5Hex(file.getInputStream());
|
|
|
String tempMD5 = fileMd5Array[i];
|
|
|
if (!realMD5.equals(tempMD5)) {
|
|
|
- throw new StatusException("400403", "文件数据不完整,请重新上传");
|
|
|
+ throw new StatusException("400403", "文件MD5验证失败");
|
|
|
}
|
|
|
|
|
|
- resultFiles.add(file.getBytes());
|
|
|
- }
|
|
|
-
|
|
|
- // todo
|
|
|
- // offlineExamService.batchSubmitPaper(examRecordDataId, resultFiles, fileType);
|
|
|
-
|
|
|
- User user = getAccessUser();
|
|
|
- ReportsUtil.report(new AdminOperateReport(user.getRootOrgId(), user.getUserId(), "考试进度详情-上传作答",
|
|
|
- "考试记录ID:" + examRecordDataId + " 考生ID:" + examRecordData.getExamStudentId()));
|
|
|
- }
|
|
|
-
|
|
|
- private boolean matchFileTypes(String[] settingFileTypes, String fileSuffix) {
|
|
|
- if (ArrayUtils.isEmpty(settingFileTypes) || StringUtils.isEmpty(fileSuffix)) {
|
|
|
- return false;
|
|
|
+ String fileSuffix = FileUtil.getFileSuffix(file.getOriginalFilename());
|
|
|
+ FileInfo fileInfo = new FileInfo();
|
|
|
+ fileInfo.setOriginalFileName(file.getOriginalFilename());
|
|
|
+ fileInfo.setFileBytes(file.getBytes());
|
|
|
+ fileInfo.setFileSize(file.getSize());
|
|
|
+ fileInfo.setFileSuffix(fileSuffix);
|
|
|
+ fileInfo.setMd5(realMD5);
|
|
|
+ fileInfoList.add(fileInfo);
|
|
|
}
|
|
|
|
|
|
- for (String fileType : settingFileTypes) {
|
|
|
- if ("IMAGE".equals(fileType)) {
|
|
|
- if (".jpg.jpeg.png".contains(fileSuffix)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- } else {
|
|
|
- // ZIP、PDF
|
|
|
- if (("." + fileType).equalsIgnoreCase(fileSuffix)) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
+ offlineExamService.batchSubmitPaper(examRecordDataId, fileInfoList, fileType, user.getUserId());
|
|
|
}
|
|
|
|
|
|
}
|