Parcourir la source

文档在线编辑之后,ES数据库内容对应修改

wukai il y a 2 ans
Parent
commit
06841dfaea

+ 4 - 1
lzga-common/lzga-common-core/src/main/java/com/jjt/common/core/utils/FileContentUtils.java

@@ -92,10 +92,13 @@ public class FileContentUtils {
                     }
                 }
             }
+        } catch (IllegalArgumentException e) {
+            //做兼容,因为onlyoffice在线编辑时,会将2003的文档保存为word2007的格式。
+            content = new StringBuffer(getContentDocx(file));
         } catch (Exception e) {
-            e.printStackTrace();
             result = "1";
             // 出现异常
+            e.printStackTrace();
         } finally {
             if (is != null) {
                 try {

+ 29 - 18
lzga-modules/lzga-doc/src/main/java/com/jjt/doc/service/impl/DocInfoServiceImpl.java

@@ -112,27 +112,10 @@ public class DocInfoServiceImpl implements IDocInfoService {
             //读取文件内容存储至ES数据库 START
             String localFilePath = remoteFileService.localFilePath4RemoteFilePath(docInfo.getDocPath()).getData();
             File file = new File(localFilePath);
-
             //获取文件扩展名
             int dot = localFilePath.lastIndexOf(".");
             String ext = localFilePath.substring(dot + 1);
-            Map<String, Function<File, String>> handlerMap = new HashMap<>(16);
-            handlerMap.put("docx", FileContentUtils::getContentDocx);
-            handlerMap.put("doc", FileContentUtils::getContentDoc);
-            handlerMap.put("wps", FileContentUtils::getContentWps);
-            handlerMap.put("txt", FileContentUtils::getContentTxt);
-
-            Function<File, String> handler = handlerMap.get(ext);
-            if (handler != null) {
-                String content = handler.apply(file);
-                System.err.println(content);
-                EsDocInfo esDocInfo = new EsDocInfo();
-                esDocInfo.setId(docInfo.getDocId());
-                esDocInfo.setYear(docInfo.getCreateYear());
-                esDocInfo.setContent(content);
-                esDocInfoService.save(esDocInfo);
-            }
-            System.err.println(file.length());
+            insertEs(file, ext, docInfo.getDocId(), docInfo.getCreateYear());
             //读取文件内容存储至ES数据库 END
 
             //文件大小,以KB保存
@@ -150,6 +133,31 @@ public class DocInfoServiceImpl implements IDocInfoService {
         return 0;
     }
 
+    /**
+     * 文件内容入es库
+     */
+    private void insertEs(File file, String ext, Long docId, Long year) {
+
+        Map<String, Function<File, String>> handlerMap = new HashMap<>(16);
+        handlerMap.put("docx", FileContentUtils::getContentDocx);
+        handlerMap.put("doc", FileContentUtils::getContentDoc);
+        handlerMap.put("wps", FileContentUtils::getContentWps);
+        handlerMap.put("txt", FileContentUtils::getContentTxt);
+
+        Function<File, String> handler = handlerMap.get(ext);
+        if (handler != null) {
+            String content = handler.apply(file);
+            System.err.println(content);
+            EsDocInfo esDocInfo = new EsDocInfo();
+            esDocInfo.setId(docId);
+            esDocInfo.setYear(year);
+            esDocInfo.setContent(content);
+            esDocInfoService.save(esDocInfo);
+        }
+        System.err.println(file.length());
+    }
+
+
     //插入文档标签
     private void insertDocTag(DocInfo docInfo) {
         //先删除文档标签再重新插入
@@ -273,6 +281,9 @@ public class DocInfoServiceImpl implements IDocInfoService {
             docInfo.setDocPath(docPath);
             docInfo.setUpdateBy(name);
             docInfo.setUpdateTime(DateUtils.getNowDate());
+
+            File file = new File(path + "/" + fileName);
+            insertEs(file, ext, docInfo.getDocId(), docInfo.getCreateYear());
             docInfoMapper.updateDocInfo(docInfo);
 
         } catch (Exception ex) {