refactor: 多租户开发和代码规范调整

This commit is contained in:
Ray.Hao
2025-12-11 21:13:52 +08:00
parent 47cabcbcfc
commit 51d8220a18
67 changed files with 922 additions and 1157 deletions

View File

@@ -11,8 +11,8 @@ spring:
# === MySQL 数据源(默认启用) ===
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://www.youlai.tech:3306/youlai_admin?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai&autoReconnect=true&allowMultiQueries=true
username: youlai
password: 123456
username: root
password: Youlai@2025
# === PostgreSQL 数据源示例(按需启用) ===
# driver-class-name: org.postgresql.Driver
@@ -275,7 +275,7 @@ youlai:
tenant:
# 是否启用多租户功能默认false
# 设置为 true 启用多租户,设置为 false 禁用多租户(零成本切换)
enabled: false
enabled: true
# 租户字段名默认tenant_id
column: tenant_id

View File

@@ -13,8 +13,8 @@ codegen:
moduleName: system
# 排除数据表
excludeTables:
- gen_config
- gen_field_config
- gen_table
- gen_table_column
## 模板配置
templateConfigs:
API:

View File

@@ -2,9 +2,9 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.ai.mapper.AiCommandLogMapper">
<mapper namespace="com.youlai.boot.platform.ai.mapper.AiCommandRecordMapper">
<resultMap id="AiCommandLogVOResult" type="com.youlai.boot.platform.ai.model.vo.AiCommandLogVO">
<resultMap id="AiCommandRecordResultMap" type="com.youlai.boot.platform.ai.model.vo.AiCommandRecordVO">
<id property="id" column="id"/>
<result property="userId" column="user_id"/>
<result property="username" column="username"/>
@@ -28,55 +28,55 @@
<result property="updateTime" column="update_time"/>
</resultMap>
<select id="getLogPage" resultMap="AiCommandLogVOResult">
<select id="getRecordPage" resultMap="AiCommandRecordResultMap">
SELECT
acl.id,
acl.user_id,
acl.username,
acl.original_command,
acl.ai_provider,
acl.ai_model,
acl.parse_status,
acl.function_calls,
acl.explanation,
acl.confidence,
acl.parse_error_message,
acl.input_tokens,
acl.output_tokens,
acl.parse_duration_ms,
acl.function_name,
acl.function_arguments,
acl.execute_status,
acl.execute_error_message,
acl.ip_address,
acl.create_time,
acl.update_time
FROM ai_command_log acl
acr.id,
acr.user_id,
acr.username,
acr.original_command,
acr.ai_provider,
acr.ai_model,
acr.parse_status,
acr.function_calls,
acr.explanation,
acr.confidence,
acr.parse_error_message,
acr.input_tokens,
acr.output_tokens,
acr.parse_duration_ms,
acr.function_name,
acr.function_arguments,
acr.execute_status,
acr.execute_error_message,
acr.ip_address,
acr.create_time,
acr.update_time
FROM ai_command_record acr
<where>
<if test="queryParams.keywords != null and queryParams.keywords != ''">
(
acl.original_command LIKE CONCAT('%', #{queryParams.keywords}, '%')
OR acl.function_name LIKE CONCAT('%', #{queryParams.keywords}, '%')
OR acl.username LIKE CONCAT('%', #{queryParams.keywords}, '%')
acr.original_command LIKE CONCAT('%', #{queryParams.keywords}, '%')
OR acr.function_name LIKE CONCAT('%', #{queryParams.keywords}, '%')
OR acr.username LIKE CONCAT('%', #{queryParams.keywords}, '%')
)
</if>
<if test="queryParams.executeStatus != null">
AND acl.execute_status = #{queryParams.executeStatus}
AND acr.execute_status = #{queryParams.executeStatus}
</if>
<if test="queryParams.userId != null">
AND acl.user_id = #{queryParams.userId}
AND acr.user_id = #{queryParams.userId}
</if>
<if test="queryParams.parseStatus != null">
AND acl.parse_status = #{queryParams.parseStatus}
AND acr.parse_status = #{queryParams.parseStatus}
</if>
<if test="queryParams.functionName != null and queryParams.functionName != ''">
AND acl.function_name = #{queryParams.functionName}
AND acr.function_name = #{queryParams.functionName}
</if>
<if test="queryParams.aiProvider != null and queryParams.aiProvider != ''">
AND acl.ai_provider = #{queryParams.aiProvider}
AND acr.ai_provider = #{queryParams.aiProvider}
</if>
<if test="queryParams.aiModel != null and queryParams.aiModel != ''">
AND acl.ai_model = #{queryParams.aiModel}
AND acr.ai_model = #{queryParams.aiModel}
</if>
<if test="
queryParams.createTime != null
@@ -86,10 +86,10 @@
and queryParams.createTime[1] != null
and queryParams.createTime[1] != ''
">
AND acl.create_time BETWEEN #{queryParams.createTime[0]} AND #{queryParams.createTime[1]}
AND acr.create_time BETWEEN #{queryParams.createTime[0]} AND #{queryParams.createTime[1]}
</if>
</where>
ORDER BY acl.create_time DESC
ORDER BY acr.create_time DESC
</select>
</mapper>

View File

@@ -16,7 +16,7 @@
CASE WHEN t2.id IS NOT NULL THEN 1 ELSE 0 END AS isConfigured
FROM
information_schema.tables t1
LEFT JOIN gen_config t2 on t1.TABLE_NAME = t2.table_name
LEFT JOIN gen_table t2 on t1.TABLE_NAME = t2.table_name
WHERE
t1.TABLE_SCHEMA = (SELECT DATABASE())
AND t1.table_type = 'BASE TABLE'
@@ -46,7 +46,7 @@
ALL_TABLES t1
LEFT JOIN ALL_TAB_COMMENTS c ON t1.TABLE_NAME = c.TABLE_NAME AND t1.OWNER = c.OWNER
LEFT JOIN ALL_OBJECTS o ON t1.TABLE_NAME = o.OBJECT_NAME AND t1.OWNER = o.OWNER AND o.OBJECT_TYPE = 'TABLE'
LEFT JOIN gen_config t2 ON t1.TABLE_NAME = t2.table_name
LEFT JOIN gen_table t2 ON t1.TABLE_NAME = t2.table_name
WHERE
t1.OWNER = 'YOULAI_BOOT'
<if test="queryParams.keywords != null and queryParams.keywords.trim() neq ''">

View File

@@ -2,6 +2,6 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.codegen.mapper.GenConfigMapper">
<mapper namespace="com.youlai.boot.platform.codegen.mapper.GenTableMapper">
</mapper>

View File

@@ -2,6 +2,6 @@
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.youlai.boot.platform.generator.mapper.GenFieldConfigMapper">
<mapper namespace="com.youlai.boot.platform.codegen.mapper.GenTableColumnMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
<?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.youlai.boot.platform.codegen.mapper.GenTableColumnMapper">
</mapper>

View File

@@ -0,0 +1,7 @@
<?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.youlai.boot.platform.codegen.mapper.GenTableMapper">
</mapper>