|
@@ -15,6 +15,7 @@ import com.smppw.modaq.application.util.EmailUtil;
|
|
|
import com.smppw.modaq.common.conts.DateConst;
|
|
|
import com.smppw.modaq.common.conts.EmailParseStatusConst;
|
|
|
import com.smppw.modaq.common.conts.EmailTypeConst;
|
|
|
+import com.smppw.modaq.common.dto.FilenamePathDTO;
|
|
|
import com.smppw.modaq.common.enums.ReportParseStatus;
|
|
|
import com.smppw.modaq.common.enums.ReportParserFileType;
|
|
|
import com.smppw.modaq.common.enums.ReportType;
|
|
@@ -175,7 +176,7 @@ public class EmailParseService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<String> extractedDirs;
|
|
|
+ List<FilenamePathDTO> extractedDirs;
|
|
|
if (ExcelUtil.isZip(filepath)) {
|
|
|
extractedDirs = ExcelUtil.extractCompressedFiles(filepath, destPath);
|
|
|
} else if (ExcelUtil.isRAR(filepath)) {
|
|
@@ -183,7 +184,8 @@ public class EmailParseService {
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
- for (String dir : extractedDirs) {
|
|
|
+ for (FilenamePathDTO dto : extractedDirs) {
|
|
|
+ String dir = dto.getFilepath();
|
|
|
// 如果邮件类型不满足解析条件则重新根据文件名判断
|
|
|
if (!Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)
|
|
|
&& !Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType)) {
|
|
@@ -194,13 +196,13 @@ public class EmailParseService {
|
|
|
String[] subDirs = file.list();
|
|
|
if (subDirs != null) {
|
|
|
for (String subDir : subDirs) {
|
|
|
- resultList.add(new EmailZipFileDTO(subDir, emailType));
|
|
|
+ resultList.add(new EmailZipFileDTO(subDir, dto.getFilename(), emailType));
|
|
|
}
|
|
|
} else {
|
|
|
log.warn("目录 {} 下无文件", dir);
|
|
|
}
|
|
|
} else {
|
|
|
- resultList.add(new EmailZipFileDTO(dir, emailType));
|
|
|
+ resultList.add(new EmailZipFileDTO(dir, dto.getFilename(), emailType));
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -232,9 +234,9 @@ public class EmailParseService {
|
|
|
List<EmailZipFileDTO> zipFiles = entry.getValue();
|
|
|
if (CollUtil.isNotEmpty(zipFiles)) {
|
|
|
for (EmailZipFileDTO zipFile : zipFiles) {
|
|
|
- EmailFileInfoDO emailFile = saveEmailFileInfo(emailId, null, zipFile.getFilename(), zipFile.getFilepath(), null);
|
|
|
- // 解析结果(可以从python获取或者自行解析)并保存报告
|
|
|
- ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailFile.getId(), zipFile.getFilename(),
|
|
|
+ EmailFileInfoDO emailFile = saveEmailFileInfo(emailId, null, zipFile.getOriginalName(), zipFile.getFilepath(), null);
|
|
|
+ // 解析并保存报告
|
|
|
+ ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailFile.getId(), zipFile.getOriginalName(),
|
|
|
zipFile.getFilepath(), zipFile.getEmailType(), emailFile.getAiFileId());
|
|
|
dataList.add(parseResult);
|
|
|
}
|
|
@@ -242,7 +244,7 @@ public class EmailParseService {
|
|
|
String fileName = emailContentInfoDTO.getFileName();
|
|
|
EmailFileInfoDO emailFile = saveEmailFileInfo(emailId, emailContentInfoDTO.getFileId(), fileName,
|
|
|
emailContentInfoDTO.getFilePath(), emailContentInfoDTO.getAiFileId());
|
|
|
- // 解析结果(可以从python获取或者自行解析)并保存报告
|
|
|
+ // 解析并保存报告
|
|
|
ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailFile.getId(), fileName,
|
|
|
emailContentInfoDTO.getFilePath(), emailContentInfoDTO.getEmailType(), emailFile.getAiFileId());
|
|
|
dataList.add(parseResult);
|
|
@@ -275,6 +277,7 @@ public class EmailParseService {
|
|
|
ParseResult<ReportData> result = new ParseResult<>();
|
|
|
boolean reportFlag = !Objects.equals(EmailTypeConst.REPORT_EMAIL_TYPE, emailType)
|
|
|
&& !Objects.equals(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE, emailType)
|
|
|
+ && !Objects.equals(EmailTypeConst.REPORT_WEEKLy_TYPE, emailType)
|
|
|
&& !Objects.equals(EmailTypeConst.REPORT_OTHER_TYPE, emailType);
|
|
|
if (reportFlag || StrUtil.isBlank(fileName) || fileName.endsWith(".html")) {
|
|
|
result.setStatus(ReportParseStatus.NOT_A_REPORT.getCode());
|
|
@@ -308,13 +311,14 @@ public class EmailParseService {
|
|
|
result.setMsg(StrUtil.format(ReportParseStatus.NOT_A_REPORT.getMsg(), fileName));
|
|
|
return result;
|
|
|
}
|
|
|
+ // 不支持解析的格式文件
|
|
|
+ boolean notSupportFile = false;
|
|
|
// 解析报告
|
|
|
ReportData reportData = null;
|
|
|
- boolean notSupportFile = false;
|
|
|
StopWatch parserWatch = new StopWatch();
|
|
|
parserWatch.start();
|
|
|
try {
|
|
|
- if (StrUtil.isBlank(aiFileId) && reportType != ReportType.OTHER) {
|
|
|
+ if (StrUtil.isBlank(aiFileId) && reportType != ReportType.OTHER && reportType != ReportType.WEEKLY) {
|
|
|
ReportParserParams params = ReportParserParams.builder().fileId(fileId).filename(fileName).filepath(filepath)
|
|
|
.registerNumber(registerNumber).reportType(reportType).build();
|
|
|
ReportParser<ReportData> instance = this.reportParserFactory.getInstance(reportType, fileType);
|
|
@@ -323,9 +327,9 @@ public class EmailParseService {
|
|
|
result.setMsg("报告解析成功");
|
|
|
result.setData(reportData);
|
|
|
} else {
|
|
|
- if (reportType == ReportType.OTHER) {
|
|
|
+ if (reportType == ReportType.OTHER || reportType == ReportType.WEEKLY) {
|
|
|
if (log.isInfoEnabled()) {
|
|
|
- log.info("报告{} 是其他类型,直接用AI解析器解析", fileName);
|
|
|
+ log.info("报告{} 是周报或其他类型,直接用AI解析器解析", fileName);
|
|
|
}
|
|
|
} else {
|
|
|
if (log.isInfoEnabled()) {
|
|
@@ -356,8 +360,12 @@ public class EmailParseService {
|
|
|
try {
|
|
|
reportData = instance.parse(params);
|
|
|
result.setStatus(1);
|
|
|
- result.setMsg("报告解析成功");
|
|
|
+ result.setMsg("报告解析成功--AI");
|
|
|
result.setData(reportData);
|
|
|
+ } catch (ReportParseException e) {
|
|
|
+ log.error("AI解析失败:{}", StrUtil.format(e.getMsg(), fileName));
|
|
|
+ result.setStatus(e.getCode());
|
|
|
+ result.setMsg(StrUtil.format(e.getMsg(), fileName));
|
|
|
} catch (Exception e) {
|
|
|
log.error("AI解析错误:{}", ExceptionUtil.stacktraceToString(e));
|
|
|
result.setStatus(ReportParseStatus.PARSE_FAIL.getCode());
|
|
@@ -461,6 +469,8 @@ public class EmailParseService {
|
|
|
ListUtil.toList(ReportType.LETTER.getPatterns()));
|
|
|
emailTypeMap.put(EmailTypeConst.REPORT_OTHER_TYPE,
|
|
|
ListUtil.toList(ReportType.OTHER.getPatterns()));
|
|
|
+ emailTypeMap.put(EmailTypeConst.REPORT_WEEKLy_TYPE,
|
|
|
+ ListUtil.toList(ReportType.WEEKLY.getPatterns()));
|
|
|
return emailTypeMap;
|
|
|
}
|
|
|
|