杜洪波
2024-08-28 25fa030044c7de10ccaaf4a9728c6037a29fa6ba
src/main/java/com/product/file/service/FileManagerService.java
@@ -20,6 +20,8 @@
import com.product.file.util.FileUtil;
import com.product.file.util.FileUtils;
import com.product.module.sys.entity.SystemUser;
import com.product.util.BaseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.context.request.RequestContextHolder;
@@ -232,6 +234,39 @@
      return baseDao.executeUpdate(sql.toString());
   }
   /**
    * 根据附件uuid判断文件是否存在
    *
    * @param uuid
    * @return
    */
   public boolean fileExist(String uuid) {
      if (StringUtils.isEmpty(uuid)) {
         return false;
      }
      FieldSetEntity attachmentFse = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_ATTACHMENTS, uuid, false);
      if (attachmentFse == null) {
         return false;
      }
      //判断文件存放在服务器还是本地
      boolean needDownloadFromServerFlag = "1".equals(attachmentFse.getString(CmnConst.UPLOAD_SIGN));
      String dir = attachmentFse.getString(CmnConst.ATTACHMENT_URL);
      String fileName = attachmentFse.getString(CmnConst.ATTACHMENT_TITLE);
      boolean encrptSignFlag = "1".equals(attachmentFse.getString(CmnConst.ENCRPT_SIGN));
      if (needDownloadFromServerFlag) {
         // 需要从附件服务器上取文件
         FTPService ftpService = new FTPService();
         return ftpService.fileIsExist(dir, fileName);
      } else {
         // 直接在本地的目录中找文件
         String localBasePath = Global.getSystemConfig("local.dir", "");
         String path = localBasePath + File.separator + dir + File.separator + fileName;
         File file = new File(path);
         return file.isFile();
      }
   }
   /**
    * 上传文件到本地服务器
@@ -384,6 +419,34 @@
      }
      return fse;
   }
   /**
    *    根据附件表数据生成文档索引
    */
   public void readAttachmentCreateIndex() {
      // 遍历附件表
      DataTableEntity dtAttachment = baseDao.listTable(CmnConst.PRODUCT_SYS_ATTACHMENTS);
      if (BaseUtil.dataTableIsEmpty(dtAttachment)) {
         return ;
      }
      for (int i = 0; i < dtAttachment.getRows(); i++) {
         // 获取附件信息,并判断是否有表和字段
         FieldSetEntity fseAttachment = dtAttachment.getFieldSetEntity(i);
         if(BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field")) || BaseUtil.strIsNull(fseAttachment.getString("attachment_data_field"))) {
            continue;
         }
         // 查询原数据,有原数据再生成文档检索
         FieldSetEntity fseRecord = baseDao.getFieldSetEntityByFilter(fseAttachment.getString("attachment_data_table"), fseAttachment.getString("attachment_data_field") + " LIKE ?", new Object[] {"%"+fseAttachment.getUUID()+"%"}, false);
         if(fseRecord != null) {
            // 生成文档检索信息
            FieldSetEntity fseIndex = new FieldSetEntity();
            fseIndex.setTableName("fseIndex");
            fseIndex.setValue("function_uuid", fseAttachment.getString("function_uuid"));
            fseIndex.setValue("attachment_uuid", fseAttachment.getUUID());
            CreateDocumentIndexThread.getInstance().appendAttaInfo(fseIndex);
         }
      }
   }
   /**
    * 提取文件信息-下载文件或者在线预览文件
@@ -504,7 +567,7 @@
            }
            os.flush();
         }
         is.close();
      }
      logger.info("文件流获取成功");
   }