Procházet zdrojové kódy

excel报告解析的表格对象字段调整

wangzaijun před 6 měsíci
rodič
revize
c6a884ea3f

+ 22 - 17
service-base/src/main/java/com/simuwang/base/pojo/dto/report/SimpleTable.java

@@ -25,7 +25,7 @@ public class SimpleTable implements Serializable {
     /**
      * 表格数据行
      */
-    private final List<List<String>> tables;
+    private final List<List<String>> data;
     /**
      * 表格列数
      */
@@ -39,14 +39,14 @@ public class SimpleTable implements Serializable {
         this.tableKey = tableKey;
         this.title = title;
         this.colCount = colCount;
-        this.tables = ListUtil.list(true);
+        this.data = ListUtil.list(true);
     }
 
     public void addRow(List<String> row) {
-        tables.add(row);
+        data.add(row);
         this.rowCount++;
         if (this.colCount == 0) {
-            this.colCount = this.tables.stream().map(List::size).max(Comparator.naturalOrder()).orElse(0);
+            this.colCount = this.data.stream().map(List::size).max(Comparator.naturalOrder()).orElse(0);
         }
     }
 
@@ -66,19 +66,24 @@ public class SimpleTable implements Serializable {
         return title;
     }
 
-    public List<List<String>> getTables() {
-        int subRows = this.rowCount - this.tables.size();
+    /**
+     * 获取表格数据,如果当前表格的行不等于约定的表格行则需要追加null值行
+     *
+     * @return /
+     */
+    public List<List<String>> getData() {
+        int subRows = this.rowCount - this.data.size();
         if (subRows <= 0) {
-            return this.tables;
+            return this.data;
         }
         for (int i = 0; i < subRows; i++) {
             List<String> row = ListUtil.list(true);
             for (int j = 0; j < this.colCount; j++) {
                 row.add(null);
             }
-            this.tables.add(row);
+            this.data.add(row);
         }
-        return this.tables;
+        return this.data;
     }
 
     /**
@@ -87,7 +92,7 @@ public class SimpleTable implements Serializable {
      * @return /
      */
     public Iterator<List<String>> iterator() {
-        return new TableIterator(this.getTables());
+        return new TableIterator(this.getData());
     }
 
     /**
@@ -98,7 +103,7 @@ public class SimpleTable implements Serializable {
      * @return 单元格内容
      */
     public String getCell(int row, int column) {
-        List<List<String>> rows = this.getTables();
+        List<List<String>> rows = this.getData();
         if (row < 0 || row >= rows.size() || column < 0 || column >= rows.get(row).size()) {
             throw new IndexOutOfBoundsException("Invalid row or column index");
         }
@@ -109,7 +114,7 @@ public class SimpleTable implements Serializable {
     public String toString() {
         return "SimpleTable{" +
                 "title='" + title + '\'' +
-                ", tables=" + tables +
+                ", data=" + data +
                 '}';
     }
 
@@ -117,21 +122,21 @@ public class SimpleTable implements Serializable {
      * 内部迭代器类
      */
     private static class TableIterator implements Iterator<List<String>> {
-        private final List<List<String>> tables;
+        private final List<List<String>> data;
         private int currentIndex = 0;
 
-        public TableIterator(List<List<String>> tables) {
-            this.tables = tables;
+        public TableIterator(List<List<String>> data) {
+            this.data = data;
         }
 
         @Override
         public boolean hasNext() {
-            return currentIndex < tables.size();
+            return currentIndex < data.size();
         }
 
         @Override
         public List<String> next() {
-            return tables.get(currentIndex++);
+            return data.get(currentIndex++);
         }
     }
 }

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

@@ -72,8 +72,8 @@ public class ExcelAnnuallyReportParser extends AbstractExcelReportParser<Annuall
         Map<String, Object> fundInfoMap = MapUtil.newHashMap(32);
         for (SimpleTable table : simpleTables) {
             Map<String, Object> baseInfoMap = MapUtil.newHashMap(32);
-            for (int i = 0; i < table.getTables().size(); i++) {
-                List<String> cols = table.getTables().get(i);
+            for (int i = 0; i < table.getData().size(); i++) {
+                List<String> cols = table.getData().get(i);
                 for (int j = 0; j < 1; j++) {
                     baseInfoMap.put(cols.get(j), cols.get(j + 1));
                 }
@@ -100,7 +100,7 @@ public class ExcelAnnuallyReportParser extends AbstractExcelReportParser<Annuall
         }
         Function<SimpleTable, Map<String, Object>> function = t -> {
             Map<String, Object> infoMap = MapUtil.newHashMap(16);
-            for (List<String> table : t.getTables()) {
+            for (List<String> table : t.getData()) {
                 String name = table.get(0);
                 if (name == null) {
                     continue;
@@ -208,7 +208,7 @@ public class ExcelAnnuallyReportParser extends AbstractExcelReportParser<Annuall
         }
         List<ReportAssetAllocationDTO> dtos = ListUtil.list(false);
         // 按行遍历
-        for (List<String> row : assetAllocationTable.getTables()) {
+        for (List<String> row : assetAllocationTable.getData()) {
             String marketValueAndRemark = row.get(2);
             String detail = row.get(1);
             if (!ReportParseUtils.ASSET_ALLOCATION_TYPE_MAPPER.containsKey(detail)) {

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

@@ -58,11 +58,10 @@ public class ExcelMonthlyReportParser extends AbstractExcelReportParser<MonthlyR
         if (fundInfoTable == null) {
             throw new ReportParseException(ReportParseStatus.PARSE_FUND_INFO_FAIL, params.getFilename());
         }
-        // 月报的基金基本信息是四列的表格
         Map<String, Object> baseInfoMap = MapUtil.newHashMap(32);
-        for (int i = 0; i < fundInfoTable.getTables().size(); i++) {
+        for (int i = 0; i < fundInfoTable.getData().size(); i++) {
             @SuppressWarnings("all")
-            List<String> row = fundInfoTable.getTables().get(i);
+            List<String> row = fundInfoTable.getData().get(i);
             for (int j = 0; j < 2; j++) {
                 baseInfoMap.put(row.get(j * 2), row.get(j * 2 + 1));
             }

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

@@ -68,10 +68,9 @@ public class ExcelQuarterlyReportParser extends AbstractExcelReportParser<Quarte
         if (fundInfoTable == null) {
             throw new ReportParseException(ReportParseStatus.PARSE_FUND_INFO_FAIL, params.getFilename());
         }
-        // 季报和年报的基金基本信息是两列的表格
         Map<String, Object> baseInfoMap = MapUtil.newHashMap(32);
-        for (int i = 0; i < fundInfoTable.getTables().size(); i++) {
-            List<String> cols = fundInfoTable.getTables().get(i);
+        for (int i = 0; i < fundInfoTable.getData().size(); i++) {
+            List<String> cols = fundInfoTable.getData().get(i);
             for (int j = 0; j < 1; j++) {
                 baseInfoMap.put(cols.get(j), cols.get(j + 1));
             }
@@ -96,7 +95,7 @@ public class ExcelQuarterlyReportParser extends AbstractExcelReportParser<Quarte
         }
         Function<SimpleTable, Map<String, Object>> function = t -> {
             Map<String, Object> infoMap = MapUtil.newHashMap(16);
-            for (List<String> table : t.getTables()) {
+            for (List<String> table : t.getData()) {
                 String name = table.get(0);
                 if (name == null) {
                     continue;
@@ -123,7 +122,7 @@ public class ExcelQuarterlyReportParser extends AbstractExcelReportParser<Quarte
         }
         Function<SimpleTable, Map<String, Object>> function = t -> {
             Map<String, Object> infoMap = MapUtil.newHashMap(16);
-            for (List<String> table : t.getTables()) {
+            for (List<String> table : t.getData()) {
                 String name = table.get(0);
                 if (name == null) {
                     continue;
@@ -186,7 +185,7 @@ public class ExcelQuarterlyReportParser extends AbstractExcelReportParser<Quarte
         }
         List<ReportAssetAllocationDTO> dtos = ListUtil.list(false);
         // 按行遍历
-        for (List<String> row : assetAllocationTable.getTables()) {
+        for (List<String> row : assetAllocationTable.getData()) {
             String marketValueAndRemark = row.get(2);
             String detail = row.get(1);
             if (!ReportParseUtils.ASSET_ALLOCATION_TYPE_MAPPER.containsKey(detail)) {