<?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.backendsys.mapper.Ai.Aiivh.AiivhMakeBroadcastAudioTaskMapper">

    <sql id="includeAiivhMakeBroadcastAudio">
        id,
        user_id,
        request_id,
        task_id,
        title,
        input_ssml,
        task_status,
        COALESCE(result_media_url, '') result_media_url,
        COALESCE(result_media_duration, '') result_media_duration,
        create_time,
        update_time
    </sql>
    <sql id="includeAiivhMakeBroadcastAudioDetail">
        id,
        user_id,
        request_id,
        task_id,
        virtualman_key,
        timbre_key,
        title,
        input_ssml,
        speed,
        task_status,
        COALESCE(task_reason, '') task_reason,
        COALESCE(result_media_url, '') result_media_url,
        COALESCE(result_media_duration, '') result_media_duration,
        COALESCE(result_subitles_url, '') result_subitles_url,
        create_time,
        update_time
    </sql>

    <resultMap id="resultMapAiivhMakeBroadcastAudio" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long"/>
        <result property="request_id" column="request_id" />
        <result property="task_id" column="task_id" />
        <result property="title" column="title" />
        <result property="input_ssml" column="input_ssml" />
        <result property="task_status" column="task_status" />
        <result property="result_media_url" column="result_media_url" />
        <result property="result_media_duration" column="result_media_duration" javaType="java.lang.Long"/>
        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>
    <resultMap id="resultMapAiivhMakeBroadcastAudioDetail" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long"/>
        <result property="request_id" column="request_id" />
        <result property="task_id" column="task_id" />
        <result property="virtualman_key" column="virtualman_key" />
        <result property="timbre_key" column="timbre_key" />
        <result property="speed" column="speed" javaType="java.lang.Float"/>
        <result property="title" column="title" />
        <result property="input_ssml" column="input_ssml" />
        <result property="task_status" column="task_status" />
        <result property="task_reason" column="task_reason" />
        <result property="result_media_url" column="result_media_url" />
        <result property="result_media_duration" column="result_media_duration" javaType="java.lang.Long"/>
        <result property="result_subitles_url" column="result_subitles_url" />
        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>

    <select id="queryAiivhMakeBroadcastAudioTask" resultMap="resultMapAiivhMakeBroadcastAudio">
        SELECT <include refid="includeAiivhMakeBroadcastAudio" />
        FROM ai_ivh_make_broadcast_audio_task
        <where>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="title != null and title != ''">
                AND title LIKE CONCAT('%', #{title}, '%')
            </if>
            <if test="task_id != null and task_id != ''">
                AND task_id = #{task_id}
            </if>
            <if test="task_status != null and task_status != ''">
                AND task_status = #{task_status}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    <select id="queryAiivhMakeBroadcastAudioTaskDetail" resultMap="resultMapAiivhMakeBroadcastAudioDetail">
        SELECT <include refid="includeAiivhMakeBroadcastAudioDetail" />
        FROM ai_ivh_make_broadcast_audio_task
        WHERE task_id = #{task_id}
    </select>

    <!-- 批量插入 (腾讯-数智人-个人资产管理-分页查询音色列表) -->
    <insert id="insertAiivhMakeBroadcastAudio" parameterType="java.util.LinkedHashMap"
        useGeneratedKeys="true" keyProperty="task_id">
        INSERT INTO ai_ivh_make_broadcast_audio_task (
            user_id, request_id, task_id, title, input_ssml
            <if test="virtualman_key != null and virtualman_key != ''">, virtualman_key</if>
            <if test="timbre_key != null and timbre_key != ''">, timbre_key</if>
            <if test="speed != null and speed != ''">, speed</if>
            <if test="task_status != null and task_status != ''">, task_status</if>
            <if test="task_reason != null and task_reason != ''">, task_reason</if>
        )
        VALUES (
            #{user_id}, #{request_id}, #{task_id}, #{title}, #{input_ssml}
            <if test="virtualman_key != null and virtualman_key != ''">, #{virtualman_key}</if>
            <if test="timbre_key != null and timbre_key != ''">, #{timbre_key}</if>
            <if test="speed != null and speed != ''">, #{speed}</if>
            <if test="task_status != null and task_status != ''">, #{task_status}</if>
            <if test="task_reason != null and task_reason != ''">, #{task_reason}</if>
        )
    </insert>
    <update id="updateAiivhMakeBroadcastAudio" parameterType="java.util.LinkedHashMap"
        useGeneratedKeys="true" keyProperty="task_id">
        UPDATE ai_ivh_make_broadcast_audio_task
        SET task_status = #{task_status}
        <if test="task_reason != null and task_reason != ''">, task_reason = #{task_reason}</if>
        <if test="result_media_url != null and result_media_url != ''">, result_media_url = #{result_media_url}</if>
        <if test="result_media_duration != null and result_media_duration != ''">, result_media_duration = #{result_media_duration}</if>
        <if test="result_subitles_url != null and result_subitles_url != ''">, result_subitles_url = #{result_subitles_url}</if>
        WHERE task_id = #{task_id}
    </update>

    <delete id="deleteAiivhMakeBroadcastAudio">
        DELETE FROM ai_ivh_make_broadcast_audio_task WHERE task_id = #{task_id};
    </delete>

</mapper>