|
@@ -1,19 +1,14 @@
|
|
|
package com.smppw.modaq.application.service;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.collection.ListUtil;
|
|
|
-import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
-import com.smppw.modaq.application.util.EmailUtil;
|
|
|
-import com.smppw.modaq.common.conts.DateConst;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
import com.smppw.modaq.common.enums.ReportParseStatus;
|
|
|
-import com.smppw.modaq.domain.dto.EmailContentInfoDTO;
|
|
|
import com.smppw.modaq.domain.dto.MailboxInfoDTO;
|
|
|
import com.smppw.modaq.domain.dto.UploadReportParams;
|
|
|
import com.smppw.modaq.domain.dto.UploadReportResult;
|
|
|
-import com.smppw.modaq.domain.entity.EmailFileInfoDO;
|
|
|
-import com.smppw.modaq.domain.entity.EmailParseInfoDO;
|
|
|
+import com.smppw.modaq.domain.dto.UploadUrlReportParams;
|
|
|
import com.smppw.modaq.domain.entity.MailboxInfoDO;
|
|
|
import com.smppw.modaq.domain.mapper.MailboxInfoMapper;
|
|
|
import com.smppw.modaq.domain.service.EmailParseService;
|
|
@@ -22,7 +17,9 @@ import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
-import java.io.*;
|
|
|
+import java.io.File;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.nio.file.Files;
|
|
|
import java.nio.file.Path;
|
|
|
import java.util.Date;
|
|
@@ -101,6 +98,41 @@ public class EmailParseApiServiceImpl implements EmailParseApiService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public List<UploadReportResult> uploadUrlReport(UploadUrlReportParams params) {
|
|
|
+ List<UploadReportParams.ReportInfo> reportInfos = ListUtil.list(false);
|
|
|
+ List<UploadUrlReportParams.UrlReportInfo> urlReportInfos = params.getReportInfos();
|
|
|
+ for (UploadUrlReportParams.UrlReportInfo urlReportInfo : urlReportInfos) {
|
|
|
+ String reportUrl = urlReportInfo.getReportUrl();
|
|
|
+ String filename;
|
|
|
+ if (StrUtil.isNotBlank(getFileExtension(urlReportInfo.getReportName()))) {
|
|
|
+ filename = reportUrl;
|
|
|
+ } else {
|
|
|
+ filename = urlReportInfo.getReportName() + "." + getFileExtension(reportUrl);
|
|
|
+ }
|
|
|
+ File saveFile = this.emailParseService.generateSavePath("upload", new Date(), filename);
|
|
|
+ if (!saveFile.exists()) {
|
|
|
+ if (!saveFile.getParentFile().exists()) {
|
|
|
+ saveFile.getParentFile().mkdirs();
|
|
|
+ }
|
|
|
+ HttpUtil.downloadFile(reportUrl, saveFile);
|
|
|
+ }
|
|
|
+ UploadReportParams.ReportInfo reportInfo = new UploadReportParams.ReportInfo(saveFile.getAbsolutePath());
|
|
|
+ reportInfo.setReportName(filename);
|
|
|
+ reportInfo.setReportType(urlReportInfo.getReportType());
|
|
|
+ reportInfo.setPdfPwd(urlReportInfo.getPdfPwd());
|
|
|
+ reportInfos.add(reportInfo);
|
|
|
+ }
|
|
|
+ UploadReportParams req = new UploadReportParams();
|
|
|
+ req.setReportInfos(reportInfos);
|
|
|
+ if (StrUtil.isBlank(params.getTitle())) {
|
|
|
+ req.setTitle("报告上传解析-url");
|
|
|
+ } else {
|
|
|
+ req.setTitle(params.getTitle());
|
|
|
+ }
|
|
|
+ return this.emailParseService.uploadReportResults(req);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public List<UploadReportResult> batchUploadReport(MultipartFile[] files) {
|
|
|
List<UploadReportResult> dataList = ListUtil.list(false);
|
|
|
UploadReportParams params = new UploadReportParams();
|
|
@@ -253,49 +285,60 @@ public class EmailParseApiServiceImpl implements EmailParseApiService {
|
|
|
// return contentInfoDTO;
|
|
|
// }
|
|
|
|
|
|
- private List<EmailContentInfoDTO> buildEmailContentInfoDTO(Integer emailId,
|
|
|
- EmailParseInfoDO emailParseInfoDO,
|
|
|
- List<EmailFileInfoDO> emailFileInfoDOList) {
|
|
|
- List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
|
|
|
- String emailDate = DateUtil.format(emailParseInfoDO.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
- String parseDate = DateUtil.format(new Date(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
- for (EmailFileInfoDO fileInfoDO : emailFileInfoDOList) {
|
|
|
- EmailContentInfoDTO contentInfoDTO = new EmailContentInfoDTO();
|
|
|
- contentInfoDTO.setEmailId(emailId);
|
|
|
- contentInfoDTO.setFileId(fileInfoDO.getId());
|
|
|
- contentInfoDTO.setSenderEmail(emailParseInfoDO.getSenderEmail());
|
|
|
- contentInfoDTO.setEmailAddress(emailParseInfoDO.getEmail());
|
|
|
- contentInfoDTO.setEmailDate(emailDate);
|
|
|
- contentInfoDTO.setEmailTitle(emailParseInfoDO.getEmailTitle());
|
|
|
- contentInfoDTO.setParseDate(parseDate);
|
|
|
- contentInfoDTO.setFileName(fileInfoDO.getFileName());
|
|
|
- contentInfoDTO.setFilePath(fileInfoDO.getFilePath());
|
|
|
- Integer emailType = EmailUtil.getEmailTypeBySubject(emailParseInfoDO.getEmailTitle());
|
|
|
- contentInfoDTO.setEmailType(emailType);
|
|
|
- String emailContent = readHtmlFileContent(fileInfoDO.getFilePath());
|
|
|
- contentInfoDTO.setEmailContent(emailContent);
|
|
|
- contentInfoDTO.setAiFileId(fileInfoDO.getAiFileId());
|
|
|
- emailContentInfoDTOList.add(contentInfoDTO);
|
|
|
- }
|
|
|
- return emailContentInfoDTOList;
|
|
|
- }
|
|
|
+// private List<EmailContentInfoDTO> buildEmailContentInfoDTO(Integer emailId,
|
|
|
+// EmailParseInfoDO emailParseInfoDO,
|
|
|
+// List<EmailFileInfoDO> emailFileInfoDOList) {
|
|
|
+// List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
|
|
|
+// String emailDate = DateUtil.format(emailParseInfoDO.getEmailDate(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+// String parseDate = DateUtil.format(new Date(), DateConst.YYYY_MM_DD_HH_MM_SS);
|
|
|
+// for (EmailFileInfoDO fileInfoDO : emailFileInfoDOList) {
|
|
|
+// EmailContentInfoDTO contentInfoDTO = new EmailContentInfoDTO();
|
|
|
+// contentInfoDTO.setEmailId(emailId);
|
|
|
+// contentInfoDTO.setFileId(fileInfoDO.getId());
|
|
|
+// contentInfoDTO.setSenderEmail(emailParseInfoDO.getSenderEmail());
|
|
|
+// contentInfoDTO.setEmailAddress(emailParseInfoDO.getEmail());
|
|
|
+// contentInfoDTO.setEmailDate(emailDate);
|
|
|
+// contentInfoDTO.setEmailTitle(emailParseInfoDO.getEmailTitle());
|
|
|
+// contentInfoDTO.setParseDate(parseDate);
|
|
|
+// contentInfoDTO.setFileName(fileInfoDO.getFileName());
|
|
|
+// contentInfoDTO.setFilePath(fileInfoDO.getFilePath());
|
|
|
+// Integer emailType = EmailUtil.getEmailTypeBySubject(emailParseInfoDO.getEmailTitle());
|
|
|
+// contentInfoDTO.setEmailType(emailType);
|
|
|
+// String emailContent = readHtmlFileContent(fileInfoDO.getFilePath());
|
|
|
+// contentInfoDTO.setEmailContent(emailContent);
|
|
|
+//// contentInfoDTO.setAiFileId(fileInfoDO.getAiFileId());
|
|
|
+// emailContentInfoDTOList.add(contentInfoDTO);
|
|
|
+// }
|
|
|
+// return emailContentInfoDTOList;
|
|
|
+// }
|
|
|
|
|
|
- public static String readHtmlFileContent(String filePath) {
|
|
|
- if (StrUtil.isNotBlank(filePath) && filePath.endsWith("html")) {
|
|
|
- StringBuilder content = new StringBuilder();
|
|
|
- try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
|
|
- String line;
|
|
|
- while ((line = reader.readLine()) != null) {
|
|
|
- // 追加每一行到StringBuilder中
|
|
|
- content.append(line).append("\n");
|
|
|
- }
|
|
|
- } catch (IOException e) {
|
|
|
- System.err.println("Error reading the file: " + e.getMessage());
|
|
|
- return null;
|
|
|
- }
|
|
|
- return content.toString();
|
|
|
+// public static String readHtmlFileContent(String filePath) {
|
|
|
+// if (StrUtil.isNotBlank(filePath) && filePath.endsWith("html")) {
|
|
|
+// StringBuilder content = new StringBuilder();
|
|
|
+// try (BufferedReader reader = new BufferedReader(new FileReader(filePath))) {
|
|
|
+// String line;
|
|
|
+// while ((line = reader.readLine()) != null) {
|
|
|
+// // 追加每一行到StringBuilder中
|
|
|
+// content.append(line).append("\n");
|
|
|
+// }
|
|
|
+// } catch (IOException e) {
|
|
|
+// System.err.println("Error reading the file: " + e.getMessage());
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+// return content.toString();
|
|
|
+// }
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+ private static String getFileExtension(String fileName) {
|
|
|
+ if (fileName == null || fileName.isEmpty()) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ int lastDotIndex = fileName.lastIndexOf('.');
|
|
|
+ // 后缀不存在的情况:无点、点在开头(隐藏文件无后缀)、点在末尾
|
|
|
+ if (lastDotIndex == -1 || lastDotIndex == 0 || lastDotIndex == fileName.length() - 1) {
|
|
|
+ return "";
|
|
|
}
|
|
|
- return null;
|
|
|
+ return fileName.substring(lastDotIndex + 1);
|
|
|
}
|
|
|
-
|
|
|
}
|