public void exportFile(File destFile, ExportConfig exportConfig) throws ExportFileException { String format = exportConfig.getFormat(); long start = System.currentTimeMillis(); if ("csv".equalsIgnoreCase(format)) { this.exportCsvFile(destFile, exportConfig); } else if ("excel".equalsIgnoreCase(format)) { this.exportExcelFile(destFile, exportConfig); } log.debug("导出耗时:" + ((System.currentTimeMillis() - start) / 1000) + " 秒"); }
private void exportCsvFile(File destFile, ExportConfig exportConfig) throws ExportFileException { CSVWriter csvWriter = null; try { csvWriter = new CSVWriter(new FileWriterWithEncoding(destFile, "gbk")); List<Map> list = this.listAllAsMap(exportConfig.getSearchCondition()); String[] line = null; line = new String[] { "机房名称", "场地号", "模块号", "框号 ", "槽号", "端口号", "设备号", "是否反极", "产品号码", "MDF横列(不准)", }; csvWriter.writeNext(line); MapValueGetter mvg = null; for (Map map : list) { mvg = new MapValueGetter(map); line = new String[] { mvg.getAsString("jfmc"), mvg.getAsIntegerString("cdh"), mvg.getAsIntegerString("mkh"), mvg.getAsIntegerString("kh"), mvg.getAsIntegerString("ch"), mvg.getAsIntegerString("dkh"), mvg.getAsIntegerString("sbh"), mvg.getAsTrimedString("fj"), mvg.getAsTrimedString("dhhm"), mvg.getAsTrimedString("hl"), }; csvWriter.writeNext(line); } csvWriter.flush(); csvWriter.close(); } catch (IOException e) { throw new ExportFileException(e); } finally { if (csvWriter != null) { try { csvWriter.close(); } catch (IOException e) { } } } }