<?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="cn.celess.blog.mapper.PartnerMapper">
    <resultMap id="partnerSiteResultMap" type="cn.celess.blog.entity.PartnerSite">
        <id column="l_id" property="id"/>
        <result column="l_name" property="name"/>
        <result column="l_url" property="url"/>
        <result column="l_is_open" property="open"/>
        <result column="l_icon_path" property="iconPath"/>
        <result column="l_desc" property="desc"/>
        <result column="is_delete" property="delete"/>
        <result column="l_email" property="email"/>
        <result column="l_notification" property="notification"/>
    </resultMap>

    <insert id="insert" parameterType="cn.celess.blog.entity.PartnerSite" useGeneratedKeys="true" keyProperty="id">
        insert into links (l_name, l_is_open, l_url, l_icon_path, l_desc, l_email, l_notification, is_delete)
        values (#{name}, #{open}, #{url}, #{iconPath}, #{desc}, #{email}, #{notification}, false)
    </insert>

    <update id="update" parameterType="cn.celess.blog.entity.PartnerSite">
        update links
        <trim prefix="set" suffixOverrides=",">
            <if test="open!=null">l_is_open=#{open},</if>
            <if test="iconPath!=null">l_icon_path=#{iconPath},</if>
            <if test="desc!=null">l_desc=#{desc},</if>
            <if test="url!=null">l_url=#{url},</if>
            <if test="name!=null">l_name=#{name},</if>
            <if test="notification!=null">l_notification=#{notification},</if>
            <if test="email!=null">l_email=#{email}</if>
        </trim>
        where l_id=#{id}
    </update>

    <update id="delete">
        update links
        set is_delete = true
        where l_id = #{id}
    </update>

    <select id="existsById" resultType="boolean">
        SELECT EXISTS(SELECT * FROM links WHERE l_id = #{id})
    </select>

    <select id="existsByName" resultType="boolean">
        SELECT EXISTS(SELECT * FROM links WHERE l_name = #{name})

    </select>

    <select id="existsByUrl" resultType="boolean">
        SELECT EXISTS(SELECT * FROM links WHERE l_url = #{url})

    </select>

    <select id="findById" resultMap="partnerSiteResultMap">
        select *
        from links
        where l_id = #{id}
    </select>

    <select id="findByName" resultMap="partnerSiteResultMap">
        select *
        from links
        where l_name = #{name}
    </select>

    <select id="findByUrl" resultMap="partnerSiteResultMap">
        select *
        from links
        where l_url = #{url}
    </select>
    <select id="getLastest" resultMap="partnerSiteResultMap">
        select *
        from links
        order by l_id desc
        limit 1
    </select>
    <select id="findAll" resultMap="partnerSiteResultMap">
        select *
        from links
        <if test="_parameter != null">
            where is_delete=#{deleted}
        </if>
    </select>


</mapper>