|
@@ -33,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 com.google.common.collect.Lists;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.commons.lang3.ArrayUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -272,6 +274,31 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
@Override
|
|
@Override
|
|
@Transactional
|
|
@Transactional
|
|
public void submitPaper(Long examRecordDataId, FileInfo fileInfo, Long userId) {
|
|
public void submitPaper(Long examRecordDataId, FileInfo fileInfo, Long userId) {
|
|
|
|
+ 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");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String fileType;
|
|
|
|
+ if (".zip".equals(fileInfo.getFileSuffix())) {
|
|
|
|
+ fileType = "ZIP";
|
|
|
|
+ } else if (".pdf".equals(fileInfo.getFileSuffix())) {
|
|
|
|
+ fileType = "PDF";
|
|
|
|
+ } else if (".jpg.jpeg.png".contains(fileInfo.getFileSuffix())) {
|
|
|
|
+ fileType = "IMAGE";
|
|
|
|
+ } else {
|
|
|
|
+ fileType = "UNKNOWN";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.batchSubmitPaper(examRecordDataId, Lists.newArrayList(fileInfo), fileType, userId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ @Transactional
|
|
|
|
+ public void batchSubmitPaper(Long examRecordDataId, List<FileInfo> fileInfoList, String fileType, 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");
|
|
@@ -283,14 +310,6 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
throw new StatusException("4001", "系统维护中... ...");
|
|
throw new StatusException("4001", "系统维护中... ...");
|
|
}
|
|
}
|
|
|
|
|
|
- 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);
|
|
Optional<ExamRecordDataEntity> optional = examRecordDataRepo.findById(examRecordDataId);
|
|
if (!optional.isPresent()) {
|
|
if (!optional.isPresent()) {
|
|
throw new StatusException("400403", "考试记录不存在");
|
|
throw new StatusException("400403", "考试记录不存在");
|
|
@@ -313,25 +332,50 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
throw new StatusException("400403", "当前考试设置不允许上传附件");
|
|
throw new StatusException("400403", "当前考试设置不允许上传附件");
|
|
}
|
|
}
|
|
|
|
|
|
- if (!matchFileTypes(settingFileTypes, fileInfo.getFileSuffix())) {
|
|
|
|
|
|
+ String uploadFileType = fileType.toUpperCase();
|
|
|
|
+ if (!ArrayUtils.contains(settingFileTypes, uploadFileType)) {
|
|
throw new StatusException("400403", "当前考试允许上传文件格式为:" + examProperty.getValue());
|
|
throw new StatusException("400403", "当前考试允许上传文件格式为:" + examProperty.getValue());
|
|
}
|
|
}
|
|
|
|
|
|
- // 上传文件
|
|
|
|
|
|
+ if (("ZIP".equals(uploadFileType) || "PDF".equals(uploadFileType)) && fileInfoList.size() > 1) {
|
|
|
|
+ throw new StatusException("400403", "上传" + uploadFileType + "类型文件时只能传一个文件");
|
|
|
|
+ }
|
|
|
|
+
|
|
ExamRecordDataBean bean = of(examRecordData);
|
|
ExamRecordDataBean bean = of(examRecordData);
|
|
- String fileNewName = createOfflineFileName(bean) + fileInfo.getFileSuffix();
|
|
|
|
- String relativePath = upyunUploadUrl + examRecordData.getExamId() + "/" + fileNewName;
|
|
|
|
|
|
|
|
- //通用存储
|
|
|
|
- FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
|
- env.setRootOrgId(String.valueOf(bean.getRootOrgId()));
|
|
|
|
- env.setRelativePath(relativePath);
|
|
|
|
- YunPathInfo pi = FileStorageUtil.saveFile("offlineFile", env, fileInfo.getFileBytes(), false);
|
|
|
|
|
|
+ // 上传文件
|
|
|
|
+ for (FileInfo fileInfo : fileInfoList) {
|
|
|
|
+ String fileNewName = createOfflineFileName(bean) + fileInfo.getFileSuffix();
|
|
|
|
+ String relativePath = upyunUploadUrl + examRecordData.getExamId() + "/" + fileNewName;
|
|
|
|
+
|
|
|
|
+ FileStoragePathEnvInfo env = new FileStoragePathEnvInfo();
|
|
|
|
+ env.setRootOrgId(String.valueOf(examRecordData.getRootOrgId()));
|
|
|
|
+ env.setRelativePath(relativePath);
|
|
|
|
+ YunPathInfo uploadResult = FileStorageUtil.saveFile("offlineFile", env, fileInfo.getFileBytes(), false);
|
|
|
|
+
|
|
|
|
+ fileInfo.setFilePath(uploadResult.getRelativePath());
|
|
|
|
+ fileInfo.setFileName(fileNewName);
|
|
|
|
+ fileInfo.setFileType(fileType);
|
|
|
|
+ }
|
|
|
|
|
|
- examRecordForMarkingService.saveOffLineExamRecordForMarking(bean, fileNewName, pi.getRelativePath());
|
|
|
|
|
|
+ // 删除原作答文件记录
|
|
|
|
+ List<ExamRecordFileAnswerEntity> fileAnswerList = examRecordFileAnswerRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(fileAnswerList)) {
|
|
|
|
+ for (ExamRecordFileAnswerEntity fileAnswer : fileAnswerList) {
|
|
|
|
+ examRecordFileAnswerRepo.delete(fileAnswer);
|
|
|
|
+ FileStorageUtil.deleteFile(fileAnswer.getFileUrl());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 保存新作答文件记录
|
|
|
|
+ for (FileInfo fileInfo : fileInfoList) {
|
|
|
|
+ saveExamRecordFileAnswer(examRecordDataId, fileInfo.getOriginalFileName(), fileInfo.getFileName(), fileInfo.getFilePath(),
|
|
|
|
+ fileInfo.getFileType().toLowerCase(), fileInfo.getFileSuffix().replaceFirst(".", ""));
|
|
|
|
+ }
|
|
|
|
|
|
- saveExamRecordFileAnswer(examRecordDataId, fileInfo.getOriginalFileName(), fileNewName, pi.getRelativePath(),
|
|
|
|
- fileInfo.getFileType().toLowerCase(), fileInfo.getFileSuffix().replaceFirst(".", ""));
|
|
|
|
|
|
+ fileInfoList.clear();
|
|
|
|
+
|
|
|
|
+ examRecordForMarkingService.saveOffLineExamRecordForMarking(bean);
|
|
|
|
|
|
//更新考试记录状态,交卷(上传)时间
|
|
//更新考试记录状态,交卷(上传)时间
|
|
examRecordDataRepo.updateExamRecordStatusById(examRecordDataId, ExamRecordStatus.EXAM_END, new Date());
|
|
examRecordDataRepo.updateExamRecordStatusById(examRecordDataId, ExamRecordStatus.EXAM_END, new Date());
|
|
@@ -439,18 +483,8 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
* @param fileType
|
|
* @param fileType
|
|
* @param fileSuffix
|
|
* @param fileSuffix
|
|
*/
|
|
*/
|
|
- private void saveExamRecordFileAnswer(Long examRecordDataId, String originalFileName,
|
|
|
|
- String fileName, String relativePath,
|
|
|
|
- String fileType, String fileSuffix) {
|
|
|
|
- //删除原文件
|
|
|
|
- List<ExamRecordFileAnswerEntity> fileAnswerList = examRecordFileAnswerRepo.findByExamRecordDataId(examRecordDataId);
|
|
|
|
- if (null != fileAnswerList && !fileAnswerList.isEmpty()) {
|
|
|
|
- for (ExamRecordFileAnswerEntity erfa : fileAnswerList) {
|
|
|
|
- examRecordFileAnswerRepo.deleteById(erfa.getId());
|
|
|
|
- FileStorageUtil.deleteFile(erfa.getFileUrl());
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ private void saveExamRecordFileAnswer(Long examRecordDataId, String originalFileName, String fileName,
|
|
|
|
+ String relativePath, String fileType, String fileSuffix) {
|
|
ExamRecordFileAnswerEntity entity = new ExamRecordFileAnswerEntity();
|
|
ExamRecordFileAnswerEntity entity = new ExamRecordFileAnswerEntity();
|
|
entity.setExamRecordDataId(examRecordDataId);
|
|
entity.setExamRecordDataId(examRecordDataId);
|
|
entity.setOriginalFileName(originalFileName);
|
|
entity.setOriginalFileName(originalFileName);
|
|
@@ -461,7 +495,6 @@ public class OfflineExamServiceImpl implements OfflineExamService {
|
|
examRecordFileAnswerRepo.save(entity);
|
|
examRecordFileAnswerRepo.save(entity);
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
private String createOfflineFileName(ExamRecordDataBean examRecordData) {
|
|
private String createOfflineFileName(ExamRecordDataBean examRecordData) {
|
|
long currentTime = System.currentTimeMillis();
|
|
long currentTime = System.currentTimeMillis();
|
|
|
|
|