ai模块
This commit is contained in:
@@ -5,18 +5,19 @@ server:
|
||||
# context-path: /urban-lifeline/agent # 微服务架构下,context-path由Gateway管理
|
||||
|
||||
# ================== Auth ====================
|
||||
urban-lifeline:
|
||||
auth:
|
||||
enabled: true
|
||||
whitelist:
|
||||
- /swagger-ui/**
|
||||
- /swagger-ui.html
|
||||
- /v3/api-docs/**
|
||||
- /webjars/**
|
||||
- /favicon.ico
|
||||
- /error
|
||||
- /actuator/health
|
||||
- /actuator/info
|
||||
auth:
|
||||
enabled: true
|
||||
gateway-mode: true
|
||||
whitelist:
|
||||
- /swagger-ui/**
|
||||
- /swagger-ui.html
|
||||
- /v3/api-docs/**
|
||||
- /webjars/**
|
||||
- /favicon.ico
|
||||
- /error
|
||||
- /actuator/health
|
||||
- /actuator/info
|
||||
- /ai/chat/* # AI对话,有非系统用户对话的接口,无登录状态
|
||||
|
||||
security:
|
||||
aes:
|
||||
|
||||
146
urbanLifelineServ/ai/src/main/resources/mapper/TbAgentMapper.xml
Normal file
146
urbanLifelineServ/ai/src/main/resources/mapper/TbAgentMapper.xml
Normal file
@@ -0,0 +1,146 @@
|
||||
<?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="org.xyzh.ai.mapper.TbAgentMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.ai.dto.TbAgent">
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="agent_id" property="agentId" jdbcType="VARCHAR"/>
|
||||
<result column="name" property="name" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" jdbcType="VARCHAR"/>
|
||||
<result column="link" property="link" jdbcType="VARCHAR"/>
|
||||
<result column="api_key" property="apiKey" jdbcType="VARCHAR"/>
|
||||
<result column="outer" property="outer" jdbcType="BOOLEAN"/>
|
||||
<result column="introduce" property="introduce" jdbcType="VARCHAR"/>
|
||||
<result column="prompt_cards" property="promptCards" jdbcType="OTHER" typeHandler="org.xyzh.ai.handler.PromptCardsTypeHandler"/>
|
||||
<result column="category" property="category" 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">
|
||||
optsn, agent_id, name, description, link, api_key, outer, introduce, prompt_cards,
|
||||
category, creator, updater, create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<insert id="insertAgent" parameterType="org.xyzh.api.ai.dto.TbAgent">
|
||||
INSERT INTO ai.tb_agent (
|
||||
optsn, agent_id, name, api_key, introduce, category
|
||||
<if test="outer !=null">, outer</if>
|
||||
<if test="description != null">, description</if>
|
||||
<if test="link != null">, link</if>
|
||||
<if test="promptCards != null">, prompt_cards</if>
|
||||
<if test="creator != null">, creator</if>
|
||||
) VALUES (
|
||||
#{optsn}, #{agentId}, #{name}, #{apiKey}, #{introduce}, #{category}
|
||||
<if test="outer !=null">, #{outer}</if>
|
||||
<if test="description != null">, #{description}</if>
|
||||
<if test="link != null">, #{link}</if>
|
||||
<if test="promptCards != null">, #{promptCards, typeHandler=org.xyzh.ai.handler.PromptCardsTypeHandler}</if>
|
||||
<if test="creator != null">, #{creator}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateAgent" parameterType="org.xyzh.api.ai.dto.TbAgent">
|
||||
UPDATE ai.tb_agent
|
||||
<set>
|
||||
<if test="name != null">name = #{name},</if>
|
||||
<if test="description != null">description = #{description},</if>
|
||||
<if test="link != null">link = #{link},</if>
|
||||
<if test="apiKey != null">api_key = #{apiKey},</if>
|
||||
<if test="outer != null">outer = #{outer},</if>
|
||||
<if test="introduce != null">introduce = #{introduce},</if>
|
||||
<if test="promptCards != null">prompt_cards = #{promptCards, typeHandler=org.xyzh.ai.handler.PromptCardsTypeHandler},</if>
|
||||
<if test="category != null">category = #{category},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = now()
|
||||
</set>
|
||||
WHERE agent_id = #{agentId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<update id="deleteAgent" parameterType="org.xyzh.api.ai.dto.TbAgent">
|
||||
UPDATE ai.tb_agent
|
||||
SET deleted = true,
|
||||
delete_time = now(),
|
||||
updater = #{updater}
|
||||
WHERE agent_id = #{agentId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectAgentById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_agent
|
||||
WHERE agent_id = #{agentId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectAgentByApiKey" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_agent
|
||||
WHERE api_key = #{apiKey} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectAgentList" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_agent
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectAgentPage" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_agent
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="countAgents" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_agent
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.name != null and filter.name != ''">
|
||||
AND name LIKE CONCAT('%', #{filter.name}, '%')
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="countByName" resultType="int">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_agent
|
||||
WHERE deleted = false AND name = #{name}
|
||||
<if test="excludeId != null and excludeId != ''">
|
||||
AND agent_id != #{excludeId}
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
103
urbanLifelineServ/ai/src/main/resources/mapper/TbChatMapper.xml
Normal file
103
urbanLifelineServ/ai/src/main/resources/mapper/TbChatMapper.xml
Normal file
@@ -0,0 +1,103 @@
|
||||
<?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="org.xyzh.ai.mapper.TbChatMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.ai.dto.TbChat">
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="chat_id" property="chatId" jdbcType="VARCHAR"/>
|
||||
<result column="agent_id" property="agentId" jdbcType="VARCHAR"/>
|
||||
<result column="user_id" property="userId" jdbcType="VARCHAR"/>
|
||||
<result column="user_type" property="userType" jdbcType="BOOLEAN"/>
|
||||
<result column="title" property="title" 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">
|
||||
optsn, chat_id, agent_id, user_id, user_type, title,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<insert id="insertChat" parameterType="org.xyzh.api.ai.dto.TbChat">
|
||||
INSERT INTO ai.tb_chat (
|
||||
optsn, chat_id, agent_id, user_id, title
|
||||
<if test="userType != null">, user_type</if>
|
||||
) VALUES (
|
||||
#{optsn}, #{chatId}, #{agentId}, #{userId}, #{title}
|
||||
<if test="userType != null">, #{userType}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateChat" parameterType="org.xyzh.api.ai.dto.TbChat">
|
||||
UPDATE ai.tb_chat
|
||||
<set>
|
||||
<if test="title != null">title = #{title},</if>
|
||||
update_time = now()
|
||||
</set>
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<update id="deleteChat" parameterType="org.xyzh.api.ai.dto.TbChat">
|
||||
UPDATE ai.tb_chat
|
||||
SET deleted = true,
|
||||
delete_time = now()
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectChatById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectChatList" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat
|
||||
WHERE deleted = false
|
||||
<if test="agentId != null and agentId != ''">
|
||||
AND agent_id = #{agentId}
|
||||
</if>
|
||||
<if test="userId != null and userId != ''">
|
||||
AND user_id = #{userId}
|
||||
</if>
|
||||
ORDER BY update_time DESC, create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectChatPage" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.agentId != null and filter.agentId != ''">
|
||||
AND agent_id = #{filter.agentId}
|
||||
</if>
|
||||
<if test="filter.userId != null and filter.userId != ''">
|
||||
AND user_id = #{filter.userId}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY update_time DESC, create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="countChats" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_chat
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.agentId != null and filter.agentId != ''">
|
||||
AND agent_id = #{filter.agentId}
|
||||
</if>
|
||||
<if test="filter.userId != null and filter.userId != ''">
|
||||
AND user_id = #{filter.userId}
|
||||
</if>
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,89 @@
|
||||
<?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="org.xyzh.ai.mapper.TbChatMessageMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.ai.dto.TbChatMessage">
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="message_id" property="messageId" jdbcType="VARCHAR"/>
|
||||
<result column="dify_message_id" property="difyMessageId" jdbcType="VARCHAR"/>
|
||||
<result column="chat_id" property="chatId" jdbcType="VARCHAR"/>
|
||||
<result column="role" property="role" jdbcType="VARCHAR"/>
|
||||
<result column="content" property="content" jdbcType="VARCHAR"/>
|
||||
<result column="files" property="files" jdbcType="ARRAY" typeHandler="org.xyzh.common.utils.json.StringArrayTypeHandler"/>
|
||||
<result column="comment" property="comment" 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">
|
||||
optsn, message_id, dify_message_id, chat_id, role, content, files, comment,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<insert id="insertChatMessage" parameterType="org.xyzh.api.ai.dto.TbChatMessage">
|
||||
INSERT INTO ai.tb_chat_message (
|
||||
optsn, message_id, chat_id, role, content
|
||||
<if test="difyMessageId != null">, dify_message_id</if>
|
||||
<if test="files != null">, files</if>
|
||||
<if test="comment != null">, comment</if>
|
||||
) VALUES (
|
||||
#{optsn}, #{messageId}, #{chatId}, #{role}, #{content}
|
||||
<if test="difyMessageId != null">, #{difyMessageId}</if>
|
||||
<if test="files != null">, #{files, typeHandler=org.xyzh.common.utils.json.StringArrayTypeHandler}</if>
|
||||
<if test="comment != null">, #{comment}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateChatMessage" parameterType="org.xyzh.api.ai.dto.TbChatMessage">
|
||||
UPDATE ai.tb_chat_message
|
||||
<set>
|
||||
<if test="content != null">content = #{content},</if>
|
||||
<if test="comment != null">comment = #{comment},</if>
|
||||
update_time = now()
|
||||
</set>
|
||||
WHERE message_id = #{messageId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<update id="deleteChatMessage" parameterType="org.xyzh.api.ai.dto.TbChatMessage">
|
||||
UPDATE ai.tb_chat_message
|
||||
SET deleted = true,
|
||||
delete_time = now()
|
||||
WHERE message_id = #{messageId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectMessageById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat_message
|
||||
WHERE message_id = #{messageId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectMessagesByChatId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat_message
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
<select id="selectMessagePage" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_chat_message
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
ORDER BY create_time ASC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="countMessages" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_chat_message
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<update id="deleteMessagesByChatId">
|
||||
UPDATE ai.tb_chat_message
|
||||
SET deleted = true,
|
||||
delete_time = now()
|
||||
WHERE chat_id = #{chatId} AND deleted = false
|
||||
</update>
|
||||
</mapper>
|
||||
@@ -0,0 +1,96 @@
|
||||
<?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="org.xyzh.ai.mapper.TbKnowledgeFileMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.ai.dto.TbKnowledgeFile">
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="knowledge_id" property="knowledgeId" jdbcType="VARCHAR"/>
|
||||
<result column="file_root_id" property="fileRootId" jdbcType="VARCHAR"/>
|
||||
<result column="file_id" property="fileId" jdbcType="VARCHAR"/>
|
||||
<result column="dify_file_id" property="difyFileId" jdbcType="VARCHAR"/>
|
||||
<result column="version" property="version" jdbcType="INTEGER"/>
|
||||
<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">
|
||||
optsn, knowledge_id, file_root_id, file_id, dify_file_id, version,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<insert id="insertKnowledgeFile" parameterType="org.xyzh.api.ai.dto.TbKnowledgeFile">
|
||||
INSERT INTO ai.tb_knowledge_file (
|
||||
optsn, knowledge_id, file_root_id, file_id, dify_file_id
|
||||
<if test="version != null">, version</if>
|
||||
) VALUES (
|
||||
#{optsn}, #{knowledgeId}, #{fileRootId}, #{fileId}, #{difyFileId}
|
||||
<if test="version != null">, #{version}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateKnowledgeFile" parameterType="org.xyzh.api.ai.dto.TbKnowledgeFile">
|
||||
UPDATE ai.tb_knowledge_file
|
||||
<set>
|
||||
<if test="difyFileId != null">dify_file_id = #{difyFileId},</if>
|
||||
<if test="version != null">version = #{version},</if>
|
||||
update_time = now()
|
||||
</set>
|
||||
WHERE knowledge_id = #{knowledgeId} AND file_id = #{fileId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<update id="deleteKnowledgeFile" parameterType="org.xyzh.api.ai.dto.TbKnowledgeFile">
|
||||
UPDATE ai.tb_knowledge_file
|
||||
SET deleted = true,
|
||||
delete_time = now()
|
||||
WHERE knowledge_id = #{knowledgeId} AND file_id = #{fileId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectKnowledgeFile" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE knowledge_id = #{knowledgeId} AND file_id = #{fileId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectFilesByKnowledgeId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectFileVersions" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE file_root_id = #{fileRootId} AND deleted = false
|
||||
ORDER BY version DESC
|
||||
</select>
|
||||
|
||||
<select id="selectFilePage" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="countFiles" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<update id="deleteFilesByRootId">
|
||||
UPDATE ai.tb_knowledge_file
|
||||
SET deleted = true,
|
||||
delete_time = now()
|
||||
WHERE file_root_id = #{fileRootId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectLatestVersion" resultType="java.lang.Integer">
|
||||
SELECT COALESCE(MAX(version), 0)
|
||||
FROM ai.tb_knowledge_file
|
||||
WHERE knowledge_id = #{knowledgeId} AND file_root_id = #{fileRootId}
|
||||
</select>
|
||||
</mapper>
|
||||
@@ -0,0 +1,198 @@
|
||||
<?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="org.xyzh.ai.mapper.TbKnowledgeMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="org.xyzh.api.ai.dto.TbKnowledge">
|
||||
<result column="optsn" property="optsn" jdbcType="VARCHAR"/>
|
||||
<result column="knowledge_id" property="knowledgeId" jdbcType="VARCHAR"/>
|
||||
<result column="title" property="title" jdbcType="VARCHAR"/>
|
||||
<result column="avatar" property="avatar" jdbcType="VARCHAR"/>
|
||||
<result column="description" property="description" 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="embedding_model_provider" property="embeddingModelProvider" jdbcType="VARCHAR"/>
|
||||
<result column="rerank_model" property="rerankModel" jdbcType="VARCHAR"/>
|
||||
<result column="rerank_model_provider" property="rerankModelProvider" jdbcType="VARCHAR"/>
|
||||
<result column="reranking_enable" property="rerankingEnable" jdbcType="INTEGER"/>
|
||||
<result column="retrieval_top_k" property="retrievalTopK" jdbcType="INTEGER"/>
|
||||
<result column="retrieval_score_threshold" property="retrievalScoreThreshold" jdbcType="DECIMAL"/>
|
||||
<result column="document_count" property="documentCount" jdbcType="INTEGER"/>
|
||||
<result column="total_chunks" property="totalChunks" jdbcType="INTEGER"/>
|
||||
<result column="service" property="service" jdbcType="VARCHAR"/>
|
||||
<result column="project_id" property="projectId" jdbcType="VARCHAR"/>
|
||||
<result column="category" property="category" jdbcType="VARCHAR"/>
|
||||
<result column="creator" property="creator" jdbcType="VARCHAR"/>
|
||||
<result column="dept_path" property="deptPath" 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">
|
||||
optsn, knowledge_id, title, avatar, description, dify_dataset_id,
|
||||
dify_indexing_technique, embedding_model, embedding_model_provider,
|
||||
rerank_model, rerank_model_provider, reranking_enable,
|
||||
retrieval_top_k, retrieval_score_threshold, document_count, total_chunks,
|
||||
service, project_id, category, creator, dept_path, updater,
|
||||
create_time, update_time, delete_time, deleted
|
||||
</sql>
|
||||
|
||||
<insert id="insertKnowledge" parameterType="org.xyzh.api.ai.dto.TbKnowledge">
|
||||
INSERT INTO ai.tb_knowledge (
|
||||
optsn, knowledge_id, title, creator
|
||||
<if test="avatar != null">, avatar</if>
|
||||
<if test="description != null">, description</if>
|
||||
<if test="difyDatasetId != null">, dify_dataset_id</if>
|
||||
<if test="difyIndexingTechnique != null">, dify_indexing_technique</if>
|
||||
<if test="embeddingModel != null">, embedding_model</if>
|
||||
<if test="embeddingModelProvider != null">, embedding_model_provider</if>
|
||||
<if test="rerankModel != null">, rerank_model</if>
|
||||
<if test="rerankModelProvider != null">, rerank_model_provider</if>
|
||||
<if test="rerankingEnable != null">, reranking_enable</if>
|
||||
<if test="retrievalTopK != null">, retrieval_top_k</if>
|
||||
<if test="retrievalScoreThreshold != null">, retrieval_score_threshold</if>
|
||||
<if test="service != null">, service</if>
|
||||
<if test="projectId != null">, project_id</if>
|
||||
<if test="category != null">, category</if>
|
||||
<if test="deptPath != null">, dept_path</if>
|
||||
) VALUES (
|
||||
#{optsn}, #{knowledgeId}, #{title}, #{creator}
|
||||
<if test="avatar != null">, #{avatar}</if>
|
||||
<if test="description != null">, #{description}</if>
|
||||
<if test="difyDatasetId != null">, #{difyDatasetId}</if>
|
||||
<if test="difyIndexingTechnique != null">, #{difyIndexingTechnique}</if>
|
||||
<if test="embeddingModel != null">, #{embeddingModel}</if>
|
||||
<if test="embeddingModelProvider != null">, #{embeddingModelProvider}</if>
|
||||
<if test="rerankModel != null">, #{rerankModel}</if>
|
||||
<if test="rerankModelProvider != null">, #{rerankModelProvider}</if>
|
||||
<if test="rerankingEnable != null">, #{rerankingEnable}</if>
|
||||
<if test="retrievalTopK != null">, #{retrievalTopK}</if>
|
||||
<if test="retrievalScoreThreshold != null">, #{retrievalScoreThreshold}</if>
|
||||
<if test="service != null">, #{service}</if>
|
||||
<if test="projectId != null">, #{projectId}</if>
|
||||
<if test="category != null">, #{category}</if>
|
||||
<if test="deptPath != null">, #{deptPath}</if>
|
||||
)
|
||||
</insert>
|
||||
|
||||
<update id="updateKnowledge" parameterType="org.xyzh.api.ai.dto.TbKnowledge">
|
||||
UPDATE ai.tb_knowledge
|
||||
<set>
|
||||
<if test="title != null">title = #{title},</if>
|
||||
<if test="avatar != null">avatar = #{avatar},</if>
|
||||
<if test="description != null">description = #{description},</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="embeddingModelProvider != null">embedding_model_provider = #{embeddingModelProvider},</if>
|
||||
<if test="rerankModel != null">rerank_model = #{rerankModel},</if>
|
||||
<if test="rerankModelProvider != null">rerank_model_provider = #{rerankModelProvider},</if>
|
||||
<if test="rerankingEnable != null">reranking_enable = #{rerankingEnable},</if>
|
||||
<if test="retrievalTopK != null">retrieval_top_k = #{retrievalTopK},</if>
|
||||
<if test="retrievalScoreThreshold != null">retrieval_score_threshold = #{retrievalScoreThreshold},</if>
|
||||
<if test="documentCount != null">document_count = #{documentCount},</if>
|
||||
<if test="totalChunks != null">total_chunks = #{totalChunks},</if>
|
||||
<if test="service != null">service = #{service},</if>
|
||||
<if test="projectId != null">project_id = #{projectId},</if>
|
||||
<if test="category != null">category = #{category},</if>
|
||||
<if test="updater != null">updater = #{updater},</if>
|
||||
update_time = now()
|
||||
</set>
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<update id="deleteKnowledge" parameterType="org.xyzh.api.ai.dto.TbKnowledge">
|
||||
UPDATE ai.tb_knowledge
|
||||
SET deleted = true,
|
||||
delete_time = now(),
|
||||
updater = #{updater}
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
</update>
|
||||
|
||||
<select id="selectKnowledgeById" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge
|
||||
WHERE knowledge_id = #{knowledgeId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectKnowledgeByDifyId" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge
|
||||
WHERE dify_dataset_id = #{difyDatasetId} AND deleted = false
|
||||
</select>
|
||||
|
||||
<select id="selectKnowledgeList" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.service != null and filter.service != ''">
|
||||
AND service = #{filter.service}
|
||||
</if>
|
||||
<if test="filter.projectId != null and filter.projectId != ''">
|
||||
AND project_id = #{filter.projectId}
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
</select>
|
||||
|
||||
<select id="selectKnowledgePage" resultMap="BaseResultMap">
|
||||
SELECT <include refid="Base_Column_List"/>
|
||||
FROM ai.tb_knowledge
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.service != null and filter.service != ''">
|
||||
AND service = #{filter.service}
|
||||
</if>
|
||||
<if test="filter.projectId != null and filter.projectId != ''">
|
||||
AND project_id = #{filter.projectId}
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
ORDER BY create_time DESC
|
||||
LIMIT #{pageParam.pageSize} OFFSET #{pageParam.offset}
|
||||
</select>
|
||||
|
||||
<select id="countKnowledges" resultType="long">
|
||||
SELECT COUNT(*)
|
||||
FROM ai.tb_knowledge
|
||||
WHERE deleted = false
|
||||
<if test="filter != null">
|
||||
<if test="filter.title != null and filter.title != ''">
|
||||
AND title LIKE CONCAT('%', #{filter.title}, '%')
|
||||
</if>
|
||||
<if test="filter.service != null and filter.service != ''">
|
||||
AND service = #{filter.service}
|
||||
</if>
|
||||
<if test="filter.projectId != null and filter.projectId != ''">
|
||||
AND project_id = #{filter.projectId}
|
||||
</if>
|
||||
<if test="filter.category != null and filter.category != ''">
|
||||
AND category = #{filter.category}
|
||||
</if>
|
||||
<if test="filter.creator != null and filter.creator != ''">
|
||||
AND creator = #{filter.creator}
|
||||
</if>
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user