wangzhibo
2026-08-30 c8515170fd399b4d2dfaebb59128d4674e58915e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?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="xiaozhi.modules.agent.dao.AiAgentChatHistoryDao">
  <resultMap id="BaseResultMap" type="xiaozhi.modules.agent.entity.AgentChatHistoryEntity">
    <!--@mbg.generated-->
    <!--@Table ai_agent_chat_history-->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="mac_address" jdbcType="VARCHAR" property="macAddress" />
    <result column="agent_id" jdbcType="VARCHAR" property="agentId" />
    <result column="session_id" jdbcType="VARCHAR" property="sessionId" />
    <result column="sort" jdbcType="BIGINT" property="sort" />
    <result column="chat_type" jdbcType="TINYINT" property="chatType" />
    <result column="content" jdbcType="VARCHAR" property="content" />
    <result column="audio" jdbcType="LONGVARCHAR" property="audio" />
    <result column="audio_url" jdbcType="VARCHAR" property="audioUrl" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, mac_address, agent_id, session_id, sort, chat_type, content, audio, audio_url, 
    created_at, updated_at
  </sql>
 
  <select id="getAudioIdsByAgentId" resultType="java.lang.String">
    SELECT DISTINCT audio_id
    FROM ai_agent_chat_history
    WHERE agent_id = #{agentId} AND audio_id IS NOT NULL
  </select>
 
  <delete id="deleteAudioByIds">
    DELETE FROM ai_agent_chat_audio
    WHERE id IN
    <foreach collection="audioIds" item="id" open="(" separator="," close=")">
      #{id}
    </foreach>
  </delete>
  
  <update id="deleteAudioIdByAgentId">
    UPDATE ai_agent_chat_history
    SET audio_id = NULL
    WHERE agent_id = #{agentId}
  </update>
 
  <delete id="deleteHistoryByAgentId">
    DELETE FROM ai_agent_chat_history 
    WHERE agent_id = #{agentId}
  </delete>
</mapper>