Pre Merge pull request !207 from XiaoHH/issue-I5AT0W

pull/207/MERGE
XiaoHH 3 years ago committed by Gitee
commit d0372623b4
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -8,14 +8,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
@ -55,6 +48,17 @@ public class GenController extends BaseController
return getDataTable(list);
}
/**
*
*/
@RequiresPermissions("tool:gen:list")
@GetMapping("/schema/list")
public AjaxResult genSchemaList()
{
List<String> list = genTableService.selectGenSchemaList();
return AjaxResult.success(list);
}
/**
*
*/
@ -102,12 +106,12 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:import")
@Log(title = "代码生成", businessType = BusinessType.IMPORT)
@PostMapping("/importTable")
public AjaxResult importTableSave(String tables)
@PostMapping("/importTable/{schemaName}")
public AjaxResult importTableSave(@PathVariable("schemaName") String schemaName, @RequestParam("tables") String tables)
{
String[] tableNames = Convert.toStrArray(tables);
// 查询表信息
List<GenTable> tableList = genTableService.selectDbTableListByNames(tableNames);
List<GenTable> tableList = genTableService.selectDbTableListByNames(schemaName, tableNames);
genTableService.importGenTable(tableList);
return AjaxResult.success();
}
@ -153,10 +157,10 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/download/{tableName}")
public void download(HttpServletResponse response, @PathVariable("tableName") String tableName) throws IOException
@GetMapping("/download/{schemaName}/{tableName}")
public void download(HttpServletResponse response, @PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName) throws IOException
{
byte[] data = genTableService.downloadCode(tableName);
byte[] data = genTableService.downloadCode(schemaName, tableName);
genCode(response, data);
}
@ -165,10 +169,10 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/genCode/{tableName}")
public AjaxResult genCode(@PathVariable("tableName") String tableName)
@GetMapping("/genCode/{schemaName}/{tableName}")
public AjaxResult genCode(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName)
{
genTableService.generatorCode(tableName);
genTableService.generatorCode(schemaName, tableName);
return AjaxResult.success();
}
@ -177,10 +181,10 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:edit")
@Log(title = "代码生成", businessType = BusinessType.UPDATE)
@GetMapping("/synchDb/{tableName}")
public AjaxResult synchDb(@PathVariable("tableName") String tableName)
@GetMapping("/synchDb/{schemaName}/{tableName}")
public AjaxResult synchDb(@PathVariable("schemaName") String schemaName, @PathVariable("tableName") String tableName)
{
genTableService.synchDb(tableName);
genTableService.synchDb(schemaName, tableName);
return AjaxResult.success();
}
@ -189,11 +193,11 @@ public class GenController extends BaseController
*/
@RequiresPermissions("tool:gen:code")
@Log(title = "代码生成", businessType = BusinessType.GENCODE)
@GetMapping("/batchGenCode")
public void batchGenCode(HttpServletResponse response, String tables) throws IOException
@GetMapping("/batchGenCode/{schemaName}")
public void batchGenCode(HttpServletResponse response, @PathVariable("schemaName") String schemaName, String tables) throws IOException
{
String[] tableNames = Convert.toStrArray(tables);
byte[] data = genTableService.downloadCode(tableNames);
byte[] data = genTableService.downloadCode(schemaName, tableNames);
genCode(response, data);
}

