初始化生成代码功能

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

@@ -40,13 +40,49 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<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
from information_schema.columns where table_schema = (select database()) and table_name = (#{tableName})
order by ordinal_position
SELECT
COLUMN_NAME = c.name,
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>
<insert id="insertGenTableColumn" parameterType="GenTableColumn" useGeneratedKeys="true" keyProperty="columnId">
insert into gen_table_column (
<if test="columnId != null ">column_id,</if>
<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>
@@ -67,6 +103,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="columnId != null ">#{columnId},</if>
<if test="tableId != null and tableId != ''">#{tableId},</if>
<if test="columnName != null and columnName != ''">#{columnName},</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="sort != null">#{sort},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
GETDATE()
)
</insert>
@@ -105,7 +142,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="dictType != null">dict_type = #{dictType},</if>
<if test="sort != null">sort = #{sort},</if>
<if test="updateBy != null">update_by = #{updateBy},</if>
update_time = sysdate()
update_time = GETDATE()
</set>
where column_id = #{columnId}
</update>

View File

@@ -77,29 +77,44 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</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)
select t.name as table_name, ISNULL(ep.value, '') AS table_comment, create_date as create_time, modify_date as update_time
from (
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)
<if test="tableName != null and tableName != ''">
AND lower(table_name) like lower(concat('%', #{tableName}, '%'))
AND lower(t.name) like lower(concat('%', #{tableName}, '%'))
</if>
<if test="tableComment != null and tableComment != ''">
AND lower(table_comment) like lower(concat('%', #{tableComment}, '%'))
AND lower(ep.value) 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')
AND date_format(create_date,'%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')
AND date_format(create_date,'%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
select t.name as table_name, ISNULL(ep.value, '') AS table_comment, create_date as create_time, modify_date as update_time
from (
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=")">
#{name}
</foreach>
@@ -107,7 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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())
where table_comment <![CDATA[ <> ]]> '' and TABLE_CATALOG = (select DB_NAME())
and table_name = #{tableName}
</select>
@@ -137,6 +152,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<insert id="insertGenTable" parameterType="GenTable" useGeneratedKeys="true" keyProperty="tableId" >
insert into gen_table (
<if test="tableId != null">table_id,</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>
@@ -153,6 +169,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="createBy != null and createBy != ''">create_by,</if>
create_time
)values(
<if test="tableId != null">#{tableId},</if>
<if test="tableName != null">#{tableName},</if>
<if test="tableComment != null and tableComment != ''">#{tableComment},</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="remark != null and remark != ''">#{remark},</if>
<if test="createBy != null and createBy != ''">#{createBy},</if>
sysdate()
GETDATE()
)
</insert>
@@ -195,7 +212,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<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()
update_time = GETDATE()
</set>
where table_id = #{tableId}
</update>

View File

@@ -356,7 +356,7 @@ export default {
handleAdd() {
this.reset()
this.open = true
this.title = this.$t('traycodeFormat.addTitle')
this.title = '新增条码格式'
},
/** 修改按钮操作 */
handleUpdate(row) {
@@ -365,7 +365,7 @@ export default {
getTraycodeFormat(id).then(response => {
this.form = response.data
this.open = true
this.title = this.$t('traycodeFormat.editTitle')
this.title = '修改条码格式'
})
},
/** 提交按钮 */
@@ -374,13 +374,13 @@ export default {
if (valid) {
if (this.form.id != null) {
updateTraycodeFormat(this.form).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.editSuccess'))
this.$modal.msgSuccess('修改成功')
this.open = false
this.getList()
})
} else {
addTraycodeFormat(this.form).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.addSuccess'))
this.$modal.msgSuccess('添加成功')
this.open = false
this.getList()
})
@@ -391,11 +391,11 @@ export default {
/** 删除按钮操作 */
handleDelete(row) {
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)
}).then(() => {
this.getList()
this.$modal.msgSuccess(this.$t('traycodeFormat.deleteSuccess'))
this.$modal.msgSuccess('删除成功')
}).catch(() => {})
},
/** 导出按钮操作 */
@@ -422,11 +422,11 @@ export default {
};
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
}
updateTraycodeFormat(printData).then(response => {
this.$modal.msgSuccess(this.$t('traycodeFormat.editSuccess'))
this.$modal.msgSuccess('生成打印数据成功')
this.printDialogVisible = false;
this.getList()
})

View File

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