<?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.fs.live.mapper.LiveAnchorMapper">

    <resultMap type="LiveAnchor" id="LiveAnchorResult">
        <result property="anchorId"    column="anchor_id"    />
        <result property="nickName"    column="nick_name"    />
        <result property="password"    column="password"    />
        <result property="mobile"    column="mobile"    />
        <result property="openId"    column="open_id"    />
        <result property="idCardBackUrl"    column="id_card_back_url"    />
        <result property="idCardFrontUrl"    column="id_card_front_url"    />
        <result property="status"    column="status"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectLiveAnchorVo">
        select anchor_id, nick_name, password, mobile, open_id, id_card_back_url, id_card_front_url, status, create_time, create_by, update_by, update_time, remark from live_anchor
    </sql>

    <select id="selectLiveAnchorList" parameterType="LiveAnchor" resultMap="LiveAnchorResult">
        <include refid="selectLiveAnchorVo"/>
        <where>
            <if test="nickName != null  and nickName != ''"> and nick_name like concat( #{nickName}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="mobile != null  and mobile != ''"> and mobile = #{mobile}</if>
            <if test="openId != null  and openId != ''"> and open_id = #{openId}</if>
            <if test="idCardBackUrl != null  and idCardBackUrl != ''"> and id_card_back_url = #{idCardBackUrl}</if>
            <if test="idCardFrontUrl != null  and idCardFrontUrl != ''"> and id_card_front_url = #{idCardFrontUrl}</if>
            <if test="status != null "> and status = #{status}</if>
        </where>
    </select>

    <select id="selectLiveAnchorByAnchorId" parameterType="Long" resultMap="LiveAnchorResult">
        <include refid="selectLiveAnchorVo"/>
        where anchor_id = #{anchorId}
    </select>

    <insert id="insertLiveAnchor" parameterType="LiveAnchor" useGeneratedKeys="true" keyProperty="anchorId">
        insert into live_anchor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="nickName != null">nick_name,</if>
            <if test="password != null">password,</if>
            <if test="mobile != null">mobile,</if>
            <if test="openId != null">open_id,</if>
            <if test="idCardBackUrl != null">id_card_back_url,</if>
            <if test="idCardFrontUrl != null">id_card_front_url,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="nickName != null">#{nickName},</if>
            <if test="password != null">#{password},</if>
            <if test="mobile != null">#{mobile},</if>
            <if test="openId != null">#{openId},</if>
            <if test="idCardBackUrl != null">#{idCardBackUrl},</if>
            <if test="idCardFrontUrl != null">#{idCardFrontUrl},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateLiveAnchor" parameterType="LiveAnchor">
        update live_anchor
        <trim prefix="SET" suffixOverrides=",">
            <if test="nickName != null">nick_name = #{nickName},</if>
            <if test="password != null">password = #{password},</if>
            <if test="mobile != null">mobile = #{mobile},</if>
            <if test="openId != null">open_id = #{openId},</if>
            <if test="idCardBackUrl != null">id_card_back_url = #{idCardBackUrl},</if>
            <if test="idCardFrontUrl != null">id_card_front_url = #{idCardFrontUrl},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where anchor_id = #{anchorId}
    </update>

    <delete id="deleteLiveAnchorByAnchorId" parameterType="Long">
        delete from live_anchor where anchor_id = #{anchorId}
    </delete>

    <delete id="deleteLiveAnchorByAnchorIds" parameterType="String">
        delete from live_anchor where anchor_id in
        <foreach item="anchorId" collection="array" open="(" separator="," close=")">
            #{anchorId}
        </foreach>
    </delete>
</mapper>
