许鹏程
2024-05-28 927359fdce884acdcd76b90008eb0303f4bdd29d
src/main/java/com/product/file/util/CreateDocumentIndexThread.java
@@ -1,6 +1,10 @@
package com.product.file.util;
import java.util.LinkedList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import org.apache.poi.openxml4j.exceptions.OLE2NotOfficeXmlFileException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -13,20 +17,26 @@
/**
 * 消息服务,添加消息,读取消息
 * @author shicf
 *
 * @author shicf
 */
@Component
public class CreateDocumentIndexThread   {
   /**自已实例**/
   /**
    * 自已实例
    **/
   private static CreateDocumentIndexThread createDocumentIndexThread;
   @Autowired
   public FileManagerService fileManagerService;
   /**内部线程**/
   /**
    * 内部线程
    **/
   private SendMailThread sendMailThread=null;
   @Autowired
   public LuceneService luceneService;
   /** 生成的新消息队列**/
   /**
    * 生成的新消息队列
    **/
   private static LinkedList <FieldSetEntity> documentIndexs=new LinkedList<>();
   
   /**
@@ -44,6 +54,7 @@
      createDocumentIndexThread.start();
      return createDocumentIndexThread;
   }
   /**
    * 启动缓存的刷新线程
    */
@@ -54,8 +65,10 @@
         SpringMVCContextHolder.getSystemLogger().info("Thread Of Refresh Cache Is Starting.............");
      }
   }
   /**
    * 把附件信息添加对列中
    *
    * @param user
    */
@@ -64,8 +77,13 @@
         documentIndexs.add(documentIndex);
      }
   }
   //重试文件的uuid集合
   private Set<String> retryFileUuids = new HashSet<>();
   /**
    * 取刷新表队表的第一个
    *
    * @return
    */
   public synchronized void pop() {
@@ -74,14 +92,37 @@
         if(luceneService ==null ) {
            luceneService=(LuceneService) SpringBeanUtil.getBean("luceneService");
         }
         try {
         ff.setValue("file", fileManagerService.getFile(ff.getString("attachment_uuid")));
         } catch (Exception e) {
            if (retryFileUuids.contains(ff.getString("attachment_uuid"))) {
               //重试过的文件不再重试,删除队列中的文件
               retryFileUuids.remove(ff.getString("attachment_uuid"));
               continue;
            } else {
               retryFileUuids.add(ff.getString("attachment_uuid"));
               //添加到队列的最后
               appendAttaInfo(ff);
               continue;
            }
         }
         try {
         luceneService.createdIndex(ff);
         } catch (OLE2NotOfficeXmlFileException e) {
            e.printStackTrace();
            SpringMVCContextHolder.getSystemLogger().error(e);
         } catch (Exception e) {
            SpringMVCContextHolder.getSystemLogger().error(e);
            e.printStackTrace();
      }
   }
   }
   /**
    * 内部线程,定时刷新缓存
    * @author shicf
    *
    * @author shicf
    */
   class SendMailThread extends Thread {   
      @Override