Commit cd0efb7a authored by Gwofoo's avatar Gwofoo

一二三级导出的合并

parent 2ec0c5bd
...@@ -67,7 +67,7 @@ public class ToolLibraryResource { ...@@ -67,7 +67,7 @@ public class ToolLibraryResource {
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出二级组件中的所有工具的SQL") @ApiOperation(httpMethod = "GET", value = "导出", notes = "导出二级组件中的所有工具的SQL")
public void exportComponentSQL( public void exportComponentSQL(
@RequestParam(value = "sequenceNbr") String sequenceNbr, @RequestParam(value = "sequenceNbr") String sequenceNbr,
HttpServletResponse httpServletResponse) throws SQLException, ClassNotFoundException { HttpServletResponse httpServletResponse) throws ClassNotFoundException, SQLException {
toolLibraryService.exportComponentSQL(sequenceNbr, httpServletResponse); toolLibraryService.exportComponentSQL(sequenceNbr, httpServletResponse);
} }
...@@ -82,5 +82,4 @@ public class ToolLibraryResource { ...@@ -82,5 +82,4 @@ public class ToolLibraryResource {
toolLibraryService.exportToolSQL(sequenceNbrs,httpServletResponse); toolLibraryService.exportToolSQL(sequenceNbrs,httpServletResponse);
} }
} }
...@@ -381,5 +381,4 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati ...@@ -381,5 +381,4 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
br.close(); br.close();
out.close(); out.close();
} }
} }
...@@ -40,6 +40,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -40,6 +40,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
@Value("${toolLibrary.passWord}") @Value("${toolLibrary.passWord}")
private String passWord; private String passWord;
/**
* 由一级到二级
*/
public List<ToolLibraryTreeModel> queryForComponentList(String designer) throws ClassNotFoundException, SQLException { public List<ToolLibraryTreeModel> queryForComponentList(String designer) throws ClassNotFoundException, SQLException {
Class.forName(className); Class.forName(className);
Connection connection = DriverManager.getConnection(url, userName, passWord); Connection connection = DriverManager.getConnection(url, userName, passWord);
...@@ -81,6 +84,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -81,6 +84,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
return result; return result;
} }
/**
* 由二级到三级
*/
public Page<ToolLibraryDetailModel> queryForComponentListDetails(Page<ToolLibraryDetailModel> page, String sequenceNbr) public Page<ToolLibraryDetailModel> queryForComponentListDetails(Page<ToolLibraryDetailModel> page, String sequenceNbr)
throws ClassNotFoundException, SQLException { throws ClassNotFoundException, SQLException {
Class.forName(className); Class.forName(className);
...@@ -138,6 +144,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -138,6 +144,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
return page; return page;
} }
/**
* 导出一级SQL
*/
public void exportDesignerSQL(String id,HttpServletResponse httpServletResponse) { public void exportDesignerSQL(String id,HttpServletResponse httpServletResponse) {
try { try {
Class.forName(className); Class.forName(className);
...@@ -155,57 +164,12 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -155,57 +164,12 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
} }
} }
private void exportDownload(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, StandardCharsets.UTF_8);
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);
}
private void download(HttpServletResponse response, String fileName, String sqlFilePath) throws IOException {
File f = new File(sqlFilePath);
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len;
response.reset(); // 非常重要
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.close();
}
/** /**
* 导出组件中的工具的SQL(二级) * 导出组件中的工具的SQL(二级)
* @param sequenceNbr
* @param httpServletResponse
* @throws ClassNotFoundException
* @throws SQLException
*/ */
public void exportComponentSQL(String sequenceNbr, HttpServletResponse httpServletResponse) public void exportComponentSQL(String sequenceNbr, HttpServletResponse httpServletResponse)
throws ClassNotFoundException, SQLException { throws ClassNotFoundException {
try {
Class.forName(className); Class.forName(className);
Connection connection = DriverManager.getConnection(url, userName, passWord); Connection connection = DriverManager.getConnection(url, userName, passWord);
// 先查当前节点的parent,看是不是0,从而判断在叶子节点还是父节点 // 先查当前节点的parent,看是不是0,从而判断在叶子节点还是父节点
...@@ -224,26 +188,27 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -224,26 +188,27 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
"\tFROM morphic_widget_group\n" + "\tFROM morphic_widget_group\n" +
"\twhere is_delete != 1 and parent = " + sequenceNbr + "\twhere is_delete != 1 and parent = " + sequenceNbr +
");"; ");";
} } else {
else {
// 叶子节点 // 叶子节点
sql = "SELECT * FROM morphic_widget\n" + sql = "SELECT * FROM morphic_widget\n" +
"WHERE is_delete!=1 AND group_id = " + sequenceNbr + ";"; "WHERE is_delete!=1 AND group_id = " + sequenceNbr + ";";
} }
List<Map<String, Object>> resultMaps = DataBaseUtils.getMaps(sql, connection); List<Map<String, Object>> resultMaps = DataBaseUtils.getMaps(sql, 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");
connection.close(); connection.close();
// 下载.sql文件
exportDownload(sequenceNbr + "-", insertSql, httpServletResponse);
} catch (Exception e) {
e.printStackTrace();
}
} }
/** /**
* 导出组件中的工具的SQL(三级) * 导出组件中的工具的SQL(三级)
* @param sequenceNbrs
* @param httpServletResponse
*/ */
public void exportToolSQL(String sequenceNbrs, HttpServletResponse httpServletResponse) { public void exportToolSQL(String sequenceNbrs, HttpServletResponse httpServletResponse) {
String[] split = sequenceNbrs.split(","); String[] split = sequenceNbrs.split(",");
...@@ -264,4 +229,47 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -264,4 +229,47 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
e.printStackTrace(); e.printStackTrace();
} }
} }
private void exportDownload(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, StandardCharsets.UTF_8);
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);
}
private void download(HttpServletResponse response, String fileName, String sqlFilePath) throws IOException {
File f = new File(sqlFilePath);
BufferedInputStream br = new BufferedInputStream(new FileInputStream(f));
byte[] buf = new byte[1024];
int len;
response.reset(); // 非常重要
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
OutputStream out = response.getOutputStream();
while ((len = br.read(buf)) > 0)
out.write(buf, 0, len);
br.close();
out.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