Commit 2ce6d0b5 authored by chenzai's avatar chenzai

commit 合并赵智代码

parent 14e10941
...@@ -39,3 +39,5 @@ public class Application { ...@@ -39,3 +39,5 @@ public class Application {
+ path + "/doc.html\n" + "----------------------------------------------------------"); + path + "/doc.html\n" + "----------------------------------------------------------");
} }
} }
...@@ -12,6 +12,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -12,6 +12,7 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.sql.SQLException;
import java.util.List; import java.util.List;
@RestController @RestController
...@@ -49,10 +50,9 @@ public class DataBaseNameListResource { ...@@ -49,10 +50,9 @@ public class DataBaseNameListResource {
public ResponseModel<Page<DataBaseNameListModel>> queryForPage( public ResponseModel<Page<DataBaseNameListModel>> queryForPage(
@RequestParam(value = "current") int current, @RequestParam(value = "current") int current,
@RequestParam(value = "size") int size, @RequestParam(value = "size") int size,
@RequestParam Long ipSeq) { @RequestParam Long ipSeq) throws SQLException, ClassNotFoundException {
Page<DataBaseNameListModel> page = new Page<>(); Page<DataBaseNameListModel> page = new Page<>();
page.setCurrent(current); return ResponseHelper.buildResponse(dataBaseNameListService.queryForDataBasePage(page, ipSeq,current,size));
page.setSize(size);
return ResponseHelper.buildResponse(dataBaseNameListService.queryForDataBasePage(page,ipSeq));
} }
} }
...@@ -2,8 +2,11 @@ package com.yeejoin.amos.api.tool.controller; ...@@ -2,8 +2,11 @@ package com.yeejoin.amos.api.tool.controller;
import com.yeejoin.amos.api.tool.face.service.DataBaseLinkService; import com.yeejoin.amos.api.tool.face.service.DataBaseLinkService;
import com.yeejoin.amos.api.tool.face.service.RelationService; import com.yeejoin.amos.api.tool.face.service.RelationService;
import com.yeejoin.amos.api.tool.face.service.StudioResourceService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.StringUtils;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.typroject.tyboot.core.foundation.enumeration.UserType; import org.typroject.tyboot.core.foundation.enumeration.UserType;
...@@ -11,7 +14,11 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation; ...@@ -11,7 +14,11 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper; import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
@CrossOrigin @CrossOrigin
...@@ -23,11 +30,13 @@ public class RelationResource { ...@@ -23,11 +30,13 @@ public class RelationResource {
private RelationService relationService; private RelationService relationService;
@Autowired @Autowired
DataBaseLinkService dataBaseLinkService; DataBaseLinkService dataBaseLinkService;
@Autowired
private StudioResourceService studioResourceService;
/** /**
* 根据机构ID和数据库sequenceNbr批量删除数据库 * 根据机构ID和数据库sequenceNbr批量删除数据库
* *
* @param agencyCode 机构ID * @param agencyCode 机构ID
* @param sequenceNbrs 多个主键 * @param sequenceNbrs 多个主键
* @return String * @return String
*/ */
...@@ -49,12 +58,24 @@ public class RelationResource { ...@@ -49,12 +58,24 @@ public class RelationResource {
@TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false) @TycloudOperation(ApiLevel = UserType.AGENCY, needAuth = false)
@GetMapping(value = "/export/{agencyCode}/{sequenceNbrs}") @GetMapping(value = "/export/{agencyCode}/{sequenceNbrs}")
@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,
public void generateSQL(
@PathVariable String agencyCode, @PathVariable String agencyCode,
@PathVariable String sequenceNbrs, @PathVariable String sequenceNbrs,
HttpServletResponse response) throws Exception { HttpServletResponse response,
relationService.outputAgency(agencyCode, sequenceNbrs,response); HttpServletRequest request) throws Exception {
return ResponseHelper.buildResponse("yes"); 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");
} }
} }
\ No newline at end of file
package com.yeejoin.amos.api.tool.enums;
public enum PictureType {
//应用
VIZMIX("vizmix", "/public/studio/graph/applist/mix-thumb.png"),
//三维
VIZ3D("viz3d", "/public/studio/graph/applist/3d-thumb.png"),
//分析
VIZDAFUN("vizdafun", "/public/studio/graph/applist/dafun-thumb.png"),
//表单
VIZFORM("vizform", "/public/studio/graph/applist/form-thumb.png"),
//组态
VIZMORPHIC("vizmorphic", "/public/studio/graph/applist/2d-thumb.png");
///public/webico/resources/缩略图-人员.png
private String designer_type;
private String picturePath;
PictureType(String designer_type, String picturePath) {
this.designer_type = designer_type;
this.picturePath = picturePath;
}
public String getDesigner_type() {
return designer_type;
}
public String getPicturePath() {
return picturePath;
}
public static String returnPath(String designer_type){
for (PictureType pictureType : PictureType.values()) {
if (pictureType.getDesigner_type().equals(designer_type)) {
return pictureType.getPicturePath();
}
}
return null;
}
}
...@@ -17,4 +17,7 @@ public class ProjectModel { ...@@ -17,4 +17,7 @@ public class ProjectModel {
@ApiModelProperty(value = "机构编码") @ApiModelProperty(value = "机构编码")
private String agencyCode; private String agencyCode;
@ApiModelProperty(value = "图片路径")
private String designerThumb;
} }
...@@ -2,8 +2,7 @@ package com.yeejoin.amos.api.tool.face.service; ...@@ -2,8 +2,7 @@ package com.yeejoin.amos.api.tool.face.service;
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.AgencyModel; import com.yeejoin.amos.api.tool.face.model.*;
import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel;
import com.yeejoin.amos.api.tool.face.orm.dao.DataBaseLinkMapper; import com.yeejoin.amos.api.tool.face.orm.dao.DataBaseLinkMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseLink; import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseLink;
import com.yeejoin.amos.api.tool.utils.AESUtils; import com.yeejoin.amos.api.tool.utils.AESUtils;
...@@ -15,12 +14,8 @@ import org.springframework.stereotype.Service; ...@@ -15,12 +14,8 @@ import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.foundation.utils.Bean; import org.typroject.tyboot.core.foundation.utils.Bean;
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.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource; import javax.sql.DataSource;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.sql.*; import java.sql.*;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -40,6 +35,7 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase ...@@ -40,6 +35,7 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
@Autowired @Autowired
private DataSource dataSource; private DataSource dataSource;
/** /**
* 新增 * 新增
*/ */
...@@ -55,8 +51,9 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase ...@@ -55,8 +51,9 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
/** /**
* 编辑 * 编辑
*/ */
public DataBaseLinkModel update(DataBaseLinkModel dataBaseLinkModel) throws Exception {
DataBaseLinkModel model = this.decryptPwd(dataBaseLinkModel); public DataBaseLinkModel update(DataBaseLinkModel model) throws Exception {
// DataBaseLinkModel model = this.decryptPwd(dataBaseLinkModel);
if (this.testConnection(model)) { if (this.testConnection(model)) {
return this.updateWithModel(encryptPwd(model)); return this.updateWithModel(encryptPwd(model));
} else { } else {
...@@ -120,6 +117,7 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase ...@@ -120,6 +117,7 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
return records; return records;
} }
/** /**
* 列表查询 * 列表查询
*/ */
...@@ -148,9 +146,15 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase ...@@ -148,9 +146,15 @@ public class DataBaseLinkService extends BaseService<DataBaseLinkModel, DataBase
try { try {
// 加载数据库驱动 // 加载数据库驱动
Class.forName("com.mysql.cj.jdbc.Driver"); Class.forName("com.mysql.cj.jdbc.Driver");
if (model.getPrefix() == null || model.getPrefix().isEmpty() || model.getPrefix().equals("null")) {
model.setPrefix("");
}
if (model.getSuffix() == null || model.getSuffix().isEmpty() || model.getSuffix().equals("null")) {
model.setSuffix("");
}
// 连接新增的数据库 // 连接新增的数据库
String dbUrl = "jdbc:mysql://" + model.getIp() + ":" + model.getPort() + "/" + String dbUrl = "jdbc:mysql://" + model.getIp() + ":" + model.getPort() + "/" +
model.getPrefix()+model.getDbName()+model.getSuffix(); model.getPrefix() + model.getDbName() + model.getSuffix();
// 解密pwd,并连接 // 解密pwd,并连接
return DriverManager.getConnection(dbUrl, model.getUserName(), AESUtils.decrypt(model.getPassWord())); return DriverManager.getConnection(dbUrl, model.getUserName(), AESUtils.decrypt(model.getPassWord()));
} catch (SQLException | ClassNotFoundException e) { } catch (SQLException | ClassNotFoundException e) {
......
...@@ -6,15 +6,14 @@ import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel; ...@@ -6,15 +6,14 @@ import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel;
import com.yeejoin.amos.api.tool.face.model.DataBaseNameListModel; import com.yeejoin.amos.api.tool.face.model.DataBaseNameListModel;
import com.yeejoin.amos.api.tool.face.orm.dao.DataBaseNameListMapper; import com.yeejoin.amos.api.tool.face.orm.dao.DataBaseNameListMapper;
import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseNameList; import com.yeejoin.amos.api.tool.face.orm.entity.DataBaseNameList;
import com.yeejoin.amos.api.tool.utils.DataBaseUtils;
import org.apache.commons.beanutils.BeanUtils; import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.typroject.tyboot.core.rdbms.service.BaseService; import org.typroject.tyboot.core.rdbms.service.BaseService;
import java.sql.Connection; import java.sql.*;
import java.util.ArrayList; import java.util.*;
import java.util.Collection;
import java.util.List;
@Service @Service
public class DataBaseNameListService extends BaseService<DataBaseNameListModel, DataBaseNameList, DataBaseNameListMapper> { public class DataBaseNameListService extends BaseService<DataBaseNameListModel, DataBaseNameList, DataBaseNameListMapper> {
...@@ -24,8 +23,46 @@ public class DataBaseNameListService extends BaseService<DataBaseNameListModel, ...@@ -24,8 +23,46 @@ public class DataBaseNameListService extends BaseService<DataBaseNameListModel,
/** /**
* 分页查询 * 分页查询
*/ */
public Page<DataBaseNameListModel> queryForDataBasePage(Page<DataBaseNameListModel> page,Long parentId) { public Page<DataBaseNameListModel> queryForDataBasePage(Page<DataBaseNameListModel> page,Long parentId,int current,int size) throws ClassNotFoundException, SQLException {
return this.queryForPage(page, null, false, parentId); Class.forName("com.mysql.cj.jdbc.Driver");
DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(parentId);
String ip=dataBaseLinkModel.getIp();
String port=dataBaseLinkModel.getPort();
String url = "jdbc:mysql://"+ip+":"+port+" ";
String user = "root";
String passWord = "Yeejoin@2020";
String sql="show databases";
Connection connection = DriverManager.getConnection(url,user,passWord);
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
List<DataBaseNameListModel> list=new ArrayList<>();
try {
while (rs.next()){
DataBaseNameListModel listModel=new DataBaseNameListModel();
listModel.setDbName(rs.getString("Database"));
listModel.setParentId(parentId);
list.add(listModel);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
connection.close();
int count = list.size();
page.setSize(size);
page.setCurrent(current);
page.setTotal(count);
//计算分页总页数
page.setPages(count %10 == 0 ? count/10 :count/10+1);
page.setRecords(list);
return page;
} }
/** /**
......
...@@ -70,8 +70,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati ...@@ -70,8 +70,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
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(nameListModel.getParentId());
model.setDbName(nameListModel.getDbName());
Connection connection = dataBaseLinkService.connectNewDatabase(model); Connection connection = dataBaseLinkService.connectNewDatabase(model);
model.setDbName(nameListModel.getDbName());
this.insertData(connection, agencyCode, model.getDbName(),seq, response); this.insertData(connection, agencyCode, model.getDbName(),seq, response);
} }
} }
...@@ -119,8 +119,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati ...@@ -119,8 +119,8 @@ public class RelationService extends BaseService<RelationModel, Relation, Relati
* 获取关系表转化为map * 获取关系表转化为map
*/ */
public List<HashMap<String, String>> queryRelation(String dbName) throws SQLException { public List<HashMap<String, String>> queryRelation(String dbName) throws SQLException {
StringBuilder sql = new StringBuilder("SELECT * FROM "); StringBuilder sql = new StringBuilder("SELECT RESOURCE_INSERT_SQL FROM studio_resource where RESOURCE_CODE = 'Agency'");
sql.append(dbName).append("_relation;"); // sql.append(dbName).append("_relation;");RESOURCE_PARAMS,
return relationMapper.getPublicItems(sql.toString()); return relationMapper.getPublicItems(sql.toString());
} }
......
...@@ -2,7 +2,7 @@ package com.yeejoin.amos.api.tool.face.service; ...@@ -2,7 +2,7 @@ package com.yeejoin.amos.api.tool.face.service;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.yeejoin.amos.api.tool.enums.PictureType;
import com.yeejoin.amos.api.tool.enums.SourceEnum; import com.yeejoin.amos.api.tool.enums.SourceEnum;
import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel; import com.yeejoin.amos.api.tool.face.model.DataBaseLinkModel;
import com.yeejoin.amos.api.tool.face.model.ProjectModel; import com.yeejoin.amos.api.tool.face.model.ProjectModel;
...@@ -176,7 +176,79 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -176,7 +176,79 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
} }
} }
public void print(String id, String msg, String step) { public void generateSQLByDatabaseName(String resourceCode, String dimension, String databaseName, Long ipSeq, Map<String, Object> variables, HttpServletResponse response) {
try {
//根据连接查询到数据库表名
Connection connection = dataBaseLinkService.connectNewDatabase(dataBaseLinkService.queryBySeq(ipSeq));
List<String> list = DataBaseUtils.getList("select table_name from information_schema.tables where table_schema='" + databaseName + "';", connection);
List<StudioResourceModel> resourceList = queryForStudioResourceList(resourceCode);
File directory = new File("");// 参数为空
String coursePath = directory.getCanonicalPath();
File parentFile = new File(coursePath).getParentFile();
String backPath = parentFile.getCanonicalPath() + BACKUP_PATH;
File sqlDirectory = new File(backPath);
if (!sqlDirectory.exists()) {
sqlDirectory.mkdir();
}
// 备份文件路径名称
String fileName = (SourceEnum.IDX.getSource().equals(resourceCode.toLowerCase()) ? (resourceCode.toLowerCase() + "_") : "studio_") + DateFormatUtils.format(new Date(), "yyyyMMdd") + "." + SUFFIX;
String sqlFilePath = backPath + SLASH + fileName;
File file = new File(sqlFilePath);
FileOutputStream out;
OutputStreamWriter writer = null;
out = new FileOutputStream(file);
writer = new OutputStreamWriter(out, "utf8");
StringBuffer deleteSql = new StringBuffer();
for (String tableName : list) {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " +
"WHERE TABLE_NAME = '" + tableName + "' AND COLUMN_NAME = '" + "AGENCY_CODE" + "';");
if (!rs.next()) {
continue;
}
deleteSql.append("DELETE FROM " + tableName + " WHERE AGENCY_CODE = '" + variables.get(dimension).toString() + "';" + BR);
rs.close();
statement.close();
}
StringBuffer insertSql = new StringBuffer();
for (StudioResourceModel model : resourceList) {
String sql = buildInsertSqlByDatabaseName(model, dimension, databaseName, list, ipSeq, variables);
if (!ObjectUtils.isEmpty(sql)) insertSql.append(sql);
}
if (deleteSql.length() > 0) {
print(variables.get(dimension).toString(), "开始创建delete语句...", "running");
writer.write(BR + DELIMITER + BR);
writer.write("/**" + BR + "* 删除历史资源数据 " + BR + "**/" + BR);
writer.write(BR + DELIMITER + BR);
writer.write(deleteSql.toString());
writer.write(BR + BR + DELIMITER + BR);
print(variables.get(dimension).toString(), "delete语句创建完成...", "running");
}
if (insertSql.length() > 0) {
print(variables.get(dimension).toString(), "开始创建insert语句...", "running");
writer.write(BR + DELIMITER + BR);
writer.write("/**" + BR + "* 资源数据" + BR + "**/" + BR);
writer.write(BR + DELIMITER + BR);
writer.write(insertSql.toString());
writer.write(BR + BR + DELIMITER + BR);
print(variables.get(dimension).toString(), "insert语句创建完成...", "running");
}
writer.flush();
writer.close();
out.close();
download(response, fileName, sqlFilePath);
} catch (IOException e) {
e.printStackTrace();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}
public void print(String id, String msg, String step) {
String percent = "0"; String percent = "0";
percent = ValidationUtil.equals(step, "end") ? "100" : ValidationUtil.equals(step, "running") ? "50" : "10"; percent = ValidationUtil.equals(step, "end") ? "100" : ValidationUtil.equals(step, "running") ? "50" : "10";
...@@ -229,6 +301,35 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -229,6 +301,35 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
return sbsql.toString(); return sbsql.toString();
} }
private String buildInsertSqlByDatabaseName(StudioResourceModel resource, String dimension, String databaseName, List<String> list, Long ipSeq, Map<String, Object> variables) throws SQLException {
StringBuffer sbsql = new StringBuffer();
DataBaseLinkModel dataBaseLinkModel = dataBaseLinkService.queryBySeq(ipSeq);
dataBaseLinkModel.setDbName(databaseName);
for (String tableName : list) {
String selectsql = format("SELECT * from `" + tableName + "` WHERE AGENCY_CODE = '${agencyCode}';", variables);
if (dimension.equals("appSeq")) {
dataBaseLinkModel.setDbName(dataBaseLinkModel.getDbName().replace("project", "studio"));
} else if (dimension.equals("projectSeq")) {
dataBaseLinkModel.setDbName(dataBaseLinkModel.getDbName().replace("project", "idx"));
}
Connection connection = dataBaseLinkService.connectNewDatabase(dataBaseLinkModel);
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS " +
"WHERE TABLE_NAME = '" + tableName + "' AND COLUMN_NAME = '" + "AGENCY_CODE" + "';");
if (!rs.next()) {
continue;
}
List<TableColumn> columns = DataBaseUtils.getTableColumn(tableName, connection);
List<Map<String, Object>> dataList = DataBaseUtils.getMaps(selectsql, connection);
sbsql.append(DataBaseUtils.getInsertSQL(dataList, columns, tableName));
rs.close();
statement.close();
connection.close();
}
return sbsql.toString();
}
public static String format(String sqlTemplate, Map<String, Object> parameter) { public static String format(String sqlTemplate, Map<String, Object> parameter) {
StringSubstitutor ss = new StringSubstitutor(parameter); StringSubstitutor ss = new StringSubstitutor(parameter);
return ss.replace(sqlTemplate); return ss.replace(sqlTemplate);
...@@ -258,7 +359,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -258,7 +359,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
model.setDbName("amos_studio"); model.setDbName("amos_studio");
Connection connection = dataBaseLinkService.connectNewDatabase(model); Connection connection = dataBaseLinkService.connectNewDatabase(model);
Statement sql = connection.createStatement(); Statement sql = connection.createStatement();
String sqlStr = "select SEQUENCE_NBR,PROJECT_NAME,AGENCY_CODE from amos_studio.studio_project " + String sqlStr = "select SEQUENCE_NBR,PROJECT_NAME,AGENCY_CODE from " + model.getPrefix() + "amos_studio" + model.getSuffix() + ".studio_project " +
"where AGENCY_CODE = " + "'" + agencyCode + "'"; "where AGENCY_CODE = " + "'" + agencyCode + "'";
// System.out.println(sqlStr); // System.out.println(sqlStr);
ResultSet resultSet = sql.executeQuery(sqlStr); ResultSet resultSet = sql.executeQuery(sqlStr);
...@@ -290,7 +391,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -290,7 +391,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
model.setDbName("amos_studio"); model.setDbName("amos_studio");
Connection connection = dataBaseLinkService.connectNewDatabase(model); Connection connection = dataBaseLinkService.connectNewDatabase(model);
Statement sql = connection.createStatement(); Statement sql = connection.createStatement();
String sqlStr = "select SEQUENCE_NBR,APP_NAME from amos_studio.studio_application " + String sqlStr = "select SEQUENCE_NBR,APP_NAME,DESIGNER_TYPE from " + model.getPrefix() + "amos_studio" + model.getSuffix() + ".studio_application " +
"where PROJECT_SEQ = " + "'" + projectNbr + "'"; "where PROJECT_SEQ = " + "'" + projectNbr + "'";
// System.out.println(sqlStr); // System.out.println(sqlStr);
ResultSet resultSet = sql.executeQuery(sqlStr); ResultSet resultSet = sql.executeQuery(sqlStr);
...@@ -303,6 +404,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -303,6 +404,7 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
ProjectModel pm = new ProjectModel(); ProjectModel pm = new ProjectModel();
pm.setName(resultSet.getString("APP_NAME")); pm.setName(resultSet.getString("APP_NAME"));
pm.setSequenceNbr(resultSet.getString("SEQUENCE_NBR")); pm.setSequenceNbr(resultSet.getString("SEQUENCE_NBR"));
pm.setDesignerThumb(PictureType.returnPath(resultSet.getString("DESIGNER_TYPE")));
listPm.add(pm); listPm.add(pm);
} }
} catch (SQLException throwables) { } catch (SQLException throwables) {
...@@ -343,9 +445,6 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud ...@@ -343,9 +445,6 @@ public class StudioResourceService extends BaseService<StudioResourceModel, Stud
//关闭资源 //关闭资源
connection.close(); connection.close();
} }
return listPm; return listPm;
} }
} }
...@@ -62,6 +62,7 @@ public class TemplateCategoryService extends BaseService<TemplateCategoryModel, ...@@ -62,6 +62,7 @@ public class TemplateCategoryService extends BaseService<TemplateCategoryModel,
return getChildren(nodes, "", 0L); return getChildren(nodes, "", 0L);
} }
/** /**
* 获得模板分类子节点(递归) * 获得模板分类子节点(递归)
*/ */
......
package com.yeejoin.amos.api.tool.utils; package com.yeejoin.amos.api.tool.utils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
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.orm.entity.TableColumn; import com.yeejoin.amos.api.tool.face.orm.entity.TableColumn;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.component.emq.EmqKeeper;
import org.typroject.tyboot.core.foundation.utils.ValidationUtil;
import javax.servlet.http.HttpServletRequest;
import javax.sql.DataSource;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.sql.*; import java.sql.*;
import java.util.*; import java.util.*;
...@@ -83,6 +70,34 @@ public class DataBaseUtils { ...@@ -83,6 +70,34 @@ public class DataBaseUtils {
return list; return list;
} }
public static List<String> getList(String sql, Connection connection) throws SQLException {
Statement statement = connection.createStatement();
ResultSet rs = statement.executeQuery(sql);
List<String> list = new ArrayList<String>();
try {
ResultSetMetaData md = rs.getMetaData();
int columnCount = md.getColumnCount();
while (rs.next()) {
for (int i = 1; i <= columnCount; i++) {
list.add(rs.getObject(i).toString());
}
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (rs != null)
rs.close();
rs = null;
} catch (SQLException e) {
e.printStackTrace();
}
}
return list;
}
/** /**
* 获取表单列名 * 获取表单列名
*/ */
...@@ -145,7 +160,18 @@ public class DataBaseUtils { ...@@ -145,7 +160,18 @@ public class DataBaseUtils {
} }
} else { } else {
if (!ObjectUtils.isEmpty(map.get(column.getColumnName()))) { if (!ObjectUtils.isEmpty(map.get(column.getColumnName()))) {
sql.append("'").append(map.get(column.getColumnName())).append("'"); if (column.getColumnName().equals("UIOBJECT") || column.getColumnName().equals("CONTENT")){
int start = sql.length()+2;
sql.append("'").append(JSON.toJSONString(map.get(column.getColumnName())).
replaceAll("'","\\\\'")).append("'");
int end = sql.length()-2;
sql.delete(start-1,start);
sql.delete(end-1,end);
}else if (column.getColumnName().equals("PUBLISH_CODE")){
sql.append("'").append((map.get(column.getColumnName())).toString().replaceAll("'","\\\\'")).append("'");
}else {
sql.append("'").append(map.get(column.getColumnName())).append("'");
}
} else { } else {
sql.append("null"); sql.append("null");
} }
...@@ -179,6 +205,4 @@ public class DataBaseUtils { ...@@ -179,6 +205,4 @@ public class DataBaseUtils {
page.setRecords(pageList); page.setRecords(pageList);
return page; return page;
} }
} }
#DB properties: #DB properties:
# jdbc_config # jdbc_config
spring.datasource.url=jdbc:mysql://39.98.45.134:3306/amos_tool_library_test?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
......
#DB properties: #DB properties:
# jdbc_config # jdbc_config
spring.datasource.url=jdbc:mysql://39.98.45.134:3306/amos_tool_library?allowMultiQueries=true spring.datasource.url=jdbc:mysql://172.16.3.18:3306/amos_tool_library?allowMultiQueries=true
#spring.datasource.url=jdbc:mysql://172.16.3.19: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
...@@ -15,7 +16,7 @@ spring.datasource.hikari.connection-timeout=30000 ...@@ -15,7 +16,7 @@ spring.datasource.hikari.connection-timeout=30000
spring.datasource.hikari.connection-test-query=SELECT 1 spring.datasource.hikari.connection-test-query=SELECT 1
#eureka #eureka
eureka.instance.hostname=39.98.45.134 eureka.instance.hostname=172.16.3.18
eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:10001/eureka/ eureka.client.serviceUrl.defaultZone=http://${eureka.instance.hostname}:10001/eureka/
eureka.instance.prefer-ip-address=true eureka.instance.prefer-ip-address=true
eureka.instance.health-check-url=http://localhost:${server.port}${server.servlet.context-path}/actuator/health eureka.instance.health-check-url=http://localhost:${server.port}${server.servlet.context-path}/actuator/health
...@@ -25,7 +26,7 @@ eureka.instance.metadata-map.management.api-docs=http://localhost:${server.port} ...@@ -25,7 +26,7 @@ eureka.instance.metadata-map.management.api-docs=http://localhost:${server.port}
#redis #redis
spring.redis.database=1 spring.redis.database=1
spring.redis.host=39.98.45.134 spring.redis.host=172.16.3.18
spring.redis.port=6379 spring.redis.port=6379
spring.redis.password=yeejoin@2020 spring.redis.password=yeejoin@2020
spring.redis.timeout=0 spring.redis.timeout=0
...@@ -33,7 +34,7 @@ spring.redis.timeout=0 ...@@ -33,7 +34,7 @@ spring.redis.timeout=0
## emqx ## emqx
emqx.clean-session=true emqx.clean-session=true
emqx.client-id=${spring.application.name}-${random.int[1024,65536]} emqx.client-id=${spring.application.name}-${random.int[1024,65536]}
emqx.broker=tcp://39.98.45.134:2883 emqx.broker=tcp://172.16.3.18:2883
emqx.client-user-name=super emqx.client-user-name=super
emqx.client-password=a123456 emqx.client-password=a123456
emqx.max-inflight=1000 emqx.max-inflight=1000
......
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