wukai пре 1 година
родитељ
комит
c41d7098b1

+ 2 - 0
doc-admin/src/main/resources/application-test.yml

@@ -14,6 +14,8 @@ ruoyi:
   captchaType: math
   # 文件路径 示例( Windows配置D:/ruoyi/uploadPath,Linux配置 /home/ruoyi/uploadPath)
   profile: /opt/doc/uploadPath
+  # pdf ocr解析开关
+  pdfOcr: false
 
 #证书相关配置
 license:

+ 2 - 0
doc-admin/src/main/resources/application.yml

@@ -12,6 +12,8 @@ ruoyi:
   addressEnabled: false
   # 验证码类型 math 数字计算 char 字符验证
   captchaType: math
+  # pdf ocr解析开关
+  pdfOcr: false
 #证书相关配置
 license:
   subject: doc_test

+ 9 - 8
doc-biz/src/main/java/com/doc/biz/service/impl/ElasticSearchServiceImpl.java

@@ -12,6 +12,7 @@ import com.doc.common.utils.StringUtils;
 import com.doc.common.utils.file.FileUtils;
 import com.doc.common.utils.file.PdfUtils;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.core.env.Environment;
 import org.springframework.data.elasticsearch.NoSuchIndexException;
 import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
@@ -46,6 +47,8 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
     private IDocInfoService docInfoService;
     @Resource
     private IDocIndexService indexService;
+    @Resource
+    private Environment environment;
 
     /**
      * 文件内容入es库
@@ -65,14 +68,12 @@ public class ElasticSearchServiceImpl implements IElasticSearchService {
 
         Map<String, Function<byte[], String>> handlerMap = createHandlerMap(fileType);
         String content = getContent(handlerMap, fileType, info.getFileId());
-
-//        if (Constants.PDF_EXTENSION.contains(fileType) && StringUtils.isEmpty(content)) {
-//            //如果是PDF未解析成功,则另外进行解析工作
-//            //TODO 暂时取消该功能
-////            DocIndex di = new DocIndex(info);
-////            indexService.insertDocIndex(di);
-//            return;
-//        }
+        boolean pdfOcr = Boolean.parseBoolean(environment.getProperty("ruoyi.pdfOcr"));
+        if (pdfOcr && Constants.PDF_EXTENSION.contains(fileType) && StringUtils.isEmpty(content)) {
+            //如果是PDF未解析成功,则另外进行解析工作
+            indexService.insertDocIndex(new DocIndex(info));
+            return;
+        }
 
         if (StringUtils.isNotEmpty(content)) {
             comboIndex(info.getSpaceId());