2025-10-15 13:11:19 +08:00
|
|
|
<?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.AiAgentConfigMapper">
|
|
|
|
|
|
|
|
|
|
<!-- 基础结果映射 -->
|
|
|
|
|
<resultMap id="BaseResultMap" type="org.xyzh.common.dto.ai.TbAiAgentConfig">
|
|
|
|
|
<id column="id" property="id" jdbcType="VARCHAR"/>
|
|
|
|
|
<result column="name" property="name" jdbcType="VARCHAR"/>
|
|
|
|
|
<result column="avatar" property="avatar" jdbcType="VARCHAR"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
<result column="description" property="description" jdbcType="VARCHAR"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
<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"/>
|
2025-11-04 18:49:37 +08:00
|
|
|
<result column="dify_app_id" property="difyAppId" jdbcType="VARCHAR"/>
|
|
|
|
|
<result column="dify_api_key" property="difyApiKey" jdbcType="VARCHAR"/>
|
2025-10-15 13:11:19 +08:00
|
|
|
<result column="status" property="status" jdbcType="INTEGER"/>
|
|
|
|
|
<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">
|
2025-11-04 18:49:37 +08:00
|
|
|
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
|
2025-10-15 13:11:19 +08:00
|
|
|
</sql>
|
|
|
|
|
|
|
|
|
|
<!-- 通用条件 -->
|
|
|
|
|
<sql id="Where_Clause">
|
|
|
|
|
<where>
|
|
|
|
|
deleted = 0
|
|
|
|
|
<if test="name != null and name != ''">
|
|
|
|
|
AND name LIKE CONCAT('%', #{name}, '%')
|
|
|
|
|
</if>
|
|
|
|
|
<if test="modelName != null and modelName != ''">
|
|
|
|
|
AND model_name = #{modelName}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="modelProvider != null and modelProvider != ''">
|
|
|
|
|
AND model_provider = #{modelProvider}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="status != null">
|
|
|
|
|
AND status = #{status}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
</sql>
|
|
|
|
|
|
2025-11-04 18:49:37 +08:00
|
|
|
<!-- 插入智能体配置 -->
|
|
|
|
|
<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 (原有方法保留兼容性) -->
|
2025-10-15 13:11:19 +08:00
|
|
|
<select id="selectAiAgentConfigs" resultMap="BaseResultMap">
|
|
|
|
|
SELECT
|
|
|
|
|
<include refid="Base_Column_List"/>
|
|
|
|
|
FROM tb_ai_agent_config
|
|
|
|
|
<include refid="Where_Clause"/>
|
|
|
|
|
ORDER BY create_time DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
</mapper>
|