许鹏程
2024-05-28 927359fdce884acdcd76b90008eb0303f4bdd29d
commit
已修改3个文件
66 ■■■■ 文件已修改
src/main/java/com/product/file/service/FileManagerService.java 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/util/CreateDocumentIndexThread.java 53 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/util/FileUtils.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/product/file/service/FileManagerService.java
@@ -348,7 +348,7 @@
                attachmentFse.setValue(CmnConst.ENCRPT_SIGN, Global.getPropertyToBoolean("file.encrypt", "true") ? 1 : 0);
                attachmentFse.setValue(CmnConst.ATTACHMENT_SIZE, fileLength);
                attachmentFse.setValue(CmnConst.UPLOAD_SIGN, needUpload2FileServerFlag ? 1 : 0);
                attachmentFse.setValue(CmnConst.FUNCTION_UUID, fse.getString(CmnConst.FUNCTION_UUID));
                attachmentFse.setValue(CmnConst.ATTACHMENT_CONTAINER, fse.getString(CmnConst.ATTACHMENT_CONTAINER));
                attachmentFse.setValue(CmnConst.ATTACHMENT_DOMAIN, fse.getString(CmnConst.ATTACHMENT_DOMAIN));
                attachmentFse.setValue(CmnConst.MODULE_UUID, fse.getString(CmnConst.MODULE_UUID));
@@ -541,7 +541,7 @@
            try {
                temp.createNewFile();
            } catch (IOException e) {
                throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : ""));
                throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : ""));
            }
            try (FileOutputStream fos = new FileOutputStream(temp); BufferedOutputStream out = new BufferedOutputStream(fos)) {
@@ -549,10 +549,10 @@
                return temp;
            } catch (Exception e) {
                e.printStackTrace();
                throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() : ""));
                throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + (e.getMessage() != null ? e.getMessage() + ",uuid:" + attachmentFse.getUUID() : ""));
            }
        }
        throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText());
        throw new BaseException(FileCode.GET_FILE_FAIL.getValue(), FileCode.GET_FILE_FAIL.getText() + ",uuid:" + attachmentFse.getUUID());
    }
    /**
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
src/main/java/com/product/file/util/FileUtils.java
@@ -462,6 +462,7 @@
                FileUtil.copyFile(file, path, encryptFile ? 1 : 0);
            }
        } catch (Exception e) {
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw new BaseException(FileCode.UPLOAD_FILE_FAIL);
        }
    }
@@ -505,6 +506,7 @@
                }
            }
        } catch (Exception e) {
            SpringMVCContextHolder.getSystemLogger().error(e);
            throw new BaseException(FileCode.REPLACE_FILE_FAIL);
        }
    }
@@ -596,8 +598,7 @@
            pdfFile = new File(s);
            uploadOtherFile(false, uploadServer, placeLocation, pdfFile, fileName);
            return true;
        }
        catch (BaseException e) {
        } catch (BaseException e) {
            throw e;
        }catch (Exception e) {
            e.printStackTrace();