<?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.ResourcePageWxworkDaoImpl">

    <resultMap type="com.pcloud.book.group.entity.ResourcePageWxwork" id="ResourcePageWxworkMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="resourcePageId" column="resource_page_id" jdbcType="INTEGER"/>
        <result property="templateType" column="template_type" jdbcType="INTEGER"/>
        <result property="displayBook" column="display_book" jdbcType="INTEGER"/>
        <result property="guide" column="guide" jdbcType="VARCHAR"/>
        <result property="qrcodeType" column="qrcode_type" jdbcType="INTEGER"/>
        <result property="qrcodeId" column="qrcode_id" jdbcType="INTEGER"/>
        <result property="qrcodeUrl" column="qrcode_url" jdbcType="VARCHAR"/>
        <result property="basePic" column="base_pic" jdbcType="VARCHAR"/>
        <result property="topSpace" column="top_space" jdbcType="INTEGER"/>
        <result property="leftSpace" column="left_space" jdbcType="INTEGER"/>
        <result property="htmlPic" column="html_pic" jdbcType="VARCHAR"/>
        <result property="fixedSet" column="fixed_set" jdbcType="VARCHAR"/>
        <result property="oldTemplate" column="is_old_template" jdbcType="VARCHAR"/>
        <result property="createUser" column="create_user" jdbcType="INTEGER"/>
        <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
        <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_columns">
        id, resource_page_id, template_type, display_book, guide, qrcode_type, qrcode_id, qrcode_url, base_pic, top_space, left_space, html_pic, fixed_set, is_old_template, create_user, create_time, update_time
    </sql>

    <!--查询单个-->
    <select id="getById" resultMap="ResourcePageWxworkMap">
        select
         <include refid="Base_columns"/>
        from resource_page_wxwork
        where id = #{id}
    </select>

    <!--新增所有列-->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into resource_page_wxwork(resource_page_id, template_type, display_book, guide, qrcode_type, qrcode_id, qrcode_url, base_pic, top_space, left_space, html_pic, fixed_set, is_old_template, create_user, create_time, update_time)
        values (#{resourcePageId}, #{templateType}, #{displayBook}, #{guide}, #{qrcodeType}, #{qrcodeId}, #{qrcodeUrl}, #{basePic}, #{topSpace}, #{leftSpace}, #{htmlPic}, #{fixedSet}, 0, #{createUser}, now(), now())
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        update resource_page_wxwork
        <set>
            <if test="templateType != null">
                template_type = #{templateType},
            </if>
            <if test="displayBook != null">
                display_book = #{displayBook},
            </if>
                guide = #{guide},
            <if test="qrcodeType != null">
                qrcode_type = #{qrcodeType},
            </if>
            <if test="qrcodeId != null">
                qrcode_id = #{qrcodeId},
            </if>
            <if test="qrcodeUrl != null and qrcodeUrl != ''">
                qrcode_url = #{qrcodeUrl},
            </if>
                is_old_template = 0,
                base_pic = #{basePic},
                top_space = #{topSpace},
                left_space = #{leftSpace},
                html_pic = #{htmlPic},
                fixed_set = #{fixedSet},
                update_time = now(),
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from resource_page_wxwork where id = #{id}
    </delete>

    <select id="getByPageId" resultMap="ResourcePageWxworkMap" parameterType="long">
        select <include refid="Base_columns"/>
        from resource_page_wxwork
        where resource_page_id = #{resourcePageId}
        limit 1
    </select>

    <select id="getWxworkBySceneIds" parameterType="map" resultType="long">
        SELECT
            p.scene_id
        FROM
            resource_page_wxwork w
        LEFT JOIN resource_page p ON w.resource_page_id = p.id
        WHERE
            p.scene_id IN
        <foreach collection="list" separator="," open="(" close=")" index="index" item="item">
            #{item}
        </foreach>
    </select>

</mapper>

