<?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.AiivhMakeBroadcastTaskMapper">

    <sql id="includeAiivhMakeBroadcastCustom">
        id,
        user_id,
        request_id,
        task_id,
        virtualman_key,
        title,
        driver_type,
        task_status,
        COALESCE(result_media_url, '') result_media_url,
        create_time,
        update_time
    </sql>
    <sql id="includeAiivhMakeBroadcastCustomDetail">
        id,
        user_id,
        request_id,
        task_id,
        virtualman_key,
        title,
        COALESCE(driver_type, '') driver_type,
        COALESCE(input_ssml, '') input_ssml,
        COALESCE(input_audio_url, '') input_audio_url,

        speech_speed,
        COALESCE(input_audio_url, '') input_audio_url,
        COALESCE(speech_timbre_key, '') speech_timbre_key,
        COALESCE(speech_volume, '') speech_volume,

        COALESCE(video_format, '') video_format,
        COALESCE(video_background_file_url, '') video_background_file_url,
        COALESCE(video_head_file_url, '') video_head_file_url,
        COALESCE(video_tail_file_url, '') video_tail_file_url,
        COALESCE(video_show_subtitles, '') video_show_subtitles,

        COALESCE(video_logo_file_url, '') video_logo_file_url,
        COALESCE(video_logo_position_x, '') video_logo_position_x,
        COALESCE(video_logo_position_y, '') video_logo_position_y,
        COALESCE(video_logo_scale, '') video_logo_scale,

        COALESCE(video_anchor_horizontal_position, '') video_anchor_horizontal_position,
        COALESCE(video_anchor_horizontal_position_x, '') video_anchor_horizontal_position_x,
        COALESCE(video_anchor_vertical_position, '') video_anchor_vertical_position,
        COALESCE(video_anchor_vertical_position_y, '') video_anchor_vertical_position_y,
        COALESCE(video_anchor_scale, '') video_anchor_scale,
        COALESCE(video_smart_action_enabled, '') video_smart_action_enabled,

        task_status,
        COALESCE(task_reason, '') task_reason,
        COALESCE(result_media_url, '') result_media_url,
        COALESCE(result_subitles_url, '') result_subitles_url,

        create_time,
        update_time
    </sql>

    <resultMap id="resultMapAiivhMakeBroadcastCustom" 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="title" column="title" />
        <result property="driver_type" column="driver_type" />
        <result property="task_status" column="task_status" />
        <result property="result_media_url" column="result_media_url" />
        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>
    <resultMap id="resultMapAiivhMakeBroadcastCustomDetail" 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="title" column="title" />
        <result property="driver_type" column="driver_type" />
        <result property="input_ssml" column="input_ssml" />
        <result property="input_audio_url" column="input_audio_url" />

        <result property="speech_speed" column="speech_speed" javaType="java.lang.Float" />
        <result property="speech_timbre_key" column="speech_timbre_key" />
        <result property="speech_volume" column="speech_volume" javaType="java.lang.Integer" />

        <result property="video_format" column="video_format" />
        <result property="video_background_file_url" column="video_background_file_url" />
        <result property="video_head_file_url" column="video_head_file_url" />
        <result property="video_tail_file_url" column="video_tail_file_url" />
        <result property="video_show_subtitles" column="video_show_subtitles" javaType="java.lang.Integer"/>

        <result property="video_logo_file_url" column="video_logo_file_url" />
        <result property="video_logo_position_x" column="video_logo_position_x" javaType="java.lang.Integer"/>
        <result property="video_logo_position_y" column="video_logo_position_y" javaType="java.lang.Integer"/>
        <result property="video_logo_scale" column="video_logo_scale" javaType="java.lang.Float"/>

        <result property="video_anchor_horizontal_position" column="video_anchor_horizontal_position" javaType="java.lang.Float"/>
        <result property="video_anchor_horizontal_position_x" column="video_anchor_horizontal_position_x" javaType="java.lang.Float"/>
        <result property="video_anchor_vertical_position" column="video_anchor_vertical_position" javaType="java.lang.Float"/>
        <result property="video_anchor_vertical_position_y" column="video_anchor_vertical_position_y" javaType="java.lang.Float"/>
        <result property="video_anchor_scale" column="video_anchor_scale" javaType="java.lang.Float"/>

        <result property="video_smart_action_enabled" column="video_smart_action_enabled" javaType="java.lang.Integer"/>

        <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_subitles_url" column="result_subitles_url" />

        <result property="create_time" column="create_time" />
        <result property="update_time" column="update_time" />
    </resultMap>

    <select id="queryAiivhMakeBroadcastTaskList" resultMap="resultMapAiivhMakeBroadcastCustom">
        SELECT <include refid="includeAiivhMakeBroadcastCustom" />
        FROM ai_ivh_make_broadcast_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="driver_type != null and driver_type != ''">
                AND driver_type = #{driver_type}
            </if>
            <if test="task_status != null and task_status != ''">
                AND task_status = #{task_status}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    <select id="queryAiivhMakeBroadcastTaskDetail" resultMap="resultMapAiivhMakeBroadcastCustomDetail">
        SELECT <include refid="includeAiivhMakeBroadcastCustomDetail" />
        FROM ai_ivh_make_broadcast_task
        WHERE task_id = #{task_id}
    </select>
