代码生成器的编辑界面~
This commit is contained in:
parent
b04db3d6d8
commit
3fb292a4c1
|
@ -37,36 +37,6 @@ import com.ruoyi.generator.service.IGenTableService;
|
|||
@RestController
|
||||
@RequestMapping("/tool/gen")
|
||||
public class GenController extends BaseController {
|
||||
@Autowired
|
||||
private IGenTableService genTableService;
|
||||
|
||||
@Autowired
|
||||
private IGenTableColumnService genTableColumnService;
|
||||
|
||||
/**
|
||||
* 查询代码生成列表
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo genList(GenTable genTable) {
|
||||
startPage();
|
||||
List<GenTable> list = genTableService.selectGenTableList(genTable);
|
||||
return getDataTable(list);
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改代码生成业务
|
||||
*/
|
||||
@PreAuthorize("@ss.hasPermi('tool:gen:query')")
|
||||
@GetMapping(value = "/{talbleId}")
|
||||
public AjaxResult getInfo(@PathVariable Long talbleId) {
|
||||
GenTable table = genTableService.selectGenTableById(talbleId);
|
||||
List<GenTableColumn> list = genTableColumnService.selectGenTableColumnListByTableId(talbleId);
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("info", table);
|
||||
map.put("rows", list);
|
||||
return AjaxResult.success(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询数据库列表
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
package com.ruoyi.generator.domain;
|
||||
|
||||
import javax.validation.constraints.NotBlank;
|
||||
|
||||
import com.ruoyi.common.core.domain.BaseEntity;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 代码生成业务字段表 gen_table_column
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public class GenTableColumn extends BaseEntity {
|
||||
|
||||
public static boolean isSuperColumn(String javaField) {
|
||||
return StringUtils.equalsAnyIgnoreCase(javaField,
|
||||
// BaseEntity
|
||||
"createBy", "createTime", "updateBy", "updateTime", "remark",
|
||||
// TreeEntity
|
||||
"parentName", "parentId", "orderNum", "ancestors");
|
||||
}
|
||||
|
||||
public boolean isUsableColumn() {
|
||||
return isUsableColumn(javaField);
|
||||
}
|
||||
|
||||
public static boolean isUsableColumn(String javaField) {
|
||||
// isSuperColumn()中的名单用于避免生成多余Domain属性,若某些属性在生成页面时需要用到不能忽略,则放在此处白名单
|
||||
return StringUtils.equalsAnyIgnoreCase(javaField, "parentId", "orderNum", "remark");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,60 +0,0 @@
|
|||
package com.ruoyi.generator.mapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.ruoyi.generator.domain.GenTableColumn;
|
||||
|
||||
/**
|
||||
* 业务字段 数据层
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
public interface GenTableColumnMapper {
|
||||
/**
|
||||
* 根据表名称查询列信息
|
||||
*
|
||||
* @param tableName 表名称
|
||||
* @return 列信息
|
||||
*/
|
||||
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
|
||||
|
||||
/**
|
||||
* 查询业务字段列表
|
||||
*
|
||||
* @param tableId 业务字段编号
|
||||
* @return 业务字段集合
|
||||
*/
|
||||
public List<GenTableColumn> selectGenTableColumnListByTableId(Long tableId);
|
||||
|
||||
/**
|
||||
* 新增业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int insertGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 修改业务字段
|
||||
*
|
||||
* @param genTableColumn 业务字段信息
|
||||
* @return 结果
|
||||
*/
|
||||
public int updateGenTableColumn(GenTableColumn genTableColumn);
|
||||
|
||||
/**
|
||||
* 删除业务字段
|
||||
*
|
||||
* @param genTableColumns 列数据
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumns(List<GenTableColumn> genTableColumns);
|
||||
|
||||
/**
|
||||
* 批量删除业务字段
|
||||
*
|
||||
* @param ids 需要删除的数据ID
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteGenTableColumnByIds(Long[] ids);
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<!DOCTYPE mapper
|
||||
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">
|
||||
|
||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
<result property="columnName" column="column_name" />
|
||||
<result property="columnComment" column="column_comment" />
|
||||
<result property="columnType" column="column_type" />
|
||||
<result property="javaType" column="java_type" />
|
||||
<result property="javaField" column="java_field" />
|
||||
<result property="isPk" column="is_pk" />
|
||||
<result property="isIncrement" column="is_increment" />
|
||||
<result property="isRequired" column="is_required" />
|
||||
<result property="isInsert" column="is_insert" />
|
||||
<result property="isEdit" column="is_edit" />
|
||||
<result property="isList" column="is_list" />
|
||||
<result property="isQuery" column="is_query" />
|
||||
<result property="queryType" column="query_type" />
|
||||
<result property="htmlType" column="html_type" />
|
||||
<result property="dictType" column="dict_type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTableColumnVo">
|
||||
select column_id, table_id, column_name, column_comment, column_type, java_type, java_field, is_pk, is_increment, is_required, is_insert, is_edit, is_list, is_query, query_type, html_type, dict_type, sort, create_by, create_time, update_by, update_time from gen_table_column
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableColumnListByTableId" parameterType="Long" resultMap="GenTableColumnResult">
|
||||
<include refid="selectGenTableColumnVo"/>
|
||||
where table_id = #{tableId}
|
||||
order by sort
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
|
||||
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else null end) as is_required, (case when column_key = 'PRI' then '1' else '0' end) as is_pk, ordinal_position as sort, column_comment, (case when extra = 'auto_increment' then '1' else '0' end) as is_increment, column_type
|
||||
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
|
||||
order by ordinal_position
|
||||
</select>
|
||||
|
||||
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
|
||||
insert into gen_table_column (
|
||||
<if test="tableId != null and tableId != ''">table_id,</if>
|
||||
<if test="columnName != null and columnName != ''">column_name,</if>
|
||||
<if test="columnComment != null and columnComment != ''">column_comment,</if>
|
||||
<if test="columnType != null and columnType != ''">column_type,</if>
|
||||
<if test="javaType != null and javaType != ''">java_type,</if>
|
||||
<if test="javaField != null and javaField != ''">java_field,</if>
|
||||
<if test="isPk != null and isPk != ''">is_pk,</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">is_increment,</if>
|
||||
<if test="isRequired != null and isRequired != ''">is_required,</if>
|
||||
<if test="isInsert != null and isInsert != ''">is_insert,</if>
|
||||
<if test="isEdit != null and isEdit != ''">is_edit,</if>
|
||||
<if test="isList != null and isList != ''">is_list,</if>
|
||||
<if test="isQuery != null and isQuery != ''">is_query,</if>
|
||||
<if test="queryType != null and queryType != ''">query_type,</if>
|
||||
<if test="htmlType != null and htmlType != ''">html_type,</if>
|
||||
<if test="dictType != null and dictType != ''">dict_type,</if>
|
||||
<if test="sort != null">sort,</if>
|
||||
<if test="createBy != null and createBy != ''">create_by,</if>
|
||||
create_time
|
||||
)values(
|
||||
<if test="tableId != null and tableId != ''">#{tableId},</if>
|
||||
<if test="columnName != null and columnName != ''">#{columnName},</if>
|
||||
<if test="columnComment != null and columnComment != ''">#{columnComment},</if>
|
||||
<if test="columnType != null and columnType != ''">#{columnType},</if>
|
||||
<if test="javaType != null and javaType != ''">#{javaType},</if>
|
||||
<if test="javaField != null and javaField != ''">#{javaField},</if>
|
||||
<if test="isPk != null and isPk != ''">#{isPk},</if>
|
||||
<if test="isIncrement != null and isIncrement != ''">#{isIncrement},</if>
|
||||
<if test="isRequired != null and isRequired != ''">#{isRequired},</if>
|
||||
<if test="isInsert != null and isInsert != ''">#{isInsert},</if>
|
||||
<if test="isEdit != null and isEdit != ''">#{isEdit},</if>
|
||||
<if test="isList != null and isList != ''">#{isList},</if>
|
||||
<if test="isQuery != null and isQuery != ''">#{isQuery},</if>
|
||||
<if test="queryType != null and queryType != ''">#{queryType},</if>
|
||||
<if test="htmlType != null and htmlType != ''">#{htmlType},</if>
|
||||
<if test="dictType != null and dictType != ''">#{dictType},</if>
|
||||
<if test="sort != null">#{sort},</if>
|
||||
<if test="createBy != null and createBy != ''">#{createBy},</if>
|
||||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateGenTableColumn" parameterType="GenTableColumn">
|
||||
update gen_table_column
|
||||
<set>
|
||||
column_comment = #{columnComment},
|
||||
java_type = #{javaType},
|
||||
java_field = #{javaField},
|
||||
is_insert = #{isInsert},
|
||||
is_edit = #{isEdit},
|
||||
is_list = #{isList},
|
||||
is_query = #{isQuery},
|
||||
is_required = #{isRequired},
|
||||
query_type = #{queryType},
|
||||
html_type = #{htmlType},
|
||||
dict_type = #{dictType},
|
||||
sort = #{sort},
|
||||
update_by = #{updateBy},
|
||||
update_time = sysdate()
|
||||
</set>
|
||||
where column_id = #{columnId}
|
||||
</update>
|
||||
|
||||
<delete id="deleteGenTableColumnByIds" parameterType="Long">
|
||||
delete from gen_table_column where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
<delete id="deleteGenTableColumns">
|
||||
delete from gen_table_column where column_id in
|
||||
<foreach collection="list" item="item" open="(" separator="," close=")">
|
||||
#{item.columnId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
|
@ -4,75 +4,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.ruoyi.generator.mapper.GenTableMapper">
|
||||
|
||||
<resultMap type="GenTable" id="GenTableResult">
|
||||
<id property="tableId" column="table_id" />
|
||||
<result property="tableName" column="table_name" />
|
||||
<result property="tableComment" column="table_comment" />
|
||||
<result property="className" column="class_name" />
|
||||
<result property="tplCategory" column="tpl_category" />
|
||||
<result property="packageName" column="package_name" />
|
||||
<result property="moduleName" column="module_name" />
|
||||
<result property="businessName" column="business_name" />
|
||||
<result property="functionName" column="function_name" />
|
||||
<result property="functionAuthor" column="function_author" />
|
||||
<result property="genType" column="gen_type" />
|
||||
<result property="genPath" column="gen_path" />
|
||||
<result property="options" column="options" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
<result property="remark" column="remark" />
|
||||
<collection property="columns" javaType="java.util.List" resultMap="GenTableColumnResult" />
|
||||
</resultMap>
|
||||
|
||||
<resultMap type="GenTableColumn" id="GenTableColumnResult">
|
||||
<id property="columnId" column="column_id" />
|
||||
<result property="tableId" column="table_id" />
|
||||
<result property="columnName" column="column_name" />
|
||||
<result property="columnComment" column="column_comment" />
|
||||
<result property="columnType" column="column_type" />
|
||||
<result property="javaType" column="java_type" />
|
||||
<result property="javaField" column="java_field" />
|
||||
<result property="isPk" column="is_pk" />
|
||||
<result property="isIncrement" column="is_increment" />
|
||||
<result property="isRequired" column="is_required" />
|
||||
<result property="isInsert" column="is_insert" />
|
||||
<result property="isEdit" column="is_edit" />
|
||||
<result property="isList" column="is_list" />
|
||||
<result property="isQuery" column="is_query" />
|
||||
<result property="queryType" column="query_type" />
|
||||
<result property="htmlType" column="html_type" />
|
||||
<result property="dictType" column="dict_type" />
|
||||
<result property="sort" column="sort" />
|
||||
<result property="createBy" column="create_by" />
|
||||
<result property="createTime" column="create_time" />
|
||||
<result property="updateBy" column="update_by" />
|
||||
<result property="updateTime" column="update_time" />
|
||||
</resultMap>
|
||||
|
||||
<sql id="selectGenTableVo">
|
||||
select table_id, table_name, table_comment, class_name, tpl_category, package_name, module_name, business_name, function_name, function_author, gen_type, gen_path, options, create_by, create_time, update_by, update_time, remark from gen_table
|
||||
</sql>
|
||||
|
||||
<select id="selectGenTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||
<include refid="selectGenTableVo"/>
|
||||
<where>
|
||||
<if test="tableName != null and tableName != ''">
|
||||
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
|
||||
</if>
|
||||
<if test="tableComment != null and tableComment != ''">
|
||||
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
|
||||
</if>
|
||||
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
|
||||
AND date_format(create_time,'%y%m%d') >= date_format(#{params.beginTime},'%y%m%d')
|
||||
</if>
|
||||
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
|
||||
AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
|
||||
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
|
||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
||||
where table_schema = (select database())
|
||||
|
@ -91,22 +22,22 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
AND date_format(create_time,'%y%m%d') <= date_format(#{params.endTime},'%y%m%d')
|
||||
</if>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectDbTableListByNames" resultMap="GenTableResult">
|
||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
||||
where table_name NOT LIKE 'qrtz_%' and table_name NOT LIKE 'gen_%' and table_schema = (select database())
|
||||
and table_name in
|
||||
<foreach collection="array" item="name" open="(" separator="," close=")">
|
||||
#{name}
|
||||
</foreach>
|
||||
</foreach>
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
|
||||
select table_name, table_comment, create_time, update_time from information_schema.tables
|
||||
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database())
|
||||
and table_name = #{tableName}
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectGenTableById" parameterType="Long" resultMap="GenTableResult">
|
||||
SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||
|
@ -114,7 +45,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||
where t.table_id = #{tableId} order by c.sort
|
||||
</select>
|
||||
|
||||
|
||||
<select id="selectGenTableByName" parameterType="String" resultMap="GenTableResult">
|
||||
SELECT t.table_id, t.table_name, t.table_comment, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, t.gen_type, t.gen_path, t.options, t.remark,
|
||||
c.column_id, c.column_name, c.column_comment, c.column_type, c.java_type, c.java_field, c.is_pk, c.is_increment, c.is_required, c.is_insert, c.is_edit, c.is_list, c.is_query, c.query_type, c.html_type, c.dict_type, c.sort
|
||||
|
@ -122,7 +53,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
|
||||
where t.table_name = #{tableName} order by c.sort
|
||||
</select>
|
||||
|
||||
|
||||
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
|
||||
insert into gen_table (
|
||||
<if test="tableName != null">table_name,</if>
|
||||
|
@ -156,7 +87,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
sysdate()
|
||||
)
|
||||
</insert>
|
||||
|
||||
|
||||
<update id="updateGenTable" parameterType="GenTable">
|
||||
update gen_table
|
||||
<set>
|
||||
|
@ -178,12 +109,12 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||
</set>
|
||||
where table_id = #{tableId}
|
||||
</update>
|
||||
|
||||
|
||||
<delete id="deleteGenTableByIds" parameterType="Long">
|
||||
delete from gen_table where table_id in
|
||||
delete from gen_table where table_id in
|
||||
<foreach collection="array" item="tableId" open="(" separator="," close=")">
|
||||
#{tableId}
|
||||
</foreach>
|
||||
</delete>
|
||||
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
|
|
@ -1,2 +1,18 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 获得表定义分页
|
||||
export function getCodeGenTablePage(query) {
|
||||
return request({
|
||||
url: '/tool/codegen/page',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
|
||||
// 获得表和字段的明细
|
||||
export function getCodeGenDetail(tableId) {
|
||||
return request({
|
||||
url: '/tool/codegen/detail?tableId=' + tableId,
|
||||
method: 'get',
|
||||
})
|
||||
}
|
||||
|
|
|
@ -1,13 +1,5 @@
|
|||
import request from '@/utils/request'
|
||||
|
||||
// 查询生成表数据
|
||||
export function listTable(query) {
|
||||
return request({
|
||||
url: '/tool/gen/list',
|
||||
method: 'get',
|
||||
params: query
|
||||
})
|
||||
}
|
||||
// 查询db数据库列表
|
||||
export function listDbTable(query) {
|
||||
return request({
|
||||
|
|
|
@ -18,8 +18,8 @@
|
|||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="12">
|
||||
<el-form-item label="作者" prop="functionAuthor">
|
||||
<el-input placeholder="请输入" v-model="info.functionAuthor" />
|
||||
<el-form-item label="作者" prop="author">
|
||||
<el-input placeholder="请输入" v-model="info.author" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
|
@ -51,7 +51,7 @@ export default {
|
|||
className: [
|
||||
{ required: true, message: "请输入实体类名称", trigger: "blur" }
|
||||
],
|
||||
functionAuthor: [
|
||||
author: [
|
||||
{ required: true, message: "请输入作者", trigger: "blur" }
|
||||
]
|
||||
}
|
||||
|
|
|
@ -2,11 +2,10 @@
|
|||
<el-card>
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane label="基本信息" name="basic">
|
||||
<basic-info-form ref="basicInfo" :info="info" />
|
||||
<basic-info-form ref="basicInfo" :info="table" />
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="字段信息" name="cloum">
|
||||
<el-table ref="dragTable" :data="cloumns" row-key="columnId" :max-height="tableHeight">
|
||||
<el-table-column label="序号" type="index" min-width="5%" class-name="allowDrag" />
|
||||
<el-table ref="dragTable" :data="columns" row-key="columnId" :max-height="tableHeight">
|
||||
<el-table-column
|
||||
label="字段列名"
|
||||
prop="columnName"
|
||||
|
@ -41,44 +40,43 @@
|
|||
<el-input v-model="scope.row.javaField"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
|
||||
<el-table-column label="插入" min-width="5%">
|
||||
<el-table-column label="插入" min-width="4%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isInsert"></el-checkbox>
|
||||
<el-checkbox true-label="true" false-label="false" v-model="scope.row.createOperation"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="编辑" min-width="5%">
|
||||
<el-table-column label="编辑" min-width="4%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isEdit"></el-checkbox>
|
||||
<el-checkbox true-label="true" false-label="false" v-model="scope.row.updateOperation"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="列表" min-width="5%">
|
||||
<el-table-column label="列表" min-width="4%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isList"></el-checkbox>
|
||||
<el-checkbox true-label="true" false-label="false" v-model="scope.row.listOperationResult"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询" min-width="5%">
|
||||
<el-table-column label="查询" min-width="4%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isQuery"></el-checkbox>
|
||||
<el-checkbox true-label="true" false-label="false" v-model="scope.row.listOperation"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="查询方式" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-select v-model="scope.row.queryType">
|
||||
<el-option label="=" value="EQ" />
|
||||
<el-option label="!=" value="NE" />
|
||||
<el-option label=">" value="GT" />
|
||||
<el-option label=">=" value="GTE" />
|
||||
<el-option label="<" value="LT" />
|
||||
<el-option label="<=" value="LTE" />
|
||||
<el-select v-model="scope.row.listOperationCondition">
|
||||
<el-option label="=" value="=" />
|
||||
<el-option label="!=" value="!=" />
|
||||
<el-option label=">" value=">" />
|
||||
<el-option label=">=" value=">=" />
|
||||
<el-option label="<" value="<>" />
|
||||
<el-option label="<=" value="<=" />
|
||||
<el-option label="LIKE" value="LIKE" />
|
||||
<el-option label="BETWEEN" value="BETWEEN" />
|
||||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="必填" min-width="5%">
|
||||
<el-table-column label="允许空" min-width="5%">
|
||||
<template slot-scope="scope">
|
||||
<el-checkbox true-label="1" v-model="scope.row.isRequired"></el-checkbox>
|
||||
<el-checkbox true-label="true" false-label="false" v-model="scope.row.nullable"></el-checkbox>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="显示类型" min-width="12%">
|
||||
|
@ -110,10 +108,15 @@
|
|||
</el-select>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="示例" min-width="10%">
|
||||
<template slot-scope="scope">
|
||||
<el-input v-model="scope.row.example"></el-input>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</el-tab-pane>
|
||||
<el-tab-pane label="生成信息" name="genInfo">
|
||||
<gen-info-form ref="genInfo" :info="info" :tables="tables" :menus="menus"/>
|
||||
<gen-info-form ref="genInfo" :info="table" :tables="tables" :menus="menus"/>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
<el-form label-width="100px">
|
||||
|
@ -125,7 +128,8 @@
|
|||
</el-card>
|
||||
</template>
|
||||
<script>
|
||||
import { getGenTable, updateGenTable } from "@/api/tool/gen";
|
||||
import { updateGenTable } from "@/api/tool/gen";
|
||||
import { getCodeGenDetail } from "@/api/tool/codegen";
|
||||
import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
|
||||
import { listMenu as getMenuTreeselect } from "@/api/system/menu";
|
||||
import basicInfoForm from "./basicInfoForm";
|
||||
|
@ -147,23 +151,22 @@ export default {
|
|||
// 表信息
|
||||
tables: [],
|
||||
// 表列信息
|
||||
cloumns: [],
|
||||
columns: [],
|
||||
// 字典信息
|
||||
dictOptions: [],
|
||||
// 菜单信息
|
||||
menus: [],
|
||||
// 表详细信息
|
||||
info: {}
|
||||
table: {}
|
||||
};
|
||||
},
|
||||
created() {
|
||||
const tableId = this.$route.params && this.$route.params.tableId;
|
||||
if (tableId) {
|
||||
// 获取表详细信息
|
||||
getGenTable(tableId).then(res => {
|
||||
this.cloumns = res.data.rows;
|
||||
this.info = res.data.info;
|
||||
this.tables = res.data.tables;
|
||||
getCodeGenDetail(tableId).then(res => {
|
||||
this.table = res.data.table;
|
||||
this.columns = res.data.columns;
|
||||
});
|
||||
/** 查询字典下拉列表 */
|
||||
getDictOptionselect().then(response => {
|
||||
|
@ -184,7 +187,7 @@ export default {
|
|||
const validateResult = res.every(item => !!item);
|
||||
if (validateResult) {
|
||||
const genTable = Object.assign({}, basicForm.model, genForm.model);
|
||||
genTable.columns = this.cloumns;
|
||||
genTable.columns = this.columns;
|
||||
genTable.params = {
|
||||
treeCode: genTable.treeCode,
|
||||
treeName: genTable.treeName,
|
||||
|
@ -220,10 +223,10 @@ export default {
|
|||
const sortable = Sortable.create(el, {
|
||||
handle: ".allowDrag",
|
||||
onEnd: evt => {
|
||||
const targetRow = this.cloumns.splice(evt.oldIndex, 1)[0];
|
||||
this.cloumns.splice(evt.newIndex, 0, targetRow);
|
||||
for (let index in this.cloumns) {
|
||||
this.cloumns[index].sort = parseInt(index) + 1;
|
||||
const targetRow = this.columns.splice(evt.oldIndex, 1)[0];
|
||||
this.columns.splice(evt.newIndex, 0, targetRow);
|
||||
for (let index in this.columns) {
|
||||
this.columns[index].sort = parseInt(index) + 1;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -64,7 +64,6 @@
|
|||
plain
|
||||
icon="el-icon-edit"
|
||||
size="mini"
|
||||
:disabled="single"
|
||||
@click="handleEditTable"
|
||||
v-hasPermi="['tool:gen:edit']"
|
||||
>修改</el-button>
|
||||
|
@ -75,7 +74,6 @@
|
|||
plain
|
||||
icon="el-icon-delete"
|
||||
size="mini"
|
||||
:disabled="multiple"
|
||||
@click="handleDelete"
|
||||
v-hasPermi="['tool:gen:remove']"
|
||||
>删除</el-button>
|
||||
|
@ -83,13 +81,7 @@
|
|||
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
|
||||
</el-row>
|
||||
|
||||
<el-table v-loading="loading" :data="tableList" @selection-change="handleSelectionChange">
|
||||
<el-table-column type="selection" align="center" width="55"></el-table-column>
|
||||
<el-table-column label="序号" type="index" width="50" align="center">
|
||||
<template slot-scope="scope">
|
||||
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table v-loading="loading" :data="tableList">
|
||||
<el-table-column
|
||||
label="表名称"
|
||||
align="center"
|
||||
|
@ -111,8 +103,16 @@
|
|||
:show-overflow-tooltip="true"
|
||||
width="120"
|
||||
/>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="160" />
|
||||
<el-table-column label="更新时间" align="center" prop="updateTime" width="160" />
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="创建时间" align="center" prop="createTime" width="160">
|
||||
<template slot-scope="scope">
|
||||
<span>{{ parseTime(scope.row.updateTime) }}</span>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||
<template slot-scope="scope">
|
||||
<el-button
|
||||
|
@ -156,7 +156,7 @@
|
|||
<pagination
|
||||
v-show="total>0"
|
||||
:total="total"
|
||||
:page.sync="queryParams.pageNum"
|
||||
:page.sync="queryParams.pageNo"
|
||||
:limit.sync="queryParams.pageSize"
|
||||
@pagination="getList"
|
||||
/>
|
||||
|
@ -178,12 +178,15 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
|
||||
import { previewTable, delTable, genCode, synchDb } from "@/api/tool/gen";
|
||||
import { getCodeGenTablePage } from "@/api/tool/codegen";
|
||||
|
||||
import importTable from "./importTable";
|
||||
import { downLoadZip } from "@/utils/zipdownload";
|
||||
// 代码高亮插件
|
||||
import hljs from "highlight.js/lib/highlight";
|
||||
import "highlight.js/styles/github-gist.css";
|
||||
import {list} from "@/api/system/loginlog";
|
||||
hljs.registerLanguage("java", require("highlight.js/lib/languages/java"));
|
||||
hljs.registerLanguage("xml", require("highlight.js/lib/languages/xml"));
|
||||
hljs.registerLanguage("html", require("highlight.js/lib/languages/xml"));
|
||||
|
@ -200,14 +203,8 @@ export default {
|
|||
loading: true,
|
||||
// 唯一标识符
|
||||
uniqueId: "",
|
||||
// 选中数组
|
||||
ids: [],
|
||||
// 选中表数组
|
||||
tableNames: [],
|
||||
// 非单个禁用
|
||||
single: true,
|
||||
// 非多个禁用
|
||||
multiple: true,
|
||||
// 显示搜索条件
|
||||
showSearch: true,
|
||||
// 总条数
|
||||
|
@ -218,7 +215,7 @@ export default {
|
|||
dateRange: "",
|
||||
// 查询参数
|
||||
queryParams: {
|
||||
pageNum: 1,
|
||||
pageNo: 1,
|
||||
pageSize: 10,
|
||||
tableName: undefined,
|
||||
tableComment: undefined
|
||||
|
@ -237,7 +234,7 @@ export default {
|
|||
},
|
||||
activated() {
|
||||
const time = this.$route.query.t;
|
||||
if (time != null && time != this.uniqueId) {
|
||||
if (time != null && time !== this.uniqueId) {
|
||||
this.uniqueId = time;
|
||||
this.resetQuery();
|
||||
}
|
||||
|
@ -246,22 +243,25 @@ export default {
|
|||
/** 查询表集合 */
|
||||
getList() {
|
||||
this.loading = true;
|
||||
listTable(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
||||
this.tableList = response.rows;
|
||||
this.total = response.total;
|
||||
this.loading = false;
|
||||
}
|
||||
getCodeGenTablePage(this.addDateRange(this.queryParams, [
|
||||
this.dateRange[0] ? this.dateRange[0] + ' 00:00:00' : undefined,
|
||||
this.dateRange[1] ? this.dateRange[1] + ' 23:59:59' : undefined,
|
||||
], 'CreateTime')).then(response => {
|
||||
this.tableList = response.data.list;
|
||||
this.total = response.data.total;
|
||||
this.loading = false;
|
||||
}
|
||||
);
|
||||
},
|
||||
/** 搜索按钮操作 */
|
||||
handleQuery() {
|
||||
this.queryParams.pageNum = 1;
|
||||
this.queryParams.pageNo = 1;
|
||||
this.getList();
|
||||
},
|
||||
/** 生成代码操作 */
|
||||
handleGenTable(row) {
|
||||
const tableNames = row.tableName || this.tableNames;
|
||||
if (tableNames == "") {
|
||||
if (tableNames === "") {
|
||||
this.msgError("请选择要生成的数据");
|
||||
return;
|
||||
}
|
||||
|
@ -310,16 +310,9 @@ export default {
|
|||
const result = hljs.highlight(language, code || "", true);
|
||||
return result.value || ' ';
|
||||
},
|
||||
// 多选框选中数据
|
||||
handleSelectionChange(selection) {
|
||||
this.ids = selection.map(item => item.tableId);
|
||||
this.tableNames = selection.map(item => item.tableName);
|
||||
this.single = selection.length != 1;
|
||||
this.multiple = !selection.length;
|
||||
},
|
||||
/** 修改按钮操作 */
|
||||
handleEditTable(row) {
|
||||
const tableId = row.tableId || this.ids[0];
|
||||
const tableId = row.id;
|
||||
this.$router.push("/gen/edit/" + tableId);
|
||||
},
|
||||
/** 删除按钮操作 */
|
||||
|
|
|
@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModel;
|
|||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
@ -14,6 +15,7 @@ import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOU
|
|||
@ApiModel("参数配置分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class InfConfigPageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "参数名称", example = "模糊匹配")
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodeGenTablePageItemRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.service.codegen.ToolCodegenService;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/tool/codegen")
|
||||
public class ToolCodeGenController {
|
||||
|
||||
@Resource
|
||||
private ToolCodegenService codegenService;
|
||||
|
||||
@GetMapping("/table/page")
|
||||
public CommonResult<PageResult<ToolCodeGenTablePageItemRespVO>> getCodeGenTablePage() {
|
||||
return success(null);
|
||||
}
|
||||
|
||||
@ApiOperation("基于数据库的表结构,创建代码生成器的表定义")
|
||||
@PostMapping("/table/create")
|
||||
// TODO 权限
|
||||
public CommonResult<Long> createCodeGenTable(@RequestParam("tableName") String tableName) {
|
||||
return success(codegenService.createCodegenTable(tableName));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,57 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.CommonResult;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTableRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.service.codegen.ToolCodegenService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.dashboard.common.pojo.CommonResult.success;
|
||||
|
||||
@Api(tags = "代码生成器 API")
|
||||
@RestController
|
||||
@RequestMapping("/tool/codegen")
|
||||
@Validated
|
||||
public class ToolCodegenController {
|
||||
|
||||
@Resource
|
||||
private ToolCodegenService codegenService;
|
||||
|
||||
@ApiOperation("获得表定义分页")
|
||||
@GetMapping("/page")
|
||||
// TODO 权限 @PreAuthorize("@ss.hasPermi('tool:gen:list')")
|
||||
public CommonResult<PageResult<ToolCodegenTableRespVO>> getCodeGenTablePage(@Valid ToolCodegenTablePageReqVO pageReqVO) {
|
||||
PageResult<ToolCodegenTableDO> pageResult = codegenService.getCodeGenTablePage(pageReqVO);
|
||||
return success(ToolCodegenConvert.INSTANCE.convertPage(pageResult));
|
||||
}
|
||||
|
||||
@ApiOperation("获得表和字段的明细")
|
||||
@GetMapping("/detail")
|
||||
// todo @PreAuthorize("@ss.hasPermi('tool:gen:query')")
|
||||
public CommonResult<ToolCodegenDetailRespVO> getCodeGenDetail(@RequestParam("tableId") Long tableId) {
|
||||
ToolCodegenTableDO table = codegenService.getCodeGenTablePage(tableId);
|
||||
List<ToolCodegenColumnDO> columns = codegenService.getCodegenColumnListByTableId(tableId);
|
||||
// 拼装返回
|
||||
return success(ToolCodegenConvert.INSTANCE.convert(table, columns));
|
||||
}
|
||||
|
||||
@ApiOperation("基于数据库的表结构,创建代码生成器的表定义")
|
||||
@PostMapping("/create")
|
||||
// TODO 权限
|
||||
public CommonResult<Long> createCodeGenTable(@RequestParam("tableName") String tableName) {
|
||||
return success(codegenService.createCodegenTable(tableName));
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
public class ToolCodeGenTableBaseRespVO {
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
public class ToolCodeGenTablePageItemRespVO extends ToolCodeGenTableBaseRespVO {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,85 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 代码生成字段定义 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class ToolCodegenColumnBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "表编号", required = true, example = "1")
|
||||
@NotNull(message = "表编号不能为空")
|
||||
private Long tableId;
|
||||
|
||||
@ApiModelProperty(value = "字段名", required = true, example = "user_age")
|
||||
@NotNull(message = "字段名不能为空")
|
||||
private String columnName;
|
||||
|
||||
@ApiModelProperty(value = "字段类型", required = true, example = "int(11)")
|
||||
@NotNull(message = "字段类型不能为空")
|
||||
private String columnType;
|
||||
|
||||
@ApiModelProperty(value = "字段描述", required = true, example = "年龄")
|
||||
@NotNull(message = "字段描述不能为空")
|
||||
private String columnComment;
|
||||
|
||||
@ApiModelProperty(value = "是否允许为空", required = true, example = "true")
|
||||
@NotNull(message = "是否允许为空不能为空")
|
||||
private Boolean nullable;
|
||||
|
||||
@ApiModelProperty(value = "是否主键", required = true, example = "false")
|
||||
@NotNull(message = "是否主键不能为空")
|
||||
private Boolean primaryKey;
|
||||
|
||||
@ApiModelProperty(value = "是否自增", required = true, example = "true")
|
||||
@NotNull(message = "是否自增不能为空")
|
||||
private String autoIncrement;
|
||||
|
||||
@ApiModelProperty(value = "排序", required = true, example = "10")
|
||||
@NotNull(message = "排序不能为空")
|
||||
private Integer ordinalPosition;
|
||||
|
||||
@ApiModelProperty(value = "Java 属性类型", required = true, example = "userAge")
|
||||
@NotNull(message = "Java 属性类型不能为空")
|
||||
private String javaType;
|
||||
|
||||
@ApiModelProperty(value = "Java 属性名", required = true, example = "Integer")
|
||||
@NotNull(message = "Java 属性名不能为空")
|
||||
private String javaField;
|
||||
|
||||
@ApiModelProperty(value = "字典类型", example = "sys_gender")
|
||||
private String dictType;
|
||||
|
||||
@ApiModelProperty(value = "数据示例", example = "1024")
|
||||
private String example;
|
||||
|
||||
@ApiModelProperty(value = "是否为 Create 创建操作的字段", required = true, example = "true")
|
||||
@NotNull(message = "是否为 Create 创建操作的字段不能为空")
|
||||
private Boolean createOperation;
|
||||
|
||||
@ApiModelProperty(value = "是否为 Update 更新操作的字段", required = true, example = "false")
|
||||
@NotNull(message = "是否为 Update 更新操作的字段不能为空")
|
||||
private Boolean updateOperation;
|
||||
|
||||
@ApiModelProperty(value = "是否为 List 查询操作的字段", required = true, example = "true")
|
||||
@NotNull(message = "是否为 List 查询操作的字段不能为空")
|
||||
private Boolean listOperation;
|
||||
|
||||
@ApiModelProperty(value = "List 查询操作的条件类型", required = true, example = "LIKE", notes = "参见 ToolCodegenColumnListConditionEnum 枚举")
|
||||
@NotNull(message = "List 查询操作的条件类型不能为空")
|
||||
private String listOperationCondition;
|
||||
|
||||
@ApiModelProperty(value = "是否为 List 查询操作的返回字段", required = true, example = "true")
|
||||
@NotNull(message = "是否为 List 查询操作的返回字段不能为空")
|
||||
private Boolean listOperationResult;
|
||||
|
||||
@ApiModelProperty(value = "显示类型", required = true, example = "input")
|
||||
@NotNull(message = "显示类型不能为空")
|
||||
private String htmlType;
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("代码生成字段定义 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ToolCodegenColumnRespVO extends ToolCodegenColumnBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ApiModel("代码生成表和字段的明细 Response VO")
|
||||
@Data
|
||||
public class ToolCodegenDetailRespVO {
|
||||
|
||||
@ApiModelProperty("表定义")
|
||||
private ToolCodegenTableRespVO table;
|
||||
|
||||
@ApiModelProperty("字段定义")
|
||||
private List<ToolCodegenColumnRespVO> columns;
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
/**
|
||||
* 代码生成 Base VO,提供给添加、修改、详细的子 VO 使用
|
||||
* 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成
|
||||
*/
|
||||
@Data
|
||||
public class ToolCodegenTableBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "表名称", required = true, example = "yudao")
|
||||
@NotNull(message = "表名称不能为空")
|
||||
private String tableName;
|
||||
|
||||
@ApiModelProperty(value = "表描述", required = true, example = "芋道")
|
||||
@NotNull(message = "表描述不能为空")
|
||||
private String tableComment;
|
||||
|
||||
@ApiModelProperty(value = "备注", example = "我是备注")
|
||||
private String remark;
|
||||
|
||||
@ApiModelProperty(value = "模块名", required = true, example = "system")
|
||||
@NotNull(message = "模块名不能为空")
|
||||
private String moduleName;
|
||||
|
||||
@ApiModelProperty(value = "业务名", required = true, example = "codegen")
|
||||
@NotNull(message = "业务名不能为空")
|
||||
private String businessName;
|
||||
|
||||
@ApiModelProperty(value = "类名称", required = true, example = "ToolCodegenTable")
|
||||
@NotNull(message = "类名称不能为空")
|
||||
private String className;
|
||||
|
||||
@ApiModelProperty(value = "类描述", required = true, example = "代码生成器的表定义")
|
||||
@NotNull(message = "类描述不能为空")
|
||||
private String classComment;
|
||||
|
||||
@ApiModelProperty(value = "作者", required = true, example = "芋道源码")
|
||||
@NotNull(message = "作者不能为空")
|
||||
private String author;
|
||||
|
||||
@ApiModelProperty(value = "模板类型", required = true, example = "1", notes = "参见 ToolCodegenTemplateTypeEnum 枚举")
|
||||
@NotNull(message = "模板类型不能为空")
|
||||
private Integer templateType;
|
||||
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import static cn.iocoder.dashboard.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@ApiModel("表定义分页 Request VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ToolCodegenTablePageReqVO extends PageParam {
|
||||
|
||||
@ApiModelProperty(value = "表名称", example = "yudao", notes = "模糊匹配")
|
||||
private String tableName;
|
||||
|
||||
@ApiModelProperty(value = "表描述", example = "芋道", notes = "模糊匹配")
|
||||
private String tableComment;
|
||||
|
||||
@ApiModelProperty(value = "开始创建时间", example = "2020-10-24 00:00:00")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date beginCreateTime;
|
||||
|
||||
@ApiModelProperty(value = "结束创建时间", example = "2020-10-24 23:59:59")
|
||||
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
|
||||
private Date endCreateTime;
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@ApiModel("代码生成表定义 Response VO")
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
public class ToolCodegenTableRespVO extends ToolCodegenTableBaseVO {
|
||||
|
||||
@ApiModelProperty(value = "编号", required = true, example = "1")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "创建时间", required = true)
|
||||
private Date createTime;
|
||||
|
||||
@ApiModelProperty(value = "更新时间", required = true)
|
||||
private Date updateTime;
|
||||
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
package cn.iocoder.dashboard.modules.tool.controller.codegen.vo;
|
|
@ -1,21 +0,0 @@
|
|||
package cn.iocoder.dashboard.modules.tool.convert.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaTableDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface CodegenConvert {
|
||||
|
||||
CodegenConvert INSTANCE = Mappers.getMapper(CodegenConvert.class);
|
||||
|
||||
ToolCodegenTableDO convert(ToolInformationSchemaTableDO bean);
|
||||
|
||||
List<ToolCodegenColumnDO> convertList(List<ToolInformationSchemaColumnDO> list);
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package cn.iocoder.dashboard.modules.tool.convert.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenColumnRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenDetailRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTableRespVO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaTableDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Mapper
|
||||
public interface ToolCodegenConvert {
|
||||
|
||||
ToolCodegenConvert INSTANCE = Mappers.getMapper(ToolCodegenConvert.class);
|
||||
|
||||
// ========== ToolInformationSchemaTableDO 和 ToolInformationSchemaColumnDO 相关 ==========
|
||||
|
||||
ToolCodegenTableDO convert(ToolInformationSchemaTableDO bean);
|
||||
|
||||
List<ToolCodegenColumnDO> convertList(List<ToolInformationSchemaColumnDO> list);
|
||||
|
||||
ToolCodegenTableRespVO convert(ToolInformationSchemaColumnDO bean);
|
||||
|
||||
// ========== ToolCodegenTableDO 相关 ==========
|
||||
|
||||
// List<ToolCodegenTableRespVO> convertList02(List<ToolCodegenTableDO> list);
|
||||
|
||||
ToolCodegenTableRespVO convert(ToolCodegenTableDO bean);
|
||||
|
||||
PageResult<ToolCodegenTableRespVO> convertPage(PageResult<ToolCodegenTableDO> page);
|
||||
|
||||
// ========== ToolCodegenTableDO 相关 ==========
|
||||
|
||||
List<ToolCodegenColumnRespVO> convertList02(List<ToolCodegenColumnDO> list);
|
||||
|
||||
// ========== 其它 ==========
|
||||
|
||||
default ToolCodegenDetailRespVO convert(ToolCodegenTableDO table, List<ToolCodegenColumnDO> columns) {
|
||||
ToolCodegenDetailRespVO respVO = new ToolCodegenDetailRespVO();
|
||||
respVO.setTable(convert(table));
|
||||
respVO.setColumns(convertList02(columns));
|
||||
return respVO;
|
||||
}
|
||||
|
||||
}
|
|
@ -10,7 +10,7 @@ import java.util.List;
|
|||
@Mapper
|
||||
public interface ToolCodegenColumnMapper extends BaseMapperX<ToolCodegenColumnDO> {
|
||||
|
||||
default List<ToolCodegenColumnDO> selectByTableId(Long tableId) {
|
||||
default List<ToolCodegenColumnDO> selectListByTableId(Long tableId) {
|
||||
return selectList(new QueryWrapper<ToolCodegenColumnDO>()
|
||||
.eq("table_id", tableId)
|
||||
.orderByAsc("ordinal_position"));
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.query.QueryWrapperX;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
@ -12,4 +15,11 @@ public interface ToolCodegenTableMapper extends BaseMapperX<ToolCodegenTableDO>
|
|||
return selectOne(new QueryWrapper<ToolCodegenTableDO>().eq("table_name", tableName));
|
||||
}
|
||||
|
||||
default PageResult<ToolCodegenTableDO> selectPage(ToolCodegenTablePageReqVO pageReqVO) {
|
||||
return selectPage(pageReqVO, new QueryWrapperX<ToolCodegenTableDO>()
|
||||
.likeIfPresent("table_name", pageReqVO.getTableName())
|
||||
.likeIfPresent("table_comment", pageReqVO.getTableComment())
|
||||
.betweenIfPresent("create_time", pageReqVO.getBeginCreateTime(), pageReqVO.getEndCreateTime()));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import lombok.EqualsAndHashCode;
|
|||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@TableName(value = "tool_codegen_table_column", autoResultMap = true)
|
||||
@TableName(value = "tool_codegen_column", autoResultMap = true)
|
||||
@Data
|
||||
@Builder
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -60,7 +60,7 @@ public class ToolCodegenColumnDO extends BaseDO {
|
|||
*/
|
||||
private Boolean autoIncrement;
|
||||
/**
|
||||
* 排序字段
|
||||
* 排序
|
||||
*/
|
||||
private Integer ordinalPosition;
|
||||
|
||||
|
@ -122,5 +122,4 @@ public class ToolCodegenColumnDO extends BaseDO {
|
|||
*/
|
||||
private String htmlType;
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -28,12 +28,10 @@ public class ToolCodegenTableDO extends BaseDO {
|
|||
/**
|
||||
* 表名称
|
||||
*/
|
||||
// @NotBlank(message = "表名称不能为空")
|
||||
private String tableName;
|
||||
/**
|
||||
* 表描述
|
||||
*/
|
||||
// @NotBlank(message = "表描述不能为空")
|
||||
private String tableComment;
|
||||
/**
|
||||
* 备注
|
||||
|
@ -47,31 +45,26 @@ public class ToolCodegenTableDO extends BaseDO {
|
|||
*
|
||||
* 例如说,infra、system、tool 等等
|
||||
*/
|
||||
// @NotBlank(message = "模块名不能为空")
|
||||
private String moduleName;
|
||||
/**
|
||||
* 业务名,即二级目录
|
||||
*
|
||||
* 例如说,user、permission、dict 等等
|
||||
*/
|
||||
// @NotBlank(message = "生成业务名不能为空")
|
||||
private String businessName;
|
||||
/**
|
||||
* 类名称(首字母大写)
|
||||
*
|
||||
* 例如说,SysUser、SysMenu、SysDictData 等等
|
||||
*/
|
||||
// @NotBlank(message = "实体类名称不能为空")
|
||||
private String className;
|
||||
/**
|
||||
* 类描述
|
||||
*/
|
||||
// @NotBlank(message = "生成功能名不能为空")
|
||||
private String classComment;
|
||||
/**
|
||||
* 作者
|
||||
*/
|
||||
// @NotBlank(message = "作者不能为空")
|
||||
private String author;
|
||||
|
||||
// ========== 生成相关字段 ==========
|
||||
|
|
|
@ -14,7 +14,8 @@ public enum ToolCodegenTemplateTypeEnum {
|
|||
|
||||
CRUD(1), // 基础 CRUD
|
||||
TREE(2), // 树形 CRUD
|
||||
SUB(3) // 子表 CRUD
|
||||
// TODO 主子表,暂时不考虑支持。原因是较为灵活,形态较多,很难评估。
|
||||
SUB(3) // 主子表 CRUD
|
||||
;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,12 @@
|
|||
package cn.iocoder.dashboard.modules.tool.service.codegen;
|
||||
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 代码生成 Service 接口
|
||||
*
|
||||
|
@ -15,4 +22,28 @@ public interface ToolCodegenService {
|
|||
*/
|
||||
Long createCodegenTable(String tableName);
|
||||
|
||||
/**
|
||||
* 获得表定义分页
|
||||
*
|
||||
* @param pageReqVO 分页条件
|
||||
* @return 表定义分页
|
||||
*/
|
||||
PageResult<ToolCodegenTableDO> getCodeGenTablePage(ToolCodegenTablePageReqVO pageReqVO);
|
||||
|
||||
/**
|
||||
* 获得表定义
|
||||
*
|
||||
* @param id 表编号
|
||||
* @return 表定义
|
||||
*/
|
||||
ToolCodegenTableDO getCodeGenTablePage(Long id);
|
||||
|
||||
/**
|
||||
* 获得指定表的字段定义数组
|
||||
*
|
||||
* @param tableId 表编号
|
||||
* @return 字段定义数组
|
||||
*/
|
||||
List<ToolCodegenColumnDO> getCodegenColumnListByTableId(Long tableId);
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
|||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.iocoder.dashboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
import cn.iocoder.dashboard.modules.tool.convert.codegen.CodegenConvert;
|
||||
import cn.iocoder.dashboard.modules.tool.convert.codegen.ToolCodegenConvert;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenColumnDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolCodegenTableDO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dataobject.codegen.ToolInformationSchemaColumnDO;
|
||||
|
@ -113,7 +113,7 @@ public class ToolCodegenBuilder {
|
|||
}
|
||||
|
||||
public ToolCodegenTableDO buildTable(ToolInformationSchemaTableDO schemaTable) {
|
||||
ToolCodegenTableDO table = CodegenConvert.INSTANCE.convert(schemaTable);
|
||||
ToolCodegenTableDO table = ToolCodegenConvert.INSTANCE.convert(schemaTable);
|
||||
initTableDefault(table);
|
||||
return table;
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class ToolCodegenBuilder {
|
|||
}
|
||||
|
||||
public List<ToolCodegenColumnDO> buildColumns(List<ToolInformationSchemaColumnDO> schemaColumns) {
|
||||
List<ToolCodegenColumnDO> columns = CodegenConvert.INSTANCE.convertList(schemaColumns);
|
||||
List<ToolCodegenColumnDO> columns = ToolCodegenConvert.INSTANCE.convertList(schemaColumns);
|
||||
columns.forEach(this::initColumnDefault);
|
||||
return columns;
|
||||
}
|
||||
|
|
|
@ -95,12 +95,12 @@ public class ToolCodegenEngine {
|
|||
// String result = templateEngine.getTemplate("codegen/controller/vo/baseVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/createReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/updateReqVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
|
||||
String result = templateEngine.getTemplate("codegen/controller/vo/respVO.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/convert/convert.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/enums/errorcode.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/service/service.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/service/serviceImpl.vm").render(bindingMap);
|
||||
String result = templateEngine.getTemplate("codegen/controller/controller.vm").render(bindingMap);
|
||||
// String result = templateEngine.getTemplate("codegen/controller/controller.vm").render(bindingMap);
|
||||
System.out.println(result);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package cn.iocoder.dashboard.modules.tool.service.codegen.impl;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.dashboard.common.pojo.PageResult;
|
||||
import cn.iocoder.dashboard.modules.tool.controller.codegen.vo.ToolCodegenTablePageReqVO;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen.ToolCodegenColumnMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen.ToolCodegenTableMapper;
|
||||
import cn.iocoder.dashboard.modules.tool.dal.mysql.dao.coegen.ToolInformationSchemaColumnMapper;
|
||||
|
@ -67,4 +69,19 @@ public class ToolCodegenServiceImpl implements ToolCodegenService {
|
|||
return table.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<ToolCodegenTableDO> getCodeGenTablePage(ToolCodegenTablePageReqVO pageReqVO) {
|
||||
return codegenTableMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ToolCodegenTableDO getCodeGenTablePage(Long id) {
|
||||
return codegenTableMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ToolCodegenColumnDO> getCodegenColumnListByTableId(Long tableId) {
|
||||
return codegenColumnMapper.selectListByTableId(tableId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,8 +24,8 @@ public class ToolCodegenEngineTest {
|
|||
|
||||
@Test
|
||||
public void testExecute() {
|
||||
ToolCodegenTableDO table = codegenTableMapper.selectById(10);
|
||||
List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectByTableId(table.getId());
|
||||
ToolCodegenTableDO table = codegenTableMapper.selectById(14);
|
||||
List<ToolCodegenColumnDO> columns = codegenColumnMapper.selectListByTableId(table.getId());
|
||||
codegenEngine.execute(table, columns);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,9 @@ class ToolCodegenServiceImplTest {
|
|||
|
||||
@Test
|
||||
public void tetCreateCodegenTable() {
|
||||
toolCodegenService.createCodegenTable("sys_test_demo");
|
||||
// toolCodegenService.createCodegenTable("sys_test_demo");
|
||||
// toolCodegenService.createCodegenTable("tool_codegen_table");
|
||||
toolCodegenService.createCodegenTable("tool_codegen_column");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue