|
@@ -61,35 +61,38 @@ 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)) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
|
|
- }
|
|
|
|
- try {
|
|
|
|
- String fileMd5 = DigestUtils.md5Hex(file.getBytes());
|
|
|
|
- if (!Objects.equals(fileMd5, md5)) {
|
|
|
|
- throw ExceptionResultEnum.MD5_EQUALS_FALSE.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)){
|
|
|
|
+ try {
|
|
|
|
+ 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)){
|
|
|
|
+ name = document.getName();
|
|
|
|
+ }
|
|
|
|
+ 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.lambda().set(MarkDocument::getFilePath, path)
|
|
|
|
+ .set(MarkDocument::getFileCount, 1)
|
|
|
|
+ .eq(MarkDocument::getId, id);
|
|
|
|
+ this.update(updateWrapper);
|
|
|
|
+ return teachcloudCommonService.filePreview(path);
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ throw new ParameterException("上传失败", e);
|
|
}
|
|
}
|
|
- String format = FilenameUtils.getExtension(file.getOriginalFilename());
|
|
|
|
- String name = document.getType().getName();
|
|
|
|
- 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);
|
|
|
|
- UpdateWrapper<MarkDocument> updateWrapper = new UpdateWrapper<>();
|
|
|
|
- updateWrapper.lambda().set(MarkDocument::getFilePath, path)
|
|
|
|
- .set(MarkDocument::getFileCount, 1)
|
|
|
|
- .eq(MarkDocument::getId, id);
|
|
|
|
- this.update(updateWrapper);
|
|
|
|
- return teachcloudCommonService.filePreview(path);
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
- throw new ParameterException("原图上传失败", e);
|
|
|
|
|
|
+ }else{
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -99,7 +102,7 @@ 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)) {
|
|
|
|
|
|
+ if (!document.getType().equals(DocumentType.CUSTOM)) {
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
|
|
}
|
|
}
|
|
this.removeById(id);
|
|
this.removeById(id);
|