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

    <sql id="includeAiivhAnchorPublic">
        id,

        virtualman_key,
        anchor_name,
        anchor_code,
        COALESCE(header_image, '') header_image,
        resolution,
        COALESCE(pose_name, '') pose_name,
        COALESCE(pose_image, '') pose_image,
        COALESCE(clothes_name, '') clothes_name,
        COALESCE(clothes_image, '') clothes_image,
        expire_date,

        create_time,
        update_time
    </sql>

    <sql id="includeAiivhAnchor">
        id,

        user_id,
        stage_status,

        virtualman_key,
        anchor_name,
        anchor_name_view,
        anchor_code,
        COALESCE(header_image, '') header_image,
        resolution,
        COALESCE(pose_name, '') pose_name,
        COALESCE(pose_image, '') pose_image,
        COALESCE(clothes_name, '') clothes_name,
        COALESCE(clothes_image, '') clothes_image,
        expire_date,

        create_time,
        update_time
    </sql>

    <resultMap id="resultMapAiivhAnchorPublic" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />

        <result property="anchor_name" column="anchor_name" />
        <result property="anchor_code" column="anchor_code" />
        <result property="header_image" column="header_image" />
        <result property="resolution" column="resolution" />
        <result property="pose_name" column="pose_name" />
        <result property="pose_image" column="pose_image" />
        <result property="clothes_name" column="clothes_name" />
        <result property="clothes_image" column="clothes_image" />
        <result property="expire_date" column="expire_date" />
        <result property="virtualman_key" column="virtualman_key" />

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

    <resultMap id="resultMapAiivhAnchor" type="java.util.LinkedHashMap">
        <id property="id" column="id" jdbcType="BIGINT" />
        <result property="user_id" column="user_id" javaType="java.lang.Long" />
        <result property="stage_status" column="stage_status" />

        <result property="anchor_name" column="anchor_name" />
        <result property="anchor_code" column="anchor_code" />
        <result property="header_image" column="header_image" />
        <result property="resolution" column="resolution" />
        <result property="pose_name" column="pose_name" />
        <result property="pose_image" column="pose_image" />
        <result property="clothes_name" column="clothes_name" />
        <result property="clothes_image" column="clothes_image" />
        <result property="expire_date" column="expire_date" />
        <result property="virtualman_key" column="virtualman_key" />

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

    <!-- 公共表 -->
    <select id="queryAiivhPublicAnchorList" resultMap="resultMapAiivhAnchorPublic">
        SELECT <include refid="includeAiivhAnchorPublic" />
        FROM ai_ivh_anchor_public
        <where>
            <if test="anchor_name != null and anchor_name != ''">
                AND anchor_name LIKE CONCAT('%', #{anchor_name}, '%')
            </if>
            <if test="virtualman_key != null and virtualman_key != ''">
                AND virtualman_key = #{virtualman_key}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>

    <!-- 初始化公共表 批量插入 (腾讯-数智人-个人资产管理-分页查询小样本形象列表) -->
    <insert id="insertAiivhPublicAnchorBatch" parameterType="java.util.List">
        INSERT INTO ai_ivh_anchor_public (
            anchor_name, anchor_code, header_image,
            resolution, pose_name, pose_image, clothes_name, clothes_image,
            expire_date, virtualman_key
        )
        VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.anchor_name}, #{item.anchor_code}, #{item.header_image},
            #{item.resolution}, #{item.pose_name}, #{item.pose_image}, #{item.clothes_name}, #{item.clothes_image},
            #{item.expire_date}, #{item.virtualman_key}
            )
        </foreach>
    </insert>

    <!-- 清除公共表 -->
    <delete id="cleanAiivhPublicAnchor">
        DELETE FROM ai_ivh_anchor_public
    </delete>


    <!-- 定制表 -->
    <select id="queryAiivhAnchorList" resultMap="resultMapAiivhAnchor">
        SELECT <include refid="includeAiivhAnchor" />
        FROM ai_ivh_anchor
        <where>
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
            <if test="anchor_name != null and anchor_name != ''">
                AND anchor_name LIKE CONCAT('%', #{anchor_name}, '%')
            </if>
            <if test="virtualman_key != null and virtualman_key != ''">
                AND virtualman_key = #{virtualman_key}
            </if>
        </where>
        ORDER BY create_time DESC
    </select>
    <!-- 定制表-详情 -->
    <select id="queryAiivhAnchorDetail" resultMap="resultMapAiivhAnchor">
        SELECT <include refid="includeAiivhAnchor" />
        FROM ai_ivh_anchor
        <where>
            virtualman_key = #{virtualman_key}
            <if test="user_id != null and user_id != ''">
                AND user_id = #{user_id}
            </if>
        </where>
    </select>

</mapper>