Commit e17ba019 authored by Gwofoo's avatar Gwofoo

修改脚本导出-库管理-导出脚本接口

parent 4bc2c299
...@@ -5,8 +5,6 @@ import com.yeejoin.amos.api.tool.face.service.RelationService; ...@@ -5,8 +5,6 @@ import com.yeejoin.amos.api.tool.face.service.RelationService;
import com.yeejoin.amos.api.tool.face.service.StudioResourceService; import com.yeejoin.amos.api.tool.face.service.StudioResourceService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
...@@ -16,7 +14,6 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel; ...@@ -16,7 +14,6 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
...@@ -84,14 +81,14 @@ public class RelationResource { ...@@ -84,14 +81,14 @@ public class RelationResource {
* @return String * @return String
*/ */
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbName}") @GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbSeqs}")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出") @ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
// public ResponseModel<String> generateSQL( // public ResponseModel<String> generateSQL(
// @RequestParam(value = "databaseName",required = false) String databaseName, // @RequestParam(value = "databaseName",required = false) String databaseName,
public void generateSQL( public void generateSQL(
@PathVariable String agencyCode, @PathVariable String agencyCode,
@PathVariable Long ipSeq, @PathVariable Long ipSeq,
@PathVariable String dbName, @PathVariable String dbSeqs,
HttpServletResponse response, HttpServletResponse response,
HttpServletRequest request) throws Exception { HttpServletRequest request) throws Exception {
Map<String, Object> variables = new HashMap<>(); Map<String, Object> variables = new HashMap<>();
...@@ -101,7 +98,7 @@ public class RelationResource { ...@@ -101,7 +98,7 @@ public class RelationResource {
// int end = referer.indexOf("&agencyCode="); // int end = referer.indexOf("&agencyCode=");
// String ipSeq = referer.substring(start,end); // String ipSeq = referer.substring(start,end);
// studioResourceService.generateSQL("Agency","agencyCode", ipSeq, variables, response); // studioResourceService.generateSQL("Agency","agencyCode", ipSeq, variables, response);
studioResourceService.generateSQLByDatabaseName("Agency","agencyCode",dbName, ipSeq, variables, response); studioResourceService.generateSQLByDatabaseName("Agency","agencyCode",dbSeqs, ipSeq, variables, response);
// return ResponseHelper.buildResponse("yes"); // return ResponseHelper.buildResponse("yes");
} }
......
...@@ -177,13 +177,24 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -177,13 +177,24 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
} }
} }
public void generateSQLByDatabaseName(String resourceCode, String dimension, String databaseName, Long ipSeq, Map<String, Object> variables, HttpServletResponse response) { public void generateSQLByDatabaseName(String resourceCode, String dimension, String dbSeqs, Long ipSeq, Map<String, Object> variables, HttpServletResponse response) {
try { try {
DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(ipSeq); DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(ipSeq);
//根据连接查询到数据库表名 //根据连接查询到数据库表名
Connection connection = dataBaseLinkService.connectNewDatabase(dataBaseLinkModel); Connection connection = dataBaseLinkService.connectNewDatabase(dataBaseLinkModel);
// List<String> list = DataBaseUtils.getList("select table_name from information_schema.tables where table_schema='" + dataBaseLinkModel.getPrefix()+""+databaseName + "';", connection);
List<String> list = DataBaseUtils.getList("select table_name from information_schema.tables where table_schema='" +""+databaseName + "';", connection); // 查询所有数据库
List<String> allDbs = DataBaseUtils.getList("show databases;", connection);
List<String> databaseNames = new ArrayList<>();
String[] queryDbSeqs = dbSeqs.split(","); // 序号从1开始
for (int i = 0; i < queryDbSeqs.length; i ++ ) {
int idx = Integer.parseInt(queryDbSeqs[i]);
databaseNames.add(allDbs.get(idx - 1));
}
// 查询到需要导出多个,在databaseNames中,循环,多次下载
for (String databaseName : databaseNames) {
List<String> list = DataBaseUtils.getList("select table_name from information_schema.tables where table_schema='" + "" + databaseName + "';", connection);
List<StudioResourceModel> resourceList = queryForStudioResourceList(resourceCode); List<StudioResourceModel> resourceList = queryForStudioResourceList(resourceCode);
File directory = new File("");// 参数为空 File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath(); String coursePath = directory.getCanonicalPath();
...@@ -195,7 +206,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -195,7 +206,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
} }
// 备份文件路径名称 // 备份文件路径名称
// String fileName = (SourceEnum.IDX.getSource().equals(resourceCode.toLowerCase()) ? (resourceCode.toLowerCase() + "_") : "studio_") + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX; // String fileName = (SourceEnum.IDX.getSource().equals(resourceCode.toLowerCase()) ? (resourceCode.toLowerCase() + "_") : "studio_") + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String fileName = databaseName+DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX; String fileName = databaseName + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String sqlFilePath = backPath + SLASH + fileName; String sqlFilePath = backPath + SLASH + fileName;
File file = new File(sqlFilePath); File file = new File(sqlFilePath);
FileOutputStream out; FileOutputStream out;
...@@ -245,6 +256,8 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -245,6 +256,8 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
writer.close(); writer.close();
out.close(); out.close();
download(response, fileName, sqlFilePath); download(response, fileName, sqlFilePath);
}
connection.close();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (SQLException e) { } catch (SQLException e) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment