|
@@ -1,14 +1,18 @@
|
|
|
package com.qmth.teachcloud.mark.service.impl;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
+import com.qmth.teachcloud.mark.entity.ScanPackage;
|
|
|
+import com.qmth.teachcloud.mark.service.ScanPackageService;
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
import org.apache.commons.collections4.CollectionUtils;
|
|
|
import org.apache.commons.io.FilenameUtils;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
@@ -42,9 +46,10 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
|
private MarkFileService markFileService;
|
|
|
@Resource
|
|
|
private TeachcloudCommonService teachcloudCommonService;
|
|
|
-
|
|
|
@Resource
|
|
|
private MarkPaperService markPaperService;
|
|
|
+ @Resource
|
|
|
+ private ScanPackageService scanPackageService;
|
|
|
|
|
|
@Override
|
|
|
public List<MarkDocument> listByExamIdAndPaperNumber(Long examId, String paperNumber) {
|
|
@@ -61,26 +66,26 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
|
@Override
|
|
|
public String importById(Long id, MultipartFile file, String md5) {
|
|
|
MarkDocument document = this.getById(id);
|
|
|
- if(document==null){
|
|
|
+ if (document == null) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("文档不存在");
|
|
|
}
|
|
|
- if(document.getType().equals(DocumentType.CUSTOM)
|
|
|
- ||document.getType().equals(DocumentType.SYLLABUS)
|
|
|
- ||document.getType().equals(DocumentType.PROCESS_SCORE)
|
|
|
- ||document.getType().equals(DocumentType.PAPER_REPORT)
|
|
|
- ||document.getType().equals(DocumentType.CHECK_IN)){
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)
|
|
|
+ || document.getType().equals(DocumentType.SYLLABUS)
|
|
|
+ || document.getType().equals(DocumentType.PROCESS_SCORE)
|
|
|
+ || document.getType().equals(DocumentType.PAPER_REPORT)
|
|
|
+ || document.getType().equals(DocumentType.CHECK_IN)) {
|
|
|
try {
|
|
|
- String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
+ String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
if (!Objects.equals(fileMd5, md5)) {
|
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
|
}
|
|
|
String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
String name = document.getType().getName();
|
|
|
- if(document.getType().equals(DocumentType.CUSTOM)){
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
|
name = document.getName();
|
|
|
}
|
|
|
String path = markFileService.uploadDocument(file.getInputStream(),
|
|
|
- md5,document.getExamId(),document.getPaperNumber(),String.valueOf(document.getType().getValue()),document.getName(),format);
|
|
|
+ md5, document.getExamId(), document.getPaperNumber(), String.valueOf(document.getType().getValue()), document.getName(), format);
|
|
|
UpdateWrapper<MarkDocument> updateWrapper = new UpdateWrapper<>();
|
|
|
updateWrapper.lambda().set(MarkDocument::getFilePath, path)
|
|
|
.set(MarkDocument::getFileCount, 1)
|
|
@@ -91,7 +96,7 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
|
throw new ParameterException("上传失败", e);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
|
}
|
|
|
}
|
|
@@ -155,11 +160,40 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
|
public void initMarkDocument(MarkPaper markPaper) {
|
|
|
List<MarkDocument> markDocumentList = this.listByExamIdAndPaperNumber(markPaper.getExamId(), markPaper.getPaperNumber());
|
|
|
if (CollectionUtils.isEmpty(markDocumentList)) {
|
|
|
+ List<MarkDocument> markDocuments = new ArrayList<>();
|
|
|
for (DocumentType documentType : DocumentType.getOptionList(false)) {
|
|
|
- MarkDocument markDocument = new MarkDocument(markPaper.getExamId(), markPaper.getCourseCode(), markPaper.getCourseName(), markPaper.getPaperNumber(), documentType, documentType.getName());
|
|
|
- }
|
|
|
- } else {
|
|
|
+ MarkDocument markDocument = new MarkDocument(markPaper.getExamId(), markPaper.getCourseCode(), markPaper.getCourseName(), markPaper.getPaperNumber(), documentType, documentType.getName(), 0);
|
|
|
+ if (documentType.equals(DocumentType.PAPER)) {
|
|
|
+ if (StringUtils.isNotBlank(markPaper.getPaperFilePath())) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ markDocument.setFilePath(markPaper.getPaperFilePath());
|
|
|
+ }
|
|
|
+ } else if (documentType.equals(DocumentType.ANSWER)) {
|
|
|
+ if (StringUtils.isNotBlank(markPaper.getAnswerFilePath())) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ markDocument.setFilePath(markPaper.getAnswerFilePath());
|
|
|
+ }
|
|
|
+ } else if (documentType.equals(DocumentType.PAPER_REPORT)) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ } else if (documentType.equals(DocumentType.APPROVE_RECORD)) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ } else if (documentType.equals(DocumentType.SCORE)) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ } else if (documentType.equals(DocumentType.SCORE_REPORT)) {
|
|
|
+ markDocument.setFileCount(1);
|
|
|
+ } else if (documentType.equals(DocumentType.SHEET)) {
|
|
|
+ markDocument.setFileCount(markPaper.getUploadCount());
|
|
|
+ } else if (documentType.equals(DocumentType.TRACK)) {
|
|
|
+ markDocument.setFileCount(markPaper.getUploadCount());
|
|
|
+ } else if (documentType.equals(DocumentType.SIGN)) {
|
|
|
+ List<ScanPackage> scanPackageList = scanPackageService.listByExamIdAndCoursePaperIdAndPackageCode(markPaper.getExamId(), markPaper.getCoursePaperId(), null);
|
|
|
+ markDocument.setFileCount(scanPackageList.size());
|
|
|
+ } else if (documentType.equals(DocumentType.CHECK_IN)) {
|
|
|
|
|
|
+ }
|
|
|
+ markDocuments.add(markDocument);
|
|
|
+ }
|
|
|
+ this.saveBatch(markDocuments);
|
|
|
}
|
|
|
}
|
|
|
}
|