Commit 2ec0c5bd authored by chenzai's avatar chenzai

commit 三级导出

parent da7628f0
...@@ -54,7 +54,7 @@ public class ToolLibraryResource { ...@@ -54,7 +54,7 @@ public class ToolLibraryResource {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@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 exportDesignerSQL(@PathVariable String id, HttpServletResponse httpServletResponse){
toolLibraryService.exportDesignerSQL(id,httpServletResponse); toolLibraryService.exportDesignerSQL(id,httpServletResponse);
} }
...@@ -71,4 +71,16 @@ public class ToolLibraryResource { ...@@ -71,4 +71,16 @@ public class ToolLibraryResource {
toolLibraryService.exportComponentSQL(sequenceNbr, httpServletResponse); toolLibraryService.exportComponentSQL(sequenceNbr, httpServletResponse);
} }
/**
* 导出SQL脚本 三级功能
* {sequenceNbrs}表示前端传递需要导出的插入sql的主键
*/
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/tool")
@ApiOperation(httpMethod = "GET", value = "导出", notes = "导出")
public void exportToolSQL( @RequestParam(value = "sequenceNbrs") String sequenceNbrs, HttpServletResponse httpServletResponse){
toolLibraryService.exportToolSQL(sequenceNbrs,httpServletResponse);
}
} }
package com.yeejoin.amos.api.tool.face.orm.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.MorphicWidget;
import org.apache.ibatis.annotations.Mapper;
@Mapper
public interface MorphicWidgetMapper extends BaseMapper<MorphicWidget> {
}
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;
import com.yeejoin.amos.api.tool.face.model.ToolLibraryTreeModel; import com.yeejoin.amos.api.tool.face.model.ToolLibraryTreeModel;
import com.yeejoin.amos.api.tool.face.orm.dao.MorphicWidgetMapper;
import com.yeejoin.amos.api.tool.face.orm.dao.ToolLibraryMapper; import com.yeejoin.amos.api.tool.face.orm.dao.ToolLibraryMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.MorphicWidget;
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 com.yeejoin.amos.api.tool.utils.SqlExportUtils;
import org.apache.commons.lang3.time.DateFormatUtils; 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.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;
import java.io.*; import java.io.*;
import java.nio.charset.StandardCharsets;
import java.sql.Connection; 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.*;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Service @Service
public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrary,ToolLibraryMapper> { public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrary,ToolLibraryMapper> {
...@@ -44,9 +40,6 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -44,9 +40,6 @@ 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);
...@@ -74,6 +67,20 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -74,6 +67,20 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
return resultList; return resultList;
} }
private ToolLibraryTreeModel getMenuTree(ToolLibraryTreeModel result, List<ToolLibraryTreeModel> list) {
for (ToolLibraryTreeModel treeModel : list) {
//如果父类主键等于传过来实体类的ID
if (treeModel.getParentId().equals(result.getId())) {
if (result.getChildren() == null) {
result.setChildren(new ArrayList<>());
}
// 递归调用
result.getChildren().add(getMenuTree(treeModel, list));
}
}
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);
...@@ -131,42 +138,24 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -131,42 +138,24 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
return page; return page;
} }
private ToolLibraryTreeModel getMenuTree(ToolLibraryTreeModel result, List<ToolLibraryTreeModel> list) {
for (ToolLibraryTreeModel treeModel : list) {
//如果父类主键等于传过来实体类的ID
if (treeModel.getParentId().equals(result.getId())) {
if (result.getChildren() == null) {
result.setChildren(new ArrayList<>());
}
// 递归调用
result.getChildren().add(getMenuTree(treeModel, list));
}
}
return result;
}
public void exportDesignerSQL(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);
List<Map<String, Object>> resultMaps = DataBaseUtils.getMaps("select * from " + List<Map<String, Object>> resultMaps = DataBaseUtils.getMaps("select * from " +
" (select SEQUENCE_NBR from morphic_widget_group " + " (select SEQUENCE_NBR from morphic_widget_group " +
" where DESIGNER_TYPE='" + id + "') as t\n" + " where DESIGNER_TYPE='" + id + "' and is_delete!=1) 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 insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget"); StringBuffer insertSql = DataBaseUtils.getInsertSQL(resultMaps, tableColumn, "morphic_widget");
connection.close(); connection.close();
exportDownload(id, insertSql, httpServletResponse);
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 { private void exportDownload(String id, StringBuffer insertSql, HttpServletResponse httpServletResponse) throws IOException {
File directory = new File("");// 参数为空 File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath(); String coursePath = directory.getCanonicalPath();
File parentFile = new File(coursePath).getParentFile(); File parentFile = new File(coursePath).getParentFile();
...@@ -180,7 +169,7 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -180,7 +169,7 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
String sqlFilePath = backPath + SqlExportUtils.SLASH + fileName; String sqlFilePath = backPath + SqlExportUtils.SLASH + fileName;
File file = new File(sqlFilePath); File file = new File(sqlFilePath);
FileOutputStream out = new FileOutputStream(file); FileOutputStream out = new FileOutputStream(file);
OutputStreamWriter writer = new OutputStreamWriter(out, "utf8"); OutputStreamWriter writer = new OutputStreamWriter(out, StandardCharsets.UTF_8);
if (insertSql.length() > 0) { if (insertSql.length() > 0) {
writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR); writer.write(SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
writer.write("/**" + SqlExportUtils.BR + "* 资源数据" + SqlExportUtils.BR + "**/" + SqlExportUtils.BR); writer.write("/**" + SqlExportUtils.BR + "* 资源数据" + SqlExportUtils.BR + "**/" + SqlExportUtils.BR);
...@@ -188,17 +177,16 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -188,17 +177,16 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
writer.write(insertSql.toString()); writer.write(insertSql.toString());
writer.write(SqlExportUtils.BR + SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR); writer.write(SqlExportUtils.BR + SqlExportUtils.BR + SqlExportUtils.DELIMITER + SqlExportUtils.BR);
} }
writer.flush(); writer.flush();
writer.close(); writer.close();
download(httpServletResponse,fileName,sqlFilePath); download(httpServletResponse,fileName,sqlFilePath);
} }
public void download(HttpServletResponse response, String fileName, String sqlFilePath) throws IOException {
private 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));
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int len = 0; int len;
response.reset(); // 非常重要 response.reset(); // 非常重要
response.setContentType("application/x-msdownload"); response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
...@@ -213,6 +201,8 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -213,6 +201,8 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
* 导出组件中的工具的SQL(二级) * 导出组件中的工具的SQL(二级)
* @param sequenceNbr * @param sequenceNbr
* @param httpServletResponse * @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, SQLException {
...@@ -250,5 +240,28 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar ...@@ -250,5 +240,28 @@ public class ToolLibraryService extends BaseService<ToolLibraryModel, ToolLibrar
} }
/**
* 导出组件中的工具的SQL(三级)
* @param sequenceNbrs
* @param httpServletResponse
*/
public void exportToolSQL(String sequenceNbrs, HttpServletResponse httpServletResponse) {
String[] split = sequenceNbrs.split(",");
String sequenceNbres = Arrays.toString(split);
sequenceNbres=sequenceNbres.substring(1,sequenceNbres.length()-1);
try {
Class.forName(className);
String sql="SELECT *\n" +
"FROM morphic_widget\n" +
"WHERE is_delete!=1 AND SEQUENCE_NBR IN ("+sequenceNbres+");";
Connection connection = DriverManager.getConnection(url, userName, passWord);
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();
exportDownload("tool", insertSql, httpServletResponse);
} catch (Exception e) {
e.printStackTrace();
}
}
} }
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