Ver código fonte

feat:pdf报告解析的字段映射配置

wangzaijun 7 meses atrás
pai
commit
41f7ae3f5e

+ 28 - 33
service-daq/src/main/java/com/simuwang/daq/components/report/parser/AbstractReportParser.java

@@ -7,13 +7,11 @@ import com.simuwang.base.common.conts.Constants;
 import com.simuwang.base.mapper.EmailFieldMappingMapper;
 import com.simuwang.base.pojo.dos.EmailFieldMappingDO;
 import com.simuwang.base.pojo.dto.report.ReportData;
-import com.smppw.common.pojo.ValueLabelVO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import java.util.List;
 import java.util.Map;
-import java.util.stream.Collectors;
 
 public abstract class AbstractReportParser<T extends ReportData> implements ReportParser<T> {
     protected final Logger logger = LoggerFactory.getLogger(this.getClass());
@@ -22,7 +20,7 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
     /**
      * 字段匹配规则
      */
-    protected List<ValueLabelVO> fieldMapper;
+    protected Map<String, String> fieldMapper;
 
     public AbstractReportParser(EmailFieldMappingMapper fieldMappingMapper) {
         this.fieldMappingMapper = fieldMappingMapper;
@@ -35,7 +33,13 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
             this.logger.error("未设置报告解析规则!");
             return;
         }
-        this.fieldMapper = emailFieldMapping.stream().map(e -> new ValueLabelVO(e.getCode(), e.getName())).collect(Collectors.toList());
+        for (EmailFieldMappingDO mapping : emailFieldMapping) {
+            String code = mapping.getCode();
+            List<String> names = StrUtil.split(mapping.getName(), ",");
+            for (String name : names) {
+                this.fieldMapper.putIfAbsent(name, code);
+            }
+        }
     }
 
     /**
@@ -46,37 +50,28 @@ public abstract class AbstractReportParser<T extends ReportData> implements Repo
      */
     protected void buildInfo(Map<String, Object> extInfoMap, Object info) {
         for (Map.Entry<String, Object> entry : extInfoMap.entrySet()) {
-            String k = entry.getKey();
-            Object v = entry.getValue();
-            String fieldValue = StrUtil.toStringOrNull(v);
-            if (fieldValue.startsWith("-") || fieldValue.endsWith("-")) {
-                fieldValue = null;
+            String k = this.cleaningValue(entry.getKey());
+            String fieldValue = this.cleaningValue(entry.getValue());
+            String fieldName = this.fieldMapper.get(k);
+            if (StrUtil.isBlank(fieldName)) {
+                continue;
             }
-            if (fieldValue != null) {
-                fieldValue = fieldValue.replace("\r", Constants.EMPTY);
-            }
-            for (ValueLabelVO vo : this.fieldMapper) {
-                String fieldName = vo.getValue();
-                List<String> labels = StrUtil.split(vo.getLabel(), ",");
-                if (labels.contains(k)) {
-                    try {
-                        ReflectUtil.setFieldValue(info, fieldName, fieldValue);
-                    } catch (Exception e) {
-                        this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
-                    }
-                    break;
-                }
-                for (String label : labels) {
-                    if (k.contains(label)) {
-                        try {
-                            ReflectUtil.setFieldValue(info, fieldName, fieldValue);
-                        } catch (Exception e) {
-                            this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
-                        }
-                        break;
-                    }
-                }
+            try {
+                ReflectUtil.setFieldValue(info, fieldName, fieldValue);
+            } catch (Exception e) {
+                this.logger.warn("{} 字段值设置错误:{}", fieldName, e.getMessage());
             }
         }
     }
+
+    private String cleaningValue(Object value) {
+        String fieldValue = StrUtil.toStringOrNull(value);
+        if (fieldValue.startsWith("-") || fieldValue.endsWith("-")) {
+            fieldValue = null;
+        }
+        if (fieldValue != null) {
+            fieldValue = fieldValue.replace("\r", Constants.EMPTY);
+        }
+        return StrUtil.isBlank(fieldValue) ? null : fieldValue;
+    }
 }

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

@@ -121,7 +121,7 @@ public abstract class AbstractPDReportParser<T extends ReportData> extends Abstr
         } else {
             reportName = text;
         }
-        return reportName.replace("(", "(").replace(")", ")");
+        return reportName.replace("(", "(").replace(")", ")").trim();
     }
 
     /**

+ 2 - 0
service-daq/src/main/java/com/simuwang/daq/components/report/parser/pdf/PDMonthlyReportParser.java

@@ -63,6 +63,7 @@ public class PDMonthlyReportParser extends AbstractPDReportParser<MonthlyReportD
         }
         // 匹配字段清洗字段
         ReportFundInfoDTO reportFundInfo = new ReportFundInfoDTO();
+        reportFundInfo.setFileId(params.getFileId());
         this.buildInfo(baseInfoMap, reportFundInfo);
         return reportFundInfo;
     }
@@ -83,6 +84,7 @@ public class PDMonthlyReportParser extends AbstractPDReportParser<MonthlyReportD
                 extInfoMap.put(key, value);
             }
             ReportNetReportDTO navInfo = new ReportNetReportDTO();
+            navInfo.setFileId(params.getFileId());
             buildInfo(extInfoMap, navInfo);
             exts.add(navInfo);
         }

+ 5 - 5
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-09-26 10:25:00", DateConst.YYYY_MM_DD_HH_MM_SS);
-        Date endDate = DateUtil.parse("2024-09-26 19:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date startDate = DateUtil.parse("2024-09-30 08:50:00", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date endDate = DateUtil.parse("2024-09-30 19:40:00", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
         } catch (Exception e) {
@@ -76,9 +76,9 @@ public class ApplicationTest {
 
     private MailboxInfoDTO buildMailbox() {
         MailboxInfoDTO emailInfoDTO = new MailboxInfoDTO();
-        emailInfoDTO.setUserId(2395446);
-        emailInfoDTO.setAccount("mozuwen@simuwang.com");
-        emailInfoDTO.setPassword("Mzw@0306");
+        emailInfoDTO.setUserId(1);
+        emailInfoDTO.setAccount("wangzaijun@simuwang.com");
+        emailInfoDTO.setPassword("WZJ2twy1314");
         emailInfoDTO.setHost("imap.exmail.qq.com");
         emailInfoDTO.setPort("993");
         emailInfoDTO.setProtocol("imap");