@ -20,6 +20,10 @@ public class GenTable extends BaseEntity
/** 编号 */
private Long tableId;
/** 库名称 */
@NotBlank(message = "库名称不能为空")
private String schemaName;
/** 表名称 */
@NotBlank(message = "表名称不能为空")
private String tableName;
@ -105,6 +109,16 @@ public class GenTable extends BaseEntity
this.tableId = tableId;
}
public String getSchemaName()
{
return schemaName;
}
public void setSchemaName(String schemaName)
{
this.schemaName = schemaName;
}
public String getTableName()
{
return tableName;

@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper;
import java.util.List;
import com.ruoyi.gen.domain.GenTableColumn;
import org.apache.ibatis.annotations.Param;
/**
*
@ -12,11 +13,12 @@ public interface GenTableColumnMapper
{
/**
*
*
* @param tableName
*
* @param schemaName
* @param tableName
* @return
*/
public List<GenTableColumn> selectDbTableColumnsByName(String tableName);
public List<GenTableColumn> selectDbTableColumnsByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName);
/**
*

@ -2,6 +2,7 @@ package com.ruoyi.gen.mapper;
import java.util.List;
import com.ruoyi.gen.domain.GenTable;
import org.apache.ibatis.annotations.Param;
/**
*
@ -18,6 +19,13 @@ public interface GenTableMapper
*/
public List<GenTable> selectGenTableList(GenTable genTable);
/**
*
*
* @return
*/
public List<String> selectGenSchemaList();
/**
*
*
@ -32,7 +40,7 @@ public interface GenTableMapper
* @param tableNames
* @return
*/
public List<GenTable> selectDbTableListByNames(String[] tableNames);
public List<GenTable> selectDbTableListByNames(@Param("schemaName") String schemaName, @Param("tableNames") String[] tableNames);
/**
*
@ -55,7 +63,7 @@ public interface GenTableMapper
* @param tableName
* @return
*/
public GenTable selectGenTableByName(String tableName);
public GenTable selectGenTableByName(@Param("schemaName") String schemaName, @Param("tableName") String tableName);
/**
*

@ -79,9 +79,20 @@ public class GenTableServiceImpl implements IGenTableService
return genTableMapper.selectGenTableList(genTable);
}
/**
*
*
* @return
*/
@Override
public List<String> selectGenSchemaList()
{
return genTableMapper.selectGenSchemaList();
}
/**
*
*
*
* @param genTable
* @return
*/
@ -93,14 +104,15 @@ public class GenTableServiceImpl implements IGenTableService
/**
*
*
*
* @param schemaName
* @param tableNames
* @return
*/
@Override
public List<GenTable> selectDbTableListByNames(String[] tableNames)
public List<GenTable> selectDbTableListByNames(String schemaName, String[] tableNames)
{
return genTableMapper.selectDbTableListByNames(tableNames);
return genTableMapper.selectDbTableListByNames(schemaName, tableNames);
}
/**
@ -170,7 +182,7 @@ public class GenTableServiceImpl implements IGenTableService
if (row > 0)
{
// 保存列信息
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
List<GenTableColumn> genTableColumns = genTableColumnMapper.selectDbTableColumnsByName(table.getSchemaName(), tableName);
for (GenTableColumn column : genTableColumns)
{
GenUtils.initColumnField(column, table);
@ -220,30 +232,32 @@ public class GenTableServiceImpl implements IGenTableService
/**
*
*
* @param tableName
*
* @param schemaName
* @param tableName
* @return
*/
@Override
public byte[] downloadCode(String tableName)
public byte[] downloadCode(String schemaName, String tableName)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
generatorCode(tableName, zip);
generatorCode(schemaName, tableName, zip);
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
}
/**
*
*
* @param tableName
*
* @param schemaName
* @param tableName
*/
@Override
public void generatorCode(String tableName)
public void generatorCode(String schemaName, String tableName)
{
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
@ -283,13 +297,13 @@ public class GenTableServiceImpl implements IGenTableService
*/
@Override
@Transactional(rollbackFor = Exception.class)
public void synchDb(String tableName)
public void synchDb(String schemaName, String tableName)
{
GenTable table = genTableMapper.selectGenTableByName(tableName);
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
List<GenTableColumn> tableColumns = table.getColumns();
Map<String, GenTableColumn> tableColumnMap = tableColumns.stream().collect(Collectors.toMap(GenTableColumn::getColumnName, Function.identity()));
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(tableName);
List<GenTableColumn> dbTableColumns = genTableColumnMapper.selectDbTableColumnsByName(schemaName, tableName);
if (StringUtils.isEmpty(dbTableColumns))
{
throw new ServiceException("同步数据失败,原表结构不存在");
@ -333,18 +347,19 @@ public class GenTableServiceImpl implements IGenTableService
/**
*
*
*
* @param schemaName
* @param tableNames
* @return
*/
@Override
public byte[] downloadCode(String[] tableNames)
public byte[] downloadCode(String schemaName, String[] tableNames)
{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
for (String tableName : tableNames)
{
generatorCode(tableName, zip);
generatorCode(schemaName, tableName, zip);
}
IOUtils.closeQuietly(zip);
return outputStream.toByteArray();
@ -353,10 +368,10 @@ public class GenTableServiceImpl implements IGenTableService
/**
*
*/
private void generatorCode(String tableName, ZipOutputStream zip)
private void generatorCode(String schemaName, String tableName, ZipOutputStream zip)
{
// 查询表信息
GenTable table = genTableMapper.selectGenTableByName(tableName);
GenTable table = genTableMapper.selectGenTableByName(schemaName, tableName);
// 设置主子表信息
setSubTable(table);
// 设置主键列信息
@ -474,7 +489,7 @@ public class GenTableServiceImpl implements IGenTableService
String subTableName = table.getSubTableName();
if (StringUtils.isNotEmpty(subTableName))
{
table.setSubTable(genTableMapper.selectGenTableByName(subTableName));
table.setSubTable(genTableMapper.selectGenTableByName(table.getSchemaName(), subTableName));
}
}

@ -19,6 +19,13 @@ public interface IGenTableService
*/
public List<GenTable> selectGenTableList(GenTable genTable);
/**
*
*
* @return
*/
public List<String> selectGenSchemaList();
/**
*
*
@ -29,11 +36,12 @@ public interface IGenTableService
/**
*
*
*
* @param schemaName
* @param tableNames
* @return
*/
public List<GenTable> selectDbTableListByNames(String[] tableNames);
public List<GenTable> selectDbTableListByNames(String schemaName, String[] tableNames);
/**
*
@ -83,11 +91,12 @@ public interface IGenTableService
/**
*
*
* @param tableName
*
* @param schemaName
* @param tableName
* @return
*/
public byte[] downloadCode(String tableName);
public byte[] downloadCode(String schemaName, String tableName);
/**
*
@ -95,22 +104,24 @@ public interface IGenTableService
* @param tableName
* @return
*/
public void generatorCode(String tableName);
public void generatorCode(String schemaName, String tableName);
/**
*
*
* @param tableName
*
* @param schemaName
* @param tableName
*/
public void synchDb(String tableName);
public void synchDb(String schemaName, String tableName);
/**
*
*
*
* @param schemaName
* @param tableNames
* @return
*/
public byte[] downloadCode(String[] tableNames);
public byte[] downloadCode(String schemaName, String[] tableNames);
/**
*

@ -41,7 +41,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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})
from information_schema.columns where table_schema = #{schemaName} and table_name = (#{tableName})
order by ordinal_position
</select>

@ -1,202 +1,216 @@
<?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.gen.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="subTableName" column="sub_table_name" />
<result property="subTableFkName" column="sub_table_fk_name" />
<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, sub_table_name, sub_table_fk_name, 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') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= 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())
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table)
<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') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
order by create_time desc
</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>
</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.sub_table_name, t.sub_table_fk_name, 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
FROM gen_table t
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.sub_table_name, t.sub_table_fk_name, 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
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.table_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, 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
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
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>
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="genType != null and genType != ''">gen_type,</if>
<if test="genPath != null and genPath != ''">gen_path,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="genType != null and genType != ''">#{genType},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateGenTable" parameterType="GenTable">
update gen_table
<set>
<if test="tableName != null">table_name = #{tableName},</if>
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="subTableName != null">sub_table_name = #{subTableName},</if>
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
<if test="className != null and className != ''">class_name = #{className},</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
<if test="options != null and options != ''">options = #{options},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>
<?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.gen.mapper.GenTableMapper">
<resultMap type="GenTable" id="GenTableResult">
<id property="tableId" column="table_id" />
<result property="schemaName" column="schema_name" />
<result property="tableName" column="table_name" />
<result property="tableComment" column="table_comment" />
<result property="subTableName" column="sub_table_name" />
<result property="subTableFkName" column="sub_table_fk_name" />
<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, schema_name, table_name, table_comment, sub_table_name, sub_table_fk_name, 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="schemaName != null and schemaName != ''">
AND lower(`schema_name`) like lower(concat('%', #{schemaName}, '%'))
</if>
<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') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
</where>
</select>
<select id="selectGenSchemaList" resultType="String">
SELECT TABLE_SCHEMA
FROM information_schema.`TABLES`
WHERE TABLE_SCHEMA NOT IN ( 'ry-config', 'ry-seata' )
AND TABLE_SCHEMA LIKE 'ry-%'
GROUP BY TABLE_SCHEMA
</select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_schema as schema_name, table_name, table_comment, create_time, update_time from information_schema.tables
where table_schema = #{schemaName}
AND table_name NOT LIKE 'qrtz_%' AND table_name NOT LIKE 'gen_%'
AND table_name NOT IN (select table_name from gen_table where schema_name = table_schema)
<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') &gt;= date_format(#{params.beginTime},'%y%m%d')
</if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%y%m%d') &lt;= date_format(#{params.endTime},'%y%m%d')
</if>
order by create_time desc
</select>
<select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_schema as schema_name, 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 = #{schemaName}
and table_name in
<foreach collection="tableNames" item="name" open="(" separator="," close=")">
#{name}
</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.schema_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, 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
FROM gen_table t
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.schema_name, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, 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
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
where t.schema_name = #{schemaName} and t.table_name = #{tableName} order by c.sort
</select>
<select id="selectGenTableAll" parameterType="String" resultMap="GenTableResult">
SELECT t.table_id, t.table_name, t.table_comment, t.sub_table_name, t.sub_table_fk_name, t.class_name, t.tpl_category, t.package_name, t.module_name, t.business_name, t.function_name, t.function_author, 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
FROM gen_table t
LEFT JOIN gen_table_column c ON t.table_id = c.table_id
order by c.sort
</select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId">
insert into gen_table (
<if test="tableName != null">schema_name ,</if>
<if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category,</if>
<if test="packageName != null and packageName != ''">package_name,</if>
<if test="moduleName != null and moduleName != ''">module_name,</if>
<if test="businessName != null and businessName != ''">business_name,</if>
<if test="functionName != null and functionName != ''">function_name,</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author,</if>
<if test="genType != null and genType != ''">gen_type,</if>
<if test="genPath != null and genPath != ''">gen_path,</if>
<if test="remark != null and remark != ''">remark,</if>
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableName != null">#{schemaName},</if>
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if>
<if test="tplCategory != null and tplCategory != ''">#{tplCategory},</if>
<if test="packageName != null and packageName != ''">#{packageName},</if>
<if test="moduleName != null and moduleName != ''">#{moduleName},</if>
<if test="businessName != null and businessName != ''">#{businessName},</if>
<if test="functionName != null and functionName != ''">#{functionName},</if>
<if test="functionAuthor != null and functionAuthor != ''">#{functionAuthor},</if>
<if test="genType != null and genType != ''">#{genType},</if>
<if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
)
</insert>
<update id="updateGenTable" parameterType="GenTable">
update gen_table
<set>
<if test="tableName != null">table_name = #{tableName},</if>
<if test="tableComment != null and tableComment != ''">table_comment = #{tableComment},</if>
<if test="subTableName != null">sub_table_name = #{subTableName},</if>
<if test="subTableFkName != null">sub_table_fk_name = #{subTableFkName},</if>
<if test="className != null and className != ''">class_name = #{className},</if>
<if test="functionAuthor != null and functionAuthor != ''">function_author = #{functionAuthor},</if>
<if test="genType != null and genType != ''">gen_type = #{genType},</if>
<if test="genPath != null and genPath != ''">gen_path = #{genPath},</if>
<if test="tplCategory != null and tplCategory != ''">tpl_category = #{tplCategory},</if>
<if test="packageName != null and packageName != ''">package_name = #{packageName},</if>
<if test="moduleName != null and moduleName != ''">module_name = #{moduleName},</if>
<if test="businessName != null and businessName != ''">business_name = #{businessName},</if>
<if test="functionName != null and functionName != ''">function_name = #{functionName},</if>
<if test="options != null and options != ''">options = #{options},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if>
update_time = sysdate()
</set>
where table_id = #{tableId}
</update>
<delete id="deleteGenTableByIds" parameterType="Long">
delete from gen_table where table_id in
<foreach collection="array" item="tableId" open="(" separator="," close=")">
#{tableId}
</foreach>
</delete>
</mapper>

@ -1,76 +1,84 @@
import request from '@/utils/request'
// 查询生成表数据
export function listTable(query) {
return request({
url: '/code/gen/list',
method: 'get',
params: query
})
}
// 查询db数据库列表
export function listDbTable(query) {
return request({
url: '/code/gen/db/list',
method: 'get',
params: query
})
}
// 查询表详细信息
export function getGenTable(tableId) {
return request({
url: '/code/gen/' + tableId,
method: 'get'
})
}
// 修改代码生成信息
export function updateGenTable(data) {
return request({
url: '/code/gen',
method: 'put',
data: data
})
}
// 导入表
export function importTable(data) {
return request({
url: '/code/gen/importTable',
method: 'post',
params: data
})
}
// 预览生成代码
export function previewTable(tableId) {
return request({
url: '/code/gen/preview/' + tableId,
method: 'get'
})
}
// 删除表数据
export function delTable(tableId) {
return request({
url: '/code/gen/' + tableId,
method: 'delete'
})
}
// 生成代码(自定义路径)
export function genCode(tableName) {
return request({
url: '/code/gen/genCode/' + tableName,
method: 'get'
})
}
// 同步数据库
export function synchDb(tableName) {
return request({
url: '/code/gen/synchDb/' + tableName,
method: 'get'
})
}
import request from '@/utils/request'
// 查询生成表数据
export function listTable(query) {
return request({
url: '/code/gen/list',
method: 'get',
params: query
})
}
export function listSchema() {
return request({
url: '/code/gen/schema/list',
method: 'get',
})
}
// 查询db数据库列表
export function listDbTable(query) {
return request({
url: '/code/gen/db/list',
method: 'get',
params: query
})
}
// 查询表详细信息
export function getGenTable(tableId) {
return request({
url: '/code/gen/' + tableId,
method: 'get'
})
}
// 修改代码生成信息
export function updateGenTable(data) {
return request({
url: '/code/gen',
method: 'put',
data: data
})
}
// 导入表
export function importTable(data, schemaName) {
return request({
url: `/code/gen/importTable/${schemaName}`,
method: 'post',
params: data
})
}
// 预览生成代码
export function previewTable(tableId) {
return request({
url: '/code/gen/preview/' + tableId,
method: 'get'
})
}
// 删除表数据
export function delTable(tableId) {
return request({
url: '/code/gen/' + tableId,
method: 'delete'
})
}
// 生成代码(自定义路径)
export function genCode(tableName) {
return request({
url: '/code/gen/genCode/' + tableName,
method: 'get'
})
}
// 同步数据库
export function synchDb(schemaName, tableName) {
return request({
url: `/code/gen/synchDb/${schemaName}/${tableName}`,
method: 'get'
})
}

@ -1,120 +1,151 @@
<template>
<!-- 导入表 -->
<el-dialog title="导入表" :visible.sync="visible" width="800px" top="5vh" append-to-body>
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
<el-form-item label="表名称" prop="tableName">
<el-input
v-model="queryParams.tableName"
placeholder="请输入表名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="表描述" prop="tableComment">
<el-input
v-model="queryParams.tableComment"
placeholder="请输入表描述"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-row>
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="createTime" label="创建时间"></el-table-column>
<el-table-column prop="updateTime" label="更新时间"></el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleImportTable"> </el-button>
<el-button @click="visible = false"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { listDbTable, importTable } from "@/api/tool/gen";
export default {
data() {
return {
//
visible: false,
//
tables: [],
//
total: 0,
//
dbTableList: [],
//
queryParams: {
pageNum: 1,
pageSize: 10,
tableName: undefined,
tableComment: undefined
}
};
},
methods: {
//
show() {
this.getList();
this.visible = true;
},
clickRow(row) {
this.$refs.table.toggleRowSelection(row);
},
//
handleSelectionChange(selection) {
this.tables = selection.map(item => item.tableName);
},
//
getList() {
listDbTable(this.queryParams).then(res => {
if (res.code === 200) {
this.dbTableList = res.rows;
this.total = res.total;
}
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 导入按钮操作 */
handleImportTable() {
const tableNames = this.tables.join(",");
if (tableNames == "") {
this.$modal.msgError("请选择要导入的表");
return;
}
importTable({ tables: tableNames }).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.visible = false;
this.$emit("ok");
}
});
}
}
};
</script>
<template>
<!-- 导入表 -->
<el-dialog title="导入表" :visible.sync="visible" width="1200px" top="5vh" append-to-body>
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true">
<el-form-item label="库名称" prop="schemaName">
<el-select v-model="queryParams.schemaName" placeholder="请选择库名称">
<el-option
v-for="item in schemaList"
:key="item"
:label="item"
:value="item">
</el-option>
</el-select>
</el-form-item>
<el-form-item label="表名称" prop="tableName">
<el-input
v-model="queryParams.tableName"
placeholder="请输入表名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="表描述" prop="tableComment">
<el-input
v-model="queryParams.tableComment"
placeholder="请输入表描述"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery"></el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery"></el-button>
</el-form-item>
</el-form>
<el-row>
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
<el-table-column type="selection" width="55"></el-table-column>
<el-table-column prop="schemaName" label="库名称" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="createTime" label="创建时间"></el-table-column>
<el-table-column prop="updateTime" label="更新时间"></el-table-column>
</el-table>
<pagination
v-show="total>0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
</el-row>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="handleImportTable"> </el-button>
<el-button @click="visible = false"> </el-button>
</div>
</el-dialog>
</template>
<script>
import { listSchema, listDbTable, importTable } from "@/api/tool/gen";
export default {
data() {
return {
//
visible: false,
//
tables: [],
//
total: 0,
//
dbTableList: [],
//
schemaList: [],
// queryParams.tableName
preTableSchema: undefined,
//
queryParams: {
pageNum: 1,
pageSize: 10,
schemaName: undefined,
tableName: undefined,
tableComment: undefined
}
};
},
methods: {
//
show() {
this.getSchemaList();
this.visible = true;
},
clickRow(row) {
this.$refs.table.toggleRowSelection(row);
},
//
handleSelectionChange(selection) {
this.tables = selection.map(item => item.tableName);
},
getSchemaList() {
//
listSchema().then(schemaRes => {
//
if (schemaRes.code === 200) {
this.schemaList = schemaRes.data;
this.queryParams.schemaName = schemaRes.data[0];
this.getList();
}
})
},
//
getList() {
//
this.tables = []
// preSchemaList
this.preTableSchema = this.queryParams.schemaName
listDbTable(this.queryParams).then(res => {
if (res.code === 200) {
this.dbTableList = res.rows;
this.total = res.total;
}
});
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
/** 导入按钮操作 */
handleImportTable() {
const tableNames = this.tables.join(",");
if (tableNames == "") {
this.$modal.msgError("请选择要导入的表");
return;
}
importTable({ tables: tableNames }, this.preTableSchema).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.visible = false;
this.$emit("ok");
}
});
}
}
};
</script>

