<?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.xingxi.business.UserFollow.mapper.UserFollowMapper">
    <resultMap type="UserFollow" id="UserFollowResult">
        <result property="userFollowId"    column="userFollowId"    />
        <result property="folllowType"    column="folllowType"    />
        <result property="followTime"    column="followTime"    />
        <result property="userId"    column="user_id"    />
        <result property="prodId"    column="prodId"    />
        <result property="designerId"    column="designerId"    />
        <result property="delFlag"    column="delFlag"    />
        <result property="createUser"    column="createUser"    />
        <result property="createTime"    column="createTime"    />
        <result property="updateUser"    column="updateUser"    />
        <result property="updateTime"    column="updateTime"    />
    </resultMap>

    <sql id="selectUserFollow">
        select userFollowId, folllowType, followTime, user_id, prodId, designerId, delFlag, createUser, createTime, updateUser, updateTime from t_user_follow
    </sql>

    <sql id="selectUserFollowExt">
        select
            ${tableAlias}.userFollowId,
            ${tableAlias}.folllowType,
            ${tableAlias}.followTime,
            ${tableAlias}.user_id,
            ${tableAlias}.prodId,
            ${tableAlias}.designerId,
            ${tableAlias}.delFlag,
            ${tableAlias}.createUser,
            ${tableAlias}.createTime,
            ${tableAlias}.updateUser,
            ${tableAlias}.updateTime
        from t_user_follow ${tableAlias}
    </sql>

    <select id="selectUserFollowList" parameterType="UserFollow" resultMap="UserFollowResult">
        <include refid="selectUserFollow"/>
        <where>  
            <if test="folllowType != null  and folllowType != ''"> and folllowType = #{folllowType}</if>
            <if test="followTime != null "> and followTime = #{followTime}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="designerId != null "> and designerId = #{designerId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </select>
    
    <select id="selectUserFollowByUserFollowId" parameterType="Long" resultMap="UserFollowResult">
        <include refid="selectUserFollow"/>
        where userFollowId = #{userFollowId}
    </select>
        
    <insert id="insertUserFollow" parameterType="UserFollow" useGeneratedKeys="true" keyProperty="userFollowId">
        insert into t_user_follow
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="folllowType != null">folllowType,</if>
            <if test="followTime != null">followTime,</if>
            <if test="userId != null">user_id,</if>
            <if test="prodId != null">prodId,</if>
            <if test="designerId != null">designerId,</if>
            <if test="delFlag != null">delFlag,</if>
            <if test="createUser != null">createUser,</if>
            <if test="createTime != null">createTime,</if>
            <if test="updateUser != null">updateUser,</if>
            <if test="updateTime != null">updateTime,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="folllowType != null">#{folllowType},</if>
            <if test="followTime != null">#{followTime},</if>
            <if test="userId != null">#{userId},</if>
            <if test="prodId != null">#{prodId},</if>
            <if test="designerId != null">#{designerId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createUser != null">#{createUser},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateUser != null">#{updateUser},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="batchInsertUserFollow">
        insert into t_user_follow( folllowType, followTime, user_id, prodId, designerId, delFlag, createUser, createTime, updateUser, updateTime) values
        <foreach item="item" index="index" collection="list" separator=",">
            ( #{item.folllowType}, #{item.followTime}, #{item.userId}, #{item.prodId}, #{item.designerId}, #{item.delFlag}, #{item.createUser}, #{item.createTime}, #{item.updateUser}, #{item.updateTime})
        </foreach>
    </insert>

    <update id="updateUserFollow" parameterType="UserFollow">
        update t_user_follow
        <trim prefix="SET" suffixOverrides=",">
            <if test="folllowType != null">folllowType = #{folllowType},</if>
            <if test="followTime != null">followTime = #{followTime},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="prodId != null">prodId = #{prodId},</if>
            <if test="designerId != null">designerId = #{designerId},</if>
            <if test="delFlag != null">delFlag = #{delFlag},</if>
            <if test="createUser != null">createUser = #{createUser},</if>
            <if test="createTime != null">createTime = #{createTime},</if>
            <if test="updateUser != null">updateUser = #{updateUser},</if>
            <if test="updateTime != null">updateTime = #{updateTime},</if>
        </trim>
        where userFollowId = #{userFollowId}
    </update>

    <delete id="deleteUserFollowByUserFollowId" parameterType="Long">
        delete from t_user_follow where userFollowId = #{userFollowId}
    </delete>

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

    <update id="logicDeleteUserFollowByUserFollowId" parameterType="Long">
        update t_user_follow
            set delFlag = '1'
        where userFollowId = #{userFollowId}
    </update>

    <update id="logicDeleteUserFollowByUserFollowIds" parameterType="String">
        update t_user_follow
        set delFlag = '1'
        where userFollowId in
        <foreach item="userFollowId" collection="array" open="(" separator="," close=")">
            #{userFollowId}
        </foreach>
    </update>

    <update id="logicDeleteUserFollowByCondition" parameterType="UserFollow">
        update t_user_follow
        set delFlag = '1'
        <where>
            <if test="folllowType != null  and folllowType != ''"> and folllowType = #{folllowType}</if>
            <if test="followTime != null "> and followTime = #{followTime}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="prodId != null "> and prodId = #{prodId}</if>
            <if test="designerId != null "> and designerId = #{designerId}</if>
            <if test="delFlag != null  and delFlag != ''"> and delFlag = #{delFlag}</if>
            <if test="createUser != null  and createUser != ''"> and createUser = #{createUser}</if>
            <if test="createTime != null "> and createTime = #{createTime}</if>
            <if test="updateUser != null  and updateUser != ''"> and updateUser = #{updateUser}</if>
            <if test="updateTime != null "> and updateTime = #{updateTime}</if>
        </where>
    </update>
</mapper>