|
@@ -7,6 +7,7 @@ import java.util.Objects;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.io.FilenameUtils;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
@@ -51,7 +52,7 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
queryWrapper.lambda().eq(MarkDocument::getExamId, examId)
|
|
queryWrapper.lambda().eq(MarkDocument::getExamId, examId)
|
|
.eq(MarkDocument::getPaperNumber, paperNumber);
|
|
.eq(MarkDocument::getPaperNumber, paperNumber);
|
|
List<MarkDocument> list = this.list(queryWrapper);
|
|
List<MarkDocument> list = this.list(queryWrapper);
|
|
- for (MarkDocument d:list) {
|
|
|
|
|
|
+ for (MarkDocument d : list) {
|
|
d.setFilePath(teachcloudCommonService.filePreview(d.getFilePath()));
|
|
d.setFilePath(teachcloudCommonService.filePreview(d.getFilePath()));
|
|
}
|
|
}
|
|
return list;
|
|
return list;
|
|
@@ -60,26 +61,26 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
@Override
|
|
@Override
|
|
public String importById(Long id, MultipartFile file, String md5) {
|
|
public String importById(Long id, MultipartFile file, String md5) {
|
|
MarkDocument document = this.getById(id);
|
|
MarkDocument document = this.getById(id);
|
|
- 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)){
|
|
|
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)
|
|
|
|
+ || document.getType().equals(DocumentType.SYLLABUS)
|
|
|
|
+ || document.getType().equals(DocumentType.PROCESS_SCORE)) {
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
|
|
|
+ String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
if (!Objects.equals(fileMd5, md5)) {
|
|
if (!Objects.equals(fileMd5, md5)) {
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
}
|
|
}
|
|
String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
String name = document.getType().getName();
|
|
String name = document.getType().getName();
|
|
- if(document.getType().equals(DocumentType.CUSTOM)){
|
|
|
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
name = document.getName();
|
|
name = document.getName();
|
|
}
|
|
}
|
|
String path = markFileService.uploadDocument(file.getInputStream(),
|
|
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<MarkDocument> updateWrapper = new UpdateWrapper<>();
|
|
updateWrapper.lambda().set(MarkDocument::getFilePath, path)
|
|
updateWrapper.lambda().set(MarkDocument::getFilePath, path)
|
|
.set(MarkDocument::getFileCount, 1)
|
|
.set(MarkDocument::getFileCount, 1)
|
|
@@ -95,10 +96,10 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
@Override
|
|
@Override
|
|
public void deleteById(Long id) {
|
|
public void deleteById(Long id) {
|
|
MarkDocument document = this.getById(id);
|
|
MarkDocument document = this.getById(id);
|
|
- if(document==null){
|
|
|
|
|
|
+ if (document == null) {
|
|
throw ExceptionResultEnum.ERROR.exception("文档不存在");
|
|
throw ExceptionResultEnum.ERROR.exception("文档不存在");
|
|
}
|
|
}
|
|
- if(document.getType().equals(DocumentType.CUSTOM)){
|
|
|
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
}
|
|
}
|
|
this.removeById(id);
|
|
this.removeById(id);
|
|
@@ -106,8 +107,8 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public String save(Long examId, String paperNumber, String documentName, MultipartFile file, String md5) {
|
|
public String save(Long examId, String paperNumber, String documentName, MultipartFile file, String md5) {
|
|
- MarkPaper markPaper=markPaperService.getByExamIdAndPaperNumber(examId,paperNumber);
|
|
|
|
- if(markPaper==null || !markPaper.getStatus().equals(MarkPaperStatus.FINISH)){
|
|
|
|
|
|
+ MarkPaper markPaper = markPaperService.getByExamIdAndPaperNumber(examId, paperNumber);
|
|
|
|
+ if (markPaper == null || !markPaper.getStatus().equals(MarkPaperStatus.FINISH)) {
|
|
throw ExceptionResultEnum.ERROR.exception("评卷未结束或试卷不存在");
|
|
throw ExceptionResultEnum.ERROR.exception("评卷未结束或试卷不存在");
|
|
}
|
|
}
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<MarkDocument> queryWrapper = new QueryWrapper<>();
|
|
@@ -115,8 +116,8 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
.eq(MarkDocument::getPaperNumber, paperNumber)
|
|
.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){
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception(documentName+"已存在");
|
|
|
|
|
|
+ if (document != null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(documentName + "已存在");
|
|
}
|
|
}
|
|
document = new MarkDocument();
|
|
document = new MarkDocument();
|
|
document.setExamId(examId);
|
|
document.setExamId(examId);
|
|
@@ -127,17 +128,17 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
document.setName(documentName);
|
|
document.setName(documentName);
|
|
document.setFileCount(1);
|
|
document.setFileCount(1);
|
|
try {
|
|
try {
|
|
- String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
|
|
|
+ String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
if (!Objects.equals(fileMd5, md5)) {
|
|
if (!Objects.equals(fileMd5, md5)) {
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
throw ExceptionResultEnum.MD5_EQUALS_FALSE.exception();
|
|
}
|
|
}
|
|
String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
String name = document.getType().getName();
|
|
String name = document.getType().getName();
|
|
- if(document.getType().equals(DocumentType.CUSTOM)){
|
|
|
|
|
|
+ if (document.getType().equals(DocumentType.CUSTOM)) {
|
|
name = document.getName();
|
|
name = document.getName();
|
|
}
|
|
}
|
|
String path = markFileService.uploadDocument(file.getInputStream(),
|
|
String path = markFileService.uploadDocument(file.getInputStream(),
|
|
- md5,examId,paperNumber,String.valueOf(document.getType().getValue()),documentName,format);
|
|
|
|
|
|
+ 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);
|
|
@@ -146,4 +147,16 @@ public class MarkDocumentServiceImpl extends ServiceImpl<MarkDocumentMapper, Mar
|
|
throw new ParameterException("文件上传失败", e);
|
|
throw new ParameterException("文件上传失败", e);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void initMarkDocument(MarkPaper markPaper) {
|
|
|
|
+ List<MarkDocument> markDocumentList = this.listByExamIdAndPaperNumber(markPaper.getExamId(), markPaper.getPaperNumber());
|
|
|
|
+ if (CollectionUtils.isEmpty(markDocumentList)) {
|
|
|
|
+ for (DocumentType documentType : DocumentType.getOptionList(false)) {
|
|
|
|
+ MarkDocument markDocument = new MarkDocument(markPaper.getExamId(), markPaper.getCourseCode(), markPaper.getCourseName(), markPaper.getPaperNumber(), documentType, documentType.getName());
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|