Commit d31e06ab authored by chenzai's avatar chenzai

commit 一级导出

parent 6b3a780f
...@@ -55,7 +55,7 @@ public class ToolLibraryResource { ...@@ -55,7 +55,7 @@ public class ToolLibraryResource {
@GetMapping(value = "/export/{id}") @GetMapping(value = "/export/{id}")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出") @ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
public void generateSQL(@PathVariable String id, HttpServletResponse httpServletResponse){ public void generateSQL(@PathVariable String id, HttpServletResponse httpServletResponse){
toolLibraryService.generateSQL(id,httpServletResponse); toolLibraryService.exportDesignerSQL(id,httpServletResponse);
} }
} }
...@@ -70,6 +70,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -70,6 +70,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
private static String DISABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 0;\r\n"; private static String DISABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 0;\r\n";
private static String ABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 1;\r\n"; private static String ABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 1;\r\n";
private static String DELIMITER = "###################################"; private static String DELIMITER = "###################################";
@Autowired @Autowired
JdbcTemplate jdbcTemplate; JdbcTemplate jdbcTemplate;
@Autowired @Autowired
......
package com.yeejoin.amos.api.tool.face.service; package com.yeejoin.amos.api.tool.face.service;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.api.tool.face.model.ToolLibraryDetailModel; import com.yeejoin.amos.api.tool.face.model.ToolLibraryDetailModel;
import com.yeejoin.amos.api.tool.face.model.ToolLibraryModel; import com.yeejoin.amos.api.tool.face.model.ToolLibraryModel;
...@@ -8,8 +9,14 @@ import com.yeejoin.amos.api.tool.face.orm.dao.ToolLibraryMapper; ...@@ -8,8 +9,14 @@ import com.yeejoin.amos.api.tool.face.orm.dao.ToolLibraryMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn; import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import com.yeejoin.amos.api.tool.face.orm.entity.ToolLibrary; import com.yeejoin.amos.api.tool.face.orm.entity.ToolLibrary;
import com.yeejoin.amos.api.tool.utils.DataBaseUtils; import com.yeejoin.amos.api.tool.utils.DataBaseUtils;
import com.yeejoin.amos.api.tool.utils.DateUtils;
import com.yeejoin.amos.api.tool.utils.SqlExportUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil; import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -18,6 +25,7 @@ import java.sql.Connection; ...@@ -18,6 +25,7 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -36,6 +44,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -36,6 +44,9 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
@Value("${toolLibrary.passWord}") @Value("${toolLibrary.passWord}")
private String passWord; private String passWord;
@Autowired
private EmqKeeper emqKeeper;
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);
...@@ -135,7 +146,7 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -135,7 +146,7 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
} }
public void generateSQL(String id,HttpServletResponse httpServletResponse) { public void exportDesignerSQL(String id,HttpServletResponse httpServletResponse) {
try { try {
Class.forName(className); Class.forName(className);
Connection connection = DriverManager.getConnection(url, userName, passWord); Connection connection = DriverManager.getConnection(url, userName, passWord);
...@@ -144,15 +155,38 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -144,15 +155,38 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
" where DESIGNER_TYPE='" + id + "') as t\n" + " where DESIGNER_TYPE='" + id + "') as t\n" +
" 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 morphic_widget = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget"); StringBuffer insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget");
// download(httpServletResponse,); 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();
writer.flush();
writer.close();
download(httpServletResponse,fileName,sqlFilePath);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
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));
......
package com.yeejoin.amos.api.tool.utils;
public class SqlExportUtils {
/**
* 数据库备份路径
*/
public static final String BACKUP_PATH = "/db/";
/**
* 数据库备份文本前缀
*/
public static String ONESQL_PREFIX = "";
public static String SUFFIX = "sql";
public static String BR = "\r\n";
public static String SLASH = "/";
public static String BRANCH = ";";
public static String SPLIT = "`";
public static String SPACE = " ";
public static String INSERT_INTO = " INSERT INTO ";
public static String CREATE_INTO = " CREATE TABLE ";
public static String VALUES = "VALUES";
public static String LEFTBRACE = "(";
public static String RIGHTBRACE = ")";
public static String QUOTES = "'";
public static String COMMA = ",";
public static String DISABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 0;\r\n";
public static String ABLEFOREIGN = "SET FOREIGN_KEY_CHECKS = 1;\r\n";
public static String DELIMITER = "###################################";
}
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