<?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.ruixuan.jinniu.mapper.KuaishouAdvertiserMapper">

    <resultMap type="com.ruixuan.jinniu.entity.KuaishouAdvertiser" id="KuaishouAdvertiserResult">
        <result property="id" column="id"/>
        <result property="advertiserName" column="advertiser_name"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="userName"/>
        <result property="mobile" column="mobile"/>
        <result property="email" column="email"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectKuaishouAdvertiserVo">
        select t1.id,
               t1.advertiser_name,
               t1.user_id,
               t2.nick_name as 'userName',
               t1.mobile,
               t1.mobile,
               t1.email,
               t1.create_by,
               t1.create_time,
               t1.update_by,
               t1.update_time
        from kuaishou_advertiser t1
                 LEFT JOIN sys_user t2 ON t2.user_id = t1.user_id

    </sql>

    <select id="selectKuaishouAdvertiserList" parameterType="com.ruixuan.jinniu.entity.KuaishouAdvertiser"
            resultMap="KuaishouAdvertiserResult">
        <include refid="selectKuaishouAdvertiserVo"/>
        <where>
            <if test="advertiserName != null  and advertiserName != ''">and t1.advertiser_name like concat('%',
                #{advertiserName}, '%')
            </if>
            <if test="userId != null  and userId != ''">and t1.user_id = #{userId}</if>
            <if test="mobile != null  and mobile != ''">and t1.mobile = #{mobile}</if>
            <if test="email != null  and email != ''">and t1.email = #{email}</if>
        </where>
    </select>

    <select id="selectKuaishouAdvertiserById" parameterType="Long" resultMap="KuaishouAdvertiserResult">
        <include refid="selectKuaishouAdvertiserVo"/>
        where t1.id = #{id}
    </select>

    <insert id="insertKuaishouAdvertiser" parameterType="com.ruixuan.jinniu.entity.KuaishouAdvertiser">
        insert into kuaishou_advertiser
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="advertiserName != null and advertiserName != ''">advertiser_name,</if>
            <if test="userId != null">user_id,</if>
            <if test="mobile != null and mobile != ''">mobile,</if>
            <if test="email != null and email != ''">email,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="advertiserName != null and advertiserName != ''">#{advertiserName},</if>
            <if test="userId != null">#{userId},</if>
            <if test="mobile != null and mobile != ''">#{mobile},</if>
            <if test="email != null and email != ''">#{email},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateKuaishouAdvertiser" parameterType="com.ruixuan.jinniu.entity.KuaishouAdvertiser">
        update kuaishou_advertiser
        <trim prefix="SET" suffixOverrides=",">
            <if test="advertiserName != null and advertiserName != ''">advertiser_name = #{advertiserName},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="mobile != null and mobile != ''">mobile = #{mobile},</if>
            <if test="email != null and email != ''">email = #{email},</if>
            <if test="createBy != null and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteKuaishouAdvertiserById" parameterType="Long">
        delete
        from kuaishou_advertiser
        where id = #{id}
    </delete>

</mapper>