Browse Source

fix:修复报告解析的相关bug

wangzaijun 6 months ago
parent
commit
cf2d61083f

+ 3 - 3
service-base/src/main/java/com/simuwang/base/common/enums/ReportType.java

@@ -4,9 +4,9 @@ import lombok.Getter;
 
 @Getter
 public enum ReportType {
-    MONTHLY(0, "月", new String[]{"月", "月度", "月报"}),
-    QUARTERLY(1, "季", new String[]{"季", "季度", "季报"}),
-    ANNUALLY(2, "年", new String[]{"年", "年度", "年报"});
+    MONTHLY(0, "月", new String[]{"月", "月度", "月报"}),
+    QUARTERLY(1, "季", new String[]{"季", "季度", "季报"}),
+    ANNUALLY(2, "年", new String[]{"年", "年度", "年报"});
 
     private final int type;
     private final String label;

+ 3 - 3
service-base/src/main/java/com/simuwang/base/pojo/dto/report/BaseReportDTO.java

@@ -47,7 +47,7 @@ public abstract class BaseReportDTO<T extends BaseReportDO> {
         try {
             // 日期格式化,支持三种格式:yyyy年MM月dd日、yyyy-MM-dd和yyyy/MM/dd
             return DateUtil.parse(input.trim(),
-                    DatePattern.CHINESE_DATE_PATTERN, DatePattern.NORM_DATE_PATTERN, "yyyy/MM/dd");
+                    DatePattern.CHINESE_DATE_PATTERN, DatePattern.NORM_DATE_PATTERN, "yyyy/MM/dd", "yyyyMMdd");
         } catch (Exception ignored) {
         }
         return null;
@@ -64,8 +64,8 @@ public abstract class BaseReportDTO<T extends BaseReportDO> {
             return null;
         }
         try {
-            // 替换掉数字分位的逗号
-            String cleanedInput = input.trim().replaceAll(",", "");
+            // 替换掉非正常的正负小数字符
+            String cleanedInput = input.trim().replaceAll("[^\\s" + "[-+]?\\d*\\.?\\d+" + "]", "");
             // 创建BigDecimal对象
             return new BigDecimal(cleanedInput);
         } catch (NumberFormatException ignored) {

+ 8 - 11
service-daq/src/main/java/com/simuwang/daq/components/report/parser/pdf/AbstractPDReportParser.java

@@ -5,6 +5,7 @@ import cn.hutool.core.exceptions.ExceptionUtil;
 import cn.hutool.core.map.MapUtil;
 import cn.hutool.core.util.StrUtil;
 import com.simuwang.base.common.conts.Constants;
+import com.simuwang.base.common.enums.ReportType;
 import com.simuwang.base.common.exception.ReportParseException;
 import com.simuwang.base.mapper.EmailFieldMappingMapper;
 import com.simuwang.base.pojo.dto.report.*;
@@ -317,18 +318,14 @@ public abstract class AbstractPDReportParser<T extends ReportData> extends Abstr
         if (string == null) {
             return null;
         }
-        // 所有报告的正则识别方式(年在最后)
-        String patterns = "年度|年报|季度|季报|季|月度|月报|月|年";
-        // 编译正则表达式模式
-        Pattern pattern = Pattern.compile(patterns);
-        // 创建Matcher对象
-        Matcher matcher = pattern.matcher(string);
-        // 尝试匹配
-        if (matcher.find()) {
-            return matcher.group();
-        } else {
-            return null;
+        // 类型识别---先识别季度报告,没有季度再识别年度报告,最后识别月报
+        ReportType reportType = ReportType.MONTHLY;
+        if (StrUtil.containsAny(string, ReportType.QUARTERLY.getPatterns())) {
+            reportType = ReportType.QUARTERLY;
+        } else if (StrUtil.containsAny(string, ReportType.ANNUALLY.getPatterns())) {
+            reportType = ReportType.ANNUALLY;
         }
+        return reportType.getLabel();
     }
 
     private int getLastDayOfMonth(int year, int month) {

+ 2 - 2
service-deploy/src/test/java/com/simuwang/ApplicationTest.java

@@ -45,8 +45,8 @@ public class ApplicationTest {
     @Test
     public void reportTest() {
         MailboxInfoDTO emailInfoDTO = this.buildMailbox();
-        Date startDate = DateUtil.parse("2024-10-12 17:42:30", DateConst.YYYY_MM_DD_HH_MM_SS);
-        Date endDate = DateUtil.parse("2024-10-12 17:59:30", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date startDate = DateUtil.parse("2024-10-12 17:40:30", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date endDate = DateUtil.parse("2024-10-12 17:50:30", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
         } catch (Exception e) {