<!--    <where>-->
<!--        task_id = #{task_id}-->
<!--        <if test="user_id != null and user_id != ''">-->
<!--            AND user_id = #{user_id}-->
<!--        </if>-->
<!--    </where>-->



    <!-- 批量插入 (腾讯-数智人-个人资产管理-分页查询音色列表) -->
    <insert id="insertAiivhMakeBroadcast" parameterType="java.util.LinkedHashMap"
        useGeneratedKeys="true" keyProperty="task_id">
        INSERT INTO ai_ivh_make_broadcast_task (
            user_id, request_id, task_id, virtualman_key, title
            <if test="driver_type != null and driver_type != ''">, driver_type</if>
            <if test="input_ssml != null and input_ssml != ''">, input_ssml</if>
            <if test="speech_speed != null and speech_speed != ''">, speech_speed</if>
            <if test="speech_timbre_key != null and speech_timbre_key != ''">, speech_timbre_key</if>
            <if test="speech_volume != null and speech_volume != ''">, speech_volume</if>
            <if test="video_format != null and video_format != ''">, video_format</if>
            <if test="video_background_file_url != null and video_background_file_url != ''">, video_background_file_url</if>
            <if test="video_head_file_url != null and video_head_file_url != ''">, video_head_file_url</if>
            <if test="video_tail_file_url != null and video_tail_file_url != ''">, video_tail_file_url</if>
            <if test="video_show_subtitles != null and video_show_subtitles != ''">, video_show_subtitles</if>
            <if test="video_logo_file_url != null and video_logo_file_url != ''">, video_logo_file_url</if>
            <if test="video_logo_position_x != null and video_logo_position_x != ''">, video_logo_position_x</if>
            <if test="video_logo_position_y != null and video_logo_position_y != ''">, video_logo_position_y</if>
            <if test="video_logo_scale != null and video_logo_scale != ''">, video_logo_scale</if>
            <if test="video_anchor_horizontal_position != null and video_anchor_horizontal_position != ''">, video_anchor_horizontal_position</if>
            <if test="video_anchor_horizontal_position_x != null and video_anchor_horizontal_position_x != ''">, video_anchor_horizontal_position_x</if>
            <if test="video_anchor_vertical_position != null and video_anchor_vertical_position != ''">, video_anchor_vertical_position</if>
            <if test="video_anchor_vertical_position_y != null and video_anchor_vertical_position_y != ''">, video_anchor_vertical_position_y</if>
            <if test="video_anchor_scale != null and video_anchor_scale != ''">, video_anchor_scale</if>
            <if test="video_smart_action_enabled != null and video_smart_action_enabled != ''">, video_smart_action_enabled</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}, #{virtualman_key}, #{title}
            <if test="driver_type != null and driver_type != ''">, #{driver_type}</if>
            <if test="input_ssml != null and input_ssml != ''">, #{input_ssml}</if>
            <if test="speech_speed != null and speech_speed != ''">, #{speech_speed}</if>
            <if test="speech_timbre_key != null and speech_timbre_key != ''">, #{speech_timbre_key}</if>
            <if test="speech_volume != null and speech_volume != ''">, #{speech_volume}</if>
            <if test="video_format != null and video_format != ''">, #{video_format}</if>
            <if test="video_background_file_url != null and video_background_file_url != ''">, #{video_background_file_url}</if>
            <if test="video_head_file_url != null and video_head_file_url != ''">, #{video_head_file_url}</if>
            <if test="video_tail_file_url != null and video_tail_file_url != ''">, #{video_tail_file_url}</if>
            <if test="video_show_subtitles != null and video_show_subtitles != ''">, #{video_show_subtitles}</if>
            <if test="video_logo_file_url != null and video_logo_file_url != ''">, #{video_logo_file_url}</if>
            <if test="video_logo_position_x != null and video_logo_position_x != ''">, #{video_logo_position_x}</if>
            <if test="video_logo_position_y != null and video_logo_position_y != ''">, #{video_logo_position_y}</if>
            <if test="video_logo_scale != null and video_logo_scale != ''">, #{video_logo_scale}</if>
            <if test="video_anchor_horizontal_position != null and video_anchor_horizontal_position != ''">, #{video_anchor_horizontal_position}</if>
            <if test="video_anchor_horizontal_position_x != null and video_anchor_horizontal_position_x != ''">, #{video_anchor_horizontal_position_x}</if>
            <if test="video_anchor_vertical_position != null and video_anchor_vertical_position != ''">, #{video_anchor_vertical_position}</if>
            <if test="video_anchor_vertical_position_y != null and video_anchor_vertical_position_y != ''">, #{video_anchor_vertical_position_y}</if>
            <if test="video_anchor_scale != null and video_anchor_scale != ''">, #{video_anchor_scale}</if>
            <if test="video_smart_action_enabled != null and video_smart_action_enabled != ''">, #{video_smart_action_enabled}</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="updateAiivhMakeBroadcast" parameterType="java.util.LinkedHashMap"
        useGeneratedKeys="true" keyProperty="task_id">
        UPDATE ai_ivh_make_broadcast_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_subitles_url != null and result_subitles_url != ''">, result_subitles_url = #{result_subitles_url}</if>
        WHERE task_id = #{task_id}
    </update>

    <delete id="deleteAiivhMakeBroadcast">
        DELETE FROM ai_ivh_make_broadcast_task WHERE task_id = #{task_id};
    </delete>

</mapper>