<?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.pcloud.book.group.dao.impl.ResourcePageOuterLinkDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.ResourcePageOuterLink">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="origin_id" property="originId" jdbcType="BIGINT"/>
        <result column="title" property="title" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="jump_url" property="jumpUrl" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="is_delete" property="isDelete" jdbcType="INTEGER"/>
        <result column="resource_column_id" property="resourceColumnId" jdbcType="BIGINT"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, origin_id, title, description, jump_url, create_time, update_time, is_delete, resource_column_id        
    </sql>

    <select id="getById" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM resource_page_outer_link
        WHERE id = #{id}
    </select>
    
    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM resource_page_outer_link
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO resource_page_outer_link(
            origin_id, 
            title, 
            description, 
            jump_url, 
            create_time, 
            update_time, 
            is_delete, 
            resource_column_id
        ) VALUES (
            #{originId, jdbcType=BIGINT}, 
            #{title, jdbcType=VARCHAR}, 
            #{description, jdbcType=VARCHAR}, 
            #{jumpUrl, jdbcType=VARCHAR}, 
            #{createTime, jdbcType=TIMESTAMP}, 
            #{updateTime, jdbcType=TIMESTAMP}, 
            #{isDelete, jdbcType=INTEGER}, 
            #{resourceColumnId, jdbcType=BIGINT}
        )
    </insert>
    
    <insert id="batchInsert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO resource_page_outer_link (
            origin_id, 
            title, 
            description, 
            jump_url, 
            create_time, 
            update_time, 
            is_delete, 
            resource_column_id
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.originId, jdbcType=BIGINT}, 
            #{item.title, jdbcType=VARCHAR}, 
            #{item.description, jdbcType=VARCHAR}, 
            #{item.jumpUrl, jdbcType=VARCHAR}, 
          now(),
         now(),
         0,
            #{item.resourceColumnId, jdbcType=BIGINT}
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE resource_page_outer_link
        <set>
            <if test="originId != null">
                origin_id = #{originId},
            </if>
            <if test="title != null and title != ''">
                title = #{title},
            </if>
            <if test="description != null and description != ''">
                description = #{description},
            </if>
            <if test="jumpUrl != null and jumpUrl != ''">
                jump_url = #{jumpUrl},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
            <if test="isDelete != null">
                is_delete = #{isDelete},
            </if>
            <if test="resourceColumnId != null">
                resource_column_id = #{resourceColumnId},
            </if>
        </set>
        WHERE id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        DELETE FROM resource_page_outer_link where id = #{id}
    </delete>
    
     <!--通过主键软删除-->
    <delete id="softDeleteById">
        update resource_page_outer_link set is_delete  = 1, update_time = now() where id = #{id}
    </delete>

    <select id="selectList" parameterType="list" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        FROM
        resource_page_outer_link
        where
        id in
        <foreach collection="list" item="item" index="index" open="(" close=")" separator=",">
            #{item}
        </foreach>
    </select>

</mapper>
