浏览代码

解决新建文件和文件协作的BUG

wukai 1 年之前
父节点
当前提交
234da206c3

+ 8 - 10
doc-biz/src/main/java/com/doc/biz/controller/DocInfoController.java

@@ -19,14 +19,12 @@ import com.doc.common.utils.poi.ExcelUtil;
 import io.swagger.annotations.*;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.data.elasticsearch.NoSuchIndexException;
-import org.springframework.util.ResourceUtils;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
 import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -125,34 +123,34 @@ public class DocInfoController extends BaseController {
     })
     public AjaxResult create(Long spaceId, Long dirId, String type) {
         try {
-            File file = null;
+            String filePath = "";
             String fileName = "";
             switch (type) {
                 case "word":
-                    file = ResourceUtils.getFile("classpath:file/new.docx");
+                    filePath = "file/new.docx";
                     fileName = "新建word文档.docx";
                     break;
                 case "excel":
-                    file = ResourceUtils.getFile("classpath:file/new.xlsx");
+                    filePath = "file/new.xlsx";
                     fileName = "新建Excel文档.xlsx";
                     break;
                 case "ppt":
-                    file = ResourceUtils.getFile("classpath:file/new.pptx");
+                    filePath = "file/new.pptx";
                     fileName = "新建ppt文档.pptx";
                     break;
                 case "txt":
-                    file = ResourceUtils.getFile("classpath:file/new.txt");
+                    filePath = "file/new.txt";
                     fileName = "新建文本文档.txt";
                     break;
             }
 
-            FileInputStream is = new FileInputStream(file);
+            InputStream is = this.getClass().getResourceAsStream("/" + filePath);
             MultipartFile multipartFile = FileUtils.getMultipartFile(is, fileName);
             DocumentVO vo = mongoService.uploadFile(multipartFile);
             process(vo, spaceId, dirId);
             return success();
         } catch (Exception e) {
-            log.error("新建文件出错啦", e.getMessage());
+            log.error("新建文件出错啦:{}", e.getMessage());
             return error("新建文件出错");
         }
     }

+ 3 - 1
doc-biz/src/main/java/com/doc/biz/service/impl/ElasticSearchServiceImpl.java

@@ -2,7 +2,6 @@ package com.doc.biz.service.impl;
 
 import com.doc.biz.domain.DocInfo;
 import com.doc.biz.domain.EsDocInfo;
-import com.doc.biz.mapper.DocInfoMapper;
 import com.doc.biz.service.IElasticSearchService;
 import com.doc.biz.service.IEsDocInfoService;
 import com.doc.biz.service.IMongoService;
@@ -38,6 +37,9 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
      */
     @Override
     public void save(DocInfo info) {
+        if (info.getFileSize() == 0) {
+            return;
+        }
         Map<String, Function<byte[], String>> handlerMap = new HashMap<>(16);
         handlerMap.put(".docx", FileContentUtils::getContentDocx);
         handlerMap.put(".doc", FileContentUtils::getContentDoc);

+ 1 - 1
doc-biz/src/main/resources/mapper/biz/DocActorMapper.xml

@@ -42,7 +42,7 @@
         from doc_info a,
              doc_actor b
         where a.doc_id = b.doc_id
-          and doc_id in (select doc_id from doc_actor_user where user_id = #{userId})
+          and b.doc_id in (select doc_id from doc_actor_user where user_id = #{userId})
     </select>
 
     <insert id="insertDocActor" parameterType="DocActor">