秦芳睿
2025-03-12 9d7ddee9fae205fbca1e6aff2893967079003671
JAVA/SMTAIServer/src/main/java/com/smtaiserver/smtaiserver/core/SMTAIServerApp.java
@@ -22,7 +22,6 @@
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.xwpf.extractor.XWPFWordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.dom4j.Document;
@@ -236,7 +235,7 @@
      Map<String, SMTMetricsDef> mapResult = mapMapMetrics.get(groupId);
      
      if(mapResult == null)
         throw new Exception("can't find metrics group : " + groupId);
         return new HashMap<String, SMTMetricsDef>();
      
      return mapResult;
   }
@@ -303,6 +302,7 @@
      _serverEncache.getMapThemeDefMap();
      _serverEncache.getAttachTableDefMap();
      _serverEncache.getAttachMetricDefMap();
      _serverEncache.getQwenAgentManager();
   }
   
   public SMTMapTableDef getMapTableDef(String tableId) throws Exception
@@ -1249,7 +1249,7 @@
   /**
    * 文件(word、pdf)转txt
    */
   public String fileTranslTxt(MultipartFile file) throws Exception {
   public static String fileTranslTxt(MultipartFile file) throws Exception {
      InputStream inputStream = file.getInputStream();
      try (BufferedInputStream bis = new BufferedInputStream(file.getInputStream())) {
         String mimeType = file.getContentType();
@@ -1272,6 +1272,10 @@
                     WordExtractor wordExtractor = new WordExtractor(doc);
                     return wordExtractor.getText();
                  }
               case "text/plain":
                  _logger.info("文件类型是 TXT");
                  byte[] fileData = readAttachFile(file);
                        return new String(fileData, "UTF-8");
               default:
                  _logger.info("未知文件类型: " + mimeType);
                  break;
@@ -1283,7 +1287,21 @@
         _logger.error("文件处理失败: " + e.getMessage());
         throw new Exception("文件处理失败: " + e.getMessage());
      }
      return null;
      return "";
   }
   public static byte[] readAttachFile(MultipartFile file) throws Exception
   {
      InputStream is = file.getInputStream();
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      byte[] data = new byte[1024 * 1024];
      while(true)
      {
         int size = is.read(data);
         if(size <= 0)
            return bos.toByteArray();
         bos.write(data, 0, size);
      }
   }
}