|
|
@@ -6,6 +6,7 @@ import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.center.excel.ExcelClassField; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.center.excel.ExcelExport; |
|
|
|
import com.qtzl.alterSales.manager.model.protocol.center.excel.ExcelImport; |
|
|
|
import com.qtzl.alterSales.manager.service.third.FileConfig; |
|
|
|
import com.qtzl.alterSales.manager.service.third.FmsService; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.poi.hssf.usermodel.HSSFDataValidation; |
|
|
@@ -399,22 +400,22 @@ public class ExcelUtils { |
|
|
|
return cell.getCellFormula(); |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> String exportTemplate(HttpServletResponse response, String fileName,String filePath, Class<T> clazz) { |
|
|
|
return exportTemplate(response, fileName,filePath, fileName, clazz, false); |
|
|
|
public static <T> String exportTemplate(HttpServletResponse response, String fileName, String filePath, Class<T> clazz) { |
|
|
|
return exportTemplate(response, fileName, filePath, fileName, clazz, false); |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> void exportTemplate(HttpServletResponse response, String fileName,String filePath, String sheetName, |
|
|
|
public static <T> void exportTemplate(HttpServletResponse response, String fileName, String filePath, String sheetName, |
|
|
|
Class<T> clazz) { |
|
|
|
exportTemplate(response, fileName,filePath, sheetName, clazz, false); |
|
|
|
exportTemplate(response, fileName, filePath, sheetName, clazz, false); |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> void exportTemplate(HttpServletResponse response, String fileName,String filePath, Class<T> clazz, |
|
|
|
public static <T> void exportTemplate(HttpServletResponse response, String fileName, String filePath, Class<T> clazz, |
|
|
|
boolean isContainExample) { |
|
|
|
exportTemplate(response, fileName,filePath, fileName, clazz, isContainExample); |
|
|
|
exportTemplate(response, fileName, filePath, fileName, clazz, isContainExample); |
|
|
|
} |
|
|
|
|
|
|
|
public static <T> String exportTemplate(HttpServletResponse response, String fileName,String filePath, String sheetName, |
|
|
|
Class<T> clazz, boolean isContainExample) { |
|
|
|
public static <T> String exportTemplate(HttpServletResponse response, String fileName, String filePath, String sheetName, |
|
|
|
Class<T> clazz, boolean isContainExample) { |
|
|
|
// 获取表头字段 |
|
|
|
List<ExcelClassField> headFieldList = getExcelClassFieldList(clazz); |
|
|
|
// 获取表头数据和示例数据 |
|
|
@@ -436,7 +437,7 @@ public class ExcelUtils { |
|
|
|
sheetDataList.add(exampleList); |
|
|
|
} |
|
|
|
// 导出数据 |
|
|
|
return export(response, fileName,filePath, sheetName, sheetDataList, selectMap); |
|
|
|
return export(response, fileName, filePath, sheetName, sheetDataList, selectMap); |
|
|
|
} |
|
|
|
|
|
|
|
private static <T> List<ExcelClassField> getExcelClassFieldList(Class<T> clazz) { |
|
|
@@ -549,7 +550,7 @@ public class ExcelUtils { |
|
|
|
} |
|
|
|
Map<String, List<List<Object>>> map = new HashMap<>(); |
|
|
|
map.put(file.getName(), sheetData); |
|
|
|
export(null, file, file.getName(),null, map, null); |
|
|
|
export(null, file, file.getName(), null, map, null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -671,61 +672,95 @@ public class ExcelUtils { |
|
|
|
return map; |
|
|
|
} |
|
|
|
|
|
|
|
public static String exportEmpty(HttpServletResponse response, String fileName,String filePath) { |
|
|
|
public static String exportEmpty(HttpServletResponse response, String fileName, String filePath) { |
|
|
|
List<List<Object>> sheetDataList = new ArrayList<>(); |
|
|
|
List<Object> headList = new ArrayList<>(); |
|
|
|
headList.add("导出无数据"); |
|
|
|
sheetDataList.add(headList); |
|
|
|
return export(response, fileName,filePath, sheetDataList); |
|
|
|
return export(response, fileName, filePath, sheetDataList); |
|
|
|
} |
|
|
|
|
|
|
|
public static String export(HttpServletResponse response, String fileName,String filePath, List<List<Object>> sheetDataList) { |
|
|
|
return export(response, fileName,filePath, fileName, sheetDataList, null); |
|
|
|
public static String export(HttpServletResponse response, String fileName, String filePath, List<List<Object>> sheetDataList) { |
|
|
|
return export(response, fileName, filePath, fileName, sheetDataList, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static void exportManySheet(HttpServletResponse response, String fileName,String filePath, Map<String, List<List<Object>>> sheetMap) { |
|
|
|
export(response, null, fileName,filePath, sheetMap, null); |
|
|
|
public static void exportManySheet(HttpServletResponse response, String fileName, String filePath, Map<String, List<List<Object>>> sheetMap) { |
|
|
|
export(response, null, fileName, filePath, sheetMap, null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void export(HttpServletResponse response, String fileName,String filePath, String sheetName, |
|
|
|
public static void export(HttpServletResponse response, String fileName, String filePath, String sheetName, |
|
|
|
List<List<Object>> sheetDataList) { |
|
|
|
export(response, fileName,filePath, sheetName, sheetDataList, null); |
|
|
|
export(response, fileName, filePath, sheetName, sheetDataList, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static String export(HttpServletResponse response, String fileName,String filePath, String sheetName, |
|
|
|
List<List<Object>> sheetDataList, Map<Integer, List<String>> selectMap) { |
|
|
|
public static String export(HttpServletResponse response, String fileName, String filePath, String sheetName, |
|
|
|
List<List<Object>> sheetDataList, Map<Integer, List<String>> selectMap) { |
|
|
|
|
|
|
|
Map<String, List<List<Object>>> map = new HashMap<>(); |
|
|
|
|
|
|
|
map.put(sheetName, sheetDataList); |
|
|
|
return export(response, null, fileName,filePath, map, selectMap); |
|
|
|
return export(response, null, fileName, filePath, map, selectMap); |
|
|
|
} |
|
|
|
|
|
|
|
public static <T, K> String export(HttpServletResponse response, String fileName,String filePath, List<T> list, Class<K> template) { |
|
|
|
|
|
|
|
public static <T, K> String export(HttpServletResponse response, String fileName, String filePath, List<T> list, Class<K> template) { |
|
|
|
// list 是否为空 |
|
|
|
boolean lisIsEmpty = list == null || list.isEmpty(); |
|
|
|
// 如果模板数据为空,且导入的数据为空,则导出空文件 |
|
|
|
if (template == null && lisIsEmpty) { |
|
|
|
return exportEmpty(response, fileName,filePath); |
|
|
|
return exportEmpty(response, fileName, filePath); |
|
|
|
|
|
|
|
} |
|
|
|
// 如果 list 数据,则导出模板数据 |
|
|
|
if (lisIsEmpty) { |
|
|
|
return exportTemplate(response, fileName,filePath, template); |
|
|
|
return exportTemplate(response, fileName, filePath, template); |
|
|
|
} |
|
|
|
// 导出数据 |
|
|
|
List<List<Object>> sheetDataList = getSheetData(list); |
|
|
|
return export(response, fileName,filePath, sheetDataList); |
|
|
|
return export(response, fileName, filePath, sheetDataList); |
|
|
|
} |
|
|
|
public static <T, K> String export(HttpServletResponse response, String fileName, String filePath, Map<String,List<T>> mapList, Class<K> template,Boolean pageSheet) { |
|
|
|
// list 是否为空 |
|
|
|
boolean lisIsEmpty = mapList == null || mapList.isEmpty(); |
|
|
|
// 如果模板数据为空,且导入的数据为空,则导出空文件 |
|
|
|
if (template == null && lisIsEmpty) { |
|
|
|
return exportEmpty(response, fileName, filePath); |
|
|
|
|
|
|
|
} |
|
|
|
// 如果 list 数据,则导出模板数据 |
|
|
|
if (lisIsEmpty) { |
|
|
|
return exportTemplate(response, fileName, filePath, template); |
|
|
|
} |
|
|
|
Map<String, List<List<Object>>> map = new HashMap<>(); |
|
|
|
Set<String> strings = mapList.keySet(); |
|
|
|
for (String key : strings) { |
|
|
|
List<T> sheetList = mapList.get(key); |
|
|
|
List<List<Object>> sheetDataList = getSheetData(sheetList); |
|
|
|
map.put(key, sheetDataList); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// for (int i = 0; i < page; i++) { |
|
|
|
// List<T> sheetList = new ArrayList<>(); |
|
|
|
// for (int j =i*FileConfig.FILEMAXNUM; j <(i+1)*FileConfig.FILEMAXNUM; j++) { |
|
|
|
// sheetList.add(list.get(j)); |
|
|
|
// } |
|
|
|
// List<List<Object>> sheetDataList = getSheetData(sheetList); |
|
|
|
// map.put(fileName+i, sheetDataList); |
|
|
|
// } |
|
|
|
return export(response, null, fileName, filePath, map, null); |
|
|
|
} |
|
|
|
|
|
|
|
public static String export(HttpServletResponse response, String fileName,String filePath, List<List<Object>> sheetDataList, Map<Integer, List<String>> selectMap) { |
|
|
|
return export(response, fileName,filePath, fileName, sheetDataList, selectMap); |
|
|
|
public static String export(HttpServletResponse response, String fileName, String filePath, List<List<Object>> sheetDataList, Map<Integer, List<String>> selectMap) { |
|
|
|
return export(response, fileName, filePath, fileName, sheetDataList, selectMap); |
|
|
|
} |
|
|
|
|
|
|
|
private static String export(HttpServletResponse response, File file, String fileName,String filePath, |
|
|
|
Map<String, List<List<Object>>> sheetMap, Map<Integer, List<String>> selectMap) { |
|
|
|
private static String export(HttpServletResponse response, File file, String fileName, String filePath, |
|
|
|
Map<String, List<List<Object>>> sheetMap, Map<Integer, List<String>> selectMap) { |
|
|
|
// 整个 Excel 表格 book 对象 |
|
|
|
SXSSFWorkbook book = new SXSSFWorkbook(); |
|
|
|
SXSSFWorkbook book = new SXSSFWorkbook(FileConfig.FILEMAXNUM); |
|
|
|
// 每个 Sheet 页 |
|
|
|
Set<Entry<String, List<List<Object>>>> entries = sheetMap.entrySet(); |
|
|
|
for (Entry<String, List<List<Object>>> entry : entries) { |
|
|
@@ -779,13 +814,13 @@ public class ExcelUtils { |
|
|
|
} |
|
|
|
// 本地导出 |
|
|
|
FileOutputStream fos; |
|
|
|
String updateFilePath =null; |
|
|
|
String updateFilePath = null; |
|
|
|
try { |
|
|
|
|
|
|
|
// String path = ResourceUtils.getURL("classpath:").getPath(); |
|
|
|
updateFilePath = filePath+ fileName + "_" + UUID.randomUUID().toString() + ".xlsx"; |
|
|
|
file= new File(updateFilePath); |
|
|
|
if(!file.isFile()) { //D |
|
|
|
// String path = ResourceUtils.getURL("classpath:").getPath(); |
|
|
|
updateFilePath = filePath + fileName + "_" + UUID.randomUUID().toString() + ".xlsx"; |
|
|
|
file = new File(updateFilePath); |
|
|
|
if (!file.isFile()) { //D |
|
|
|
file.createNewFile(); //E |
|
|
|
} |
|
|
|
fos = new FileOutputStream(file); |
|
|
@@ -999,7 +1034,7 @@ public class ExcelUtils { |
|
|
|
if (StringUtils.isBlank(str)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (StringUtils.isEmpty(str)){ |
|
|
|
if (StringUtils.isEmpty(str)) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
for (int i = str.length(); --i >= 0; ) { |