Parcourir la source

fix:feat:excel报告解析完成,提测

wangzaijun il y a 6 mois
Parent
commit
c4bb3898a5

+ 12 - 12
service-base/src/main/java/com/simuwang/base/pojo/dto/report/CustomExcelTable.java

@@ -18,9 +18,9 @@ public class CustomExcelTable implements Serializable {
      */
     private final String key;
     /**
-     * 表格识别标题(equals或者contains识别),不能为空
+     * 表格识别标题(equals或者contains识别),不能为空,多个用逗号分隔
      */
-    private final String title;
+    private final String titles;
     /**
      * 表格识别列数(不能小于等于0)
      */
@@ -34,26 +34,26 @@ public class CustomExcelTable implements Serializable {
      */
     private final int startCol;
 
-    public CustomExcelTable(String key, String title, int colCount) {
-        this(key, title, colCount, 0);
+    public CustomExcelTable(String key, String titles, int colCount) {
+        this(key, titles, colCount, 0);
     }
 
-    public CustomExcelTable(String key, String title, int colCount, int rowCount) {
-        this(key, title, colCount, rowCount, 1);
+    public CustomExcelTable(String key, String titles, int colCount, int rowCount) {
+        this(key, titles, colCount, rowCount, 1);
     }
 
-    public CustomExcelTable(String key, String title, int colCount, int rowCount, int startCol) {
+    public CustomExcelTable(String key, String titles, int colCount, int rowCount, int startCol) {
         if (key == null) {
             throw new NullPointerException("table key is null.");
         }
-        if (title == null) {
-            throw new NullPointerException("table title is null.");
+        if (titles == null) {
+            throw new NullPointerException("table titles is null.");
         }
         if (colCount <= 0) {
             throw new IndexOutOfBoundsException("table col index out of.");
         }
         this.key = key;
-        this.title = title;
+        this.titles = titles;
         this.colCount = colCount;
         this.rowCount = rowCount <= 0 ? Integer.MAX_VALUE : rowCount;
         this.startCol = Math.max(startCol, 1);
@@ -63,8 +63,8 @@ public class CustomExcelTable implements Serializable {
         return key;
     }
 
-    public String getTitle() {
-        return title;
+    public String getTitles() {
+        return titles;
     }
 
     public int getColCount() {

+ 0 - 12
service-base/src/main/java/com/simuwang/base/pojo/dto/report/ReportInvestmentIndustryDTO.java

@@ -13,10 +13,6 @@ import lombok.Setter;
 @Getter
 public class ReportInvestmentIndustryDTO extends BaseReportDTO<ReportInvestmentIndustryDO> {
     /**
-     * 行业分类编码
-     */
-    private String industryCode;
-    /**
      * 行业分类名称
      */
     private String industryName;
@@ -25,10 +21,6 @@ public class ReportInvestmentIndustryDTO extends BaseReportDTO<ReportInvestmentI
      */
     private Integer investType;
     /**
-     * 行业标准编码
-     */
-    private String isbCode;
-    /**
      * 公允价值,市值
      */
     private String marketValue;
@@ -49,10 +41,8 @@ public class ReportInvestmentIndustryDTO extends BaseReportDTO<ReportInvestmentI
     public ReportInvestmentIndustryDO toEntity() {
         ReportInvestmentIndustryDO entity = new ReportInvestmentIndustryDO();
         entity.setFileId(this.getFileId());
-        entity.setIndustryCode(this.industryCode);
         entity.setIndustryName(this.industryName);
         entity.setInvestType(this.investType);
-        entity.setIsbCode(this.isbCode);
         entity.setMarketValue(this.toBigDecimal(this.marketValue));
         entity.setRatio(this.toBigDecimal(this.ratio));
         return entity;
@@ -62,10 +52,8 @@ public class ReportInvestmentIndustryDTO extends BaseReportDTO<ReportInvestmentI
     public String toString() {
         return "{" +
                 super.toString() +
-                ", industryCode='" + industryCode + '\'' +
                 ", industryName='" + industryName + '\'' +
                 ", investType=" + investType +
-                ", isbCode='" + isbCode + '\'' +
                 ", marketValue=" + marketValue +
                 ", ratio=" + ratio +
                 '}';

+ 6 - 2
service-daq/src/main/java/com/simuwang/daq/components/CustomExcelMultiSheetListener.java

@@ -1,6 +1,7 @@
 package com.simuwang.daq.components;
 
 import cn.hutool.core.collection.ListUtil;
+import cn.hutool.core.util.StrUtil;
 import com.alibaba.excel.context.AnalysisContext;
 import com.alibaba.excel.event.AnalysisEventListener;
 import com.alibaba.excel.read.metadata.holder.ReadSheetHolder;
@@ -44,11 +45,14 @@ public class CustomExcelMultiSheetListener extends AnalysisEventListener<LinkedH
         }
         @SuppressWarnings("unchecked")
         List<CustomExcelTable> customExcelTables = (List<CustomExcelTable>) analysisContext.getCustom();
+        // 表格行的第一个位置的字符串
         String title = ReportParseUtils.cleaningValue(row.get(1));
         if (title != null) {
+            // 判断是否标题行:如果是标题行或者是另外一个表格的标题行,则重新声明一个表格并追加到解析结果中
             for (CustomExcelTable customExcelTable : customExcelTables) {
-                String tableTitle = customExcelTable.getTitle();
-                if (title.equals(tableTitle) || title.contains(tableTitle)) {
+                String tableTitles = customExcelTable.getTitles();
+                long containCount = StrUtil.split(tableTitles, ",").stream().filter(title::contains).count();
+                if (title.equals(tableTitles) || title.contains(tableTitles) || containCount > 0) {
                     this.table = new SimpleTable(customExcelTable.getKey(), title, customExcelTable.getColCount());
                     this.customExcelTable = customExcelTable;
                     this.tables.add(this.table);

+ 2 - 1
service-daq/src/main/java/com/simuwang/daq/components/ReportParseUtils.java

@@ -90,7 +90,7 @@ public final class ReportParseUtils {
         ASSET_ALLOCATION_TYPE_MAPPER.put("其中:优先股", "境内未上市、未挂牌公司股权投资");
         ASSET_ALLOCATION_TYPE_MAPPER.put("其他股权类投资", "境内未上市、未挂牌公司股权投资");
         // 上市公司定向增发投资
-        ASSET_ALLOCATION_TYPE_MAPPER.put("上市公司定向增发投资", "上市公司定向增发投资");
+        ASSET_ALLOCATION_TYPE_MAPPER.put("上市公司定向增发股票投资", "上市公司定向增发投资");
         // 新三板投资
         ASSET_ALLOCATION_TYPE_MAPPER.put("新三板挂牌企业投资", "新三板投资");
         // 境内证券投资规模
@@ -183,6 +183,7 @@ public final class ReportParseUtils {
     public static List<String> matchTieredFund(String text) {
         List<String> matches = ListUtil.list(false);
         if (StrUtil.isBlank(text)) {
+            matches.add("母基金");
             return matches;
         }
         // 使用正则表达式查找匹配项

+ 5 - 2
service-daq/src/main/java/com/simuwang/daq/components/report/parser/excel/AbstractExcelReportParser.java

@@ -32,6 +32,9 @@ public abstract class AbstractExcelReportParser<T extends ReportData> extends Ab
         try {
             ExcelReaderBuilder readerBuilder = EasyExcel.read(params.getFilepath());
             readerBuilder.sheet();
+            // 没有表头
+            readerBuilder.headRowNumber(0);
+            // 自定义的对象,传递到事件监听器中
             readerBuilder.customObject(this.customExcelTables());
             readerBuilder.registerReadListener(excelListener);
             readerBuilder.doReadAll();
@@ -104,9 +107,9 @@ public abstract class AbstractExcelReportParser<T extends ReportData> extends Ab
         String titles = tables.stream().map(SimpleTable::getTitle).collect(Collectors.joining(","));
         List<String> levels = ReportParseUtils.matchTieredFund(titles);
         List<DTO> dtos = ListUtil.list(true);
-        for (int i = 0; i < tables.size(); i++) {
+        for (int i = 0; i < levels.size(); i++) {
             String level = levels.get(i);
-            if (StrUtil.isBlank(level)) {
+            if (i >= tables.size() || StrUtil.isBlank(level)) {
                 continue;
             }
             Map<String, Object> infoMap = function.apply(tables.get(i));

+ 6 - 3
service-daq/src/main/java/com/simuwang/daq/components/report/parser/excel/ExcelAnnuallyReportParser.java

@@ -35,7 +35,7 @@ public class ExcelAnnuallyReportParser extends AbstractExcelReportParser<Annuall
         customExcelTables.add(new CustomExcelTable("financialIndicators", "主要会计数据和财务指标", 4));
         customExcelTables.add(new CustomExcelTable("financialIndicators", "级基金主要会计数据和财务指标", 4, 10));
         customExcelTables.add(new CustomExcelTable("assetAllocation", "期末基金资产组合情况", 3));
-        customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的股票投资组合", 4));
+        customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的境内股票投资组合", 4));
         customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的港股通投资股票投资组合", 3));
         customExcelTables.add(new CustomExcelTable("shareChange", "基金份额变动情况", 2, 6));
         customExcelTables.add(new CustomExcelTable("shareChange", "级基金份额变动情况", 2, 6));
@@ -129,8 +129,11 @@ public class ExcelAnnuallyReportParser extends AbstractExcelReportParser<Annuall
         // 分级基金
         String titles = simpleTables.stream().map(SimpleTable::getTitle).collect(Collectors.joining(","));
         List<String> levels = ReportParseUtils.matchTieredFund(titles);
-        // 存在分级基金
-        for (int k = 0; k < simpleTables.size(); k++) {
+        for (int k = 0; k < levels.size(); k++) {
+            String level = levels.get(k);
+            if (k >= simpleTables.size() || StrUtil.isBlank(level)) {
+                continue;
+            }
             SimpleTable table = simpleTables.get(k);
             int colCount = table.getColCount();
             for (int j = 1; j < colCount; j++) {

+ 1 - 1
service-daq/src/main/java/com/simuwang/daq/components/report/parser/excel/ExcelQuarterlyReportParser.java

@@ -34,7 +34,7 @@ public class ExcelQuarterlyReportParser extends AbstractExcelReportParser<Quarte
         customExcelTables.add(new CustomExcelTable("financialIndicators", "主要财务指标", 5, 6));
         customExcelTables.add(new CustomExcelTable("financialIndicators", "级基金主要财务指标", 5, 6));
         customExcelTables.add(new CustomExcelTable("assetAllocation", "期末基金资产组合情况", 3));
-        customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的股票投资组合", 4));
+        customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的境内股票投资组合,报告期末按行业分类的股票投资组合", 4));
         customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的港股通投资股票投资组合", 3));
         customExcelTables.add(new CustomExcelTable("shareChange", "基金份额变动情况", 2, 6));
         customExcelTables.add(new CustomExcelTable("shareChange", "级基金份额变动情况", 2, 6));

+ 3 - 1
service-daq/src/main/java/com/simuwang/daq/utils/ExcelReportParseUtil.java

@@ -18,7 +18,7 @@ public class ExcelReportParseUtil {
         customExcelTables.add(new CustomExcelTable("financialIndicators", "主要财务指标", 5, 6));
         customExcelTables.add(new CustomExcelTable("financialIndicators", "级基金主要财务指标", 5, 6));
         customExcelTables.add(new CustomExcelTable("assetAllocation", "期末基金资产组合情况", 3));
-        customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的股票投资组合", 4));
+        customExcelTables.add(new CustomExcelTable("investmentIndustry", "按行业分类的", 4));
         customExcelTables.add(new CustomExcelTable("investmentIndustry", "报告期末按行业分类的港股通投资股票投资组合", 3));
         customExcelTables.add(new CustomExcelTable("shareChange", "基金份额变动情况", 3, 6));
         customExcelTables.add(new CustomExcelTable("shareChange", "级基金份额变动情况", 3, 6));
@@ -26,6 +26,8 @@ public class ExcelReportParseUtil {
         CustomExcelMultiSheetListener readListener = new CustomExcelMultiSheetListener();
         ExcelReaderBuilder readerBuilder = EasyExcel.read(filepath);
         readerBuilder.sheet();
+        // 没有表头行
+        readerBuilder.headRowNumber(0);
         readerBuilder.customObject(customExcelTables);
         readerBuilder.registerReadListener(readListener);
         readerBuilder.doReadAll();

+ 4 - 4
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: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);
+        Date startDate = DateUtil.parse("2024-10-15 11:10:30", DateConst.YYYY_MM_DD_HH_MM_SS);
+        Date endDate = DateUtil.parse("2024-10-15 17:50:30", DateConst.YYYY_MM_DD_HH_MM_SS);
         try {
             emailParseService.parseEmail(emailInfoDTO, startDate, endDate);
         } catch (Exception e) {
@@ -77,8 +77,8 @@ public class ApplicationTest {
     private MailboxInfoDTO buildMailbox() {
         MailboxInfoDTO emailInfoDTO = new MailboxInfoDTO();
         emailInfoDTO.setUserId(1);
-        emailInfoDTO.setAccount("*");
-        emailInfoDTO.setPassword("*");
+        emailInfoDTO.setAccount("wangzaijun@simuwang.com");
+        emailInfoDTO.setPassword("WZJ2twy1314");
         emailInfoDTO.setHost("imap.exmail.qq.com");
         emailInfoDTO.setPort("993");
         emailInfoDTO.setProtocol("imap");