|
@@ -3,6 +3,9 @@ package cn.com.qmth.examcloud.core.oe.admin.service.impl;
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamSpecialSettingsType;
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
import cn.com.qmth.examcloud.api.commons.enums.ExamType;
|
|
import cn.com.qmth.examcloud.commons.exception.StatusException;
|
|
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.base.Constants;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.admin.base.utils.Check;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordDataRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordFileAnswerRepo;
|
|
import cn.com.qmth.examcloud.core.oe.admin.dao.ExamRecordFileAnswerRepo;
|
|
@@ -20,6 +23,8 @@ import cn.com.qmth.examcloud.core.oe.admin.service.bean.uploadfile.FileInfo;
|
|
import cn.com.qmth.examcloud.core.questions.api.ExtractConfigCloudService;
|
|
import cn.com.qmth.examcloud.core.questions.api.ExtractConfigCloudService;
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetPaperReq;
|
|
import cn.com.qmth.examcloud.core.questions.api.request.GetPaperReq;
|
|
import cn.com.qmth.examcloud.core.questions.api.response.GetPaperResp;
|
|
import cn.com.qmth.examcloud.core.questions.api.response.GetPaperResp;
|
|
|
|
+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.CacheHelper;
|
|
import cn.com.qmth.examcloud.support.cache.CacheHelper;
|
|
import cn.com.qmth.examcloud.support.cache.bean.*;
|
|
import cn.com.qmth.examcloud.support.cache.bean.*;
|
|
import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
import cn.com.qmth.examcloud.support.enums.ExamProperties;
|
|
@@ -28,6 +33,8 @@ import cn.com.qmth.examcloud.support.helper.ExamCacheTransferHelper;
|
|
import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
import cn.com.qmth.examcloud.web.filestorage.FileStoragePathEnvInfo;
|
|
import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
import cn.com.qmth.examcloud.web.filestorage.YunPathInfo;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
import cn.com.qmth.examcloud.web.helpers.GlobalHelper;
|
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -39,6 +46,7 @@ import java.io.File;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @author chenken
|
|
* @author chenken
|
|
@@ -263,7 +271,7 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
- public void submitPaper(Long examRecordDataId, FileInfo fileInfo) throws Exception {
|
|
|
|
|
|
+ public void submitPaper(Long examRecordDataId, FileInfo fileInfo, Long userId) {
|
|
Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
Check.isNull(examRecordDataId, "examRecordDataId不能为空");
|
|
|
|
|
|
SysPropertyCacheBean stuClientLoginLimit = CacheHelper.getSysProperty("STU_CLIENT_LOGIN_LIMIT");
|
|
SysPropertyCacheBean stuClientLoginLimit = CacheHelper.getSysProperty("STU_CLIENT_LOGIN_LIMIT");
|
|
@@ -275,12 +283,41 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
throw new StatusException("4001", "系统维护中... ...");
|
|
throw new StatusException("4001", "系统维护中... ...");
|
|
}
|
|
}
|
|
|
|
|
|
- ExamRecordDataEntity examRecordData = GlobalHelper.getEntity(examRecordDataRepo, examRecordDataId, ExamRecordDataEntity.class);
|
|
|
|
- if (examRecordData == null) {
|
|
|
|
- return;
|
|
|
|
|
|
+ if (!FileUtil.checkFileSuffix("jpg|jpeg|png|pdf|zip", fileInfo.getFileSuffix())) {
|
|
|
|
+ throw new StatusException("400401", "文件格式不正确");
|
|
}
|
|
}
|
|
|
|
|
|
- //上传文件至又拍云
|
|
|
|
|
|
+ if (fileInfo.getFileSize() > Constants.ANSWER_FILE_MAX_SIZE * Constants.M_SIZE) {
|
|
|
|
+ throw new StatusException("400402", "文件大小不能超过" + Constants.ANSWER_FILE_MAX_SIZE + "M");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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", "当前考试设置不允许上传附件");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (!matchFileTypes(settingFileTypes, fileInfo.getFileSuffix())) {
|
|
|
|
+ throw new StatusException("400403", "当前考试允许上传文件格式为:" + examProperty.getValue());
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 上传文件
|
|
ExamRecordDataBean bean = of(examRecordData);
|
|
ExamRecordDataBean bean = of(examRecordData);
|
|
String fileNewName = createOfflineFileName(bean) + fileInfo.getFileSuffix();
|
|
String fileNewName = createOfflineFileName(bean) + fileInfo.getFileSuffix();
|
|
String relativePath = upyunUploadUrl + examRecordData.getExamId() + "/" + fileNewName;
|
|
String relativePath = upyunUploadUrl + examRecordData.getExamId() + "/" + fileNewName;
|
|
@@ -294,10 +331,13 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
examRecordForMarkingService.saveOffLineExamRecordForMarking(bean, fileNewName, pi.getRelativePath());
|
|
examRecordForMarkingService.saveOffLineExamRecordForMarking(bean, fileNewName, pi.getRelativePath());
|
|
|
|
|
|
saveExamRecordFileAnswer(examRecordDataId, fileInfo.getOriginalFileName(), fileNewName, pi.getRelativePath(),
|
|
saveExamRecordFileAnswer(examRecordDataId, fileInfo.getOriginalFileName(), fileNewName, pi.getRelativePath(),
|
|
- fileInfo.getFileType().toLowerCase(), fileInfo.getFileSuffix().toLowerCase());
|
|
|
|
|
|
+ fileInfo.getFileType().toLowerCase(), fileInfo.getFileSuffix().replaceFirst(".", ""));
|
|
|
|
|
|
//更新考试记录状态,交卷(上传)时间
|
|
//更新考试记录状态,交卷(上传)时间
|
|
examRecordDataRepo.updateExamRecordStatusById(examRecordDataId, ExamRecordStatus.EXAM_END, new Date());
|
|
examRecordDataRepo.updateExamRecordStatusById(examRecordDataId, ExamRecordStatus.EXAM_END, new Date());
|
|
|
|
+
|
|
|
|
+ ReportsUtil.report(new AdminOperateReport(examRecordData.getRootOrgId(), userId, "考试进度详情-上传作答",
|
|
|
|
+ "考试记录ID:" + examRecordDataId + " 考生ID:" + examRecordData.getExamStudentId()));
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -369,6 +409,26 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private boolean matchFileTypes(String[] settingFileTypes, String fileSuffix) {
|
|
|
|
+ if (ArrayUtils.isEmpty(settingFileTypes) || StringUtils.isEmpty(fileSuffix)) {
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* 保存考试记录文件作答
|
|
* 保存考试记录文件作答
|
|
*
|
|
*
|