Commit 97f06ed9 authored by chenzai's avatar chenzai

commit 排查原赵智代码

parent 2ce6d0b5
......@@ -55,27 +55,69 @@ public class RelationResource {
*
* @return String
*/
// @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
// @GetMapping(value = "/export/{agencyCode}/{sequenceNbrs}")
// @ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
//// public ResponseModel<String> generateSQL(
//// @RequestParam(value = "databaseName",required = false) String databaseName,
// public void generateSQL(
// @PathVariable String agencyCode,
// @PathVariable String sequenceNbrs,
// HttpServletResponse response,
// HttpServletRequest request) throws Exception {
// Map<String, Object> variables = new HashMap<>();
// variables.put("agencyCode", agencyCode);
// String referer = request.getHeader("Referer");
// int start = referer.indexOf("ipSeq=")+6;
// int end = referer.indexOf("&agencyCode=");
// String ipSeq = referer.substring(start,end);
// Long longIpSql = Long.parseLong(ipSeq);
// studioResourceService.generateSQL("Agency","agencyCode", longIpSql, variables, response);
// studioResourceService.generateSQLByDatabaseName("Agency","agencyCode",databaseName, longIpSql, variables, response);
//// return ResponseHelper.buildResponse("yes");
// }
/**
* 导出SQL脚本
*
* @return String
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/{agencyCode}/{sequenceNbrs}")
@GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbName}")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
// public ResponseModel<String> generateSQL(
// @RequestParam(value = "databaseName",required = false) String databaseName,
public void generateSQL(
@PathVariable String agencyCode,
@PathVariable String sequenceNbrs,
@PathVariable Long ipSeq,
@PathVariable String dbName,
HttpServletResponse response,
HttpServletRequest request) throws Exception {
Map<String, Object> variables = new HashMap<>();
variables.put("agencyCode", agencyCode);
String referer = request.getHeader("Referer");
int start = referer.indexOf("ipSeq=")+6;
int end = referer.indexOf("&agencyCode=");
String ipSeq = referer.substring(start,end);
Long longIpSql = Long.parseLong(ipSeq);
studioResourceService.generateSQL("Agency","agencyCode", longIpSql, variables, response);
// studioResourceService.generateSQLByDatabaseName("Agency","agencyCode",databaseName, longIpSql, variables, response);
// String referer = request.getHeader("Referer");
// int start = referer.indexOf("ipSeq=")+6;
// 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);
// return ResponseHelper.buildResponse("yes");
}
// @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
// @GetMapping(value = "/export/{agencyCode}/{ipSeq}/{dbName}")
// @ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
// public ResponseModel<String> generateSQL(
// @PathVariable String agencyCode,
// @PathVariable Long ipSeq,
// @PathVariable String dbName,
// HttpServletResponse response) throws Exception {
// relationService.outputAgency(agencyCode, ipSeq,dbName,response);
// return ResponseHelper.buildResponse("yes");
// }
}
\ No newline at end of file
......@@ -5,7 +5,12 @@ import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseNameList;
import org.mapstruct.Mapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Mapper
@Repository
public interface DataBaseNameListMapper extends BaseMapper<DataBaseNameList> {
List<DataBaseNameList> queryList();
}
package com.yeejoin.amos.api.tool.face.service;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel;
......@@ -20,6 +21,9 @@ public class DataBaseNameListService extends BaseService<DataBaseNameListModel,
@Autowired
private DataBaseLinkService dataBaseLinkService;
@Autowired
private DataBaseNameListMapper dataBaseNameListMapper;
/**
* 分页查询
*/
......@@ -36,12 +40,15 @@ public class DataBaseNameListService extends BaseService<DataBaseNameListModel,
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
List<DataBaseNameListModel> list=new ArrayList<>();
long result=1;
try {
while (rs.next()){
DataBaseNameListModel listModel=new DataBaseNameListModel();
listModel.setDbName(rs.getString("Database"));
listModel.setParentId(parentId);
listModel.setSequenceNbr(result);
list.add(listModel);
result++;
}
} catch (SQLException e) {
e.printStackTrace();
......@@ -55,13 +62,22 @@ public class DataBaseNameListService extends BaseService<DataBaseNameListModel,
}
}
connection.close();
// List<DataBaseNameList> dataBaseNameLists = dataBaseNameListMapper.queryList();
// for (DataBaseNameList dataBaseNameList:dataBaseNameLists){
// for (DataBaseNameListModel dataBaseNameListModel:list){
// if (dataBaseNameList.getDbName().equals(dataBaseNameListModel.getDbName())){
// dataBaseLinkModel.setSequenceNbr(dataBaseNameList.getSequenceNbr());
// }
// }
// }
int count = list.size();
page.setSize(size);
page.setCurrent(current);
page.setTotal(count);
//计算分页总页数
page.setPages(count %10 == 0 ? count/10 :count/10+1);
page.setRecords(list);
int startIndex = (current - 1) * size;
page.setRecords(list.subList(startIndex, Math.min(startIndex + size, list.size())));
return page;
}
......
......@@ -66,14 +66,14 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
/**
* 导出机构
*/
public void outputAgency(String agencyCode, String sequenceNbrs, HttpServletResponse response) throws Exception {
for (Long seq : (Long[]) ConvertUtils.convert(StringUtil.string2Array(sequenceNbrs), Long.class)) {
DataBaseNameListModel nameListModel = dataBaseNameListService.queryBySeq(seq);
DataBaseLinkModel model = dataBaseLinkService.queryBySeq(nameListModel.getParentId());
public void outputAgency(String agencyCode,Long ipSeq, String dbName, HttpServletResponse response) throws Exception {
// for (Long seq : (Long[]) ConvertUtils.convert(StringUtil.string2Array(sequenceNbrs), Long.class)) {
// DataBaseNameListModel nameListModel = dataBaseNameListService.queryBySeq(seq);
DataBaseLinkModel model = dataBaseLinkService.queryBySeq(ipSeq);
Connection connection = dataBaseLinkService.connectNewDatabase(model);
model.setDbName(nameListModel.getDbName());
this.insertData(connection, agencyCode, model.getDbName(),seq, response);
}
model.setDbName(dbName);
this.insertData(connection, agencyCode, model.getDbName(), ipSeq, response);
// }
}
/**
......@@ -130,6 +130,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
public List<RelationTreeModel> createTree(List<RelationTreeModel> relationTreeModels, String parentName) {
List<RelationTreeModel> tree = new ArrayList<>();
for (RelationTreeModel relationTreeModel : relationTreeModels) {
if (relationTreeModel == null) continue;
if (parentName.equals(relationTreeModel.getParentName())) {
relationTreeModel.setChildren(createTree(relationTreeModels, relationTreeModel.getName()));
tree.add(relationTreeModel);
......
......@@ -178,9 +178,10 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
public void generateSQLByDatabaseName(String resourceCode, String dimension, String databaseName, Long ipSeq, Map<String, Object> variables, HttpServletResponse response) {
try {
DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(ipSeq);
//根据连接查询到数据库表名
Connection connection = dataBaseLinkService.connectNewDatabase(dataBaseLinkService.queryBySeq(ipSeq));
List<String> list = DataBaseUtils.getList("select table_name from information_schema.tables where table_schema='" + databaseName + "';", connection);
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<StudioResourceModel> resourceList = queryForStudioResourceList(resourceCode);
File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath();
......@@ -213,7 +214,8 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
StringBuffer insertSql = new StringBuffer();
for (StudioResourceModel model : resourceList) {
String sql = buildInsertSqlByDatabaseName(model, dimension, databaseName, list, ipSeq, variables);
if (!ObjectUtils.isEmpty(sql)) insertSql.append(sql);
if (!ObjectUtils.isEmpty(sql))
insertSql.append(sql);
}
if (deleteSql.length() > 0) {
......
......@@ -49,6 +49,8 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
return getChildren(displayLists,"",0L);
}
/**
* 获得模板分类子节点(递归)
*/
......
......@@ -44,9 +44,10 @@ public class DataBaseUtils {
*/
public static List<Map<String, Object>> getMaps(String sql, Connection connection) throws SQLException {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
ResultSet rs = null;
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
try {
rs = statement.executeQuery(sql);
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
......@@ -57,7 +58,8 @@ public class DataBaseUtils {
list.add(rowData);
}
} catch (SQLException e) {
e.printStackTrace();
// e.printStackTrace();
return list;
} finally {
try {
if (rs != null)
......@@ -82,7 +84,6 @@ public class DataBaseUtils {
for (int i = 1; i <= columnCount; i++) {
list.add(rs.getObject(i).toString());
}
}
} catch (SQLException e) {
e.printStackTrace();
......
#DB properties:
# jdbc_config
spring.datasource.url=jdbc:mysql://172.16.3.18:3306/amos_tool_library?allowMultiQueries=true
spring.datasource.url=jdbc:mysql://172.16.3.18:3306/amos_tool_library?allowMultiQueries=true
spring.datasource.username=root
spring.datasource.password=Yeejoin@2020
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
......
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