@ -1,6 +1,14 @@
<template>
<div class="app-container">
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<el-form-item label="库名称" prop="schemaName">
<el-input
v-model="queryParams.schemaName"
placeholder="请输入库名称"
clearable
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="表名称" prop="tableName">
<el-input
v-model="queryParams.tableName"
@ -87,6 +95,13 @@
<span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
</template>
</el-table-column>
<el-table-column
label="库名称"
align="center"
prop="schemaName"
:show-overflow-tooltip="true"
width="120"
/>
<el-table-column
label="表名称"
align="center"
@ -180,6 +195,7 @@ import { listTable, previewTable, delTable, genCode, synchDb } from "@/api/tool/
import importTable from "./importTable";
import hljs from "highlight.js/lib/highlight";
import "highlight.js/styles/github-gist.css";
import {MessageBox} from "element-ui";
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"));
@ -198,6 +214,8 @@ export default {
uniqueId: "",
//
ids: [],
//
schemaNames: [],
//
tableNames: [],
//
@ -216,6 +234,7 @@ export default {
queryParams: {
pageNum: 1,
pageSize: 10,
schemaName: undefined,
tableName: undefined,
tableComment: undefined
},
@ -257,24 +276,41 @@ export default {
},
/** 生成代码操作 */
handleGenTable(row) {
console.log(schemaName)
console.log(this.schemaNames)
const tableNames = row.tableName || this.tableNames;
if (tableNames == "") {
this.$modal.msgError("请选择要生成的数据");
return;
}
//
let schemaName = row.schemaName
if (schemaName === undefined) {
// this.schemaNames
schemaName = this.schemaNames[0];
for (let i = 1; i < this.schemaNames.length; i++) {
if (schemaName != this.schemaNames[i]) {
MessageBox.alert("请确保选中的表在同一个数据库当中", {
confirmButtonText: '知道了',
type: "error",
});
return;
}
}
}
if(row.genType === "1") {
genCode(row.tableName).then(response => {
genCode(schemaName, row.tableName).then(response => {
this.$modal.msgSuccess("成功生成到自定义路径:" + row.genPath);
});
} else {
this.$download.zip("/code/gen/batchGenCode?tables=" + tableNames, "ruoyi");
this.$download.zip(`/code/gen/batchGenCode/${schemaName}?tables=${tableNames}`, "ruoyi");
}
},
/** 同步数据库操作 */
handleSynchDb(row) {
const tableName = row.tableName;
this.$modal.confirm('确认要强制同步"' + tableName + '"表结构吗?').then(function() {
return synchDb(tableName);
return synchDb(row.schemaName, tableName);
}).then(() => {
this.$modal.msgSuccess("同步成功");
}).catch(() => {});
@ -311,6 +347,7 @@ export default {
//
handleSelectionChange(selection) {
this.ids = selection.map(item => item.tableId);
this.schemaNames = selection.map(item => item.schemaName);
this.tableNames = selection.map(item => item.tableName);
this.single = selection.length != 1;
this.multiple = !selection.length;

@ -634,6 +634,7 @@ insert into sys_notice values('2', '维护通知2018-07-01 若依系统凌晨
drop table if exists gen_table;
create table gen_table (
table_id bigint(20) not null auto_increment comment '编号',
schema_name varchar(200) default '' comment '数据库名称',
table_name varchar(200) default '' comment '表名称',
table_comment varchar(500) default '' comment '表描述',
sub_table_name varchar(64) default null comment '关联子表的表名',

Loading…
Cancel
Save