Selaa lähdekoodia

归档文件验证

yin 1 vuosi sitten
vanhempi
commit
631c594c7e

+ 4 - 4
distributed-print/src/main/java/com/qmth/distributed/print/api/mark/MarkDocumentController.java

@@ -67,7 +67,7 @@ public class MarkDocumentController {
     public Result importFile(@ApiParam(value = "文档ID", required = true) Long id,
                            @ApiParam(value = "文件md5", required = true) String md5,
                            @ApiParam(value = "文件", required = true) @RequestParam MultipartFile file) {
-        return ResultUtil.ok(markDocumentService.importById(id, file, md5),"");
+        return ResultUtil.ok(markDocumentService.importById(id, file, md5));
     }
 
     @ApiOperation(value = "文档新建")
@@ -77,14 +77,14 @@ public class MarkDocumentController {
                        @ApiParam(value = "文档ID", required = true) String documentName,
                        @ApiParam(value = "文件md5", required = true) String md5,
                        @ApiParam(value = "文件", required = true) @RequestParam MultipartFile file) {
-        return ResultUtil.ok(markDocumentService.save(examId, paperNumber,documentName, file,md5),"");
+        return ResultUtil.ok(markDocumentService.save(examId, paperNumber,documentName, file,md5));
     }
 
     @ApiOperation(value = "文档删除")
     @RequestMapping(value = "/delete", method = RequestMethod.POST)
-    public void delete(@ApiParam(value = "文档ID", required = true) Long id) {
+    public Result delete(@ApiParam(value = "文档ID", required = true) Long id) {
         markDocumentService.deleteById(id);
-        ResultUtil.ok(true);
+        return ResultUtil.ok(true);
     }
 
     @ApiOperation(value = "文档下载")

+ 30 - 27
teachcloud-mark/src/main/java/com/qmth/teachcloud/mark/service/impl/MarkDocumentServiceImpl.java

@@ -61,35 +61,38 @@ 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)) {
-            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) {
             throw ExceptionResultEnum.ERROR.exception("文档不存在");
         }
-        if (document.getType().equals(DocumentType.CUSTOM)) {
+        if (!document.getType().equals(DocumentType.CUSTOM)) {
             throw ExceptionResultEnum.ERROR.exception("文档类型不正确");
         }
         this.removeById(id);