Commit da7628f0 authored by Gwofoo's avatar Gwofoo

二级组件的导出

parent d31e06ab
...@@ -58,4 +58,17 @@ public class ToolLibraryResource { ...@@ -58,4 +58,17 @@ public class ToolLibraryResource {
toolLibraryService.exportDesignerSQL(id,httpServletResponse); toolLibraryService.exportDesignerSQL(id,httpServletResponse);
} }
/**
* 导出SQL脚本 二级功能
* @param sequenceNbr 组件在数据库表中的键
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/component")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出二级组件中的所有工具的SQL")
public void exportComponentSQL(
@RequestParam(value = "sequenceNbr") String sequenceNbr,
HttpServletResponse httpServletResponse) throws SQLException, ClassNotFoundException {
toolLibraryService.exportComponentSQL(sequenceNbr, httpServletResponse);
}
} }
...@@ -156,37 +156,44 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -156,37 +156,44 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
" inner join morphic_widget mw on mw.group_id=t.SEQUENCE_NBR", connection); " inner join morphic_widget mw on mw.group_id=t.SEQUENCE_NBR", connection);
List<TableColumn> tableColumn = DataBaseUtils.getTableColumn("morphic_widget",connection); List<TableColumn> tableColumn = DataBaseUtils.getTableColumn("morphic_widget",connection);
StringBuffer insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget"); StringBuffer insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget");
File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath();
File parentFile = new File(coursePath).getParentFile();
String backPath = parentFile.getCanonicalPath() + SqlExportUtils.BACKUP_PATH;
File sqlDirectory = new File(backPath);
if (!sqlDirectory.exists()) {
sqlDirectory.mkdir();
}
// 备份文件路径名称
String fileName =id+DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "." + SqlExportUtils.SUFFIX;
String sqlFilePath = backPath + SqlExportUtils.SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
if (insertSql.length() > 0) {
writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
writer.write("/**" + SqlExportUtils.BR + "* 资源数据" + SqlExportUtils.BR + "**/" + SqlExportUtils.BR);
writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
writer.write(insertSql.toString());
writer.write(SqlExportUtils.BR + SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
}
connection.close(); connection.close();
writer.flush();
writer.close();
download(httpServletResponse,fileName,sqlFilePath); prepareDownload(id, insertSql, httpServletResponse);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public void prepareDownload(String id, StringBuffer insertSql, HttpServletResponse httpServletResponse) throws IOException {
File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath();
File parentFile = new File(coursePath).getParentFile();
String backPath = parentFile.getCanonicalPath() + SqlExportUtils.BACKUP_PATH;
File sqlDirectory = new File(backPath);
if (!sqlDirectory.exists()) {
sqlDirectory.mkdir();
}
// 备份文件路径名称
String fileName =id+DateFormatUtils.format(new Date(), "yyyyMMddHHmmss") + "." + SqlExportUtils.SUFFIX;
String sqlFilePath = backPath + SqlExportUtils.SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(out, "utf8");
if (insertSql.length() > 0) {
writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
writer.write("/**" + SqlExportUtils.BR + "* 资源数据" + SqlExportUtils.BR + "**/" + SqlExportUtils.BR);
writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
writer.write(insertSql.toString());
writer.write(SqlExportUtils.BR + SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
}
writer.flush();
writer.close();
download(httpServletResponse,fileName,sqlFilePath);
}
public void download(HttpServletResponse response, String fileName, String sqlFilePath) throws IOException { public void download(HttpServletResponse response, String fileName, String sqlFilePath) throws IOException {
File f = new File(sqlFilePath); File f = new File(sqlFilePath);
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f)); BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
...@@ -202,5 +209,46 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -202,5 +209,46 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
out.close(); out.close();
} }
/**
* 导出组件中的工具的SQL(二级)
* @param sequenceNbr
* @param httpServletResponse
*/
public void exportComponentSQL(String sequenceNbr, HttpServletResponse httpServletResponse)
throws ClassNotFoundException, SQLException {
Class.forName(className);
Connection connection = DriverManager.getConnection(url, userName, passWord);
// 先查当前节点的parent,看是不是0,从而判断在叶子节点还是父节点
List<Map<String, Object>> clickedNodeMaps = DataBaseUtils.getMaps(
"select SEQUENCE_NBR, parent, DESIGNER_TYPE, display_name " +
"from morphic_widget_group " +
"where is_delete != 1 and SEQUENCE_NBR = " + sequenceNbr, connection);
String parent = clickedNodeMaps.get(0).get("parent").toString();
List<Map<String, Object>> displayTools = new ArrayList<>();
String sql;
if (parent.equals("0")) {
// 父节点
sql = "SELECT * FROM morphic_widget\n" +
"WHERE is_delete != 1 and group_id IN (\n" +
"\tSELECT SEQUENCE_NBR\n" +
"\tFROM morphic_widget_group\n" +
"\twhere is_delete != 1 and parent = " + sequenceNbr +
");";
}
else {
// 叶子节点
sql = "SELECT * FROM morphic_widget\n" +
"WHERE is_delete!=1 AND group_id = " + sequenceNbr + ";";
}
List<Map<String, Object>> resultMaps = DataBaseUtils.getMaps(sql, connection);
List<TableColumn> tableColumn = DataBaseUtils.getTableColumn("morphic_widget",connection);
StringBuffer insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget");
connection.close();
}
} }
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