| @@ -154,7 +154,10 @@ | |||
| Object.keys(resp.data.data).forEach(async (key) => { | |||
| await this.getHeaders(key); | |||
| }); | |||
| setTimeout(() => {this.result = resp.data.data; this.progress = false;}, 500); | |||
| setTimeout(() => { | |||
| this.result = resp.data.data; | |||
| this.progress = false; | |||
| }, 500); | |||
| // this.result = resp.data.data; | |||
| }); | |||
| }, | |||
| @@ -141,7 +141,8 @@ public class InventoryController { | |||
| descriptMap.put(m.getColname(), m.getDescript2()); | |||
| } | |||
| ExcelExpoter excelExpoter = new ExcelExpoter(""); | |||
| excelExpoter.expoerDataExcel(resp, titleKeyList, titleMap, descriptMap, items, info.get("tablename")); | |||
| String sheetName = mappingTableDAO.findTitle(info.get("tablename")); | |||
| excelExpoter.expoerDataExcel(resp, titleKeyList, titleMap, descriptMap, items, info.get("tablename"), sheetName); | |||
| } | |||
| @GetMapping("/allHeaders") | |||
| @@ -55,30 +55,60 @@ public class SearchController { | |||
| Iterator<Map.Entry<String, List<Map<String, Object>>>> iterator = data.entrySet().iterator(); | |||
| // Iterator<Map.Entry<String, List<Map<String, Object>>>> iterator = data.entrySet().iterator(); | |||
| // | |||
| // | |||
| // Map<String, ArrayList<String>>titleKeyLists = new ManagedMap<>(); | |||
| // Map<String, Map<String, String>> titleMaps = new ManagedMap<>(); | |||
| // Map<String, Map<String, String>> descriptMaps = new ManagedMap<>(); | |||
| // while (iterator.hasNext()) { | |||
| // Map.Entry<String, List<Map<String, Object>>> next = iterator.next(); | |||
| // String key = next.getKey(); | |||
| // List<MappingCol> mappingCols = mappingColDAO.findByTable(key); | |||
| // ArrayList<String> titleKeyList= new ArrayList<>(); | |||
| // Map<String, String> titleMap = new ManagedMap<>(); | |||
| // Map<String, String> descriptMap = new ManagedMap<>(); | |||
| // for(MappingCol m: mappingCols) { | |||
| // titleKeyList.add(m.getColname()); | |||
| // titleMap.put(m.getColname(), m.getDescript()); | |||
| // descriptMap.put(m.getColname(), m.getDescript2()); | |||
| // } | |||
| // titleKeyLists.put(key, titleKeyList); | |||
| // titleMaps.put(key, titleMap); | |||
| // descriptMaps.put(key, descriptMap); | |||
| // } | |||
| // ExcelExpoter excelExpoter = new ExcelExpoter(""); | |||
| // List<MappingTable> mappingTables = mappingTableDAO.findAll(); | |||
| // Map<String, String> mappingSheetNames = new HashMap<>(); | |||
| // for (MappingTable mappingTable : mappingTables) { | |||
| // mappingSheetNames.put(mappingTable.getTablename(), mappingTable.getDescript()); | |||
| // } | |||
| // excelExpoter.expoerDataExcelMultiSheet(resp, titleKeyLists, titleMaps, descriptMaps, data, "", mappingSheetNames); | |||
| List<MappingTable> mappingTables = mappingTableDAO.findAll(); | |||
| Map<String, String> mappingSheetNames = new ManagedMap<>(); | |||
| Map<String, ArrayList<String>>titleKeyLists = new ManagedMap<>(); | |||
| Map<String, Map<String, String>> titleMaps = new ManagedMap<>(); | |||
| Map<String, Map<String, String>> descriptMaps = new ManagedMap<>(); | |||
| while (iterator.hasNext()) { | |||
| Map.Entry<String, List<Map<String, Object>>> next = iterator.next(); | |||
| String key = next.getKey(); | |||
| List<MappingCol> mappingCols = mappingColDAO.findByTable(key); | |||
| ArrayList<String> titleKeyList= new ArrayList<>(); | |||
| Map<String, String> titleMap = new ManagedMap<>(); | |||
| Map<String, String> descriptMap = new ManagedMap<>(); | |||
| for(MappingCol m: mappingCols) { | |||
| titleKeyList.add(m.getColname()); | |||
| titleMap.put(m.getColname(), m.getDescript()); | |||
| descriptMap.put(m.getColname(), m.getDescript2()); | |||
| for (MappingTable mappingTable : mappingTables) { | |||
| if (data.get(mappingTable.getTablename()) != null) { | |||
| List<MappingCol> mappingCols = mappingColDAO.findByTable(mappingTable.getTablename()); | |||
| ArrayList<String> titleKeyList= new ArrayList<>(); | |||
| Map<String, String> titleMap = new ManagedMap<>(); | |||
| Map<String, String> descriptMap = new ManagedMap<>(); | |||
| for(MappingCol m: mappingCols) { | |||
| titleKeyList.add(m.getColname()); | |||
| titleMap.put(m.getColname(), m.getDescript()); | |||
| descriptMap.put(m.getColname(), m.getDescript2()); | |||
| } | |||
| titleKeyLists.put(mappingTable.getTablename(), titleKeyList); | |||
| titleMaps.put(mappingTable.getTablename(), titleMap); | |||
| descriptMaps.put(mappingTable.getTablename(), descriptMap); | |||
| mappingSheetNames.put(mappingTable.getTablename(), mappingTable.getDescript()); | |||
| } | |||
| titleKeyLists.put(key, titleKeyList); | |||
| titleMaps.put(key, titleMap); | |||
| descriptMaps.put(key, descriptMap); | |||
| } | |||
| ExcelExpoter excelExpoter = new ExcelExpoter(""); | |||
| excelExpoter.expoerDataExcelMultiSheet(resp, titleKeyLists, titleMaps, descriptMaps, data, ""); | |||
| excelExpoter.expoerDataExcelMultiSheet(resp, titleKeyLists, titleMaps, descriptMaps, data, "", mappingSheetNames); | |||
| } | |||
| } | |||
| @@ -24,7 +24,7 @@ public interface AccountDAO extends SqlObject { | |||
| List<Account> findAll(); | |||
| @RegisterBeanMapper(List.class) | |||
| @SqlQuery("select * from department;") | |||
| @SqlQuery("select * from department order by department;") | |||
| List<String> finfDepartments(); | |||
| @@ -3,6 +3,7 @@ package com.moze.rms.utils; | |||
| import java.io.*; | |||
| import java.util.*; | |||
| import com.moze.rms.entity.model.MappingTable; | |||
| import org.apache.poi.hssf.usermodel.HSSFCellStyle; | |||
| import org.apache.poi.hssf.usermodel.HSSFFont; | |||
| import org.apache.poi.hssf.usermodel.HSSFWorkbook; | |||
| @@ -177,7 +178,7 @@ public class ExcelExpoter { | |||
| } | |||
| public void expoerDataExcel(HttpServletResponse response, ArrayList<String> titleKeyList, Map<String, String> titleMap, Map<String, String> descriptMap, List<Map<String, Object>> src_list, String filename) throws IOException { | |||
| public void expoerDataExcel(HttpServletResponse response, ArrayList<String> titleKeyList, Map<String, String> titleMap, Map<String, String> descriptMap, List<Map<String, Object>> src_list, String filename, String sheetName) throws IOException { | |||
| String xlsFile_name = filename + ".xls"; //輸出xls檔名稱 | |||
| //記憶體中只建立100個物件 | |||
| @@ -199,7 +200,7 @@ public class ExcelExpoter { | |||
| //寫入300000條後切換到下個工作表 | |||
| if (rowNo % 300000 == 0) { | |||
| System.out.println("Current Sheet:" + rowNo / 300000); | |||
| sheet = wb.createSheet("工作表1");//建立新的sheet物件 | |||
| sheet = wb.createSheet(sheetName);//建立新的sheet物件 | |||
| sheet = wb.getSheetAt(rowNo / 300000); //動態指定當前的工作表 | |||
| pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | |||
| // -----------定義表頭----------- | |||
| @@ -238,6 +239,7 @@ public class ExcelExpoter { | |||
| cell_tem.setCellStyle(descriptStyle); | |||
| } | |||
| rowNo++; | |||
| sheet.createFreezePane(0, 2); | |||
| // --------------------------- | |||
| } | |||
| rowNo++; | |||
| @@ -265,7 +267,7 @@ public class ExcelExpoter { | |||
| } | |||
| public void expoerDataExcelMultiSheet(HttpServletResponse response, Map<String, ArrayList<String>> titleKeyLists, Map<String, Map<String, String>> titleMaps, Map<String, Map<String, String>> descriptMaps, Map<String, List<Map<String, Object>>> src_lists, String filename) throws IOException { | |||
| public void expoerDataExcelMultiSheet(HttpServletResponse response, Map<String, ArrayList<String>> titleKeyLists, Map<String, Map<String, String>> titleMaps, Map<String, Map<String, String>> descriptMaps, Map<String, List<Map<String, Object>>> src_lists, String filename, Map<String, String> sheetNames) throws IOException { | |||
| String xlsFile_name = "SeverList.xls"; //輸出xls檔名稱 | |||
| //記憶體中只建立100個物件 | |||
| @@ -295,7 +297,7 @@ public class ExcelExpoter { | |||
| //寫入300000條後切換到下個工作表 | |||
| if (rowNo % 300000 == 0) { | |||
| System.out.println("Current Sheet:" + key); | |||
| sheet = wb.createSheet(key);//建立新的sheet物件 | |||
| sheet = wb.createSheet(sheetNames.get(key));//建立新的sheet物件 | |||
| // sheet = wb.getSheetAt(k); //動態指定當前的工作表 | |||
| pageRowNo = 0; //新建了工作表,重置工作表的行號為0 | |||
| // -----------定義表頭----------- | |||
| @@ -334,12 +336,11 @@ public class ExcelExpoter { | |||
| cell_tem.setCellStyle(descriptStyle); | |||
| } | |||
| rowNo++; | |||
| sheet.createFreezePane(0, 2); | |||
| // --------------------------- | |||
| } | |||
| rowNo++; | |||
| nRow = sheet.createRow(pageRowNo++); //新建行物件 | |||
| // 行,獲取cell值 | |||
| for (int j = 0; j < titleKeyLists.get(key).size(); j++) { | |||
| nCell = nRow.createCell(j); | |||
| @@ -369,4 +370,5 @@ public class ExcelExpoter { | |||
| outputStream.flush(); | |||
| outputStream.close(); | |||
| } | |||
| } | |||
| @@ -3,6 +3,9 @@ package com.moze.rms; | |||
| import org.junit.jupiter.api.Test; | |||
| import org.springframework.boot.test.context.SpringBootTest; | |||
| import java.util.HashMap; | |||
| import java.util.Map; | |||
| @SpringBootTest | |||
| class RmsApplicationTests { | |||
| @@ -10,4 +13,9 @@ class RmsApplicationTests { | |||
| void contextLoads() { | |||
| } | |||
| @Test | |||
| public static void main(String[] args) { | |||
| Map<String, String> a = new HashMap<>(); | |||
| System.out.println(a.get("asd")); | |||
| } | |||
| } | |||