|
@@ -19,8 +19,10 @@ import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
import com.ruoyi.framework.config.ServerConfig;
|
|
import com.ruoyi.system.entity.CommonEntity;
|
|
import com.ruoyi.system.entity.CommonEntity;
|
|
import com.ruoyi.system.entity.TableInfo;
|
|
import com.ruoyi.system.entity.TableInfo;
|
|
|
|
+import com.ruoyi.system.entity.TableSql;
|
|
import com.ruoyi.system.service.ICommonService;
|
|
import com.ruoyi.system.service.ICommonService;
|
|
import com.ruoyi.system.service.IDataSourceService;
|
|
import com.ruoyi.system.service.IDataSourceService;
|
|
|
|
+import com.ruoyi.system.service.ITableSqlService;
|
|
import io.lettuce.core.ScriptOutputType;
|
|
import io.lettuce.core.ScriptOutputType;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.models.auth.In;
|
|
import io.swagger.models.auth.In;
|
|
@@ -72,6 +74,9 @@ public class CommonFileController {
|
|
@Resource
|
|
@Resource
|
|
private ICommonService commonService;
|
|
private ICommonService commonService;
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
+ private ITableSqlService iTableSqlService;
|
|
|
|
+
|
|
private static final String FILE_DELIMETER = ",";
|
|
private static final String FILE_DELIMETER = ",";
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -185,22 +190,20 @@ public class CommonFileController {
|
|
@Anonymous
|
|
@Anonymous
|
|
@ApiOperation("上传文件")
|
|
@ApiOperation("上传文件")
|
|
@PostMapping(value = "/uploadData", headers = "content-type=multipart/form-data")
|
|
@PostMapping(value = "/uploadData", headers = "content-type=multipart/form-data")
|
|
- public AjaxResult uploadDataFile(String tableName, @RequestPart("file") MultipartFile file) throws Exception {
|
|
|
|
- Map<String, Object> map = new HashMap<>();
|
|
|
|
- map.put("tableName", "test");
|
|
|
|
- map.put("databaseType", "mysql");
|
|
|
|
- map.put("databaseName", "zkqy-call");
|
|
|
|
|
|
+ public AjaxResult uploadDataFile(String tableName, String sqlKey, @RequestPart("file") MultipartFile file) throws Exception {
|
|
try {
|
|
try {
|
|
// 创建一个工作簿对象 解析上传的excel表数据
|
|
// 创建一个工作簿对象 解析上传的excel表数据
|
|
List<Map<String, String>> listMap = convertList(EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync());
|
|
List<Map<String, String>> listMap = convertList(EasyExcel.read(file.getInputStream()).sheet().headRowNumber(0).doReadSync());
|
|
- // 查询当前文件插入表结构
|
|
|
|
- List<TableInfo> tableInfoList = dataSourceService.tableFieldInfo(map);
|
|
|
|
- Map<String, Object> fieldMap = new HashMap<>(); // 存储 字段描述:字段列名
|
|
|
|
- tableInfoList.forEach(item -> {
|
|
|
|
- fieldMap.put(item.getFieldDescription(), item.getFieldName());
|
|
|
|
|
|
+ // 得到当前导出入数据的格式k/v
|
|
|
|
+ TableSql tableSql = iTableSqlService.selectTableSqlByTSqlKey(sqlKey);
|
|
|
|
+ // 存储 字段描述:字段列名
|
|
|
|
+ Map<String, Object> fieldMap = (Map<String, Object>) JSON.parse(tableSql.getTableExportField());
|
|
|
|
+ Map<String, Object> endFieldMap = new HashMap<>();
|
|
|
|
+ fieldMap.forEach((mKey, mVal) -> {
|
|
|
|
+ endFieldMap.put(mVal.toString(), mKey);
|
|
});
|
|
});
|
|
listMap.get(0).forEach((mKey, mVal) -> {
|
|
listMap.get(0).forEach((mKey, mVal) -> {
|
|
- if (mVal != null) listMap.get(0).put(mKey, fieldMap.get(mVal).toString());
|
|
|
|
|
|
+ if (mVal != null) listMap.get(0).put(mKey, endFieldMap.get(mVal).toString());
|
|
});
|
|
});
|
|
// 挣个excel文件数据
|
|
// 挣个excel文件数据
|
|
listMap.forEach(item -> {
|
|
listMap.forEach(item -> {
|
|
@@ -213,7 +216,7 @@ public class CommonFileController {
|
|
});
|
|
});
|
|
listMap.remove(0);
|
|
listMap.remove(0);
|
|
CommonEntity commonEntity = new CommonEntity();
|
|
CommonEntity commonEntity = new CommonEntity();
|
|
- commonEntity.setBasicMap(JSONObject.parseObject("{ \"tableName\":\"test\"}", new TypeReference<Map<String, Object>>() {
|
|
|
|
|
|
+ commonEntity.setBasicMap(JSONObject.parseObject("{ \"tableName\":\"" + tableName + "\"}", new TypeReference<Map<String, Object>>() {
|
|
}));
|
|
}));
|
|
commonEntity.setAddListMap(listMap);
|
|
commonEntity.setAddListMap(listMap);
|
|
return success(commonService.batchInsert(commonEntity));
|
|
return success(commonService.batchInsert(commonEntity));
|