完成代码生成器~

This commit is contained in:
YunaiV 2021-02-13 13:40:29 +08:00
parent 95757db6be
commit 2f66829a41
14 changed files with 1147 additions and 1329 deletions

View File

@ -1,30 +0,0 @@
package com.ruoyi.generator.config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;
/**
* 读取代码生成相关配置
*
* @author ruoyi
*/
@Component
@ConfigurationProperties(prefix = "gen")
@PropertySource(value = { "classpath:generator.yml" })
public class GenConfig {
/** 作者 */
public static String author;
/** 生成包路径 */
public static String packageName;
/** 自动去除表前缀默认是false */
public static boolean autoRemovePre;
/** 表前缀(类名不会包含表前缀) */
public static String tablePrefix;
}

View File

@ -1,45 +0,0 @@
package com.ruoyi.generator.domain;
import java.util.List;
import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import org.apache.commons.lang3.ArrayUtils;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.core.domain.BaseEntity;
import com.ruoyi.common.utils.StringUtils;
/**
* 业务表 gen_table
*
* @author ruoyi
*/
public class GenTable extends BaseEntity {
/**
* 生成包路径
*/
@NotBlank(message = "生成包路径不能为空")
private String packageName;
/**
* 其它生成选项
*/
private String options;
/**
* 树编码字段
*/
private String treeCode;
/**
* 树父编码字段
*/
private String treeParentCode;
/**
* 树名称字段
*/
private String treeName;
}

View File

