<?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.pnkx.mapper.PxFriendLinkMapper">

    <resultMap type="com.pnkx.domain.po.PxFriendLink" id="PxFriendLinkResult">
        <result property="id" column="id"/>
        <result property="img" column="img"/>
        <result property="title" column="title"/>
        <result property="url" column="url"/>
        <result property="email" column="email"/>
        <result property="emailFlag" column="email_flag"/>
        <result property="status" column="status"/>
        <result property="version" column="version"/>
        <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="selectPxFriendLinkVo">
        select id,
               img,
               title,
               url,
               status,
               email,
               email_flag,
               version,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from px_friend_link
    </sql>

    <select id="selectPxFriendLinkList" parameterType="com.pnkx.domain.po.PxFriendLink"
            resultMap="PxFriendLinkResult">
        <include refid="selectPxFriendLinkVo"/>
        <where>
            <if test="img != null and img != ''">and img = #{img}</if>
            <if test="title != null and title != ''">and title like concat('%', #{title}, '%')</if>
            <if test="url != null and url != ''">and url = #{url}</if>
            <if test="status != null">and status = #{status}</if>
            <if test="version != null  and version != ''">and version = #{version}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectPxFriendLinkById" parameterType="Long" resultMap="PxFriendLinkResult">
        <include refid="selectPxFriendLinkVo"/>
        where id = #{id}
    </select>

    <insert id="insertPxFriendLink" parameterType="com.pnkx.domain.po.PxFriendLink" useGeneratedKeys="true"
            keyProperty="id">
        insert into px_friend_link
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="img != null">img,</if>
            <if test="title != null">title,</if>
            <if test="url != null">url,</if>
            <if test="email != null">email,</if>
            <if test="emailFlag != null">email_flag,</if>
            <if test="version != null">version,</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="img != null">#{img},</if>
            <if test="title != null">#{title},</if>
            <if test="url != null">#{url},</if>
            <if test="email != null">#{email},</if>
            <if test="emailFlag != null">#{emailFlag},</if>
            <if test="version != null">#{version},</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="updatePxFriendLink" parameterType="com.pnkx.domain.po.PxFriendLink">
        update px_friend_link
        <trim prefix="SET" suffixOverrides=",">
            <if test="img != null">img = #{img},</if>
            <if test="title != null">title = #{title},</if>
            <if test="url != null">url = #{url},</if>
            <if test="email != null">email = #{email},</if>
            <if test="emailFlag != null">email_flag = #{emailFlag},</if>
            <if test="status != null">status = #{status},</if>
            <if test="version != null">version = #{version},</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>

    <delete id="deletePxFriendLinkById" parameterType="Long">
        delete
        from px_friend_link
        where id = #{id}
    </delete>

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