初始化生成代码功能

This commit is contained in:
liuhanqing
2025-09-11 15:33:38 +08:00
parent 1b91f79326
commit fd797fe91d
4 changed files with 245 additions and 191 deletions

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper"> <mapper namespace="com.ruoyi.generator.mapper.GenTableColumnMapper">
<resultMap type="GenTableColumn" id="GenTableColumnResult"> <resultMap type="GenTableColumn" id="GenTableColumnResult">
@@ -40,13 +40,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult"> <select id="selectDbTableColumnsByName" parameterType="String" resultMap="GenTableColumnResult">
select column_name, (case when (is_nullable = 'no' <![CDATA[ && ]]> column_key != 'PRI') then '1' else '0' 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 SELECT
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName}) COLUMN_NAME = c.name,
order by ordinal_position is_required = CASE WHEN c.is_nullable = 0 AND pk.object_id IS NULL THEN '1' ELSE '0' END,
is_pk = CASE WHEN pk.object_id IS NOT NULL THEN '1' ELSE '0' END,
sort = c.column_id,
column_comment = ISNULL(ep.value, ''),
is_increment = CASE WHEN ic.column_id IS NOT NULL THEN '1' ELSE '0' END,
column_type = ty.name +
CASE WHEN ty.name IN ('char', 'nchar', 'varchar', 'nvarchar') THEN '(' + CAST(c.max_length AS VARCHAR(10)) + ')'
WHEN ty.name IN ('decimal', 'numeric') THEN '(' + CAST(c.precision AS VARCHAR(10)) + ',' + CAST(c.scale AS VARCHAR(10)) + ')'
ELSE ''
END
FROM
sys.columns c
INNER JOIN
(SELECT object_id, name FROM sys.tables
UNION ALL
SELECT object_id, name FROM sys.views) t ON c.object_id = t.object_id
LEFT JOIN
sys.types ty ON c.user_type_id = ty.user_type_id
LEFT JOIN (
-- 获取主键列
SELECT ic.object_id, ic.column_id
FROM sys.indexes i
INNER JOIN sys.index_columns ic ON i.object_id = ic.object_id AND i.index_id = ic.index_id
WHERE i.is_primary_key = 1
) pk ON c.object_id = pk.object_id AND c.column_id = pk.column_id
LEFT JOIN (
-- 获取自增列
SELECT object_id, column_id
FROM sys.identity_columns
) ic ON c.object_id = ic.object_id AND c.column_id = ic.column_id
LEFT JOIN
sys.extended_properties ep ON ep.major_id = c.object_id AND ep.minor_id = c.column_id AND ep.name = 'MS_Description'
WHERE
t.name =#{table}
ORDER BY
c.column_id
</select> </select>
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId"> <insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
insert into gen_table_column ( insert into gen_table_column (
<if test="columnId != null ">column_id,</if>
<if test="tableId != null and tableId != ''">table_id,</if> <if test="tableId != null and tableId != ''">table_id,</if>
<if test="columnName != null and columnName != ''">column_name,</if> <if test="columnName != null and columnName != ''">column_name,</if>
<if test="columnComment != null and columnComment != ''">column_comment,</if> <if test="columnComment != null and columnComment != ''">column_comment,</if>
@@ -67,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
create_time create_time
)values( )values(
<if test="columnId != null ">#{columnId},</if>
<if test="tableId != null and tableId != ''">#{tableId},</if> <if test="tableId != null and tableId != ''">#{tableId},</if>
<if test="columnName != null and columnName != ''">#{columnName},</if> <if test="columnName != null and columnName != ''">#{columnName},</if>
<if test="columnComment != null and columnComment != ''">#{columnComment},</if> <if test="columnComment != null and columnComment != ''">#{columnComment},</if>
@@ -85,7 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dictType != null and dictType != ''">#{dictType},</if> <if test="dictType != null and dictType != ''">#{dictType},</if>
<if test="sort != null">#{sort},</if> <if test="sort != null">#{sort},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate() GETDATE()
) )
</insert> </insert>
@@ -105,7 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dictType != null">dict_type = #{dictType},</if> <if test="dictType != null">dict_type = #{dictType},</if>
<if test="sort != null">sort = #{sort},</if> <if test="sort != null">sort = #{sort},</if>
<if test="updateBy != null">update_by = #{updateBy},</if> <if test="updateBy != null">update_by = #{updateBy},</if>
update_time = sysdate() update_time = GETDATE()
</set> </set>
where column_id = #{columnId} where column_id = #{columnId}
</update> </update>

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper <!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd"> "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.generator.mapper.GenTableMapper"> <mapper namespace="com.ruoyi.generator.mapper.GenTableMapper">
<resultMap type="GenTable" id="GenTableResult"> <resultMap type="GenTable" id="GenTableResult">
@@ -77,29 +77,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select> </select>
<select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult"> <select id="selectDbTableList" parameterType="GenTable" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select t.name as table_name, ISNULL(ep.value, '') AS table_comment, create_date as create_time, modify_date as update_time
where table_schema = (select database()) from (
AND table_name NOT LIKE 'qrtz\_%' AND table_name NOT LIKE 'gen\_%' select name, object_id, create_date, modify_date from sys.tables
AND table_name NOT IN (select table_name from gen_table) union all
select name, object_id, create_date, modify_date from sys.views
) t
LEFT JOIN
sys.extended_properties ep ON ep.major_id = t.object_id AND ep.minor_id = 0 -- 表示是对整个表的注释(不是列)
AND ep.name = 'MS_Description' -- 标准注释名称
where t.name NOT LIKE 'qrtz\_%' AND t.name NOT LIKE 'gen\_%'
AND t.name NOT IN (select table_name from gen_table)
<if test="tableName != null and tableName != ''"> <if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%')) AND lower(t.name) like lower(concat('%', #{tableName}, '%'))
</if> </if>
<if test="tableComment != null and tableComment != ''"> <if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%')) AND lower(ep.value) like lower(concat('%', #{tableComment}, '%'))
</if> </if>
<if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 --> <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
AND date_format(create_time,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d') AND date_format(create_date,'%Y%m%d') &gt;= date_format(#{params.beginTime},'%Y%m%d')
</if> </if>
<if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 --> <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
AND date_format(create_time,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d') AND date_format(create_date,'%Y%m%d') &lt;= date_format(#{params.endTime},'%Y%m%d')
</if> </if>
order by create_time desc
</select> </select>
<select id="selectDbTableListByNames" resultMap="GenTableResult"> <select id="selectDbTableListByNames" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select t.name as table_name, ISNULL(ep.value, '') AS table_comment, create_date as create_time, modify_date as update_time
where table_name NOT LIKE 'qrtz\_%' and table_name NOT LIKE 'gen\_%' and table_schema = (select database()) from (
and table_name in select name, object_id, create_date, modify_date from sys.tables
union all
select name, object_id, create_date, modify_date from sys.views
) t
LEFT JOIN
sys.extended_properties ep ON ep.major_id = t.object_id AND ep.minor_id = 0 -- 表示是对整个表的注释(不是列)
AND ep.name = 'MS_Description' -- 标准注释名称
where t.name NOT LIKE 'qrtz\_%' AND t.name NOT LIKE 'gen\_%'
AND t.name NOT IN (select table_name from gen_table)
and t.name in
<foreach collection="array" item="name" open="(" separator="," close=")"> <foreach collection="array" item="name" open="(" separator="," close=")">
#{name} #{name}
</foreach> </foreach>
@@ -107,7 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectTableByName" parameterType="String" resultMap="GenTableResult"> <select id="selectTableByName" parameterType="String" resultMap="GenTableResult">
select table_name, table_comment, create_time, update_time from information_schema.tables select table_name, table_comment, create_time, update_time from information_schema.tables
where table_comment <![CDATA[ <> ]]> '' and table_schema = (select database()) where table_comment <![CDATA[ <> ]]> '' and TABLE_CATALOG = (select DB_NAME())
and table_name = #{tableName} and table_name = #{tableName}
</select> </select>
@@ -135,8 +150,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
order by c.sort order by c.sort
</select> </select>
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId"> <insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId" >
insert into gen_table ( insert into gen_table (
<if test="tableId != null">table_id,</if>
<if test="tableName != null">table_name,</if> <if test="tableName != null">table_name,</if>
<if test="tableComment != null and tableComment != ''">table_comment,</if> <if test="tableComment != null and tableComment != ''">table_comment,</if>
<if test="className != null and className != ''">class_name,</if> <if test="className != null and className != ''">class_name,</if>
@@ -153,6 +169,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">create_by,</if> <if test="createBy != null and createBy != ''">create_by,</if>
create_time create_time
)values( )values(
<if test="tableId != null">#{tableId},</if>
<if test="tableName != null">#{tableName},</if> <if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</if> <if test="tableComment != null and tableComment != ''">#{tableComment},</if>
<if test="className != null and className != ''">#{className},</if> <if test="className != null and className != ''">#{className},</if>
@@ -167,7 +184,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="genPath != null and genPath != ''">#{genPath},</if> <if test="genPath != null and genPath != ''">#{genPath},</if>
<if test="remark != null and remark != ''">#{remark},</if> <if test="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if> <if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate() GETDATE()
) )
</insert> </insert>
@@ -195,7 +212,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="options != null and options != ''">options = #{options},</if> <if test="options != null and options != ''">options = #{options},</if>
<if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if> <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
<if test="remark != null">remark = #{remark},</if> <if test="remark != null">remark = #{remark},</if>
update_time = sysdate() update_time = GETDATE()
</set> </set>
where table_id = #{tableId} where table_id = #{tableId}
</update> </update>

View File

@@ -356,7 +356,7 @@ export default {
handleAdd() { handleAdd() {
this.reset() this.reset()
this.open = true this.open = true
this.title = this.$t('traycodeFormat.addTitle') this.title = '新增条码格式'
}, },
/** 修改按钮操作 */ /** 修改按钮操作 */
handleUpdate(row) { handleUpdate(row) {
@@ -365,7 +365,7 @@ export default {
getTraycodeFormat(id).then(response => { getTraycodeFormat(id).then(response => {
this.form = response.data this.form = response.data
this.open = true this.open = true
this.title = this.$t('traycodeFormat.editTitle') this.title = '修改条码格式'
}) })
}, },
/** 提交按钮 */ /** 提交按钮 */
@@ -374,13 +374,13 @@ export default {
if (valid) { if (valid) {
if (this.form.id != null) { if (this.form.id != null) {
updateTraycodeFormat(this.form).then(response => { updateTraycodeFormat(this.form).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.editSuccess')) this.$modal.msgSuccess('修改成功')
this.open = false this.open = false
this.getList() this.getList()
}) })
} else { } else {
addTraycodeFormat(this.form).then(response => { addTraycodeFormat(this.form).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.addSuccess')) this.$modal.msgSuccess('添加成功')
this.open = false this.open = false
this.getList() this.getList()
}) })
@@ -391,11 +391,11 @@ export default {
/** 删除按钮操作 */ /** 删除按钮操作 */
handleDelete(row) { handleDelete(row) {
const ids = row.id || this.ids const ids = row.id || this.ids
this.$modal.confirm(this.$t('traycodeFormat.deleteConfirm', { id: ids })).then(function() { this.$modal.confirm('删除条码格式', { id: ids }).then(function() {
return delTraycodeFormat(ids) return delTraycodeFormat(ids)
}).then(() => { }).then(() => {
this.getList() this.getList()
this.$modal.msgSuccess(this.$t('traycodeFormat.deleteSuccess')) this.$modal.msgSuccess('删除成功')
}).catch(() => {}) }).catch(() => {})
}, },
/** 导出按钮操作 */ /** 导出按钮操作 */
@@ -422,11 +422,11 @@ export default {
}; };
if (Number(this.printForm.printCount)+Number(this.selectData[0].serialRule)-1>this.selectData[0].maxNum){ if (Number(this.printForm.printCount)+Number(this.selectData[0].serialRule)-1>this.selectData[0].maxNum){
this.$modal.msgError(this.$t('traycodeFormat.printCountError')) this.$modal.msgError('生成打印数据失败')
return return
} }
updateTraycodeFormat(printData).then(response => { updateTraycodeFormat(printData).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.editSuccess')) this.$modal.msgSuccess('生成打印数据成功')
this.printDialogVisible = false; this.printDialogVisible = false;
this.getList() this.getList()
}) })

View File

@@ -147,7 +147,7 @@
icon="el-icon-delete" icon="el-icon-delete"
@click="handleDelete(scope.row)" @click="handleDelete(scope.row)"
v-hasPermi="['system:dict:remove']" v-hasPermi="['system:dict:remove']"
>{{ }}</el-button> >删除</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>