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

    <sql id="includeAiivhMakeVirtualmanTask">
        id,
        user_id,
        request_id,
        task_id,
        COALESCE(quota_code, '') quota_code,

        anchor_name,
        anchor_name_view,
        make_type,
        COALESCE(identity_cos_url, '') identity_cos_url,
        COALESCE(identity_written_cos_url, '') identity_written_cos_url,
        material_cos_url,
        is_remove_background,
        sex_type,

        task_status,
        COALESCE(task_status_info, '') task_status_info,
        stage_status,
        COALESCE(stage_status_info, '') stage_status_info,
        confirm_status,
        COALESCE(confirm_status_info, '') confirm_status_info,

        COALESCE(tencent_order_code, '') tencent_order_code,
        COALESCE(launch_note, '') launch_note,

        create_time,
        update_time
    </sql>
    <sql id="includeAiivhMakeVirtualmanTaskDetail">
        id,
        user_id,
        request_id,
        task_id,
        COALESCE(quota_code, '') quota_code,

        anchor_name,
        anchor_name_view,
        make_type,
        COALESCE(identity_cos_url, '') identity_cos_url,
        COALESCE(identity_written_cos_url, '') identity_written_cos_url,
        material_cos_url,
        is_remove_background,
        sex_type,
        COALESCE(notes, '') notes,
        COALESCE(text_driver, '') text_driver,
        COALESCE(voice_driver_cos_file, '') voice_driver_cos_file,

        task_status,
        COALESCE(task_status_info, '') task_status_info,
        stage_status,
        COALESCE(stage_status_info, '') stage_status_info,
        confirm_status,
        COALESCE(confirm_status_info, '') confirm_status_info,
        COALESCE(result, '') result,

        COALESCE(tencent_order_code, '') tencent_order_code,
        COALESCE(launch_note, '') launch_note,

        create_time,
        update_time
    </sql>
    <resultMap id="resultMapAiivhMakeVirtualmanTask" 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="quota_code" column="quota_code" />

        <result property="anchor_name" column="anchor_name" />
        <result property="anchor_name_view" column="anchor_name_view" />
        <result property="make_type" column="make_type" />
        <result property="identity_cos_url" column="identity_cos_url" />
        <result property="identity_written_cos_url" column="identity_written_cos_url" />
        <result property="material_cos_url" column="material_cos_url" />
        <result property="is_remove_background" column="is_remove_background" javaType="java.lang.Integer" />
        <result property="sex_type" column="sex_type" />

        <result property="task_status" column="task_status" />
        <result property="task_status_info" column="task_status_info" />
        <result property="stage_status" column="stage_status" />
        <result property="stage_status_info" column="stage_status_info" />
        <result property="confirm_status" column="confirm_status" />
        <result property="confirm_status_info" column="confirm_status_info" />

        <result property="tencent_order_code" column="tencent_order_code" />
        <result property="launch_note" column="launch_note" />

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

    <resultMap id="resultMapAiivhMakeVirtualmanTaskDetail" 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="quota_code" column="quota_code" />

        <result property="anchor_name" column="anchor_name" />
        <result property="anchor_name_view" column="anchor_name_view" />
        <result property="make_type" column="make_type" />
        <result property="identity_cos_url" column="identity_cos_url" />
        <result property="identity_written_cos_url" column="identity_written_cos_url" />
        <result property="material_cos_url" column="material_cos_url" />
        <result property="is_remove_background" column="is_remove_background" javaType="java.lang.Integer" />
        <result property="sex_type" column="sex_type" />
        <result property="notes" column="notes" />
        <result property="text_driver" column="text_driver" />
        <result property="voice_driver_cos_file" column="voice_driver_cos_file" />

        <result property="task_status" column="task_status" />
        <result property="task_status_info" column="task_status_info" />
        <result property="stage_status" column="stage_status" />
        <result property="stage_status_info" column="stage_status_info" />
        <result property="confirm_status" column="confirm_status" />
        <result property="confirm_status_info" column="confirm_status_info" />
        <result property="result" column="result" />

        <result property="tencent_order_code" column="tencent_order_code" />
        <result property="launch_note" column="launch_note" />

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



    <select id="queryAiivhMakeVirtualmanTaskList" resultMap="resultMapAiivhMakeVirtualmanTask">
        SELECT <include refid="includeAiivhMakeVirtualmanTask" />
        FROM ai_ivh_make_virtualman_task
        <where>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="request_id != null and request_id != ''">
                AND request_id = #{request_id}
            </if>
            <if test="task_id != null and task_id != ''">
                AND task_id = #{task_id}
            </if>
            <if test="quota_code != null and quota_code != ''">
                AND quota_code = #{quota_code}
            </if>
            <if test="anchor_name != null and anchor_name != ''">
                AND anchor_name LIKE CONCAT('%', #{anchor_name}, '%')
            </if>
            <if test="anchor_name_view != null and anchor_name_view != ''">
                AND anchor_name_view LIKE CONCAT('%', #{anchor_name_view}, '%')
            </if>
            <if test="make_type != null and make_type != ''">
                AND make_type = #{make_type}
            </if>
            <if test="sex_type != null and sex_type != ''">
                AND sex_type = #{sex_type}
            </if>
            <if test="task_status != null and task_status != ''">
                AND task_status = #{task_status}
            </if>
            <if test="stage_status != null and stage_status != ''">
                AND stage_status = #{stage_status}
            </if>
            <if test="confirm_status != null and confirm_status != ''">
                AND confirm_status = #{confirm_status}
            </if>
            <if test="tencent_order_code != null and tencent_order_code != ''">
                AND tencent_order_code = #{tencent_order_code}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <select id="queryAiivhMakeVirtualmanTaskDetail" resultMap="resultMapAiivhMakeVirtualmanTaskDetail">
        SELECT <include refid="includeAiivhMakeVirtualmanTaskDetail" />
        FROM ai_ivh_make_virtualman_task
        <where>
            <if test="id != null and id != ''">
                AND id = #{id}
            </if>
            <if test="task_id != null and task_id != ''">
                AND task_id = #{task_id}
            </if>
            <if test="quota_code != null and quota_code != ''">
                AND quota_code = #{quota_code}
            </if>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="tencent_order_code != null and tencent_order_code != ''">
                AND tencent_order_code = #{tencent_order_code}
            </if>
        </where>
    </select>

    <!-- 创建 -->
    <insert id="insertAiivhMakeVirtualmanTask" parameterType="com.backendsys.entity.Ai.Aiivh.AiPersonDTO"
        useGeneratedKeys="true" keyProperty="task_id">
        INSERT INTO ai_ivh_make_virtualman_task (
            user_id, request_id, task_id, quota_code, anchor_name, anchor_name_view, make_type, material_cos_url, sex_type
            <if test="identity_cos_url != null and identity_cos_url != ''">, identity_cos_url</if>
            <if test="identity_written_cos_url != null and identity_written_cos_url != ''">, identity_written_cos_url</if>
            <if test="is_remove_background != null and is_remove_background != ''">, is_remove_background</if>
            <if test="notes != null and notes != ''">, notes</if>
            <if test="text_driver != null and text_driver != ''">, text_driver</if>
            <if test="voice_driver_cos_file != null and voice_driver_cos_file != ''">, voice_driver_cos_file</if>
            <if test="tencent_order_code != null and tencent_order_code != ''">, tencent_order_code</if>
            <if test="launch_note != null and launch_note != ''">, launch_note</if>
        )
        VALUES (
            #{user_id}, #{request_id}, #{task_id}, #{quota_code}, #{anchor_name}, #{anchor_name_view}, #{make_type}, #{material_cos_url}, #{sex_type}
            <if test="identity_cos_url != null and identity_cos_url != ''">, #{identity_cos_url}</if>
            <if test="identity_written_cos_url != null and identity_written_cos_url != ''">, #{identity_written_cos_url}</if>
            <if test="is_remove_background != null and is_remove_background != ''">, #{is_remove_background}</if>
            <if test="notes != null and notes != ''">, #{notes}</if>
            <if test="text_driver != null and text_driver != ''">, #{text_driver}</if>
            <if test="voice_driver_cos_file != null and voice_driver_cos_file != ''">, #{voice_driver_cos_file}</if>
            <if test="tencent_order_code != null and tencent_order_code != ''">, #{tencent_order_code}</if>
            <if test="launch_note != null and launch_note != ''">, #{launch_note}</if>
        )
    </insert>

    <!-- 更新 -->
    <update id="updateAiivhMakeVirtualmanTask" parameterType="com.backendsys.entity.Ai.Aiivh.AiPersonDTO"
        useGeneratedKeys="true" keyProperty="task_id">
        UPDATE ai_ivh_make_virtualman_task
        SET task_id = #{task_id}
            <if test="quota_code != null and quota_code != ''">, quota_code = #{quota_code}</if>
            <if test="task_status != null and task_status != ''">, task_status = #{task_status}</if>
            <if test="stage_status != null and stage_status != ''">, stage_status = #{stage_status}</if>
            <if test="confirm_status != null and confirm_status != ''">, confirm_status = #{confirm_status}</if>
            <if test="task_status_info != null and task_status_info != ''">, task_status_info = #{task_status_info}</if>
            <if test="stage_status_info != null and stage_status_info != ''">, stage_status_info = #{stage_status_info}</if>
            <if test="confirm_status_info != null and confirm_status_info != ''">, confirm_status_info = #{confirm_status_info}</if>
            <if test="result != null and result != ''">, result = #{result}</if>
            <if test="tencent_order_code != null and tencent_order_code != ''">, tencent_order_code = #{tencent_order_code}</if>
            <if test="launch_note != null and launch_note != ''">, launch_note = #{launch_note}</if>
        WHERE task_id = #{task_id} AND user_id = #{user_id}
    </update>



    <!-- 定制 -> 新增临时记录 (在定制成功后插入一条记录，记录 {用户ID, 主播名称}，再根据 主播名称 来请求远程接口获得具体参数 -->
    <insert id="insertAiPersonVirtualmanCustom" parameterType="com.backendsys.entity.Ai.Aiivh.AiivhAnchorDTO"
        useGeneratedKeys="true" keyProperty="anchor_name">
        INSERT INTO ai_ivh_anchor (
        user_id, anchor_name, anchor_name_view
        <if test="stage_status != null and stage_status != ''">, stage_status</if>
        <if test="virtualman_key != null and virtualman_key != ''">, virtualman_key</if>
        <if test="anchor_code != null and anchor_code != ''">, anchor_code</if>
        <if test="header_image != null and header_image != ''">, header_image</if>
        <if test="resolution != null and resolution != ''">, resolution</if>
        <if test="pose_name != null and pose_name != ''">, pose_name</if>
        <if test="pose_image != null and pose_image != ''">, pose_image</if>
        <if test="clothes_name != null and clothes_name != ''">, clothes_name</if>
        <if test="clothes_image != null and clothes_image != ''">, clothes_image</if>
        <if test="expire_date != null and expire_date != ''">, expire_date</if>
        )
        VALUES (
        #{user_id}, #{anchor_name}, #{anchor_name_view}
        <if test="stage_status != null and stage_status != ''">, #{stage_status}</if>
        <if test="virtualman_key != null and virtualman_key != ''">, #{virtualman_key}</if>
        <if test="anchor_code != null and anchor_code != ''">, #{anchor_code}</if>
        <if test="header_image != null and header_image != ''">, #{header_image}</if>
        <if test="resolution != null and resolution != ''">, #{resolution}</if>
        <if test="pose_name != null and pose_name != ''">, #{pose_name}</if>
        <if test="pose_image != null and pose_image != ''">, #{pose_image}</if>
        <if test="clothes_name != null and clothes_name != ''">, #{clothes_name}</if>
        <if test="clothes_image != null and clothes_image != ''">, #{clothes_image}</if>
        <if test="expire_date != null and expire_date != ''">, #{expire_date}</if>
        )
    </insert>
    <update id="updateAiPersonVirtualmanCustom" parameterType="com.backendsys.entity.Ai.Aiivh.AiivhAnchorDTO"
            useGeneratedKeys="true" keyProperty="anchor_name">
        UPDATE ai_ivh_anchor
        SET stage_status = #{stage_status}
        <if test="virtualman_key != null and virtualman_key != ''">, virtualman_key = #{virtualman_key}</if>
        <if test="anchor_code != null and anchor_code != ''">, anchor_code = #{anchor_code}</if>
        <if test="header_image != null and header_image != ''">, header_image = #{header_image}</if>
        <if test="resolution != null and resolution != ''">, resolution = #{resolution}</if>
        <if test="pose_name != null and pose_name != ''">, pose_name = #{pose_name}</if>
        <if test="pose_image != null and pose_image != ''">, pose_image = #{pose_image}</if>
        <if test="clothes_name != null and clothes_name != ''">, clothes_name = #{clothes_name}</if>
        <if test="clothes_image != null and clothes_image != ''">, clothes_image = #{clothes_image}</if>
        <if test="expire_date != null and expire_date != ''">, expire_date = #{expire_date}</if>
        WHERE anchor_name = #{anchor_name}
    </update>



    <insert id="insertAiPersonTimbreCustom" parameterType="com.backendsys.entity.Ai.Aiivh.AiPersonTimbreCustomDTO"
            useGeneratedKeys="true" keyProperty="timbre_name">
        INSERT INTO ai_ivh_timbre (
        user_id, timbre_name, timbre_name_view
        <if test="stage_status != null and stage_status != ''">, stage_status</if>
        <if test="timbre_key != null and timbre_key != ''">, timbre_key</if>
        <if test="timbre_sample != null and timbre_sample != ''">, timbre_sample</if>
        <if test="timbre_desc != null and timbre_desc != ''">, timbre_desc</if>
        <if test="timbre_gender != null and timbre_gender != ''">, timbre_gender</if>
        <if test="expire_date != null and expire_date != ''">, expire_date</if>
        )
        VALUES (
        #{user_id}, #{timbre_name}, #{timbre_name_view}
        <if test="stage_status != null and stage_status != ''">, #{stage_status}</if>
        <if test="timbre_key != null and timbre_key != ''">, #{timbre_key}</if>
        <if test="timbre_sample != null and timbre_sample != ''">, #{timbre_sample}</if>
        <if test="timbre_desc != null and timbre_desc != ''">, #{timbre_desc}</if>
        <if test="timbre_gender != null and timbre_gender != ''">, #{timbre_gender}</if>
        <if test="expire_date != null and expire_date != ''">, #{expire_date}</if>
        )
    </insert>
    <update id="updateAiPersonTimbreCustom" parameterType="com.backendsys.entity.Ai.Aiivh.AiPersonTimbreCustomDTO"
            useGeneratedKeys="true" keyProperty="timbre_name">
        UPDATE ai_ivh_timbre
        SET stage_status = #{stage_status}
        <if test="timbre_key != null and timbre_key != ''">, timbre_key = #{timbre_key}</if>
        <if test="timbre_sample != null and timbre_sample != ''">, timbre_sample = #{timbre_sample}</if>
        <if test="timbre_desc != null and timbre_desc != ''">, timbre_desc = #{timbre_desc}</if>
        <if test="timbre_gender != null and timbre_gender != ''">, timbre_gender = #{timbre_gender}</if>
        <if test="expire_date != null and expire_date != ''">, expire_date = #{expire_date}</if>
        WHERE timbre_name = #{timbre_name}
    </update>

</mapper>