|
@@ -45,10 +45,7 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
import java.io.File;
|
|
|
import java.io.FileInputStream;
|
|
|
import java.io.FileReader;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
|
|
@@ -79,6 +76,26 @@ public class CommonFileController {
|
|
|
|
|
|
private static final String FILE_DELIMETER = ",";
|
|
|
|
|
|
+ /**
|
|
|
+ * 通用导出excel
|
|
|
+ */
|
|
|
+ @PostMapping("/export")
|
|
|
+ public void export(HttpServletResponse response, CommonEntity commonEntity) throws Exception {
|
|
|
+ commonService.export(response, commonEntity);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 通用导出excel模版
|
|
|
+ *
|
|
|
+ * @param response
|
|
|
+ * @param tableName
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @PostMapping("/exportTemplate")
|
|
|
+ public void exportTemplate(HttpServletResponse response, String tableName, String sqlkey) throws Exception {
|
|
|
+ commonService.exportTemplate(response, tableName, sqlkey);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 通用下载请求
|
|
|
*
|
|
@@ -194,16 +211,38 @@ public class CommonFileController {
|
|
|
try {
|
|
|
// 创建一个工作簿对象 解析上传的excel表数据
|
|
|
List<Map<String, String>> listMap = convertList(EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync());
|
|
|
+
|
|
|
+ if (listMap.size() <= 1) {
|
|
|
+ return AjaxResult.warn("请检查表格中的数据!");
|
|
|
+ }
|
|
|
+
|
|
|
// 得到当前导出入数据的格式k/v
|
|
|
TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(sqlKey);
|
|
|
// 存储 字段描述:字段列名
|
|
|
Map<String, Object> fieldMap = (Map<String, Object>) JSON.parse(tableSql.getTableExportField());
|
|
|
Map<String, Object> endFieldMap = new HashMap<>();
|
|
|
+ // 处理导入title对应问题,双重校验
|
|
|
fieldMap.forEach((mKey, mVal) -> {
|
|
|
- endFieldMap.put(mVal.toString(), mKey);
|
|
|
+ if (!mKey.contains("@")) {
|
|
|
+ endFieldMap.put(mVal.toString(), mKey);
|
|
|
+ } else {
|
|
|
+ // 定义新的title map集合
|
|
|
+ Map<String, String> map = listMap.get(0);
|
|
|
+ // 根据val值删除当前map中的k/v(此处是title,理论上不会有重复的val存在)
|
|
|
+ map.values().removeIf(value -> value.contains(mVal.toString()));
|
|
|
+ // 删除旧title
|
|
|
+ listMap.remove(0);
|
|
|
+ // 替换新title
|
|
|
+ listMap.add(0, map);
|
|
|
+ }
|
|
|
});
|
|
|
+ if (listMap.get(0).size() != listMap.get(2).size()) {
|
|
|
+ return AjaxResult.error("请检查表格中的数据是否正确!");
|
|
|
+ }
|
|
|
listMap.get(0).forEach((mKey, mVal) -> {
|
|
|
- if (mVal != null) listMap.get(0).put(mKey, endFieldMap.get(mVal).toString());
|
|
|
+ if (mVal != null)
|
|
|
+ if (endFieldMap.get(mVal) != null)
|
|
|
+ listMap.get(0).put(mKey, endFieldMap.get(mVal).toString());
|
|
|
});
|
|
|
// 挣个excel文件数据
|
|
|
listMap.forEach(item -> {
|
|
@@ -225,7 +264,6 @@ public class CommonFileController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
// map类型转换
|
|
|
public static List<Map<String, String>> convertList(List<Map<Integer, String>> inputList) {
|
|
|
List<Map<String, String>> resultList = new ArrayList<>();
|