| | |
| | | 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;
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | _serverEncache.getMapThemeDefMap();
|
| | | _serverEncache.getAttachTableDefMap();
|
| | | _serverEncache.getAttachMetricDefMap();
|
| | | _serverEncache.getQwenAgentManager();
|
| | | }
|
| | |
|
| | | public SMTMapTableDef getMapTableDef(String tableId) throws Exception
|
| | |
| | | /**
|
| | | * 文件(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();
|
| | |
| | | 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;
|
| | |
| | | _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);
|
| | | }
|
| | | }
|
| | |
|
| | | }
|