Browse Source

fix:修复bug+with_seals字段先不保存

wangzaijun 3 tuần trước cách đây
mục cha
commit
0b43086f17

+ 24 - 5
mo-daq/src/main/java/com/smppw/modaq/application/components/report/parser/ReportParserConstant.java

@@ -38,10 +38,24 @@ public final class ReportParserConstant {
 
     static {
         // 其他报告解析
-        REPORT_PARSER_BEAN_MAP.put(ReportType.OTHER, Map.of(ReportParserFileType.AI, PARSER_AI_OTHER));
+        REPORT_PARSER_BEAN_MAP.put(ReportType.OTHER,
+                Map.of(
+                        ReportParserFileType.AI, PARSER_AI_OTHER,
+                        ReportParserFileType.IMG_PNG, PARSER_AI_OTHER,
+                        ReportParserFileType.IMG_JPG, PARSER_AI_OTHER,
+                        ReportParserFileType.WORD, PARSER_AI_OTHER
+                )
+        );
 
         // 周报
-        REPORT_PARSER_BEAN_MAP.put(ReportType.WEEKLY, Map.of(ReportParserFileType.AI, PARSER_AI_WEEKLY));
+        REPORT_PARSER_BEAN_MAP.put(ReportType.WEEKLY,
+                Map.of(
+                        ReportParserFileType.AI, PARSER_AI_WEEKLY,
+                        ReportParserFileType.IMG_PNG, PARSER_AI_WEEKLY,
+                        ReportParserFileType.IMG_JPG, PARSER_AI_WEEKLY,
+                        ReportParserFileType.WORD, PARSER_AI_WEEKLY
+                )
+        );
 
         // 交易流水确认函解析
         REPORT_PARSER_BEAN_MAP.put(ReportType.LETTER,
@@ -55,7 +69,10 @@ public final class ReportParserConstant {
                 Map.of(
                         ReportParserFileType.PDF, PARSER_PDF_MONTHLY,
 //                        ReportParserFileType.EXCEL, PARSER_EXCEL_MONTHLY,
-                        ReportParserFileType.AI, PARSER_AI_MONTHLY
+                        ReportParserFileType.AI, PARSER_AI_MONTHLY,
+                        ReportParserFileType.IMG_PNG, PARSER_AI_MONTHLY,
+                        ReportParserFileType.IMG_JPG, PARSER_AI_MONTHLY,
+                        ReportParserFileType.WORD, PARSER_AI_MONTHLY
                 ));
 
         // 季度报告
@@ -63,7 +80,8 @@ public final class ReportParserConstant {
                 Map.of(
                         ReportParserFileType.PDF, PARSER_PDF_QUARTERLY,
 //                        ReportParserFileType.EXCEL, PARSER_EXCEL_QUARTERLY,
-                        ReportParserFileType.AI, PARSER_AI_QUARTERLY
+                        ReportParserFileType.AI, PARSER_AI_QUARTERLY,
+                        ReportParserFileType.WORD, PARSER_AI_QUARTERLY
                 ));
 
         // 年度报告
@@ -71,7 +89,8 @@ public final class ReportParserConstant {
                 Map.of(
                         ReportParserFileType.PDF, PARSER_PDF_ANNUALLY,
 //                        ReportParserFileType.EXCEL, PARSER_EXCEL_ANNUALLY,
-                        ReportParserFileType.AI, PARSER_AI_ANNUALLY
+                        ReportParserFileType.AI, PARSER_AI_ANNUALLY,
+                        ReportParserFileType.WORD, PARSER_AI_ANNUALLY
                 ));
     }
 }

+ 19 - 19
mo-daq/src/main/java/com/smppw/modaq/application/task/ParseSchedulerTask.java

@@ -29,25 +29,25 @@ public class ParseSchedulerTask {
 
     @PostConstruct
     public void executeOnStartup() {
-//        try {
-//            // 定期报告从 其他文件夹/报告公告 文件夹获取邮件
-//            this.emailParseApiService.parseEmail(
-//                    DateUtil.parseDateTime("2025-05-30 14:53:00"),
-//                    DateUtil.parseDateTime("2025-05-50 14:54:00"),
-//                    ListUtil.of("其他文件夹/报告公告"), EmailTypeConst.REPORT_EMAIL_TYPES);
-//        } catch (Exception e) {
-//            logger.error(ExceptionUtil.getMessage(e));
-//        }
-//
-//        try {
-//            // 确认函从 INBOX 文件夹获取邮件
-//            this.emailParseApiService.parseEmail(
-//                    DateUtil.parseDateTime("2025-05-15 11:44:00"),
-//                    DateUtil.parseDateTime("2025-05-15 16:32:00"),
-//                    null, ListUtil.of(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE));
-//        } catch (Exception e) {
-//            logger.error(ExceptionUtil.getMessage(e));
-//        }
+        try {
+            // 定期报告从 其他文件夹/报告公告 文件夹获取邮件
+            this.emailParseApiService.parseEmail(
+                    DateUtil.parseDateTime("2025-06-03 18:40:00"),
+                    DateUtil.parseDateTime("2025-06-03 19:56:00"),
+                    ListUtil.of("其他文件夹/报告公告"), EmailTypeConst.REPORT_EMAIL_TYPES);
+        } catch (Exception e) {
+            logger.error(ExceptionUtil.getMessage(e));
+        }
+
+        try {
+            // 确认函从 INBOX 文件夹获取邮件
+            this.emailParseApiService.parseEmail(
+                    DateUtil.parseDateTime("2025-06-03 18:50:00"),
+                    DateUtil.parseDateTime("2025-06-03 19:56:00"),
+                    null, ListUtil.of(EmailTypeConst.REPORT_LETTER_EMAIL_TYPE));
+        } catch (Exception e) {
+            logger.error(ExceptionUtil.getMessage(e));
+        }
     }
 
     /**

+ 9 - 4
mo-daq/src/main/java/com/smppw/modaq/common/enums/ReportParserFileType.java

@@ -1,15 +1,22 @@
 package com.smppw.modaq.common.enums;
 
+import cn.hutool.core.collection.ListUtil;
+import lombok.Getter;
+
 import java.util.Arrays;
+import java.util.List;
 
 /**
  * @author wangzaijun
  * @date 2024/9/29 10:57
  * @description 解析文件格式类型,支持调用python接口解析
  */
+@Getter
 public enum ReportParserFileType {
     PDF("pdf"),
-//    WORD("docx,doc"),
+    WORD("docx,doc"),
+    IMG_PNG("png"),
+    IMG_JPG("jpg"),
 //    EXCEL("xlsx,xls"),
 //    PYTHON("python");
     AI("ai");
@@ -25,7 +32,5 @@ public enum ReportParserFileType {
                 .filter(e -> e.getSuffix().contains(suffix)).findFirst().orElse(null);
     }
 
-    public String getSuffix() {
-        return suffix;
-    }
+    public static final List<ReportParserFileType> GENERATE_PNG_FILE_TYPES = ListUtil.of(ReportParserFileType.PDF, ReportParserFileType.WORD);
 }

+ 1 - 1
mo-daq/src/main/java/com/smppw/modaq/domain/dto/report/ReportBaseInfoDTO.java

@@ -51,7 +51,7 @@ public class ReportBaseInfoDTO extends BaseReportDTO<ReportBaseInfoDO> {
         entity.setReportDate(this.reportDate);
         entity.setReportName(this.reportName);
         entity.setReportType(this.reportType);
-        entity.setWithSeals(this.withSeals);
+//        entity.setWithSeals(this.withSeals);
         entity.setWithContacts(this.withContacts);
         this.initEntity(entity);
         return entity;

+ 4 - 4
mo-daq/src/main/java/com/smppw/modaq/domain/entity/report/ReportBaseInfoDO.java

@@ -27,10 +27,10 @@ public class ReportBaseInfoDO extends BaseReportDO {
      * 报告类型
      */
     private String reportType;
-    /**
-     * 报告是否用印
-     */
-    private Boolean withSeals;
+//    /**
+//     * 报告是否用印
+//     */
+//    private Boolean withSeals;
     /**
      * 观点报告是否存在联系人信息(可能包含联系电话、地址等敏感信息)
      */

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

@@ -421,19 +421,24 @@ public class EmailParseService {
         Integer fileId = emailFileInfo.getId();
 
         // 首页和尾页转为png图片,首页用来识别基金名称和基金代码、尾页用来识别印章和联系人
-        List<String> images = ListUtil.empty();
-        try {
-            String output = FileUtil.getParent(filepath, 1) + File.separator + "image";
-            images = PdfUtil.convertFirstAndLastPagesToPng(filepath, FileUtil.file(output), 300);
-            if (log.isDebugEnabled()) {
-                log.debug("报告[{}] 生成的图片地址是:{}", fileName, images);
-            }
-            // 首页和尾页相等
-            if (images.size() == 1) {
-                images.add(images.get(0));
+        List<String> images = ListUtil.list(true);
+        if (Objects.equals(ReportParserFileType.PDF, fileType)) {
+            try {
+                String output = FileUtil.getParent(filepath, 1) + File.separator + "image";
+                images = PdfUtil.convertFirstAndLastPagesToPng(filepath, FileUtil.file(output), 300);
+                if (log.isDebugEnabled()) {
+                    log.debug("报告[{}] 生成的图片地址是:{}", fileName, images);
+                }
+                // 首页和尾页相等
+                if (images.size() == 1) {
+                    images.add(images.get(0));
+                }
+            } catch (Exception e) {
+                log.warn("报告[{}] 生成图片失败:{}", fileName, ExceptionUtil.stacktraceToString(e));
             }
-        } catch (Exception e) {
-            log.warn("报告[{}] 生成图片失败:{}", fileName, ExceptionUtil.stacktraceToString(e));
+        } else if (Objects.equals(ReportParserFileType.IMG_PNG, fileType)) {
+            images.add(filepath);
+            images.add(filepath);
         }
 
         // 不支持解析的格式文件
@@ -553,15 +558,18 @@ public class EmailParseService {
             }
             if (reportData.getBaseInfo() != null && parseRes != null) {
                 Date reportDate = DateUtils.toDate(parseRes.getReportDate());
-                if (reportDate != null) {
+                if (reportDate != null && reportData.getBaseInfo().getReportDate() == null) {
                     reportData.getBaseInfo().setReportDate(reportDate);
                 }
             }
+            // ocr 识别的结果优先级更高
             if (reportData.getFundInfo() != null && parseRes != null) {
-                if (StrUtil.isBlank(reportData.getFundInfo().getFundName())) {
+                if (StrUtil.isBlank(reportData.getFundInfo().getFundName())
+                        || !Objects.equals(reportData.getFundInfo().getFundName(), parseRes.getFundName())) {
                     reportData.getFundInfo().setFundName(parseRes.getFundName());
                 }
-                if (StrUtil.isBlank(reportData.getFundInfo().getFundCode())) {
+                if (StrUtil.isBlank(reportData.getFundInfo().getFundCode())
+                        || !Objects.equals(reportData.getFundInfo().getFundCode(), parseRes.getFundCode())) {
                     reportData.getFundInfo().setFundCode(parseRes.getFundCode());
                 }
             }

+ 4 - 0
mo-daq/src/main/java/com/smppw/modaq/infrastructure/util/DateUtils.java

@@ -18,6 +18,10 @@ public class DateUtils {
         if (StrUtil.isBlank(input)) {
             return null;
         }
+        // 处理类似这样的日期区间"2024/01/01-2024/02/01"
+        if (input.contains("-") && input.contains("/")) {
+            input = StrUtil.split(input, "-").get(1);
+        }
         // 把字符串中的日期分隔符去掉,包括前后和中间
         input = input.replaceAll("-_/", "");
         try {

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

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