commit
5b160a275b
|
@ -29,6 +29,12 @@
|
||||||
<artifactId>ruoyi-common</artifactId>
|
<artifactId>ruoyi-common</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- 阿里数据库连接池 -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.alibaba</groupId>
|
||||||
|
<artifactId>druid-spring-boot-starter</artifactId>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
</project>
|
</project>
|
|
@ -30,6 +30,11 @@ import com.ruoyi.generator.domain.GenTable;
|
||||||
import com.ruoyi.generator.domain.GenTableColumn;
|
import com.ruoyi.generator.domain.GenTableColumn;
|
||||||
import com.ruoyi.generator.service.IGenTableColumnService;
|
import com.ruoyi.generator.service.IGenTableColumnService;
|
||||||
import com.ruoyi.generator.service.IGenTableService;
|
import com.ruoyi.generator.service.IGenTableService;
|
||||||
|
import com.alibaba.druid.DbType;
|
||||||
|
import com.alibaba.druid.sql.SQLUtils;
|
||||||
|
import com.alibaba.druid.sql.ast.SQLStatement;
|
||||||
|
import com.alibaba.druid.sql.dialect.mysql.ast.statement.MySqlCreateTableStatement;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 代码生成 操作处理
|
* 代码生成 操作处理
|
||||||
|
@ -106,6 +111,15 @@ public class GenController extends BaseController
|
||||||
return prefix + "/importTable";
|
return prefix + "/importTable";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表结构
|
||||||
|
*/
|
||||||
|
|
||||||
|
@GetMapping("/createTable")
|
||||||
|
public String createTable() {
|
||||||
|
return prefix + "/createTable" ;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入表结构(保存)
|
* 导入表结构(保存)
|
||||||
*/
|
*/
|
||||||
|
@ -175,6 +189,32 @@ public class GenController extends BaseController
|
||||||
return AjaxResult.success();
|
return AjaxResult.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Log(title = "创建表", businessType = BusinessType.OTHER)
|
||||||
|
@PostMapping("/createTable")
|
||||||
|
@ResponseBody
|
||||||
|
public AjaxResult create(String sql) {
|
||||||
|
List<SQLStatement> sqlStatements = SQLUtils.parseStatements(sql, DbType.mysql);
|
||||||
|
List<String> tableNames = new ArrayList<>();
|
||||||
|
for (SQLStatement sqlStatement : sqlStatements) {
|
||||||
|
if (sqlStatement instanceof MySqlCreateTableStatement) {
|
||||||
|
MySqlCreateTableStatement sqlStatement1 = (MySqlCreateTableStatement) sqlStatement;
|
||||||
|
String tableName = sqlStatement1.getTableName();
|
||||||
|
tableName = tableName.replaceAll("`", "");
|
||||||
|
|
||||||
|
int msg = genTableService.createTable(sqlStatement1.toString());
|
||||||
|
if (msg == 0) {
|
||||||
|
tableNames.add(tableName);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error("请输入建表语句");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<GenTable> tableList = genTableService.selectDbTableListByNames(
|
||||||
|
(tableNames.toArray(new String[tableNames.size()])));
|
||||||
|
genTableService.importGenTable(tableList, "admin");
|
||||||
|
return AjaxResult.success();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 预览代码
|
* 预览代码
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -80,4 +80,12 @@ public interface GenTableMapper
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteGenTableByIds(Long[] ids);
|
public int deleteGenTableByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表
|
||||||
|
*
|
||||||
|
* @param sql
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public int createTable(String sql);
|
||||||
}
|
}
|
|
@ -66,6 +66,14 @@ public interface IGenTableService
|
||||||
*/
|
*/
|
||||||
public void deleteGenTableByIds(String ids);
|
public void deleteGenTableByIds(String ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 创建表
|
||||||
|
*
|
||||||
|
* @param sql 创建表语句
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int createTable(String sql);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入表结构
|
* 导入表结构
|
||||||
*
|
*
|
||||||
|
|
|
@ -150,6 +150,11 @@ public class GenTableServiceImpl implements IGenTableService
|
||||||
genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
genTableColumnMapper.deleteGenTableColumnByIds(Convert.toLongArray(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int createTable(String sql) {
|
||||||
|
return genTableMapper.createTable(sql);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导入表结构
|
* 导入表结构
|
||||||
*
|
*
|
||||||
|
|
|
@ -156,6 +156,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
)
|
)
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<update id="createTable">
|
||||||
|
${sql}
|
||||||
|
</update>
|
||||||
|
|
||||||
<update id="updateGenTable" parameterType="GenTable">
|
<update id="updateGenTable" parameterType="GenTable">
|
||||||
update gen_table
|
update gen_table
|
||||||
<set>
|
<set>
|
||||||
|
|
|
@ -34,6 +34,9 @@
|
||||||
<div class="btn-group-sm" id="toolbar" role="group">
|
<div class="btn-group-sm" id="toolbar" role="group">
|
||||||
<a class="btn btn-success multiple disabled" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
|
<a class="btn btn-success multiple disabled" onclick="javascript:batchGenCode()" shiro:hasPermission="tool:gen:code">
|
||||||
<i class="fa fa-download"></i> 生成
|
<i class="fa fa-download"></i> 生成
|
||||||
|
</a>
|
||||||
|
<a class="btn btn-success" onclick="createTable()">
|
||||||
|
<i class="fa fa-plus"></i> 创建
|
||||||
</a>
|
</a>
|
||||||
<a class="btn btn-info" onclick="importTable()">
|
<a class="btn btn-info" onclick="importTable()">
|
||||||
<i class="fa fa-upload"></i> 导入
|
<i class="fa fa-upload"></i> 导入
|
||||||
|
@ -204,6 +207,12 @@
|
||||||
var importTableUrl = prefix + "/importTable";
|
var importTableUrl = prefix + "/importTable";
|
||||||
$.modal.open("导入表结构", importTableUrl);
|
$.modal.open("导入表结构", importTableUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 创建表结构
|
||||||
|
function createTable() {
|
||||||
|
var creatTableUrl = prefix + "/createTable";
|
||||||
|
$.modal.open("创建表结构", creatTableUrl);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -0,0 +1,30 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
|
||||||
|
<head>
|
||||||
|
<th:block th:include="include :: header('创建表结构')"/>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="main-content">
|
||||||
|
<label class="col-sm-6 control-label">创建表语句(支持多个建表语句):</label>
|
||||||
|
<div class="col-sm-11 col">
|
||||||
|
<textarea class="form-control" id="text_create" name="" placeholder="请输入文本" rows="12" type="text"></textarea>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<th:block th:include="include :: footer"/>
|
||||||
|
|
||||||
|
<script type="text/javascript">
|
||||||
|
var prefix = ctx + "tool/gen";
|
||||||
|
|
||||||
|
/* 创建表结构 */
|
||||||
|
function submitHandler() {
|
||||||
|
var rows = $("#text_create").val();
|
||||||
|
if (rows.length == 0) {
|
||||||
|
$.modal.alertWarning("请输入建表语句");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var data = {"sql": rows};
|
||||||
|
$.operate.save(prefix + "/createTable", data);
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
Reference in New Issue