|
@@ -1,37 +1,42 @@
|
|
package com.qmth.teachcloud.mark.service.impl;
|
|
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.common.entity.BasicExam;
|
|
|
|
-import com.qmth.teachcloud.common.enums.ExamModelEnum;
|
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
-import org.apache.commons.io.FilenameUtils;
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
-import org.springframework.stereotype.Service;
|
|
|
|
-import org.springframework.web.multipart.MultipartFile;
|
|
|
|
-
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
|
|
+import com.qmth.boot.tools.io.ZipWriter;
|
|
|
|
+import com.qmth.teachcloud.common.bean.vo.FilePathVo;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.teachcloud.common.entity.BasicExam;
|
|
|
|
+import com.qmth.teachcloud.common.enums.ExamModelEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.ExceptionResultEnum;
|
|
import com.qmth.teachcloud.common.enums.mark.MarkPaperStatus;
|
|
import com.qmth.teachcloud.common.enums.mark.MarkPaperStatus;
|
|
|
|
+import com.qmth.teachcloud.common.service.FileUploadService;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
import com.qmth.teachcloud.common.service.TeachcloudCommonService;
|
|
|
|
+import com.qmth.teachcloud.mark.bean.archivescore.ArchiveStudentQuery;
|
|
import com.qmth.teachcloud.mark.entity.MarkDocument;
|
|
import com.qmth.teachcloud.mark.entity.MarkDocument;
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
import com.qmth.teachcloud.mark.entity.MarkPaper;
|
|
import com.qmth.teachcloud.mark.entity.ScanPackage;
|
|
import com.qmth.teachcloud.mark.entity.ScanPackage;
|
|
import com.qmth.teachcloud.mark.enums.DocumentType;
|
|
import com.qmth.teachcloud.mark.enums.DocumentType;
|
|
import com.qmth.teachcloud.mark.mapper.MarkDocumentMapper;
|
|
import com.qmth.teachcloud.mark.mapper.MarkDocumentMapper;
|
|
-import com.qmth.teachcloud.mark.service.MarkDocumentService;
|
|
|
|
-import com.qmth.teachcloud.mark.service.MarkFileService;
|
|
|
|
-import com.qmth.teachcloud.mark.service.MarkPaperService;
|
|
|
|
-import com.qmth.teachcloud.mark.service.ScanPackageService;
|
|
|
|
|
|
+import com.qmth.teachcloud.mark.service.*;
|
|
|
|
+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;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.net.URLEncoder;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.Comparator;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -43,24 +48,31 @@ import com.qmth.teachcloud.mark.service.ScanPackageService;
|
|
*/
|
|
*/
|
|
@Service
|
|
@Service
|
|
public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, MarkDocument> implements MarkDocumentService {
|
|
public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, MarkDocument> implements MarkDocumentService {
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private MarkFileService markFileService;
|
|
private MarkFileService markFileService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private TeachcloudCommonService teachcloudCommonService;
|
|
private TeachcloudCommonService teachcloudCommonService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private MarkPaperService markPaperService;
|
|
private MarkPaperService markPaperService;
|
|
|
|
+
|
|
@Resource
|
|
@Resource
|
|
private ScanPackageService scanPackageService;
|
|
private ScanPackageService scanPackageService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private MarkStudentService markStudentService;
|
|
|
|
+
|
|
|
|
+ @Resource
|
|
|
|
+ private FileUploadService fileUploadService;
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public List<MarkDocument> listByExamIdAndPaperNumber(Long examId, String paperNumber) {
|
|
public List<MarkDocument> listByExamIdAndPaperNumber(Long examId, String paperNumber) {
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
- queryWrapper.lambda().eq(MarkDocument::getExamId, examId)
|
|
|
|
- .eq(MarkDocument::getPaperNumber, paperNumber);
|
|
|
|
|
|
+ queryWrapper.lambda().eq(MarkDocument::getExamId, examId).eq(MarkDocument::getPaperNumber, paperNumber);
|
|
List<MarkDocument> list = this.list(queryWrapper);
|
|
List<MarkDocument> list = this.list(queryWrapper);
|
|
- list.sort((d1, d2) -> {
|
|
|
|
- return d1.getType().getValue() - d2.getType().getValue();
|
|
|
|
- });
|
|
|
|
|
|
+ list.sort(Comparator.comparingInt(d -> d.getType().getValue()));
|
|
for (MarkDocument d : list) {
|
|
for (MarkDocument d : list) {
|
|
d.setFilePath(teachcloudCommonService.filePreview(d.getFilePath()));
|
|
d.setFilePath(teachcloudCommonService.filePreview(d.getFilePath()));
|
|
}
|
|
}
|
|
@@ -73,10 +85,8 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
if (document == null) {
|
|
if (document == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("文档不存在");
|
|
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)
|
|
|
|
|
|
+ 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)) {
|
|
|| document.getType().equals(DocumentType.CHECK_IN)) {
|
|
try {
|
|
try {
|
|
String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
@@ -88,11 +98,10 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
name = document.getName();
|
|
name = document.getName();
|
|
}
|
|
}
|
|
- String path = markFileService.uploadDocument(file.getInputStream(),
|
|
|
|
- md5, document.getExamId(), document.getPaperNumber(), String.valueOf(document.getType().getValue()), document.getName(), format);
|
|
|
|
|
|
+ String path = markFileService.uploadDocument(file.getInputStream(), md5, document.getExamId(), document.getPaperNumber(), String.valueOf(document.getType().getValue()), document.getName(),
|
|
|
|
+ format);
|
|
UpdateWrapper<MarkDocument> updateWrapper = new UpdateWrapper<>();
|
|
UpdateWrapper<MarkDocument> updateWrapper = new UpdateWrapper<>();
|
|
- updateWrapper.lambda().set(MarkDocument::getFilePath, path)
|
|
|
|
- .set(MarkDocument::getFileCount, 1)
|
|
|
|
|
|
+ updateWrapper.lambda().set(MarkDocument::getFilePath, path).set(MarkDocument::getFileCount, 1)
|
|
.eq(MarkDocument::getId, id);
|
|
.eq(MarkDocument::getId, id);
|
|
this.update(updateWrapper);
|
|
this.update(updateWrapper);
|
|
return teachcloudCommonService.filePreview(path);
|
|
return teachcloudCommonService.filePreview(path);
|
|
@@ -124,8 +133,7 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
throw ExceptionResultEnum.ERROR.exception("评卷未结束或试卷不存在");
|
|
throw ExceptionResultEnum.ERROR.exception("评卷未结束或试卷不存在");
|
|
}
|
|
}
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
- queryWrapper.lambda().eq(MarkDocument::getExamId, examId)
|
|
|
|
- .eq(MarkDocument::getPaperNumber, paperNumber)
|
|
|
|
|
|
+ queryWrapper.lambda().eq(MarkDocument::getExamId, examId).eq(MarkDocument::getPaperNumber, paperNumber)
|
|
.eq(MarkDocument::getName, documentName);
|
|
.eq(MarkDocument::getName, documentName);
|
|
MarkDocument document = this.getOne(queryWrapper);
|
|
MarkDocument document = this.getOne(queryWrapper);
|
|
if (document != null) {
|
|
if (document != null) {
|
|
@@ -150,8 +158,8 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
name = document.getName();
|
|
name = document.getName();
|
|
}
|
|
}
|
|
- String path = markFileService.uploadDocument(file.getInputStream(),
|
|
|
|
- md5, examId, paperNumber, String.valueOf(document.getType().getValue()), documentName, format);
|
|
|
|
|
|
+ String path = markFileService.uploadDocument(file.getInputStream(), md5, examId, paperNumber,
|
|
|
|
+ String.valueOf(document.getType().getValue()), documentName, format);
|
|
document.setFilePath(path);
|
|
document.setFilePath(path);
|
|
this.save(document);
|
|
this.save(document);
|
|
return teachcloudCommonService.filePreview(path);
|
|
return teachcloudCommonService.filePreview(path);
|
|
@@ -187,19 +195,21 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
markDocument.setFilePath(markPaper.getAnswerFilePath());
|
|
markDocument.setFilePath(markPaper.getAnswerFilePath());
|
|
}
|
|
}
|
|
} else if (documentType.equals(DocumentType.PAPER_REPORT)) {
|
|
} else if (documentType.equals(DocumentType.PAPER_REPORT)) {
|
|
-// markDocument.setFileCount(1);
|
|
|
|
|
|
+ // markDocument.setFileCount(1);
|
|
} else if (documentType.equals(DocumentType.APPROVE_RECORD)) {
|
|
} else if (documentType.equals(DocumentType.APPROVE_RECORD)) {
|
|
- markDocument.setFileCount(basicExam != null && !ExamModelEnum.MODEL4.equals(basicExam.getExamModel()) ? 1 : 0);
|
|
|
|
|
|
+ markDocument.setFileCount(
|
|
|
|
+ basicExam != null && !ExamModelEnum.MODEL4.equals(basicExam.getExamModel()) ? 1 : 0);
|
|
} else if (documentType.equals(DocumentType.SCORE)) {
|
|
} else if (documentType.equals(DocumentType.SCORE)) {
|
|
markDocument.setFileCount(1);
|
|
markDocument.setFileCount(1);
|
|
} else if (documentType.equals(DocumentType.SCORE_REPORT)) {
|
|
} else if (documentType.equals(DocumentType.SCORE_REPORT)) {
|
|
markDocument.setFileCount(1);
|
|
markDocument.setFileCount(1);
|
|
} else if (documentType.equals(DocumentType.SHEET)) {
|
|
} else if (documentType.equals(DocumentType.SHEET)) {
|
|
markDocument.setFileCount(markPaper.getUploadCount());
|
|
markDocument.setFileCount(markPaper.getUploadCount());
|
|
-// } else if (documentType.equals(DocumentType.TRACK)) {
|
|
|
|
-// markDocument.setFileCount(markPaper.getUploadCount());
|
|
|
|
|
|
+ // } else if (documentType.equals(DocumentType.TRACK)) {
|
|
|
|
+ // markDocument.setFileCount(markPaper.getUploadCount());
|
|
} else if (documentType.equals(DocumentType.SIGN)) {
|
|
} else if (documentType.equals(DocumentType.SIGN)) {
|
|
- List<ScanPackage> scanPackageList = scanPackageService.listByExamIdAndCoursePaperIdAndPackageCode(markPaper.getExamId(), markPaper.getCoursePaperId(), null);
|
|
|
|
|
|
+ List<ScanPackage> scanPackageList = scanPackageService.listByExamIdAndCoursePaperIdAndPackageCode(
|
|
|
|
+ markPaper.getExamId(), markPaper.getCoursePaperId(), null);
|
|
markDocument.setFileCount(scanPackageList.size());
|
|
markDocument.setFileCount(scanPackageList.size());
|
|
} else if (documentType.equals(DocumentType.CHECK_IN)) {
|
|
} else if (documentType.equals(DocumentType.CHECK_IN)) {
|
|
|
|
|
|
@@ -208,4 +218,89 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
}
|
|
}
|
|
this.saveOrUpdateBatch(markDocuments);
|
|
this.saveOrUpdateBatch(markDocuments);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void downloadBatch(Long examId, String paperNumber, HttpServletResponse response) {
|
|
|
|
+ List<MarkDocument> documentList = this.listByExamIdAndPaperNumber(examId, paperNumber);
|
|
|
|
+ try {
|
|
|
|
+ response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("文档管理.zip", "UTF-8"));
|
|
|
|
+ ZipWriter writer = ZipWriter.create(response.getOutputStream());
|
|
|
|
+ ByteArrayOutputStream os = new ByteArrayOutputStream();
|
|
|
|
+
|
|
|
|
+ // 本地保存目录
|
|
|
|
+ File tempFile = SystemConstant.getFileTempParentDirVar(SystemConstant.TEMP_PREFIX);
|
|
|
|
+ String filePath = "";
|
|
|
|
+ for (int i = 0; i < documentList.size(); i++) {
|
|
|
|
+ MarkDocument markDocument = documentList.get(i);
|
|
|
|
+ String path = markDocument.getFilePath();
|
|
|
|
+ String name = i + '-' + markDocument.getName();
|
|
|
|
+ DocumentType documentType = markDocument.getType();
|
|
|
|
+
|
|
|
|
+ switch (documentType) {
|
|
|
|
+ case SYLLABUS:
|
|
|
|
+ case PROCESS_SCORE:
|
|
|
|
+ case PAPER:
|
|
|
|
+ case ANSWER:
|
|
|
|
+ case PAPER_REPORT:
|
|
|
|
+ case CHECK_IN:
|
|
|
|
+ case CUSTOM:
|
|
|
|
+ if (SystemConstant.strNotNull(path)) {
|
|
|
|
+ FilePathVo filePathVo = JSON.parseObject(path, FilePathVo.class);
|
|
|
|
+ String suffix = FilenameUtils.getExtension(filePathVo.getPath());
|
|
|
|
+ filePath = tempFile.getPath() + File.separator + name + "." + suffix;
|
|
|
|
+ File file = fileUploadService.downloadFile(markDocument.getFilePath(), filePath);
|
|
|
|
+ writer.write(file, file.getName());
|
|
|
|
+ file.delete();
|
|
|
|
+ }
|
|
|
|
+ break;
|
|
|
|
+ case APPROVE_RECORD:
|
|
|
|
+ case SCORE_REPORT:
|
|
|
|
+ case SHEET:
|
|
|
|
+ case TRACK:
|
|
|
|
+ break;
|
|
|
|
+ case SCORE:
|
|
|
|
+ ArchiveStudentQuery query = new ArchiveStudentQuery();
|
|
|
|
+ query.setExamId(examId);
|
|
|
|
+ query.setPaperNumber(paperNumber);
|
|
|
|
+
|
|
|
|
+ filePath = tempFile.getPath() + File.separator + name + SystemConstant.EXCEL_PREFIX;
|
|
|
|
+ File file = new File(filePath);
|
|
|
|
+ OutputStream outputStream = new FileOutputStream(file);
|
|
|
|
+ markStudentService.scoreExport(query, outputStream);
|
|
|
|
+ writer.write(file, file.getName());
|
|
|
|
+ file.delete();
|
|
|
|
+ break;
|
|
|
|
+ case SIGN:
|
|
|
|
+ String signClassifyPath = tempFile.getPath() + File.separator + name;
|
|
|
|
+ MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
|
|
|
|
+ if (markPaper == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("试卷不存在");
|
|
|
|
+ }
|
|
|
|
+ QueryWrapper<ScanPackage> wrapper = new QueryWrapper<>();
|
|
|
|
+ LambdaQueryWrapper<ScanPackage> lw = wrapper.lambda();
|
|
|
|
+ lw.eq(ScanPackage::getExamId, examId);
|
|
|
|
+ lw.eq(ScanPackage::getCoursePaperId, markPaper.getCoursePaperId());
|
|
|
|
+ lw.orderByAsc(ScanPackage::getPackageNo);
|
|
|
|
+ List<ScanPackage> scanPackageList = scanPackageService.list(wrapper);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(scanPackageList)) {
|
|
|
|
+ File signClassifyFile = new File(signClassifyPath);
|
|
|
|
+ if (!signClassifyFile.exists()) {
|
|
|
|
+ signClassifyFile.mkdirs();
|
|
|
|
+ }
|
|
|
|
+ for (ScanPackage scanPackage : scanPackageList) {
|
|
|
|
+ FilePathVo filePathVo = JSON.parseObject(scanPackage.getPath(), FilePathVo.class);
|
|
|
|
+ filePath = signClassifyFile.getPath() + File.separator + FilenameUtils.getName(filePathVo.getPath());
|
|
|
|
+ File scanPackageFile = fileUploadService.downloadFile(scanPackage.getPath(), filePath);
|
|
|
|
+ writer.write(scanPackageFile, scanPackageFile.getName());
|
|
|
|
+ scanPackageFile.delete();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ writer.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ throw new ParameterException("文件下载失败", e);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|