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

    <resultMap id="BaseResultMap" type="com.pcloud.book.applet.entity.AppletSubscribeSend">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="wechat_user_id" property="wechatUserId" jdbcType="BIGINT"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>
    
    <sql id="Base_Column_List">
        id, wechat_user_id, create_time        
    </sql>

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

    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        INSERT INTO applet_subscribe_send(
            wechat_user_id, 
            create_time
        ) VALUES (
            #{wechatUserId, jdbcType=BIGINT}, 
            #{createTime, jdbcType=TIMESTAMP}
        )
    </insert>
    
    <insert id="batchInsert">
        INSERT INTO applet_subscribe_send (
            wechat_user_id, 
            create_time
        ) VALUES 
        <foreach collection="list" item="item" separator=",">
        (
            #{item.wechatUserId, jdbcType=BIGINT}, 
            #{item.createTime, jdbcType=TIMESTAMP}
        )
        </foreach>
    </insert>

    <!--通过主键修改数据-->
    <update id="update">
        UPDATE applet_subscribe_send
        <set>
            <if test="wechatUserId != null">
                wechat_user_id = #{wechatUserId},
            </if>
            <if test="createTime != null">
                create_time = #{createTime},
            </if>
        </set>
        WHERE id = #{id}
    </update>

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

    <select id="getAllUserIds" resultType="long">
        select wechat_user_id
        from applet_subscribe_send
    </select>



</mapper>
