<?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.dgtly.member.mapper.MemberFollowMapper">
    
    <resultMap type="MemberFollow" id="MemberFollowResult">
        <result property="id"    column="id"    />
        <result property="memberId"    column="member_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="followDate"    column="follow_date"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
    </resultMap>

    <sql id="selectMemberFollowVo">
        select id, member_id, company_id, follow_date, create_by, create_time, update_by, update_time, remark from member_follow
    </sql>

    <select id="selectMemberFollowList" parameterType="MemberFollow" resultMap="MemberFollowResult">
        <include refid="selectMemberFollowVo"/>
        <where>  
            <if test="memberId != null "> and member_id = #{memberId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="followDate != null "> and follow_date = #{followDate}</if>
        </where>
    </select>
    
    <select id="selectMemberFollowById" parameterType="Long" resultMap="MemberFollowResult">
        <include refid="selectMemberFollowVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertMemberFollow" parameterType="MemberFollow">
        insert into member_follow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null ">id,</if>
            <if test="memberId != null ">member_id,</if>
            <if test="companyId != null ">company_id,</if>
            <if test="followDate != null ">follow_date,</if>
            <if test="createBy != null  and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
            <if test="updateBy != null  and updateBy != ''">update_by,</if>
            <if test="updateTime != null ">update_time,</if>
            <if test="remark != null  and remark != ''">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null ">#{id},</if>
            <if test="memberId != null ">#{memberId},</if>
            <if test="companyId != null ">#{companyId},</if>
            <if test="followDate != null ">#{followDate},</if>
            <if test="createBy != null  and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">#{updateBy},</if>
            <if test="updateTime != null ">#{updateTime},</if>
            <if test="remark != null  and remark != ''">#{remark},</if>
         </trim>
    </insert>

    <update id="updateMemberFollow" parameterType="MemberFollow">
        update member_follow
        <trim prefix="SET" suffixOverrides=",">
            <if test="memberId != null ">member_id = #{memberId},</if>
            <if test="companyId != null ">company_id = #{companyId},</if>
            <if test="followDate != null ">follow_date = #{followDate},</if>
            <if test="createBy != null  and createBy != ''">create_by = #{createBy},</if>
            <if test="createTime != null ">create_time = #{createTime},</if>
            <if test="updateBy != null  and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
            <if test="remark != null  and remark != ''">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteMemberFollowById" parameterType="Long">
        delete from member_follow where id = #{id}
    </delete>

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