소스 검색

fix:代码优化

wangzaijun 2 주 전
부모
커밋
2e71d695ee

+ 5 - 0
mo-daq/src/main/java/com/smppw/modaq/domain/dto/report/ReportData.java

@@ -64,10 +64,15 @@ public abstract class ReportData implements Serializable {
     public String toString() {
         return "baseInfo=" + baseInfo +
                 ", fundInfo=" + fundInfo +
+                ", reportPath='" + reportPath + '\'' +
                 ", aiParse=" + aiParse;
     }
 
     public static class DefaultReportData extends ReportData {
+        public DefaultReportData() {
+            this(null, null);
+        }
+
         public DefaultReportData(ReportBaseInfoDTO baseInfo, ReportFundInfoDTO fundInfo) {
             super(baseInfo, fundInfo);
         }

+ 10 - 2
mo-daq/src/main/java/com/smppw/modaq/domain/dto/report/ReportFundInfoDTO.java

@@ -1,5 +1,6 @@
 package com.smppw.modaq.domain.dto.report;
 
+import cn.hutool.core.util.StrUtil;
 import com.smppw.modaq.application.components.ReportParseUtils;
 import com.smppw.modaq.domain.entity.report.ReportFundInfoDO;
 import com.smppw.modaq.infrastructure.util.DateUtils;
@@ -18,7 +19,6 @@ public class ReportFundInfoDTO extends BaseReportDTO<ReportFundInfoDO> {
     /**
      * 基金的名称
      */
-    @Getter
     private String fundName;
 
     /**
@@ -118,6 +118,13 @@ public class ReportFundInfoDTO extends BaseReportDTO<ReportFundInfoDO> {
         return ReportParseUtils.matchFundCode(this.fundCode);
     }
 
+    public String getFundName() {
+        if (StrUtil.isBlank(this.fundName)) {
+            return null;
+        }
+        return StrUtil.trim(this.fundName);
+    }
+
     public ReportFundInfoDTO() {
         super();
     }
@@ -157,7 +164,8 @@ public class ReportFundInfoDTO extends BaseReportDTO<ReportFundInfoDO> {
     public String toString() {
         return "{" +
                 super.toString() +
-                ", fundName='" + this.getFundName() + '\'' +
+                ", fundName='" + this.fundName + '\'' +
+                ", cleanFundName='" + this.getFundName() + '\'' +
                 ", fundCode='" + this.fundCode + '\'' +
                 ", matchFundCode='" + this.getFundCode() + '\'' +
                 ", companyName='" + this.companyName + '\'' +

+ 19 - 19
mo-daq/src/main/java/com/smppw/modaq/domain/service/EmailParseService.java

@@ -6,6 +6,7 @@ import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.exceptions.ExceptionUtil;
 import cn.hutool.core.io.FileUtil;
 import cn.hutool.core.map.MapUtil;
+import cn.hutool.core.util.IdUtil;
 import cn.hutool.core.util.StrUtil;
 import com.smppw.modaq.application.components.OCRReportParser;
 import com.smppw.modaq.application.components.ReportParseUtils;
@@ -190,6 +191,13 @@ public class EmailParseService {
         }
     }
 
+    /**
+     * 解压压缩包,如果不是压缩包需转换
+     *
+     * @param emailContentInfoDTO 邮件信息
+     * @return 解压后的文件列表
+     * @throws IOException /
+     */
     public List<EmailZipFileDTO> parseZipEmail(EmailContentInfoDTO emailContentInfoDTO) throws IOException {
         List<EmailZipFileDTO> resultList = ListUtil.list(false);
         Integer emailType = emailContentInfoDTO.getEmailType();
@@ -209,16 +217,11 @@ public class EmailParseService {
             emailType = EmailUtil.getEmailTypeBySubject(emailContentInfoDTO.getFileName());
             emailContentInfoDTO.setEmailType(emailType);
         }
-
         if (CollUtil.isNotEmpty(resultList)) {
             for (EmailZipFileDTO dto : resultList) {
                 dto.setEmailType(emailType);
             }
-            if (log.isInfoEnabled()) {
-                log.info("当前邮件{} 所有解压缩文件解压完成:{}", emailTitle, resultList);
-            }
         }
-
         return resultList;
     }
 
@@ -333,7 +336,7 @@ public class EmailParseService {
                     ParseResult<ReportData> result = new ParseResult<>();
                     result.setStatus(ReportParseStatus.ARCHIVE_FAIL.getCode());
                     result.setMsg(ReportParseStatus.ARCHIVE_FAIL.getMsg());
-                    ReportData reportData = new ReportData.DefaultReportData(null, null);
+                    ReportData reportData = new ReportData.DefaultReportData();
                     reportData.setReportPath(reportPath);
                     dataList.add(result);
                 }
@@ -459,7 +462,7 @@ public class EmailParseService {
             // 解析并保存报告
             ParseResult<ReportData> parseResult = this.parseReportAndHandleResult(emailTitle, emailFile, zipFile);
             if (parseResult.getData() == null) {
-                parseResult.setData(new ReportData.DefaultReportData(null, null));
+                parseResult.setData(new ReportData.DefaultReportData());
             }
             parseResult.getData().setReportPath(zipFile.getFilepath());
             resultList.add(parseResult);
@@ -881,10 +884,7 @@ public class EmailParseService {
         Map<String, List<EmailContentInfoDTO>> emailMessageMap = MapUtil.newHashMap();
         for (Message message : messages) {
             long start = System.currentTimeMillis();
-            List<EmailContentInfoDTO> emailContentInfoDTOList = CollUtil.newArrayList();
-            String uuidKey = UUID.randomUUID().toString().replaceAll("-", "");
-            Integer emailType;
-            String senderEmail;
+            List<EmailContentInfoDTO> dtos = CollUtil.newArrayList();
             String emailTitle = message.getSubject();
             if (this.readWriteSeen && isMessageRead(message)) {
                 log.warn("{} 邮件{} 已读,不用重新下载解析!", folderName, emailTitle);
@@ -906,8 +906,8 @@ public class EmailParseService {
                     log.warn("{} 邮件[{}]日期{}不在区间内【{} ~ {}】", folderName, emailTitle, emailDateStr, st, ed);
                     continue;
                 }
-                senderEmail = getSenderEmail(message);
-                emailType = EmailUtil.getEmailTypeBySubject(emailTitle);
+                String senderEmail = getSenderEmail(message);
+                Integer emailType = EmailUtil.getEmailTypeBySubject(emailTitle);
                 if (emailType == null) {
                     log.warn("{} 邮件不满足解析条件 -> 邮件主题:{},邮件日期:{}", folderName, emailTitle, emailDateStr);
                     continue;
@@ -918,27 +918,27 @@ public class EmailParseService {
                 Object content = message.getContent();
 
                 if (content instanceof Multipart multipart) {
-                    this.reMultipart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, multipart, emailContentInfoDTOList);
+                    this.reMultipart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, multipart, dtos);
                 } else if (content instanceof Part part) {
-                    this.rePart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, part, emailContentInfoDTOList);
+                    this.rePart(mailboxInfoDTO.getAccount(), emailTitle, emailDate, part, dtos);
                 } else {
                     log.warn("{} 不支持的邮件数据 {}", folderName, emailTitle);
                 }
-                if (CollUtil.isEmpty(emailContentInfoDTOList)) {
+                if (CollUtil.isEmpty(dtos)) {
                     log.warn("{} 邮件{} 没有获取到附件", folderName, emailTitle);
                     continue;
                 }
-                emailContentInfoDTOList.forEach(e -> {
+                dtos.forEach(e -> {
                     e.setEmailType(emailType);
                     e.setSenderEmail(senderEmail);
                 });
-                emailMessageMap.put(uuidKey, emailContentInfoDTOList);
+                emailMessageMap.put(IdUtil.simpleUUID(), dtos);
             } catch (Exception e) {
                 log.error("{} 获取邮箱的邮件{} 报错,堆栈信息:{}", folderName, emailTitle, ExceptionUtil.stacktraceToString(e));
             } finally {
                 if (log.isInfoEnabled()) {
                     log.info("{} 邮件{} 下载完成,总计耗时{} ms,文件内容如下\n {}", folderName,
-                            emailTitle, System.currentTimeMillis() - start, emailContentInfoDTOList);
+                            emailTitle, System.currentTimeMillis() - start, dtos);
                 }
             }
         }

+ 2 - 2
mo-daq/src/test/java/com/smppw/modaq/MoDaqApplicationTests.java

@@ -42,8 +42,8 @@ public class MoDaqApplicationTests {
     @Test
     public void reportTest() {
         MailboxInfoDTO emailInfoDTO = this.buildMailbox("*@simuwang.com", "*");
-        Date startDate = DateUtil.parse("2025-06-09 14:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
-        Date endDate = DateUtil.parse("2025-06-09 18:56:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date startDate = DateUtil.parse("2025-06-10 11:20:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date endDate = DateUtil.parse("2025-06-10 18:56:00", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             List<String> folderNames = ListUtil.list(false);
 //            folderNames.add("其他文件夹/报告公告");