Commit 97f06ed9 authored by chenzai's avatar chenzai

commit 排查原赵智代码

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