dify
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
# AI模块配置示例
|
||||
# 使用前请复制为 application-ai.yml 并填写实际配置
|
||||
|
||||
dify:
|
||||
# Dify API基础地址
|
||||
# 云端服务: https://api.dify.ai/v1
|
||||
# 自建服务: http://your-dify-server:5001/v1
|
||||
api-base-url: https://api.dify.ai/v1
|
||||
|
||||
# Dify API密钥(默认密钥,可被智能体的密钥覆盖)
|
||||
# 在Dify控制台获取: 设置 -> API密钥
|
||||
api-key: ${DIFY_API_KEY:your-dify-api-key-here}
|
||||
|
||||
# 请求超时时间(秒)
|
||||
timeout: 60
|
||||
connect-timeout: 10
|
||||
read-timeout: 60
|
||||
stream-timeout: 300
|
||||
|
||||
# 重试配置
|
||||
max-retries: 3
|
||||
retry-interval: 1000
|
||||
|
||||
# 是否启用Dify集成
|
||||
enabled: true
|
||||
|
||||
# 文件上传配置
|
||||
upload:
|
||||
# 支持的文件类型
|
||||
allowed-types:
|
||||
- pdf
|
||||
- txt
|
||||
- docx
|
||||
- doc
|
||||
- md
|
||||
- html
|
||||
- htm
|
||||
# 最大文件大小(MB)
|
||||
max-size: 50
|
||||
# 批量上传最大文件数
|
||||
batch-max-count: 10
|
||||
|
||||
# 知识库配置
|
||||
dataset:
|
||||
# 默认索引方式:high_quality(高质量,慢但准确)或 economy(经济模式,快但略差)
|
||||
default-indexing-technique: high_quality
|
||||
# 默认Embedding模型
|
||||
default-embedding-model: text-embedding-ada-002
|
||||
# 文档分段策略:automatic(自动)或 custom(自定义)
|
||||
segmentation-strategy: automatic
|
||||
# 分段最大长度(字符数)
|
||||
max-segment-length: 1000
|
||||
# 分段重叠长度(字符数)
|
||||
segment-overlap: 50
|
||||
|
||||
# 对话配置
|
||||
chat:
|
||||
# 默认温度值(0-1,越高越随机)
|
||||
default-temperature: 0.7
|
||||
# 默认最大Token数
|
||||
default-max-tokens: 2000
|
||||
# 默认Top P值(0-1)
|
||||
default-top-p: 1.0
|
||||
# 是否启用流式响应
|
||||
enable-stream: true
|
||||
# 对话上下文最大消息数
|
||||
max-context-messages: 10
|
||||
|
||||
@@ -7,12 +7,15 @@
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="avatar" property="avatar" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="system_prompt" property="systemPrompt" jdbcType="LONGVARCHAR"/>
|
||||
<result column="model_name" property="modelName" jdbcType="VARCHAR"/>
|
||||
<result column="model_provider" property="modelProvider" jdbcType="VARCHAR"/>
|
||||
<result column="temperature" property="temperature" jdbcType="DECIMAL"/>
|
||||
<result column="max_tokens" property="maxTokens" jdbcType="INTEGER"/>
|
||||
<result column="top_p" property="topP" jdbcType="DECIMAL"/>
|
||||
<result column="dify_app_id" property="difyAppId" jdbcType="VARCHAR"/>
|
||||
<result column="dify_api_key" property="difyApiKey" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
@@ -24,9 +27,9 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, name, avatar, system_prompt, model_name, model_provider, temperature,
|
||||
max_tokens, top_p, status, creator, updater, create_time, update_time,
|
||||
delete_time, deleted
|
||||
id, name, avatar, description, system_prompt, model_name, model_provider,
|
||||
temperature, max_tokens, top_p, dify_app_id, dify_api_key, status,
|
||||
creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
@@ -48,7 +51,129 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectAiAgentConfigs -->
|
||||
<!-- 插入智能体配置 -->
|
||||
<insert id="insertAgentConfig" parameterType="org.xyzh.common.dto.ai.TbAiAgentConfig">
|
||||
INSERT INTO tb_ai_agent_config (
|
||||
id, name, avatar, description, system_prompt, model_name, model_provider,
|
||||
temperature, max_tokens, top_p, dify_app_id, dify_api_key, status,
|
||||
creator, updater, create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{id}, #{name}, #{avatar}, #{description}, #{systemPrompt}, #{modelName}, #{modelProvider},
|
||||
#{temperature}, #{maxTokens}, #{topP}, #{difyAppId}, #{difyApiKey}, #{status},
|
||||
#{creator}, #{updater}, #{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新智能体配置(动态更新) -->
|
||||
<update id="updateAgentConfig" parameterType="org.xyzh.common.dto.ai.TbAiAgentConfig">
|
||||
UPDATE tb_ai_agent_config
|
||||
<set>
|
||||
<if test="name != null and name != ''">name = #{name},</if>
|
||||
<if test="avatar != null">avatar = #{avatar},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="systemPrompt != null">system_prompt = #{systemPrompt},</if>
|
||||
<if test="modelName != null">model_name = #{modelName},</if>
|
||||
<if test="modelProvider != null">model_provider = #{modelProvider},</if>
|
||||
<if test="temperature != null">temperature = #{temperature},</if>
|
||||
<if test="maxTokens != null">max_tokens = #{maxTokens},</if>
|
||||
<if test="topP != null">top_p = #{topP},</if>
|
||||
<if test="difyAppId != null">dify_app_id = #{difyAppId},</if>
|
||||
<if test="difyApiKey != null">dify_api_key = #{difyApiKey},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除智能体配置 -->
|
||||
<update id="deleteAgentConfig" parameterType="org.xyzh.common.dto.ai.TbAiAgentConfig">
|
||||
UPDATE tb_ai_agent_config
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID查询智能体配置 -->
|
||||
<select id="selectAgentConfigById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_agent_config
|
||||
WHERE id = #{agentId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 查询所有智能体配置(支持过滤) -->
|
||||
<select id="selectAgentConfigs" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_agent_config
|
||||
WHERE deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.modelProvider != null and filter.modelProvider != ''">
|
||||
AND model_provider = #{filter.modelProvider}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 分页查询智能体配置 -->
|
||||
<select id="selectAgentConfigsPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_agent_config
|
||||
WHERE deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.modelProvider != null and filter.modelProvider != ''">
|
||||
AND model_provider = #{filter.modelProvider}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 统计智能体配置总数 -->
|
||||
<select id="countAgentConfigs" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_agent_config
|
||||
WHERE deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
<if test="filter.modelProvider != null and filter.modelProvider != ''">
|
||||
AND model_provider = #{filter.modelProvider}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- 根据名称统计数量 -->
|
||||
<select id="countAgentConfigByName" resultType="java.lang.Integer">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_agent_config
|
||||
WHERE name = #{name}
|
||||
AND deleted = 0
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<!-- selectAiAgentConfigs (原有方法保留兼容性) -->
|
||||
<select id="selectAiAgentConfigs" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
|
||||
@@ -6,9 +6,15 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiConversation">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="agent_id" property="agentID" jdbcType="VARCHAR"/>
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="summary" property="summary" jdbcType="VARCHAR"/>
|
||||
<result column="dify_conversation_id" property="difyConversationId" jdbcType="VARCHAR"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="is_favorite" property="isFavorite" jdbcType="BOOLEAN"/>
|
||||
<result column="is_pinned" property="isPinned" jdbcType="BOOLEAN"/>
|
||||
<result column="message_count" property="messageCount" jdbcType="INTEGER"/>
|
||||
<result column="total_tokens" property="totalTokens" jdbcType="INTEGER"/>
|
||||
<result column="last_message_time" property="lastMessageTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
@@ -16,7 +22,8 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, title, status, message_count, last_message_time,
|
||||
id, user_id, agent_id, title, summary, dify_conversation_id, status,
|
||||
is_favorite, is_pinned, message_count, total_tokens, last_message_time,
|
||||
create_time, update_time
|
||||
</sql>
|
||||
|
||||
@@ -26,21 +33,214 @@
|
||||
<if test="userID != null and userID != ''">
|
||||
AND user_id = #{userID}
|
||||
</if>
|
||||
<if test="agentID != null and agentID != ''">
|
||||
AND agent_id = #{agentID}
|
||||
</if>
|
||||
<if test="title != null and title != ''">
|
||||
AND title LIKE CONCAT('%', #{title}, '%')
|
||||
</if>
|
||||
<if test="difyConversationId != null and difyConversationId != ''">
|
||||
AND dify_conversation_id = #{difyConversationId}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
<if test="isFavorite != null">
|
||||
AND is_favorite = #{isFavorite}
|
||||
</if>
|
||||
<if test="isPinned != null">
|
||||
AND is_pinned = #{isPinned}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 插入会话 -->
|
||||
<insert id="insertConversation" parameterType="org.xyzh.common.dto.ai.TbAiConversation">
|
||||
INSERT INTO tb_ai_conversation (
|
||||
id, user_id, agent_id, title, summary, dify_conversation_id,
|
||||
status, is_favorite, is_pinned, message_count, total_tokens,
|
||||
last_message_time, create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{ID}, #{userID}, #{agentID}, #{title}, #{summary}, #{difyConversationId},
|
||||
#{status}, #{isFavorite}, #{isPinned}, #{messageCount}, #{totalTokens},
|
||||
#{lastMessageTime}, #{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新会话(动态更新非null字段) -->
|
||||
<update id="updateConversation" parameterType="org.xyzh.common.dto.ai.TbAiConversation">
|
||||
UPDATE tb_ai_conversation
|
||||
<set>
|
||||
<if test="title != null">title = #{title},</if>
|
||||
<if test="summary != null">summary = #{summary},</if>
|
||||
<if test="difyConversationId != null">dify_conversation_id = #{difyConversationId},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="isFavorite != null">is_favorite = #{isFavorite},</if>
|
||||
<if test="isPinned != null">is_pinned = #{isPinned},</if>
|
||||
<if test="messageCount != null">message_count = #{messageCount},</if>
|
||||
<if test="totalTokens != null">total_tokens = #{totalTokens},</if>
|
||||
<if test="lastMessageTime != null">last_message_time = #{lastMessageTime},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除会话 -->
|
||||
<update id="deleteConversation" parameterType="org.xyzh.common.dto.ai.TbAiConversation">
|
||||
UPDATE tb_ai_conversation
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID查询会话 -->
|
||||
<select id="selectConversationById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE id = #{conversationId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据用户ID查询会话列表 -->
|
||||
<select id="selectConversationsByUserId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
<if test="agentId != null and agentId != ''">
|
||||
AND agent_id = #{agentId}
|
||||
</if>
|
||||
AND deleted = 0
|
||||
ORDER BY is_pinned DESC, last_message_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- 统计用户的会话数量 -->
|
||||
<select id="countUserConversations" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 分页查询用户会话(支持关键词、日期范围、收藏筛选) -->
|
||||
<select id="selectUserConversationsPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
<if test="agentId != null and agentId != ''">
|
||||
AND agent_id = #{agentId}
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (title LIKE CONCAT('%', #{keyword}, '%') OR summary LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
<if test="isFavorite != null">
|
||||
AND is_favorite = #{isFavorite}
|
||||
</if>
|
||||
<if test="startDate != null">
|
||||
AND create_time >= #{startDate}
|
||||
</if>
|
||||
<if test="endDate != null">
|
||||
AND create_time <= #{endDate}
|
||||
</if>
|
||||
AND deleted = 0
|
||||
ORDER BY is_pinned DESC, last_message_time DESC, create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 统计查询条件下的会话数量 -->
|
||||
<select id="countUserConversationsWithFilter" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
<if test="agentId != null and agentId != ''">
|
||||
AND agent_id = #{agentId}
|
||||
</if>
|
||||
<if test="keyword != null and keyword != ''">
|
||||
AND (title LIKE CONCAT('%', #{keyword}, '%') OR summary LIKE CONCAT('%', #{keyword}, '%'))
|
||||
</if>
|
||||
<if test="isFavorite != null">
|
||||
AND is_favorite = #{isFavorite}
|
||||
</if>
|
||||
<if test="startDate != null">
|
||||
AND create_time >= #{startDate}
|
||||
</if>
|
||||
<if test="endDate != null">
|
||||
AND create_time <= #{endDate}
|
||||
</if>
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 搜索会话(标题和摘要全文搜索) -->
|
||||
<select id="searchConversationsByKeyword" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND (title LIKE CONCAT('%', #{keyword}, '%') OR summary LIKE CONCAT('%', #{keyword}, '%'))
|
||||
AND deleted = 0
|
||||
ORDER BY last_message_time DESC, create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 统计搜索结果数量 -->
|
||||
<select id="countSearchConversations" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND (title LIKE CONCAT('%', #{keyword}, '%') OR summary LIKE CONCAT('%', #{keyword}, '%'))
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 批量更新会话状态 -->
|
||||
<update id="batchUpdateConversations">
|
||||
UPDATE tb_ai_conversation
|
||||
SET deleted = #{deleted},
|
||||
delete_time = NOW()
|
||||
WHERE id IN
|
||||
<foreach collection="ids" item="id" open="(" separator="," close=")">
|
||||
#{id}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<!-- 查询用户最近的会话 -->
|
||||
<select id="selectRecentConversations" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND deleted = 0
|
||||
ORDER BY last_message_time DESC, create_time DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 查询热门会话(按消息数排序) -->
|
||||
<select id="selectPopularConversations" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND deleted = 0
|
||||
ORDER BY message_count DESC, total_tokens DESC
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
|
||||
<!-- 查询过期会话ID列表 -->
|
||||
<select id="selectExpiredConversationIds" resultType="java.lang.String">
|
||||
SELECT id
|
||||
FROM tb_ai_conversation
|
||||
WHERE user_id = #{userId}
|
||||
AND create_time < #{beforeDate}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- selectAiConversations -->
|
||||
<select id="selectAiConversations" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_conversation
|
||||
<include refid="Where_Clause"/>
|
||||
AND deleted = 0
|
||||
ORDER BY last_message_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiKnowledge">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="source_type" property="sourceType" jdbcType="INTEGER"/>
|
||||
<result column="source_id" property="sourceID" jdbcType="VARCHAR"/>
|
||||
@@ -13,9 +14,15 @@
|
||||
<result column="file_path" property="filePath" jdbcType="VARCHAR"/>
|
||||
<result column="category" property="category" jdbcType="VARCHAR"/>
|
||||
<result column="tags" property="tags" jdbcType="VARCHAR"/>
|
||||
<result column="dify_dataset_id" property="difyDatasetId" jdbcType="VARCHAR"/>
|
||||
<result column="dify_indexing_technique" property="difyIndexingTechnique" jdbcType="VARCHAR"/>
|
||||
<result column="embedding_model" property="embeddingModel" jdbcType="VARCHAR"/>
|
||||
<result column="vector_id" property="vectorID" jdbcType="VARCHAR"/>
|
||||
<result column="document_count" property="documentCount" jdbcType="INTEGER"/>
|
||||
<result column="total_chunks" property="totalChunks" jdbcType="INTEGER"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="creator_dept" property="creatorDept" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
@@ -25,40 +32,235 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, title, content, source_type, source_id, file_name, file_path,
|
||||
category, tags, vector_id, status, creator, updater, create_time,
|
||||
update_time, delete_time, deleted
|
||||
id, title, description, content, source_type, source_id, file_name, file_path,
|
||||
category, tags, dify_dataset_id, dify_indexing_technique, embedding_model,
|
||||
vector_id, document_count, total_chunks, status, creator, creator_dept,
|
||||
updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<!-- 过滤条件 -->
|
||||
<sql id="Filter_Clause">
|
||||
<where>
|
||||
deleted = 0
|
||||
<if test="title != null and title != ''">
|
||||
AND title LIKE CONCAT('%', #{title}, '%')
|
||||
k.deleted = 0
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND k.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="sourceType != null">
|
||||
AND source_type = #{sourceType}
|
||||
<if test="filter.sourceType != null">
|
||||
AND k.source_type = #{filter.sourceType}
|
||||
</if>
|
||||
<if test="sourceID != null and sourceID != ''">
|
||||
AND source_id = #{sourceID}
|
||||
<if test="filter.sourceID != null and filter.sourceID != ''">
|
||||
AND k.source_id = #{filter.sourceID}
|
||||
</if>
|
||||
<if test="category != null and category != ''">
|
||||
AND category = #{category}
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND k.category = #{filter.category}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND k.creator = #{filter.creator}
|
||||
</if>
|
||||
<if test="filter.creatorDept != null and filter.creatorDept != ''">
|
||||
AND k.creator_dept = #{filter.creatorDept}
|
||||
</if>
|
||||
<if test="filter.difyDatasetId != null and filter.difyDatasetId != ''">
|
||||
AND k.dify_dataset_id = #{filter.difyDatasetId}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND k.status = #{filter.status}
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectAiKnowledges -->
|
||||
<!-- 权限过滤条件(基于dept_path的高效继承) -->
|
||||
<sql id="Permission_Filter">
|
||||
INNER JOIN tb_resource_permission rp ON k.id = rp.resource_id
|
||||
AND rp.resource_type = 10
|
||||
AND rp.deleted = 0
|
||||
AND rp.can_read = 1
|
||||
AND (
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</sql>
|
||||
|
||||
<!-- selectAiKnowledges(带权限过滤) -->
|
||||
<select id="selectAiKnowledges" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
SELECT DISTINCT k.*
|
||||
FROM tb_ai_knowledge k
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY k.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- selectByIdWithPermission(根据ID查询并检查权限) -->
|
||||
<select id="selectByIdWithPermission" resultMap="BaseResultMap">
|
||||
SELECT k.*
|
||||
FROM tb_ai_knowledge k
|
||||
<include refid="Permission_Filter"/>
|
||||
WHERE k.id = #{knowledgeId}
|
||||
AND k.deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- checkKnowledgePermission(检查权限) -->
|
||||
<select id="checkKnowledgePermission" resultType="java.lang.Integer">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_resource_permission rp
|
||||
WHERE rp.resource_type = 10
|
||||
AND rp.resource_id = #{knowledgeId}
|
||||
AND rp.deleted = 0
|
||||
AND (
|
||||
<choose>
|
||||
<when test="permissionType == 'read'">
|
||||
rp.can_read = 1
|
||||
</when>
|
||||
<when test="permissionType == 'write'">
|
||||
rp.can_write = 1
|
||||
</when>
|
||||
<when test="permissionType == 'execute'">
|
||||
rp.can_execute = 1
|
||||
</when>
|
||||
<otherwise>
|
||||
rp.can_read = 1
|
||||
</otherwise>
|
||||
</choose>
|
||||
)
|
||||
AND (
|
||||
(rp.dept_id IS NULL AND rp.role_id IS NULL)
|
||||
<if test="userDeptRoles != null and userDeptRoles.size() > 0">
|
||||
OR EXISTS (
|
||||
SELECT 1
|
||||
FROM (
|
||||
<foreach collection="userDeptRoles" item="udr" separator=" UNION ALL ">
|
||||
SELECT #{udr.deptID} AS dept_id, #{udr.deptPath} AS dept_path, #{udr.roleID} AS role_id
|
||||
</foreach>
|
||||
) user_roles
|
||||
LEFT JOIN tb_sys_dept perm_dept ON perm_dept.dept_id = rp.dept_id AND perm_dept.deleted = 0
|
||||
WHERE
|
||||
(rp.role_id IS NULL AND rp.dept_id IS NOT NULL
|
||||
AND user_roles.dept_path LIKE CONCAT(perm_dept.dept_path, '%'))
|
||||
OR (rp.dept_id IS NULL AND rp.role_id = user_roles.role_id)
|
||||
OR (rp.dept_id = user_roles.dept_id AND rp.role_id = user_roles.role_id)
|
||||
)
|
||||
</if>
|
||||
)
|
||||
</select>
|
||||
|
||||
<!-- insertKnowledge(插入知识库) -->
|
||||
<insert id="insertKnowledge" parameterType="org.xyzh.common.dto.ai.TbAiKnowledge">
|
||||
INSERT INTO tb_ai_knowledge (
|
||||
id, title, description, content, source_type, source_id, file_name, file_path,
|
||||
category, tags, dify_dataset_id, dify_indexing_technique, embedding_model,
|
||||
vector_id, document_count, total_chunks, status, creator, creator_dept,
|
||||
updater, create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{ID}, #{title}, #{description}, #{content}, #{sourceType}, #{sourceID}, #{fileName}, #{filePath},
|
||||
#{category}, #{tags}, #{difyDatasetId}, #{difyIndexingTechnique}, #{embeddingModel},
|
||||
#{vectorID}, #{documentCount}, #{totalChunks}, #{status}, #{creator}, #{creatorDept},
|
||||
#{updater}, #{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- updateKnowledge(更新知识库) -->
|
||||
<update id="updateKnowledge" parameterType="org.xyzh.common.dto.ai.TbAiKnowledge">
|
||||
UPDATE tb_ai_knowledge
|
||||
<set>
|
||||
<if test="title != null and title != ''">title = #{title},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="content != null">content = #{content},</if>
|
||||
<if test="sourceType != null">source_type = #{sourceType},</if>
|
||||
<if test="sourceID != null">source_id = #{sourceID},</if>
|
||||
<if test="fileName != null">file_name = #{fileName},</if>
|
||||
<if test="filePath != null">file_path = #{filePath},</if>
|
||||
<if test="category != null">category = #{category},</if>
|
||||
<if test="tags != null">tags = #{tags},</if>
|
||||
<if test="difyDatasetId != null">dify_dataset_id = #{difyDatasetId},</if>
|
||||
<if test="difyIndexingTechnique != null">dify_indexing_technique = #{difyIndexingTechnique},</if>
|
||||
<if test="embeddingModel != null">embedding_model = #{embeddingModel},</if>
|
||||
<if test="vectorID != null">vector_id = #{vectorID},</if>
|
||||
<if test="documentCount != null">document_count = #{documentCount},</if>
|
||||
<if test="totalChunks != null">total_chunks = #{totalChunks},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- deleteKnowledge(逻辑删除知识库) -->
|
||||
<update id="deleteKnowledge" parameterType="org.xyzh.common.dto.ai.TbAiKnowledge">
|
||||
UPDATE tb_ai_knowledge
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- selectKnowledgeById(根据ID查询知识库,不带权限校验) -->
|
||||
<select id="selectKnowledgeById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_knowledge
|
||||
<include refid="Where_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
WHERE id = #{knowledgeId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- selectAllKnowledges(查询所有知识库,管理员使用) -->
|
||||
<select id="selectAllKnowledges" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_knowledge k
|
||||
WHERE k.deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND k.title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND k.category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND k.status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY k.create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- selectKnowledgesPage(分页查询知识库,带权限过滤) -->
|
||||
<select id="selectKnowledgesPage" resultMap="BaseResultMap">
|
||||
SELECT DISTINCT k.*
|
||||
FROM tb_ai_knowledge k
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY k.create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- countKnowledges(统计知识库总数,带权限过滤) -->
|
||||
<select id="countKnowledges" resultType="java.lang.Long">
|
||||
SELECT COUNT(DISTINCT k.id)
|
||||
FROM tb_ai_knowledge k
|
||||
<include refid="Permission_Filter"/>
|
||||
<include refid="Filter_Clause"/>
|
||||
</select>
|
||||
|
||||
<!-- findByDifyDatasetId(根据Dify数据集ID查询知识库) -->
|
||||
<select id="findByDifyDatasetId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_knowledge
|
||||
WHERE dify_dataset_id = #{difyDatasetId} AND deleted = 0
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
</mapper>
|
||||
|
||||
@@ -7,18 +7,25 @@
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="conversation_id" property="conversationID" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="agent_id" property="agentID" jdbcType="VARCHAR"/>
|
||||
<result column="role" property="role" jdbcType="VARCHAR"/>
|
||||
<result column="content" property="content" jdbcType="LONGVARCHAR"/>
|
||||
<result column="file_ids" property="fileIDs" jdbcType="VARCHAR"/>
|
||||
<result column="knowledge_ids" property="knowledgeIDs" jdbcType="VARCHAR"/>
|
||||
<result column="knowledge_refs" property="knowledgeRefs" jdbcType="LONGVARCHAR"/>
|
||||
<result column="token_count" property="tokenCount" jdbcType="INTEGER"/>
|
||||
<result column="dify_message_id" property="difyMessageId" jdbcType="VARCHAR"/>
|
||||
<result column="rating" property="rating" jdbcType="INTEGER"/>
|
||||
<result column="feedback" property="feedback" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, conversation_id, user_id, role, content, file_ids, knowledge_ids,
|
||||
token_count, create_time
|
||||
id, conversation_id, user_id, agent_id, role, content, file_ids, knowledge_ids,
|
||||
knowledge_refs, token_count, dify_message_id, rating, feedback,
|
||||
create_time, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
@@ -36,12 +43,130 @@
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- 插入消息 -->
|
||||
<insert id="insertMessage" parameterType="org.xyzh.common.dto.ai.TbAiMessage">
|
||||
INSERT INTO tb_ai_message (
|
||||
id, conversation_id, user_id, agent_id, role, content,
|
||||
file_ids, knowledge_ids, knowledge_refs, token_count,
|
||||
dify_message_id, rating, feedback, create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{ID}, #{conversationID}, #{userID}, #{agentID}, #{role}, #{content},
|
||||
#{fileIDs}, #{knowledgeIDs}, #{knowledgeRefs}, #{tokenCount},
|
||||
#{difyMessageId}, #{rating}, #{feedback}, #{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- 更新消息(动态更新非null字段) -->
|
||||
<update id="updateMessage" parameterType="org.xyzh.common.dto.ai.TbAiMessage">
|
||||
UPDATE tb_ai_message
|
||||
<set>
|
||||
<if test="content != null">content = #{content},</if>
|
||||
<if test="fileIDs != null">file_ids = #{fileIDs},</if>
|
||||
<if test="knowledgeIDs != null">knowledge_ids = #{knowledgeIDs},</if>
|
||||
<if test="knowledgeRefs != null">knowledge_refs = #{knowledgeRefs},</if>
|
||||
<if test="tokenCount != null">token_count = #{tokenCount},</if>
|
||||
<if test="difyMessageId != null">dify_message_id = #{difyMessageId},</if>
|
||||
<if test="rating != null">rating = #{rating},</if>
|
||||
<if test="feedback != null">feedback = #{feedback},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 逻辑删除消息 -->
|
||||
<update id="deleteMessage" parameterType="org.xyzh.common.dto.ai.TbAiMessage">
|
||||
UPDATE tb_ai_message
|
||||
SET deleted = 1,
|
||||
delete_time = NOW()
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- 根据ID查询消息 -->
|
||||
<select id="selectMessageById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_message
|
||||
WHERE id = #{messageId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 根据会话ID查询消息列表(按时间正序) -->
|
||||
<select id="selectMessagesByConversationId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_message
|
||||
WHERE conversation_id = #{conversationId}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 统计会话的消息数量 -->
|
||||
<select id="countConversationMessages" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_message
|
||||
WHERE conversation_id = #{conversationId}
|
||||
AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 查询会话的最后一条消息 -->
|
||||
<select id="selectLastMessage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_message
|
||||
WHERE conversation_id = #{conversationId}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
LIMIT 1
|
||||
</select>
|
||||
|
||||
<!-- 搜索消息内容(全文搜索) -->
|
||||
<select id="searchMessagesByContent" resultMap="BaseResultMap">
|
||||
SELECT m.*
|
||||
FROM tb_ai_message m
|
||||
INNER JOIN tb_ai_conversation c ON m.conversation_id = c.id
|
||||
WHERE c.user_id = #{userId}
|
||||
AND m.content LIKE CONCAT('%', #{keyword}, '%')
|
||||
<if test="conversationId != null and conversationId != ''">
|
||||
AND m.conversation_id = #{conversationId}
|
||||
</if>
|
||||
AND m.deleted = 0
|
||||
AND c.deleted = 0
|
||||
ORDER BY m.create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- 统计搜索消息数量 -->
|
||||
<select id="countSearchMessages" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_message m
|
||||
INNER JOIN tb_ai_conversation c ON m.conversation_id = c.id
|
||||
WHERE c.user_id = #{userId}
|
||||
AND m.content LIKE CONCAT('%', #{keyword}, '%')
|
||||
<if test="conversationId != null and conversationId != ''">
|
||||
AND m.conversation_id = #{conversationId}
|
||||
</if>
|
||||
AND m.deleted = 0
|
||||
AND c.deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- 统计会话的评分分布 -->
|
||||
<select id="countMessageRatings" resultType="java.util.HashMap">
|
||||
SELECT
|
||||
rating,
|
||||
COUNT(1) as count
|
||||
FROM tb_ai_message
|
||||
WHERE conversation_id = #{conversationId}
|
||||
AND rating IS NOT NULL
|
||||
AND deleted = 0
|
||||
GROUP BY rating
|
||||
</select>
|
||||
|
||||
<!-- selectAiMessages -->
|
||||
<select id="selectAiMessages" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_message
|
||||
<include refid="Where_Clause"/>
|
||||
AND deleted = 0
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiUploadFile">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="knowledge_id" property="knowledgeId" jdbcType="VARCHAR"/>
|
||||
<result column="conversation_id" property="conversationID" jdbcType="VARCHAR"/>
|
||||
<result column="file_name" property="fileName" jdbcType="VARCHAR"/>
|
||||
<result column="file_path" property="filePath" jdbcType="VARCHAR"/>
|
||||
@@ -13,44 +14,175 @@
|
||||
<result column="file_type" property="fileType" jdbcType="VARCHAR"/>
|
||||
<result column="mime_type" property="mimeType" jdbcType="VARCHAR"/>
|
||||
<result column="extracted_text" property="extractedText" jdbcType="LONGVARCHAR"/>
|
||||
<result column="dify_document_id" property="difyDocumentId" jdbcType="VARCHAR"/>
|
||||
<result column="dify_batch_id" property="difyBatchId" jdbcType="VARCHAR"/>
|
||||
<result column="vector_status" property="vectorStatus" jdbcType="INTEGER"/>
|
||||
<result column="chunk_count" property="chunkCount" jdbcType="INTEGER"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="error_message" property="errorMessage" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="updater" property="updater" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, conversation_id, file_name, file_path, file_size,
|
||||
file_type, mime_type, extracted_text, status, create_time, update_time
|
||||
id, user_id, knowledge_id, conversation_id, file_name, file_path, file_size,
|
||||
file_type, mime_type, extracted_text, dify_document_id, dify_batch_id,
|
||||
vector_status, chunk_count, status, error_message, creator, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
<sql id="Where_Clause">
|
||||
<sql id="Filter_Clause">
|
||||
<where>
|
||||
<if test="userID != null and userID != ''">
|
||||
AND user_id = #{userID}
|
||||
</if>
|
||||
<if test="conversationID != null and conversationID != ''">
|
||||
AND conversation_id = #{conversationID}
|
||||
</if>
|
||||
<if test="fileName != null and fileName != ''">
|
||||
AND file_name LIKE CONCAT('%', #{fileName}, '%')
|
||||
</if>
|
||||
<if test="fileType != null and fileType != ''">
|
||||
AND file_type = #{fileType}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
deleted = 0
|
||||
<if test="filter != null">
|
||||
<if test="filter.userID != null and filter.userID != ''">
|
||||
AND user_id = #{filter.userID}
|
||||
</if>
|
||||
<if test="filter.knowledgeId != null and filter.knowledgeId != ''">
|
||||
AND knowledge_id = #{filter.knowledgeId}
|
||||
</if>
|
||||
<if test="filter.conversationID != null and filter.conversationID != ''">
|
||||
AND conversation_id = #{filter.conversationID}
|
||||
</if>
|
||||
<if test="filter.fileName != null and filter.fileName != ''">
|
||||
AND file_name LIKE CONCAT('%', #{filter.fileName}, '%')
|
||||
</if>
|
||||
<if test="filter.fileType != null and filter.fileType != ''">
|
||||
AND file_type = #{filter.fileType}
|
||||
</if>
|
||||
<if test="filter.vectorStatus != null">
|
||||
AND vector_status = #{filter.vectorStatus}
|
||||
</if>
|
||||
<if test="filter.status != null">
|
||||
AND status = #{filter.status}
|
||||
</if>
|
||||
</if>
|
||||
</where>
|
||||
</sql>
|
||||
|
||||
<!-- selectAiUploadFiles -->
|
||||
<!-- insertUploadFile(插入文件记录) -->
|
||||
<insert id="insertUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
||||
INSERT INTO tb_ai_upload_file (
|
||||
id, user_id, knowledge_id, conversation_id, file_name, file_path, file_size,
|
||||
file_type, mime_type, extracted_text, dify_document_id, dify_batch_id,
|
||||
vector_status, chunk_count, status, error_message, creator, updater,
|
||||
create_time, update_time, deleted
|
||||
) VALUES (
|
||||
#{ID}, #{userID}, #{knowledgeId}, #{conversationID}, #{fileName}, #{filePath}, #{fileSize},
|
||||
#{fileType}, #{mimeType}, #{extractedText}, #{difyDocumentId}, #{difyBatchId},
|
||||
#{vectorStatus}, #{chunkCount}, #{status}, #{errorMessage}, #{creator}, #{updater},
|
||||
#{createTime}, #{updateTime}, #{deleted}
|
||||
)
|
||||
</insert>
|
||||
|
||||
<!-- updateUploadFile(更新文件记录) -->
|
||||
<update id="updateUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
||||
UPDATE tb_ai_upload_file
|
||||
<set>
|
||||
<if test="userID != null">user_id = #{userID},</if>
|
||||
<if test="knowledgeId != null">knowledge_id = #{knowledgeId},</if>
|
||||
<if test="conversationID != null">conversation_id = #{conversationID},</if>
|
||||
<if test="fileName != null">file_name = #{fileName},</if>
|
||||
<if test="filePath != null">file_path = #{filePath},</if>
|
||||
<if test="fileSize != null">file_size = #{fileSize},</if>
|
||||
<if test="fileType != null">file_type = #{fileType},</if>
|
||||
<if test="mimeType != null">mime_type = #{mimeType},</if>
|
||||
<if test="extractedText != null">extracted_text = #{extractedText},</if>
|
||||
<if test="difyDocumentId != null">dify_document_id = #{difyDocumentId},</if>
|
||||
<if test="difyBatchId != null">dify_batch_id = #{difyBatchId},</if>
|
||||
<if test="vectorStatus != null">vector_status = #{vectorStatus},</if>
|
||||
<if test="chunkCount != null">chunk_count = #{chunkCount},</if>
|
||||
<if test="status != null">status = #{status},</if>
|
||||
<if test="errorMessage != null">error_message = #{errorMessage},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
<if test="updateTime != null">update_time = #{updateTime},</if>
|
||||
</set>
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- deleteUploadFile(逻辑删除文件记录) -->
|
||||
<update id="deleteUploadFile" parameterType="org.xyzh.common.dto.ai.TbAiUploadFile">
|
||||
UPDATE tb_ai_upload_file
|
||||
SET deleted = 1,
|
||||
delete_time = NOW(),
|
||||
updater = #{updater}
|
||||
WHERE id = #{ID} AND deleted = 0
|
||||
</update>
|
||||
|
||||
<!-- selectUploadFileById(根据ID查询文件) -->
|
||||
<select id="selectUploadFileById" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_upload_file
|
||||
WHERE id = #{fileId} AND deleted = 0
|
||||
</select>
|
||||
|
||||
<!-- selectAllUploadFiles(查询所有文件) -->
|
||||
<select id="selectAllUploadFiles" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_upload_file
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- selectFilesByKnowledgeId(根据知识库ID查询文件列表) -->
|
||||
<select id="selectFilesByKnowledgeId" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_upload_file
|
||||
WHERE knowledge_id = #{knowledgeId}
|
||||
AND deleted = 0
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<!-- selectUploadFilesPage(分页查询文件) -->
|
||||
<select id="selectUploadFilesPage" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_upload_file
|
||||
<include refid="Filter_Clause"/>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.offset}, #{pageParam.pageSize}
|
||||
</select>
|
||||
|
||||
<!-- countUploadFiles(统计文件总数) -->
|
||||
<select id="countUploadFiles" resultType="java.lang.Long">
|
||||
SELECT COUNT(1)
|
||||
FROM tb_ai_upload_file
|
||||
<include refid="Filter_Clause"/>
|
||||
</select>
|
||||
|
||||
<!-- selectAiUploadFiles(原有方法保留兼容性) -->
|
||||
<select id="selectAiUploadFiles" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM tb_ai_upload_file
|
||||
<include refid="Where_Clause"/>
|
||||
WHERE deleted = 0
|
||||
<if test="userID != null and userID != ''">
|
||||
AND user_id = #{userID}
|
||||
</if>
|
||||
<if test="knowledgeId != null and knowledgeId != ''">
|
||||
AND knowledge_id = #{knowledgeId}
|
||||
</if>
|
||||
<if test="conversationID != null and conversationID != ''">
|
||||
AND conversation_id = #{conversationID}
|
||||
</if>
|
||||
<if test="fileName != null and fileName != ''">
|
||||
AND file_name LIKE CONCAT('%', #{fileName}, '%')
|
||||
</if>
|
||||
<if test="fileType != null and fileType != ''">
|
||||
AND file_type = #{fileType}
|
||||
</if>
|
||||
<if test="status != null">
|
||||
AND status = #{status}
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
|
||||
@@ -6,19 +6,21 @@
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiUsageStatistics">
|
||||
<id column="id" property="id" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userID" jdbcType="VARCHAR"/>
|
||||
<result column="agent_id" property="agentID" jdbcType="VARCHAR"/>
|
||||
<result column="stat_date" property="statDate" jdbcType="DATE"/>
|
||||
<result column="conversation_count" property="conversationCount" jdbcType="INTEGER"/>
|
||||
<result column="message_count" property="messageCount" jdbcType="INTEGER"/>
|
||||
<result column="total_tokens" property="totalTokens" jdbcType="INTEGER"/>
|
||||
<result column="file_count" property="fileCount" jdbcType="INTEGER"/>
|
||||
<result column="knowledge_query_count" property="knowledgeQueryCount" jdbcType="INTEGER"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, user_id, stat_date, conversation_count, message_count,
|
||||
total_tokens, file_count, create_time, update_time
|
||||
id, user_id, agent_id, stat_date, conversation_count, message_count,
|
||||
total_tokens, file_count, knowledge_query_count, create_time, update_time
|
||||
</sql>
|
||||
|
||||
<!-- 通用条件 -->
|
||||
@@ -27,6 +29,9 @@
|
||||
<if test="userID != null and userID != ''">
|
||||
AND user_id = #{userID}
|
||||
</if>
|
||||
<if test="agentID != null and agentID != ''">
|
||||
AND agent_id = #{agentID}
|
||||
</if>
|
||||
<if test="statDate != null">
|
||||
AND stat_date = #{statDate}
|
||||
</if>
|
||||
|
||||
Reference in New Issue
Block a user