Browse Source

解析变更记录数据修改为通过sheetname解析

fengyanjie 4 years ago
parent
commit
6b1482200a

+ 54 - 0
dmp-common/src/main/java/com/persagy/dmp/common/excel/ExcelUtils.java

@@ -43,6 +43,60 @@ public class ExcelUtils {
         return null;
     }
 
+    public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos, List<String> sheetNameList) {
+        List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
+
+        try {
+            Workbook workbook = new XSSFWorkbook(inputStream);
+
+            for (int infoIndex = 0; infoIndex < infos.size(); infoIndex++) {
+                List<Map<String, Object>> result = new ArrayList<>();
+                answer.add(result);
+
+                Sheet sheet = workbook.getSheet(sheetNameList.get(infoIndex));
+                SheetReadInfo info = infos.get(infoIndex);
+                Integer startRow = info.getStartRow();
+                List<Integer> columnIndexs = info.getColumnIndexs();
+                List<String> keys = info.getColumnKeys();
+                List<String> types = info.getColumnTypes();
+
+                int lastRowNum = sheet.getLastRowNum();
+                for (int rowIndex = startRow; rowIndex < lastRowNum + 1; rowIndex++) {
+                    Row row = sheet.getRow(rowIndex);
+                    if (null == row) {
+                        System.err.println("==========rowIndex:" + rowIndex);
+                        continue;
+                    }
+                    Map<String, Object> data = new HashMap<>();
+                    for (int columnDefIndex = 0; columnDefIndex < columnIndexs.size(); columnDefIndex++) {
+                        Integer columnIndex = columnIndexs.get(columnDefIndex);
+                        String key = keys.get(columnDefIndex);
+                        String type = types.get(columnDefIndex);
+                        Cell cell = row.getCell(columnIndex);
+                        if (null == cell) {
+                            System.err.println("==========columnIndex:" + columnIndex);
+                            continue;
+                        }
+                        Object value = parseCell(cell, type);
+                        if (null != value) {
+                            data.put(key, value);
+                        }
+                    }
+                    if (0 < data.size()) {
+                        data.put(info.getSeqKey(), rowIndex);
+                        result.add(data);
+                    }
+                }
+            }
+            workbook.close();
+        } catch (Exception e) {
+            e.printStackTrace();
+        } finally {
+        }
+        return answer;
+
+    }
+
     public static List<List<Map<String, Object>>> read(InputStream inputStream, List<SheetReadInfo> infos) {
         List<List<Map<String, Object>>> answer = new ArrayList<>(infos.size());
 

+ 3 - 3
dmp-rwd-edit/src/main/java/com/persagy/dmp/rwd/edit/service/UploadService.java

@@ -100,9 +100,9 @@ public class UploadService {
         info2.add(14, "formater", "string");
         info2.add(15, "note", "string");
 
-        List<List<Map<String, Object>>> result = ExcelUtils.read(file.getInputStream(), Arrays.asList(new SheetReadInfo(), info1, info2));
-        List<ClassDefChangeRecord> classDefChangeRecordList = compareDataExcelReadClass(result.get(1));
-        List<FuncidDefChangeRecord> funcidDefChangeRecordList = compareDataExcelReadFuncid(result.get(2));
+        List<List<Map<String, Object>>> result = ExcelUtils.read(file.getInputStream(), Arrays.asList(info1, info2),Arrays.asList("类型变更","信息点变更"));
+        List<ClassDefChangeRecord> classDefChangeRecordList = compareDataExcelReadClass(result.get(0));
+        List<FuncidDefChangeRecord> funcidDefChangeRecordList = compareDataExcelReadFuncid(result.get(1));
 
         Map<String, Object> map = new HashMap<>();
         map.put("classDefChangeRecordList", classDefChangeRecordList);