@ -1,265 +0,0 @@
package com.ruoyi.generator.util;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import org.apache.velocity.VelocityContext;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.GenConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
/**
* 模板处理工具类
*
* @author ruoyi
*/
public class VelocityUtils {
/**
* 默认上级菜单系统工具
*/
private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
* 设置模板变量信息
*
* @return 模板列表
*/
public static VelocityContext prepareContext(GenTable genTable) {
String moduleName = genTable.getModuleName();
String businessName = genTable.getBusinessName();
String packageName = genTable.getPackageName();
String tplCategory = genTable.getTplCategory();
String functionName = genTable.getFunctionName();
VelocityContext velocityContext = new VelocityContext();
velocityContext.put("tplCategory", genTable.getTplCategory());
velocityContext.put("tableName", genTable.getTableName());
velocityContext.put("functionName", StringUtils.isNotEmpty(functionName) ? functionName : "【请填写功能名称】");
velocityContext.put("ClassName", genTable.getClassName());
velocityContext.put("className", StringUtils.uncapitalize(genTable.getClassName()));
velocityContext.put("moduleName", genTable.getModuleName());
velocityContext.put("BusinessName", StringUtils.capitalize(genTable.getBusinessName()));
velocityContext.put("businessName", genTable.getBusinessName());
velocityContext.put("basePackage", getPackagePrefix(packageName));
velocityContext.put("packageName", packageName);
velocityContext.put("author", genTable.getFunctionAuthor());
velocityContext.put("datetime", DateUtils.getDate());
velocityContext.put("pkColumn", genTable.getPkColumn());
velocityContext.put("importList", getImportList(genTable.getColumns()));
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory)) {
setTreeVelocityContext(velocityContext, genTable);
}
return velocityContext;
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeCode = getTreecode(paramsObj);
String treeParentCode = getTreeParentCode(paramsObj);
String treeName = getTreeName(paramsObj);
context.put("treeCode", treeCode);
context.put("treeParentCode", treeParentCode);
context.put("treeName", treeName);
context.put("expandColumn", getExpandColumn(genTable));
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
context.put("tree_parent_code", paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
context.put("tree_name", paramsObj.getString(GenConstants.TREE_NAME));
}
}
/**
* 获取模板信息
*
* @return 模板列表
*/
public static List<String> getTemplateList(String tplCategory) {
List<String> templates = new ArrayList<String>();
templates.add("vm/java/domain.java.vm");
templates.add("vm/java/mapper.java.vm");
templates.add("vm/java/service.java.vm");
templates.add("vm/java/serviceImpl.java.vm");
templates.add("vm/java/controller.java.vm");
templates.add("vm/xml/mapper.xml.vm");
templates.add("vm/sql/sql.vm");
templates.add("vm/js/api.js.vm");
if (GenConstants.TPL_CRUD.equals(tplCategory)) {
templates.add("vm/vue/index.vue.vm");
} else if (GenConstants.TPL_TREE.equals(tplCategory)) {
templates.add("vm/vue/index-tree.vue.vm");
}
return templates;
}
/**
* 获取文件名
*/
public static String getFileName(String template, GenTable genTable) {
// 文件名称
String fileName = "";
// 包路径
String packageName = genTable.getPackageName();
// 模块名
String moduleName = genTable.getModuleName();
// 大写类名
String className = genTable.getClassName();
// 业务名称
String businessName = genTable.getBusinessName();
String javaPath = PROJECT_PATH + "/" + StringUtils.replace(packageName, ".", "/");
String mybatisPath = MYBATIS_PATH + "/" + moduleName;
String vuePath = "vue";
if (template.contains("domain.java.vm")) {
fileName = StringUtils.format("{}/domain/{}.java", javaPath, className);
} else if (template.contains("mapper.java.vm")) {
fileName = StringUtils.format("{}/mapper/{}Mapper.java", javaPath, className);
} else if (template.contains("service.java.vm")) {
fileName = StringUtils.format("{}/service/I{}Service.java", javaPath, className);
} else if (template.contains("serviceImpl.java.vm")) {
fileName = StringUtils.format("{}/service/impl/{}ServiceImpl.java", javaPath, className);
} else if (template.contains("controller.java.vm")) {
fileName = StringUtils.format("{}/controller/{}Controller.java", javaPath, className);
} else if (template.contains("mapper.xml.vm")) {
fileName = StringUtils.format("{}/{}Mapper.xml", mybatisPath, className);
} else if (template.contains("sql.vm")) {
fileName = businessName + "Menu.sql";
} else if (template.contains("api.js.vm")) {
fileName = StringUtils.format("{}/api/{}/{}.js", vuePath, moduleName, businessName);
} else if (template.contains("index.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
} else if (template.contains("index-tree.vue.vm")) {
fileName = StringUtils.format("{}/views/{}/{}/index.vue", vuePath, moduleName, businessName);
}
return fileName;
}
/**
* 获取包前缀
*
* @param packageName 包名称
* @return 包前缀名称
*/
public static String getPackagePrefix(String packageName) {
int lastIndex = packageName.lastIndexOf(".");
String basePackage = StringUtils.substring(packageName, 0, lastIndex);
return basePackage;
}
/**
* 根据列类型获取导入包
*
* @param columns 列集合
* @return 返回需要导入的包列表
*/
public static HashSet<String> getImportList(List<GenTableColumn> columns) {
HashSet<String> importList = new HashSet<String>();
for (GenTableColumn column : columns) {
if (!column.isSuperColumn() && GenConstants.TYPE_DATE.equals(column.getJavaType())) {
importList.add("java.util.Date");
importList.add("com.fasterxml.jackson.annotation.JsonFormat");
} else if (!column.isSuperColumn() && GenConstants.TYPE_BIGDECIMAL.equals(column.getJavaType())) {
importList.add("java.math.BigDecimal");
}
}
return importList;
}
/**
* 获取权限前缀
*
* @param moduleName 模块名称
* @param businessName 业务名称
* @return 返回权限前缀
*/
public static String getPermissionPrefix(String moduleName, String businessName) {
return StringUtils.format("{}:{}", moduleName, businessName);
}
/**
* 获取上级菜单ID字段
*
* @param paramsObj 生成其他选项
* @return 上级菜单ID字段
*/
public static String getParentMenuId(JSONObject paramsObj) {
if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID)) {
return paramsObj.getString(GenConstants.PARENT_MENU_ID);
}
return DEFAULT_PARENT_MENU_ID;
}
/**
* 获取树编码
*
* @param paramsObj 生成其他选项
* @return 树编码
*/
public static String getTreecode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
return StringUtils.EMPTY;
}
/**
* 获取树父编码
*
* @param paramsObj 生成其他选项
* @return 树父编码
*/
public static String getTreeParentCode(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_PARENT_CODE)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
return StringUtils.EMPTY;
}
/**
* 获取树名称
*
* @param paramsObj 生成其他选项
* @return 树名称
*/
public static String getTreeName(JSONObject paramsObj) {
if (paramsObj.containsKey(GenConstants.TREE_NAME)) {
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
return StringUtils.EMPTY;
}
/**
* 获取需要在哪一列上面显示展开按钮
*
* @param genTable 业务表对象
* @return 展开按钮列序号
*/
public static int getExpandColumn(GenTable genTable) {
String options = genTable.getOptions();
JSONObject paramsObj = JSONObject.parseObject(options);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
int num = 0;
for (GenTableColumn column : genTable.getColumns()) {
if (column.isList()) {
num++;
String columnName = column.getColumnName();
if (columnName.equals(treeName)) {
break;
}
}
}
return num;
}
}

