<?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.easyproject.service.mapper.aichat.BotConversationMapper">

    <resultMap type="BotConversation" id="BotConversationResult">
        <result property="id"    column="id"    />
        <result property="botId"    column="bot_id"    />
        <result property="conversationId"    column="conversation_id"    />
        <result property="conversationTile"    column="conversation_tile"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectBotConversationVo">
        select id, bot_id, conversation_id, conversation_tile, create_by, create_time, update_by, update_time, remark from bot_conversation
    </sql>

    <select id="selectBotConversationList" parameterType="BotConversation" resultMap="BotConversationResult">
        <include refid="selectBotConversationVo"/>
        <where>
            <if test="conversationId != null  and conversationId != ''"> and conversation_id like concat('%', #{conversationId}, '%')</if>
            <if test="conversationTile != null  and conversationTile != ''"> and conversation_tile like concat('%', #{conversationTile}, '%')</if>
            <if test="params.beginCreateTime != null and params.beginCreateTime != '' and params.endCreateTime != null and params.endCreateTime != ''"> and create_time between #{params.beginCreateTime} and #{params.endCreateTime}</if>
        </where>
        order by id desc
    </select>

    <select id="selectBotConversationById" parameterType="Long" resultMap="BotConversationResult">
        <include refid="selectBotConversationVo"/>
        where id = #{id}
    </select>

    <!--会话数量统计-->
    <select id="selectConversationNum" resultType="java.lang.Integer">
        SELECT
            count(*)
        FROM bot_conversation
            WHERE 1 = 1
        <if test="type == 1">
            AND DATE_FORMAT(create_time, '%Y-%m-%d') = DATE_FORMAT(NOW(), '%Y-%m-%d') <!-- 今日 -->
        </if>
    </select>

</mapper>
