<?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.zbf.system.mapper.TUserFavoritesMapper">

    <resultMap type="TUserFavorites" id="TUserFavoritesResult">
            <result property="id"    column="id"    />
            <result property="userId"    column="user_id"    />
            <result property="deptId"    column="dept_id"    />
            <result property="userName"    column="user_name"    />
            <result property="nickName"    column="nick_name"    />
            <result property="fullPath"    column="full_path"    />
            <result property="matched"    column="matched"    />
            <result property="meta"    column="meta"    />
            <result property="name"    column="name"    />
            <result property="seq"    column="seq"    />
            <result property="path"    column="path"    />
            <result property="query"    column="query"    />
            <result property="title"    column="title"    />
            <result property="status"    column="status"    />
            <result property="delFlag"    column="del_flag"    />
            <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="selectTUserFavoritesVo">
        select id, user_id, dept_id, user_name, nick_name, full_path, matched, meta, name, seq, path, query, title, status, del_flag, create_by, create_time, update_by, update_time, remark from t_user_favorites d
    </sql>

    <select id="selectTUserFavoritesList" parameterType="TUserFavorites" resultMap="TUserFavoritesResult">
        <include refid="selectTUserFavoritesVo"/>
        <where>
                        <if test="userId != null "> and user_id = #{userId}</if>
                        <if test="deptId != null "> and dept_id = #{deptId}</if>
                        <if test="userName != null  and userName != ''"> and user_name like concat('%', #{userName}, '%')</if>
                        <if test="nickName != null  and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
                        <if test="fullPath != null  and fullPath != ''"> and full_path = #{fullPath}</if>
                        <if test="matched != null  and matched != ''"> and matched = #{matched}</if>
                        <if test="meta != null  and meta != ''"> and meta = #{meta}</if>
                        <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>

                        <if test="path != null  and path != ''"> and path = #{path}</if>
                        <if test="query != null  and query != ''"> and query = #{query}</if>
                        <if test="title != null  and title != ''"> and title = #{title}</if>
                        <if test="status != null  and status != ''"> and status = #{status}</if>
        </where>
    </select>

    <select id="selectTUserFavoritesById" parameterType="String" resultMap="TUserFavoritesResult">
            <include refid="selectTUserFavoritesVo"/>
            where id = #{id}
    </select>

    <insert id="insertTUserFavorites" parameterType="TUserFavorites">
        insert into t_user_favorites
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="userId != null">user_id,</if>
                    <if test="deptId != null">dept_id,</if>
                    <if test="userName != null">user_name,</if>
                    <if test="nickName != null">nick_name,</if>
                    <if test="fullPath != null">full_path,</if>
                    <if test="matched != null">matched,</if>
                    <if test="meta != null">meta,</if>
                    <if test="name != null">name,</if>
                    <if test="seq != null">seq,</if>
                    <if test="path != null">path,</if>
                    <if test="query != null">query,</if>
                    <if test="title != null">title,</if>
                    <if test="status != null">status,</if>
                    <if test="delFlag != null">del_flag,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="createTime != null">create_time,</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="id != null">#{id},</if>
                    <if test="userId != null">#{userId},</if>
                    <if test="deptId != null">#{deptId},</if>
                    <if test="userName != null">#{userName},</if>
                    <if test="nickName != null">#{nickName},</if>
                    <if test="fullPath != null">#{fullPath},</if>
                    <if test="matched != null">#{matched},</if>
                    <if test="meta != null">#{meta},</if>
                    <if test="name != null">#{name},</if>
                    <if test="seq != null">#{seq},</if>
                    <if test="path != null">#{path},</if>
                    <if test="query != null">#{query},</if>
                    <if test="title != null">#{title},</if>
                    <if test="status != null">#{status},</if>
                    <if test="delFlag != null">#{delFlag},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateTUserFavorites" parameterType="TUserFavorites">
        update t_user_favorites
        <trim prefix="SET" suffixOverrides=",">
                    <if test="userId != null">user_id = #{userId},</if>
                    <if test="deptId != null">dept_id = #{deptId},</if>
                    <if test="userName != null">user_name = #{userName},</if>
                    <if test="nickName != null">nick_name = #{nickName},</if>
                    <if test="fullPath != null">full_path = #{fullPath},</if>
                    <if test="matched != null">matched = #{matched},</if>
                    <if test="meta != null">meta = #{meta},</if>
                    <if test="name != null">name = #{name},</if>
                    <if test="seq != null">seq = #{seq},</if>
                    <if test="path != null">path = #{path},</if>
                    <if test="query != null">query = #{query},</if>
                    <if test="title != null">title = #{title},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="delFlag != null">del_flag = #{delFlag},</if>
                    <if test="createBy != null">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>
                    <if test="remark != null">remark = #{remark},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTUserFavoritesByIds" parameterType="String">
        update t_user_favorites set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTUserFavoritesByIds" parameterType="String">
        update t_user_favorites set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTUserFavoritesById" parameterType="String">
        delete from t_user_favorites  where id = #{id}
    </delete>

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