View File

@ -1,10 +0,0 @@
# 代码生成
gen:
# 作者
author: ruoyi
# 默认生成包路径 system 需改成自己的模块名称 如 system monitor tool
packageName: com.ruoyi.system
# 自动去除表前缀默认是false
autoRemovePre: false
# 表前缀(生成类名不会包含表前缀,多个用逗号分隔)
tablePrefix: sys_

View File

@ -27,13 +27,25 @@ export function updateCodegen(data) {
} }
// 基于数据库的表结构,同步数据库的表和字段定义 // 基于数据库的表结构,同步数据库的表和字段定义
export function syncCodegen(tableId) { export function syncCodegenFromDB(tableId) {
return request({ return request({
url: '/tool/codegen/sync?tableId=' + tableId, url: '/tool/codegen/sync-from-db?tableId=' + tableId,
method: 'put' method: 'put'
}) })
} }
// 基于 SQL 建表语句,同步数据库的表和字段定义
export function syncCodegenFromSQL(tableId, sql) {
return request({
url: '/tool/codegen/sync-from-sql?tableId=' + tableId,
method: 'put',
headers:{
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'tableId=' + tableId + "&sql=" + sql,
})
}
// 预览生成代码 // 预览生成代码
export function previewCodegen(tableId) { export function previewCodegen(tableId) {
return request({ return request({
@ -61,9 +73,9 @@ export function getSchemaTableList(query) {
} }
// 基于数据库的表结构,创建代码生成器的表定义 // 基于数据库的表结构,创建代码生成器的表定义
export function createCodegenList(tableNames) { export function createCodegenListFromDB(tableNames) {
return request({ return request({
url: '/tool/codegen/create-list', url: '/tool/codegen/create-list-from-db',
method: 'post', method: 'post',
headers:{ headers:{
'Content-type': 'application/x-www-form-urlencoded' 'Content-type': 'application/x-www-form-urlencoded'
@ -72,6 +84,18 @@ export function createCodegenList(tableNames) {
}) })
} }
// 基于 SQL 建表语句,创建代码生成器的表定义
export function createCodegenListFromSQL(data) {
return request({
url: '/tool/codegen/create-list-from-sql',
method: 'post',
headers:{
'Content-type': 'application/x-www-form-urlencoded'
},
data: 'sql=' + data.sql,
})
}
// 删除数据库的表和字段定义 // 删除数据库的表和字段定义
export function deleteCodegen(tableId) { export function deleteCodegen(tableId) {
return request({ return request({

View File

@ -107,13 +107,13 @@ export const constantRoutes = [
] ]
}, },
{ {
path: '/gen', path: '/codegen',
component: Layout, component: Layout,
hidden: true, hidden: true,
children: [ children: [
{ {
path: 'edit/:tableId(\\d+)', path: 'edit/:tableId(\\d+)',
component: (resolve) => require(['@/views/tool/gen/editTable'], resolve), component: (resolve) => require(['@/views/tool/codegen/editTable'], resolve),
name: 'GenEdit', name: 'GenEdit',
meta: { title: '修改生成配置' } meta: { title: '修改生成配置' }
} }

View File

@ -128,7 +128,6 @@
<script> <script>
import { getCodegenDetail, updateCodegen } from "@/api/tool/codegen"; import { getCodegenDetail, updateCodegen } from "@/api/tool/codegen";
import { listAllSimple as listAllSimpleDictType } from "@/api/system/dict/type"; import { listAllSimple as listAllSimpleDictType } from "@/api/system/dict/type";
import { listMenu as getMenuTreeselect } from "@/api/system/menu";
import { listSimpleMenus } from "@/api/system/menu"; import { listSimpleMenus } from "@/api/system/menu";
import basicInfoForm from "./basicInfoForm"; import basicInfoForm from "./basicInfoForm";
import genInfoForm from "./genInfoForm"; import genInfoForm from "./genInfoForm";

View File

@ -46,7 +46,7 @@
</template> </template>
<script> <script>
import { getSchemaTableList, createCodegenList } from "@/api/tool/codegen"; import { getSchemaTableList, createCodegenListFromDB } from "@/api/tool/codegen";
export default { export default {
data() { data() {
return { return {
@ -95,7 +95,7 @@ export default {
}, },
/** 导入按钮操作 */ /** 导入按钮操作 */
handleImportTable() { handleImportTable() {
createCodegenList(this.tables.join(",")).then(res => { createCodegenListFromDB(this.tables.join(",")).then(res => {
this.msgSuccess("导入成功"); this.msgSuccess("导入成功");
this.visible = false; this.visible = false;
this.$emit("ok"); this.$emit("ok");

View File

@ -1,5 +1,6 @@
<template> <template>
<div class="app-container"> <div class="app-container">
<!-- 操作工作栏 -->
<el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px"> <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="表名称" prop="tableName"> <el-form-item label="表名称" prop="tableName">
<el-input <el-input
@ -37,13 +38,18 @@
</el-form-item> </el-form-item>
</el-form> </el-form>
<!-- 操作工作栏 -->
<el-row :gutter="10" class="mb8"> <el-row :gutter="10" class="mb8">
<el-col :span="1.5"> <el-col :span="1.5">
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable" v-hasPermi="['tool:gen:import']">导入</el-button> <el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportTable"
v-hasPermi="['tool:codegen:create']">基于 DB 导入</el-button>
<el-button type="info" plain icon="el-icon-upload" size="mini" @click="openImportSQL"
v-hasPermi="['tool:codegen:create']">基于 SQL 导入</el-button>
</el-col> </el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<!-- 列表 -->
<el-table v-loading="loading" :data="tableList"> <el-table v-loading="loading" :data="tableList">
<el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" width="200"/> <el-table-column label="表名称" align="center" prop="tableName" :show-overflow-tooltip="true" width="200"/>
<el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" width="120"/> <el-table-column label="表描述" align="center" prop="tableComment" :show-overflow-tooltip="true" width="120"/>
@ -60,15 +66,16 @@
</el-table-column> </el-table-column>
<el-table-column label="操作" align="center" class-name="small-padding fixed-width"> <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
<template slot-scope="scope"> <template slot-scope="scope">
<el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['tool:gen:preview']">预览</el-button> <el-button type="text" size="small" icon="el-icon-view" @click="handlePreview(scope.row)" v-hasPermi="['tool:codegen:preview']">预览</el-button>
<el-button type="text" size="small" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['tool:gen:edit']">编辑</el-button> <el-button type="text" size="small" icon="el-icon-edit" @click="handleEditTable(scope.row)" v-hasPermi="['tool:codegen:update']">编辑</el-button>
<el-button type="text" size="small" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['tool:gen:remove']">删除</el-button> <el-button type="text" size="small" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['tool:codegen:delete']">删除</el-button>
<el-button type="text" size="small" icon="el-icon-refresh" @click="handleSynchDb(scope.row)" v-hasPermi="['tool:gen:edit']">同步</el-button> <el-button type="text" size="small" icon="el-icon-refresh" @click="handleSynchDb(scope.row)" v-hasPermi="['tool:codegen:update']">同步</el-button>
<el-button type="text" size="small" icon="el-icon-download" @click="handleGenTable(scope.row)" v-hasPermi="['tool:gen:code']">生成代码</el-button> <el-button type="text" size="small" icon="el-icon-download" @click="handleGenTable(scope.row)" v-hasPermi="['tool:codegen:download']">生成代码</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/> <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize" @pagination="getList"/>
<!-- 预览界面 --> <!-- 预览界面 -->
<el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body> <el-dialog :title="preview.title" :visible.sync="preview.open" width="80%" top="5vh" append-to-body>
<el-tabs tab-position="left" v-model="preview.activeName"> <el-tabs tab-position="left" v-model="preview.activeName">
@ -77,17 +84,39 @@
</el-tab-pane> </el-tab-pane>
</el-tabs> </el-tabs>
</el-dialog> </el-dialog>
<!-- 基于 DB 导入 -->
<import-table ref="import" @ok="handleQuery" /> <import-table ref="import" @ok="handleQuery" />
<!-- 基于 SQL 导入 -->
<el-dialog :title="importSQL.title" :visible.sync="importSQL.open" width="800px" append-to-body>
<el-form ref="importSQLForm" :model="importSQL.form" :rules="importSQL.rules" label-width="120px">
<el-row>
<el-col :span="12">
<el-form-item label="建表 SQL 语句" prop="sql">
<el-input v-model="importSQL.form.sql" type="textarea" rows="30" style="width: 650px;" placeholder="请输入建 SQL 语句" />
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitImportSQLForm"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
</div> </div>
</template> </template>
<script> <script>
import { getCodegenTablePage, previewCodegen, downloadCodegen, deleteCodegen, syncCodegen } from "@/api/tool/codegen"; import { getCodegenTablePage, previewCodegen, downloadCodegen, deleteCodegen,
syncCodegenFromDB, syncCodegenFromSQL, createCodegenListFromSQL } from "@/api/tool/codegen";
import importTable from "./importTable"; import importTable from "./importTable";
// //
import hljs from "highlight.js/lib/highlight"; import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css"; import "highlight.js/styles/github-gist.css";
import {SysCommonStatusEnum} from "@/utils/constants";
import {createTestDemo, updateTestDemo} from "@/api/tool/testDemo";
hljs.registerLanguage("java", require("highlight.js/lib/languages/java")); hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml")); hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml")); hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
@ -96,7 +125,7 @@ hljs.registerLanguage("javascript", require("highlight.js/lib/languages/javascri
hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql")); hljs.registerLanguage("sql", require("highlight.js/lib/languages/sql"));
export default { export default {
name: "Gen", name: "Codegen",
components: { importTable }, components: { importTable },
data() { data() {
return { return {
@ -127,6 +156,17 @@ export default {
title: "代码预览", title: "代码预览",
data: {}, data: {},
activeName: "domain.java" activeName: "domain.java"
},
// SQL
importSQL: {
open: false,
title: "",
form: {
},
rules: {
sql: [{ required: true, message: "SQL 不能为空", trigger: "blur" }]
}
} }
}; };
}, },
@ -167,13 +207,20 @@ export default {
}, },
/** 同步数据库操作 */ /** 同步数据库操作 */
handleSynchDb(row) { handleSynchDb(row) {
// SQL
if (row.importType === 2) {
this.importSQL.open = true;
this.importSQL.form.tableId = row.id;
return;
}
// DB
const tableName = row.tableName; const tableName = row.tableName;
this.$confirm('确认要强制同步"' + tableName + '"表结构吗?', "警告", { this.$confirm('确认要强制同步"' + tableName + '"表结构吗?', "警告", {
confirmButtonText: "确定", confirmButtonText: "确定",
cancelButtonText: "取消", cancelButtonText: "取消",
type: "warning" type: "warning"
}).then(function() { }).then(function() {
return syncCodegen(row.id); return syncCodegenFromDB(row.id);
}).then(() => { }).then(() => {
this.msgSuccess("同步成功"); this.msgSuccess("同步成功");
}) })
@ -182,6 +229,10 @@ export default {
openImportTable() { openImportTable() {
this.$refs.import.show(); this.$refs.import.show();
}, },
/** 打开 SQL 导入的弹窗 **/
openImportSQL() {
this.importSQL.open = true;
},
/** 重置按钮操作 */ /** 重置按钮操作 */
resetQuery() { resetQuery() {
this.dateRange = []; this.dateRange = [];
@ -207,7 +258,7 @@ export default {
/** 修改按钮操作 */ /** 修改按钮操作 */
handleEditTable(row) { handleEditTable(row) {
const tableId = row.id; const tableId = row.id;
this.$router.push("/gen/edit/" + tableId); this.$router.push("/codegen/edit/" + tableId);
}, },
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
@ -222,6 +273,43 @@ export default {
this.getList(); this.getList();
this.msgSuccess("删除成功"); this.msgSuccess("删除成功");
}) })
},
//
cancel() {
this.importSQL.open = false;
this.reset();
},
//
reset() {
this.importSQL.form = {
tableId: undefined,
sql: undefined,
};
this.resetForm("importSQLForm");
},
// import SQL
submitImportSQLForm() {
this.$refs["importSQLForm"].validate(valid => {
if (!valid) {
return;
}
//
let form = this.importSQL.form;
if (form.tableId != null) {
syncCodegenFromSQL(form.tableId, form.sql).then(response => {
this.msgSuccess("同步成功");
this.importSQL.open = false;
this.getList();
});
return;
}
//
createCodegenListFromSQL(form).then(response => {
this.msgSuccess("导入成功");
this.importSQL.open = false;
this.getList();
});
});
} }
} }
}; };

File diff suppressed because one or more lines are too long

View File

@ -56,9 +56,6 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
@Resource @Resource
private CodegenProperties codegenProperties; private CodegenProperties codegenProperties;
@Resource
private ToolCodegenServiceImpl self;
private Long createCodegen0(ToolCodegenImportTypeEnum importType, private Long createCodegen0(ToolCodegenImportTypeEnum importType,
ToolSchemaTableDO schemaTable, List<ToolSchemaColumnDO> schemaColumns) { ToolSchemaTableDO schemaTable, List<ToolSchemaColumnDO> schemaColumns) {
// 校验导入的表和字段非空 // 校验导入的表和字段非空
@ -99,7 +96,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
throw exception(CODEGEN_PARSE_SQL_ERROR); throw exception(CODEGEN_PARSE_SQL_ERROR);
} }
// 导入 // 导入
return self.createCodegen0(ToolCodegenImportTypeEnum.SQL, schemaTable, schemaColumns); return this.createCodegen0(ToolCodegenImportTypeEnum.SQL, schemaTable, schemaColumns);
} }
@Override @Override
@ -108,7 +105,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName(tableName); ToolSchemaTableDO schemaTable = schemaTableMapper.selectByTableName(tableName);
List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableName); List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(tableName);
// 导入 // 导入
return self.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns); return this.createCodegen0(ToolCodegenImportTypeEnum.DB, schemaTable, schemaColumns);
} }
@Override @Override
@ -147,7 +144,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(table.getTableName()); List<ToolSchemaColumnDO> schemaColumns = schemaColumnMapper.selectListByTableName(table.getTableName());
// 执行同步 // 执行同步
self.syncCodegen0(tableId, schemaColumns); this.syncCodegen0(tableId, schemaColumns);
} }
@Override @Override
@ -167,7 +164,7 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
} }
// 执行同步 // 执行同步
self.syncCodegen0(tableId, schemaColumns); this.syncCodegen0(tableId, schemaColumns);
} }
private void syncCodegen0(Long tableId, List<ToolSchemaColumnDO> schemaColumns) { private void syncCodegen0(Long tableId, List<ToolSchemaColumnDO> schemaColumns) {

View File

@ -268,12 +268,12 @@ export default {
this.loading = false; this.loading = false;
}); });
}, },
// 取消按钮 /** 取消按钮 */
cancel() { cancel() {
this.open = false; this.open = false;
this.reset(); this.reset();
}, },
// 表单重置 /** 表单重置 */
reset() { reset() {
this.form = { this.form = {
#foreach ($column in $columns) #foreach ($column in $columns)