<?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.ruoyi.system.mapper.FriendLinkMapper">

    <resultMap type="FriendLink" id="FriendLinkResult">
        <result property="linkId" column="link_id"/>
        <result property="linkName" column="link_name"/>
        <result property="linkSpace" column="link_space"/>
        <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"/>
    </resultMap>

    <sql id="selectFriendLinkVo">
        select link_id, link_name, link_space, status, del_flag, create_by, create_time, update_by, update_time from friend_link
    </sql>

    <select id="selectFriendLinkList" parameterType="FriendLink" resultMap="FriendLinkResult">
        select link_id, link_name, link_space, status, del_flag from friend_link
        <where>
            del_flag = 'N'
            <if test="linkName != null  and linkName != ''">and link_name like concat('%', #{linkName}, '%')</if>
            <if test="linkSpace != null  and linkSpace != ''">and link_space = #{linkSpace}</if>
            <if test="status != null  and status != ''">and status = #{status}</if>
        </where>
        order by create_time DESC
    </select>

    <select id="selectFriendLinkByLinkId" parameterType="Long" resultMap="FriendLinkResult">
        <include refid="selectFriendLinkVo"/>
        where link_id = #{linkId} and del_flag = 'N'
    </select>

    <insert id="insertFriendLink" parameterType="FriendLink" useGeneratedKeys="true" keyProperty="linkId">
        insert into friend_link
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="linkName != null">link_name,</if>
            <if test="linkSpace != null">link_space,</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>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="linkName != null">#{linkName},</if>
            <if test="linkSpace != null">#{linkSpace},</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>
        </trim>
    </insert>

    <update id="updateFriendLink" parameterType="FriendLink">
        update friend_link
        <trim prefix="SET" suffixOverrides=",">
            <if test="linkName != null">link_name = #{linkName},</if>
            <if test="linkSpace != null">link_space = #{linkSpace},</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>
        </trim>
        where link_id = #{linkId}
    </update>

    <delete id="deleteFriendLinkByLinkId" parameterType="Long">
        delete from friend_link where link_id = #{linkId}
    </delete>

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