<?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.mapper.ResourcePageMarketingActivityMapper">
    <resultMap id="BaseResultMap" type="com.pcloud.book.group.entity.ResourcePageMarketingActivity">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="resource_page_id" jdbcType="BIGINT" property="resourcePageId"/>
        <result column="type" jdbcType="TINYINT" property="type"/>
        <result column="content" jdbcType="VARCHAR" property="content"/>
        <result column="img" jdbcType="VARCHAR" property="img"/>
        <result column="serve_id" jdbcType="BIGINT" property="serveId"/>
        <result column="serve_type" jdbcType="VARCHAR" property="serveType"/>
        <result column="link_url" jdbcType="VARCHAR" property="linkUrl"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
        <result column="create_user" jdbcType="BIGINT" property="createUser"/>
    </resultMap>
    <resultMap id="resourcePageMarketingActivityVO" type="com.pcloud.book.group.vo.ResourcePageMarketingActivityVO" extends="BaseResultMap">
    </resultMap>
    <sql id="Base_Column_List">
        id,
        resource_page_id,
        `type`,
        content,
        img,
        serve_id,
        serve_type,
        link_url,
        create_time,
        update_time,
        create_user
    </sql>
    <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from resource_page_marketing_activity
        where id = #{id,jdbcType=BIGINT}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        delete
        from resource_page_marketing_activity
        where id = #{id,jdbcType=BIGINT}
    </delete>
    <insert id="insert" parameterType="com.pcloud.book.group.entity.ResourcePageMarketingActivity">
        insert into resource_page_marketing_activity (id, resource_page_id, `type`,
                                                      content, img, serve_id,
                                                      serve_type, link_url, create_time,
                                                      update_time, create_user)
        values (#{id,jdbcType=BIGINT}, #{resourcePageId,jdbcType=BIGINT}, #{type,jdbcType=TINYINT},
                #{content,jdbcType=VARCHAR}, #{img,jdbcType=VARCHAR}, #{serveId,jdbcType=BIGINT},
                #{serveType,jdbcType=VARCHAR}, #{linkUrl,jdbcType=VARCHAR}, now(),
                now(), #{createUser,jdbcType=BIGINT})
    </insert>
    <insert id="insertSelective" parameterType="com.pcloud.book.group.entity.ResourcePageMarketingActivity">
        insert into resource_page_marketing_activity
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="resourcePageId != null">
                resource_page_id,
            </if>
            <if test="type != null">
                `type`,
            </if>
            <if test="content != null and content != ''">
                content,
            </if>
            <if test="img != null and img != ''">
                img,
            </if>
            <if test="serveId != null">
                serve_id,
            </if>
            <if test="serveType != null and serveType != ''">
                serve_type,
            </if>
            <if test="linkUrl != null and linkUrl != ''">
                link_url,
            </if>
            create_time,
            update_time,
            <if test="createUser != null">
                create_user,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="resourcePageId != null">
                #{resourcePageId,jdbcType=BIGINT},
            </if>
            <if test="type != null">
                #{type,jdbcType=TINYINT},
            </if>
            <if test="content != null and content != ''">
                #{content,jdbcType=VARCHAR},
            </if>
            <if test="img != null and img != ''">
                #{img,jdbcType=VARCHAR},
            </if>
            <if test="serveId != null">
                #{serveId,jdbcType=BIGINT},
            </if>
            <if test="serveType != null and serveType != ''">
                #{serveType,jdbcType=VARCHAR},
            </if>
            <if test="linkUrl != null and linkUrl != ''">
                #{linkUrl,jdbcType=VARCHAR},
            </if>
            now(),
            now(),
            <if test="createUser != null">
                #{createUser,jdbcType=BIGINT},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.pcloud.book.group.entity.ResourcePageMarketingActivity">
        update resource_page_marketing_activity
        <set>
            <if test="resourcePageId != null">
                resource_page_id = #{resourcePageId,jdbcType=BIGINT},
            </if>
            <if test="type != null">
                `type` = #{type,jdbcType=TINYINT},
            </if>
            <if test="content != null and content != ''">
                content = #{content,jdbcType=VARCHAR},
            </if>
            <if test="img != null and img != ''">
                img = #{img,jdbcType=VARCHAR},
            </if>
            <if test="serveId != null">
                serve_id = #{serveId,jdbcType=BIGINT},
            </if>
            <if test="serveType != null and serveType != ''">
                serve_type = #{serveType,jdbcType=VARCHAR},
            </if>
            <if test="linkUrl != null and linkUrl != ''">
                link_url = #{linkUrl,jdbcType=VARCHAR},
            </if>
            update_time = now(),
            <if test="createUser != null">
                create_user = #{createUser,jdbcType=BIGINT},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.pcloud.book.group.entity.ResourcePageMarketingActivity">
        update resource_page_marketing_activity
        set resource_page_id = #{resourcePageId,jdbcType=BIGINT},
            `type`           = #{type,jdbcType=TINYINT},
            content          = #{content,jdbcType=VARCHAR},
            img              = #{img,jdbcType=VARCHAR},
            serve_id         = #{serveId,jdbcType=BIGINT},
            serve_type       = #{serveType,jdbcType=VARCHAR},
            link_url         = #{linkUrl,jdbcType=VARCHAR},
            update_time      = now(),
            create_user      = #{createUser,jdbcType=BIGINT}
        where id = #{id,jdbcType=BIGINT}
    </update>

    <insert id="batchInsert">
        insert into resource_page_marketing_activity (id, resource_page_id, `type`,
                                                      content, img, serve_id,
                                                      serve_type, link_url, create_time,
                                                      update_time, create_user)
        values
        <foreach collection="records" separator="," item="it">
            (#{it.id,jdbcType=BIGINT}, #{it.resourcePageId,jdbcType=BIGINT}, #{it.type,jdbcType=TINYINT},
             #{it.content,jdbcType=VARCHAR}, #{it.img,jdbcType=VARCHAR}, #{it.serveId,jdbcType=BIGINT},
             #{it.serveType,jdbcType=VARCHAR}, #{it.linkUrl,jdbcType=VARCHAR}, now(),
             now(), #{it.createUser,jdbcType=BIGINT})
        </foreach>
    </insert>

    <delete id="deleteByResourcePageId">
        delete
        from resource_page_marketing_activity
        where resource_page_id = #{resourcePageId,jdbcType=BIGINT}
    </delete>

    <select id="listByResourcePageId" resultMap="resourcePageMarketingActivityVO">
        select
        <include refid="Base_Column_List"/>
        from resource_page_marketing_activity
        where resource_page_id = #{resourcePageId,jdbcType=BIGINT}
    </select>
</mapper>