<?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.applet.dao.impl.AppletThirdResourcesStaticDaoImpl">

    <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletThirdResourcesStatic">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="date" property="date" jdbcType="DATE"/>
        <result column="stage_str" property="stageStr" jdbcType="VARCHAR"/>
        <result column="stage" property="stage" jdbcType="VARCHAR"/>
        <result column="channel_name" property="channelName" jdbcType="VARCHAR"/>
        <result column="channel_remark" property="channelRemark" jdbcType="VARCHAR"/>
        <result column="push_uv" property="pushUv" jdbcType="INTEGER"/>
        <result column="get_qr_code_uv" property="getQrCodeUv" jdbcType="INTEGER"/>
        <result column="press_qr_code_uv" property="pressQrCodeUv" jdbcType="INTEGER"/>
        <result column="join_chatroom_count" property="joinChatroomCount" jdbcType="INTEGER"/>
        <result column="join_chatroom_rate" property="joinChatroomRate" jdbcType="VARCHAR"/>
        <result column="stay_user_count" property="stayUserCount" jdbcType="INTEGER"/>
        <result column="share_rate" property="shareRate" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>


    <sql id="Base_Column_List">
        id, date, stage_str, stage, channel_name, channel_remark, push_uv, get_qr_code_uv, press_qr_code_uv, join_chatroom_count, join_chatroom_rate, stay_user_count, share_rate, create_time, update_time        
    </sql>

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

    <select id="getList" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM applet_third_resources_static
    </select>

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO applet_third_resources_static(
            date, 
            stage_str, 
            stage, 
            channel_name, 
            channel_remark, 
            push_uv, 
            get_qr_code_uv, 
            press_qr_code_uv, 
            join_chatroom_count, 
            join_chatroom_rate, 
            stay_user_count, 
            share_rate, 
            create_time, 
            update_time,
            resource_type
        ) VALUES (
            #{date, jdbcType=DATE}, 
            #{stageStr, jdbcType=VARCHAR}, 
            #{stage, jdbcType=VARCHAR}, 
            #{channelName, jdbcType=VARCHAR}, 
            #{channelRemark, jdbcType=VARCHAR}, 
            #{pushUv, jdbcType=INTEGER}, 
            #{getQrCodeUv, jdbcType=INTEGER}, 
            #{pressQrCodeUv, jdbcType=INTEGER}, 
            #{joinChatroomCount, jdbcType=INTEGER}, 
            #{joinChatroomRate, jdbcType=VARCHAR},
            #{stayUserCount, jdbcType=INTEGER}, 
            #{shareRate, jdbcType=VARCHAR},
           now(),
           now(),
            #{resourceType, jdbcType=INTEGER},
        )
    </insert>

    <insert id="batchInsert">
        INSERT INTO applet_third_resources_static (
        date,
        stage_str,
        stage,
        channel_name,
        channel_remark,
        push_uv,
        get_qr_code_uv,
        press_qr_code_uv,
        join_chatroom_count,
        join_chatroom_rate,
        stay_user_count,
        share_rate,
        create_time,
        update_time,
        resource_type
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.date, jdbcType=DATE},
            #{item.stageStr, jdbcType=VARCHAR},
            #{item.stage, jdbcType=VARCHAR},
            #{item.channelName, jdbcType=VARCHAR},
            #{item.channelRemark, jdbcType=VARCHAR},
            #{item.pushUv, jdbcType=INTEGER},
            #{item.getQrCodeUv, jdbcType=INTEGER},
            #{item.pressQrCodeUv, jdbcType=INTEGER},
            #{item.joinChatroomCount, jdbcType=INTEGER},
            #{item.joinChatroomRate, jdbcType=VARCHAR},
            #{item.stayUserCount, jdbcType=INTEGER},
            #{item.shareRate, jdbcType=VARCHAR},
            now(),
            now(),
            #{item.resourceType}
            )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE applet_third_resources_static
        <set>
            <if test="date != null">
                date = #{date},
            </if>
            <if test="stageStr != null and stageStr != ''">
                stage_str = #{stageStr},
            </if>
            <if test="stage != null and stage != ''">
                stage = #{stage},
            </if>
            <if test="channelName != null and channelName != ''">
                channel_name = #{channelName},
            </if>
            <if test="channelRemark != null and channelRemark != ''">
                channel_remark = #{channelRemark},
            </if>
            <if test="pushUv != null">
                push_uv = #{pushUv},
            </if>
            <if test="getQrCodeUv != null">
                get_qr_code_uv = #{getQrCodeUv},
            </if>
            <if test="pressQrCodeUv != null">
                press_qr_code_uv = #{pressQrCodeUv},
            </if>
            <if test="joinChatroomCount != null">
                join_chatroom_count = #{joinChatroomCount},
            </if>
            <if test="joinChatroomRate != null">
                join_chatroom_rate = #{joinChatroomRate},
            </if>
            <if test="stayUserCount != null">
                stay_user_count = #{stayUserCount},
            </if>
            <if test="shareRate != null">
                share_rate = #{shareRate},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
            <if test="updateTime != null">
                update_time = #{updateTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

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


</mapper>