Commit e17ba019 authored by Gwofoo's avatar Gwofoo

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

parent 4bc2c299
......@@ -5,8 +5,6 @@ import com.yeejoin.amos.api.tool.face.service.RelationService;
import com.yeejoin.amos.api.tool.face.service.StudioResourceService;
import io.swagger.annotations.Api;
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.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType;
......@@ -16,7 +14,6 @@ import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
......@@ -84,14 +81,14 @@ public class RelationResource {
* @return String
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbName}")
@GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbSeqs}")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
// public ResponseModel<String> generateSQL(
// @RequestParam(value = "databaseName",required = false) String databaseName,
public void generateSQL(
@PathVariable String agencyCode,
@PathVariable Long ipSeq,
@PathVariable String dbName,
@PathVariable String dbSeqs,
HttpServletResponse response,
HttpServletRequest request) throws Exception {
Map<String, Object> variables = new HashMap<>();
......@@ -101,7 +98,7 @@ public class RelationResource {
// int end = referer.indexOf("&agencyCode=");
// String ipSeq = referer.substring(start,end);
// 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");
}
......
......@@ -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 {
DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(ipSeq);
//根据连接查询到数据库表名
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);
File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath();
......@@ -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 = databaseName+DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String fileName = databaseName + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String sqlFilePath = backPath + SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out;
......@@ -245,6 +256,8 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
writer.close();
out.close();
download(response, fileName, sqlFilePath);
}
connection.close();
} catch (IOException e) {
e.printStackTrace();
} 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